Clover coverage report - Alipes Project - 0.1
Coverage timestamp: Sat Sep 10 2005 21:25:58 BST
file stats: LOC: 102   Methods: 5
NCLOC: 42   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
EmailMessengerFactoryImpl.java 0% 0% 0% 0%
coverage
 1    /* $Id: EmailMessengerFactoryImpl.java,v 1.1 2004/06/02 20:10:05 johndavidtaylor Exp $
 2    * Created on Mar 14, 2004 by jdt
 3    * The alipes project
 4    * (c) 2004
 5    *
 6    */
 7    package org.abraracourcix.alipes.common.messaging;
 8    import java.util.Properties;
 9   
 10    import javax.mail.Authenticator;
 11    import javax.mail.PasswordAuthentication;
 12    import javax.mail.Session;
 13    /**
 14    * Messenger that dispatches emails
 15    *
 16    * @author jdt
 17    */
 18    public final class EmailMessengerFactoryImpl implements EmailMessengerFactory {
 19    /**
 20    * The mail session
 21    */
 22    private Session session;
 23   
 24    /**
 25    * Constructor
 26    * @param smtpServer IP address of server, port 25 assumed
 27    * @param user username of sender's account
 28    * @param password password for said account
 29    * @param returnAddress who shall we say it's from?
 30    */
 31  0 public EmailMessengerFactoryImpl(final String smtpServer, final String user, final String password,final String returnAddress) {
 32  0 final Properties props = new Properties();
 33  0 props.setProperty("mail.transport.protocol", "smtp");
 34  0 props.setProperty("mail.host", smtpServer);
 35  0 props.setProperty("mail.user", user);
 36  0 props.setProperty("mail.password", password);
 37  0 props.setProperty("mail.from", returnAddress);
 38    //final MyAuthenticator authenticator =new MyAuthenticator(user, password);
 39  0 session = Session.getInstance(props,null);
 40   
 41    }
 42   
 43    /**
 44    * Create a messenger that can be used to message these recipients
 45    * @param recipients comma separated list of recipients
 46    * @return an EmailMessenger
 47    */
 48  0 public Messenger getEmailMessenger(final String recipients) {
 49  0 return new EmailMessenger(session, recipients);
 50    }
 51   
 52    /**
 53    * Quick test
 54    *
 55    * @param args server, user, password, return address, destinationAddress
 56    * @throws MessengerException but hopefully not
 57    */
 58  0 public static void main(final String[] args) throws MessengerException {
 59  0 if (args.length!=5) {
 60  0 System.out.println("Usage: server user password returnAddress destination");
 61  0 return;
 62    }
 63  0 final EmailMessengerFactoryImpl factory = new EmailMessengerFactoryImpl(args[0],args[1],args[2],args[3]);
 64  0 final Messenger messenger = factory.getEmailMessenger(args[4]);
 65  0 messenger.sendMessage("Test message 1", "Hello!");
 66  0 messenger.sendMessage("Test message 2", "Hello again!");
 67  0 final Messenger messenger2 = factory.getEmailMessenger(args[4]);
 68  0 messenger2.sendMessage("Test message 3", "Goodbye!");
 69    }
 70   
 71    }
 72   
 73    class MyAuthenticator extends Authenticator {
 74   
 75    private PasswordAuthentication pa;
 76  0 public MyAuthenticator(String user, String password) {
 77  0 pa = new PasswordAuthentication(user, password);
 78    }
 79  0 protected PasswordAuthentication getPasswordAuthentication() {
 80  0 System.out.println("authentication reqd");
 81  0 return pa;
 82    }
 83    };
 84   
 85   
 86    /*
 87    * $Log: EmailMessengerFactoryImpl.java,v $
 88    * Revision 1.1 2004/06/02 20:10:05 johndavidtaylor
 89    * Refactoring to allow email templates.
 90    *
 91    * Revision 1.1 2004/03/18 15:21:54 johndavidtaylor
 92    * Copied across from incubation in beanpeeler
 93    *
 94    * Revision 1.2 2004/03/15 13:40:13 johndavidtaylor
 95    * Now up the stage where it can be used. Things still to do:
 96    * change the way email.txt is picked up so it can be modified mid-flight,
 97    * remove the annoying logging.
 98    *
 99    * Revision 1.1 2004/03/14 16:26:49 johndavidtaylor
 100    * refactored email
 101    *
 102    */