Coverage Report - org.apache.camel.component.mail.MailConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
MailConfiguration
72% 
100% 
1.571
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.component.mail;
 18  
 
 19  
 import java.net.URI;
 20  
 import java.util.Properties;
 21  
 
 22  
 import javax.mail.Session;
 23  
 
 24  
 import org.apache.camel.RuntimeCamelException;
 25  
 
 26  
 /**
 27  
  * Represents the configuration data for communicating over email
 28  
  * 
 29  
  * @version $Revision: 532790 $
 30  
  */
 31  
 public class MailConfiguration implements Cloneable {
 32  
     private String defaultEncoding;
 33  
     private String host;
 34  
     private Properties javaMailProperties;
 35  
     private String password;
 36  
     private String protocol;
 37  
     private Session session;
 38  
     private String username;
 39  8
     private int port = -1;
 40  
     private String destination;
 41  8
     private String from = "camel@localhost";
 42  8
     private boolean deleteProcessedMessages = true;
 43  8
     private String folderName = "INBOX";
 44  
 
 45  8
     public MailConfiguration() {
 46  8
     }
 47  
 
 48  
     /**
 49  
      * Returns a copy of this configuration
 50  
      */
 51  
     public MailConfiguration copy() {
 52  
         try {
 53  12
             return (MailConfiguration)clone();
 54  0
         } catch (CloneNotSupportedException e) {
 55  0
             throw new RuntimeCamelException(e);
 56  
         }
 57  
     }
 58  
 
 59  
     public void configure(URI uri) {
 60  12
         String value = uri.getHost();
 61  12
         if (value != null) {
 62  12
             setHost(value);
 63  
         }
 64  
 
 65  12
         String scheme = uri.getScheme();
 66  12
         if (scheme != null) {
 67  12
             setProtocol(scheme);
 68  
         }
 69  12
         String userInfo = uri.getUserInfo();
 70  12
         if (userInfo != null) {
 71  12
             setUsername(userInfo);
 72  
         }
 73  12
         int port = uri.getPort();
 74  12
         if (port >= 0) {
 75  5
             setPort(port);
 76  
         }
 77  
 
 78  
         // we can either be invoked with
 79  
         // mailto:address
 80  
         // or
 81  
         // smtp:user@host:port/name@address
 82  
 
 83  12
         String fragment = uri.getFragment();
 84  12
         if (fragment == null || fragment.length() == 0) {
 85  12
             fragment = userInfo + "@" + host;
 86  12
         } else {
 87  0
             setFolderName(fragment);
 88  
         }
 89  12
         setDestination(fragment);
 90  12
     }
 91  
 
 92  
     public JavaMailConnection createJavaMailConnection(MailEndpoint mailEndpoint) {
 93  7
         JavaMailConnection answer = new JavaMailConnection();
 94  7
         if (defaultEncoding != null) {
 95  0
             answer.setDefaultEncoding(defaultEncoding);
 96  
         }
 97  
         // answer.setDefaultFileTypeMap(fileTypeMap);
 98  7
         if (host != null) {
 99  7
             answer.setHost(host);
 100  
         }
 101  7
         if (javaMailProperties != null) {
 102  0
             answer.setJavaMailProperties(javaMailProperties);
 103  
         }
 104  7
         if (port >= 0) {
 105  0
             answer.setPort(port);
 106  
         }
 107  7
         if (password != null) {
 108  1
             answer.setPassword(password);
 109  
         }
 110  7
         if (protocol != null) {
 111  7
             answer.setProtocol(protocol);
 112  
         }
 113  7
         if (session != null) {
 114  0
             answer.setSession(session);
 115  
         }
 116  7
         if (username != null) {
 117  7
             answer.setUsername(username);
 118  
         }
 119  7
         return answer;
 120  
     }
 121  
 
 122  
     // Properties
 123  
     // -------------------------------------------------------------------------
 124  
 
 125  
     public String getDefaultEncoding() {
 126  0
         return defaultEncoding;
 127  
     }
 128  
 
 129  
     public void setDefaultEncoding(String defaultEncoding) {
 130  0
         this.defaultEncoding = defaultEncoding;
 131  0
     }
 132  
 
 133  
     public String getHost() {
 134  3
         return host;
 135  
     }
 136  
 
 137  
     public void setHost(String host) {
 138  12
         this.host = host;
 139  12
     }
 140  
 
 141  
     public Properties getJavaMailProperties() {
 142  0
         return javaMailProperties;
 143  
     }
 144  
 
 145  
     public void setJavaMailProperties(Properties javaMailProperties) {
 146  0
         this.javaMailProperties = javaMailProperties;
 147  0
     }
 148  
 
 149  
     public String getPassword() {
 150  0
         return password;
 151  
     }
 152  
 
 153  
     public void setPassword(String password) {
 154  1
         this.password = password;
 155  1
     }
 156  
 
 157  
     public int getPort() {
 158  3
         return port;
 159  
     }
 160  
 
 161  
     public void setPort(int port) {
 162  5
         this.port = port;
 163  5
     }
 164  
 
 165  
     public String getProtocol() {
 166  7
         return protocol;
 167  
     }
 168  
 
 169  
     public void setProtocol(String protocol) {
 170  12
         this.protocol = protocol;
 171  12
     }
 172  
 
 173  
     public Session getSession() {
 174  0
         return session;
 175  
     }
 176  
 
 177  
     public void setSession(Session session) {
 178  0
         this.session = session;
 179  0
     }
 180  
 
 181  
     public String getUsername() {
 182  3
         return username;
 183  
     }
 184  
 
 185  
     public void setUsername(String username) {
 186  12
         this.username = username;
 187  12
     }
 188  
 
 189  
     public String getDestination() {
 190  3
         return destination;
 191  
     }
 192  
 
 193  
     public void setDestination(String destination) {
 194  12
         this.destination = destination;
 195  12
     }
 196  
 
 197  
     public String getFrom() {
 198  1
         return from;
 199  
     }
 200  
 
 201  
     public void setFrom(String from) {
 202  0
         this.from = from;
 203  0
     }
 204  
 
 205  
     public boolean isDeleteProcessedMessages() {
 206  4
         return deleteProcessedMessages;
 207  
     }
 208  
 
 209  
     public void setDeleteProcessedMessages(boolean deleteProcessedMessages) {
 210  0
         this.deleteProcessedMessages = deleteProcessedMessages;
 211  0
     }
 212  
 
 213  
     public String getFolderName() {
 214  4
         return folderName;
 215  
     }
 216  
 
 217  
     public void setFolderName(String folderName) {
 218  0
         this.folderName = folderName;
 219  0
     }
 220  
 }