Coverage Report - org.mule.providers.email.SmtpConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
SmtpConnector
71%
34/48
67%
4/6
1.071
 
 1  
 /*
 2  
  * $Id: SmtpConnector.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.email;
 12  
 
 13  
 import org.mule.umo.UMOComponent;
 14  
 import org.mule.umo.lifecycle.InitialisationException;
 15  
 import org.mule.umo.endpoint.UMOEndpoint;
 16  
 import org.mule.umo.provider.UMOMessageReceiver;
 17  
 
 18  
 import java.util.Properties;
 19  
 
 20  
 /**
 21  
  * <code>SmtpConnector</code> is used to connect to and send data to an SMTP mail
 22  
  * server
 23  
  */
 24  
 public class SmtpConnector extends AbstractMailConnector
 25  
 {
 26  
     public static final String DEFAULT_SMTP_HOST = "localhost";
 27  
     public static final int DEFAULT_SMTP_PORT = 25;
 28  
     public static final String DEFAULT_CONTENT_TYPE = "text/plain";
 29  
 
 30  56
     private String host = DEFAULT_SMTP_HOST;
 31  56
     private int port = DEFAULT_SMTP_PORT;
 32  
     private String username;
 33  
     private String password;
 34  
 
 35  
     /**
 36  
      * Holds value of bcc addresses.
 37  
      */
 38  
     private String bcc;
 39  
 
 40  
     /**
 41  
      * Holds value of cc addresses.
 42  
      */
 43  
     private String cc;
 44  
 
 45  
     /**
 46  
      * Holds value of replyTo addresses.
 47  
      */
 48  
     private String replyTo;
 49  
 
 50  
     /**
 51  
      * Holds value of default subject
 52  
      */
 53  56
     private String defaultSubject = "[No Subject]";
 54  
 
 55  
     /**
 56  
      * Holds value of the from address.
 57  
      */
 58  
     private String from;
 59  
 
 60  
     /**
 61  
      * Any custom headers to be set on messages sent using this connector
 62  
      */
 63  56
     private Properties customHeaders = new Properties();
 64  
 
 65  56
     private String contentType = DEFAULT_CONTENT_TYPE;
 66  
 
 67  
     
 68  
     public SmtpConnector()
 69  
     {
 70  36
         this(DEFAULT_SMTP_PORT);
 71  36
     }
 72  
     
 73  
     SmtpConnector(int defaultPort)
 74  
     {
 75  56
         super(defaultPort, null);
 76  56
     }
 77  
     
 78  
     public String getProtocol()
 79  
     {
 80  192
         return "smtp";
 81  
     }
 82  
 
 83  
     //@java.lang.Override
 84  
     protected void doInitialise() throws InitialisationException
 85  
     {
 86  
         //If the User ID for SMTP is an email address and the from address is not set, then
 87  
         //use the username
 88  32
         if(getFromAddress()==null && getUsername()!=null && getUsername().indexOf('@') > -1)
 89  
         {
 90  0
             setFromAddress(getUsername());
 91  
         }
 92  32
     }
 93  
 
 94  
     /*
 95  
      * (non-Javadoc)
 96  
      * 
 97  
      * @see org.mule.providers.UMOConnector#registerListener(javax.jms.MessageListener,
 98  
      *      java.lang.String)
 99  
      */
 100  
     public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception
 101  
     {
 102  4
         throw new UnsupportedOperationException("Listeners cannot be registered on a SMTP endpoint");
 103  
     }
 104  
 
 105  
     /**
 106  
      * @return The default from address to use
 107  
      */
 108  
     public String getFromAddress()
 109  
     {
 110  44
         return from;
 111  
     }
 112  
 
 113  
     /**
 114  
      * @return the default comma separated list of BCC addresses to use
 115  
      */
 116  
     public String getBccAddresses()
 117  
     {
 118  10
         return bcc;
 119  
     }
 120  
 
 121  
     /**
 122  
      * @return the default comma separated list of CC addresses to use
 123  
      */
 124  
     public String getCcAddresses()
 125  
     {
 126  10
         return cc;
 127  
     }
 128  
 
 129  
     /**
 130  
      * @return the default message subject to use
 131  
      */
 132  
     public String getSubject()
 133  
     {
 134  12
         return defaultSubject;
 135  
     }
 136  
 
 137  
     public void setBccAddresses(String string)
 138  
     {
 139  0
         bcc = string;
 140  0
     }
 141  
 
 142  
     public void setCcAddresses(String string)
 143  
     {
 144  0
         cc = string;
 145  0
     }
 146  
 
 147  
     public void setSubject(String string)
 148  
     {
 149  2
         defaultSubject = string;
 150  2
     }
 151  
 
 152  
     public void setFromAddress(String string)
 153  
     {
 154  2
         from = string;
 155  2
     }
 156  
 
 157  
     public String getReplyToAddresses()
 158  
     {
 159  10
         return replyTo;
 160  
     }
 161  
 
 162  
     public void setReplyToAddresses(String replyTo)
 163  
     {
 164  0
         this.replyTo = replyTo;
 165  0
     }
 166  
 
 167  
     public Properties getCustomHeaders()
 168  
     {
 169  10
         return customHeaders;
 170  
     }
 171  
 
 172  
     public void setCustomHeaders(Properties customHeaders)
 173  
     {
 174  0
         this.customHeaders = customHeaders;
 175  0
     }
 176  
 
 177  
     public String getContentType()
 178  
     {
 179  10
         return contentType;
 180  
     }
 181  
 
 182  
     public void setContentType(String contentType)
 183  
     {
 184  0
         this.contentType = contentType;
 185  0
     }
 186  
 
 187  
     public int getDefaultPort()
 188  
     {
 189  8
         return DEFAULT_SMTP_PORT;
 190  
     }
 191  
 
 192  
     public String getHost()
 193  
     {
 194  0
         return host;
 195  
     }
 196  
 
 197  
     public void setHost(String host)
 198  
     {
 199  14
         this.host = host;
 200  14
     }
 201  
 
 202  
     public String getPassword()
 203  
     {
 204  0
         return password;
 205  
     }
 206  
 
 207  
     public void setPassword(String password)
 208  
     {
 209  12
         this.password = password;
 210  12
     }
 211  
 
 212  
     public int getPort()
 213  
     {
 214  0
         return port;
 215  
     }
 216  
 
 217  
     public void setPort(int port)
 218  
     {
 219  4
         this.port = port;
 220  4
     }
 221  
 
 222  
     public String getUsername()
 223  
     {
 224  40
         return username;
 225  
     }
 226  
 
 227  
     public void setUsername(String username)
 228  
     {
 229  12
         this.username = username;
 230  12
     }
 231  
 
 232  
 }