turbine-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject svn commit: r667474 [1/2] - in /turbine/fulcrum/trunk/commonsemail/src: java/org/apache/fulcrum/commonsemail/ java/org/apache/fulcrum/commonsemail/impl/ test/ test/org/apache/fulcrum/commonsemail/
Date Fri, 13 Jun 2008 11:10:29 GMT
Author: sgoeschl
Date: Fri Jun 13 04:10:29 2008
New Revision: 667474

URL: http://svn.apache.org/viewvc?rev=667474&view=rev
Log:
Syncing current development with SVN repository

Added:
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/SendDeliveryStatus.java
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailUtils.java
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/SendDeliveryStatusImpl.java
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/StringUtils.java
Modified:
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java
    turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java
    turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml
    turbine/fulcrum/trunk/commonsemail/src/test/TestRoleConfig.xml
    turbine/fulcrum/trunk/commonsemail/src/test/org/apache/fulcrum/commonsemail/CommonsEmailServiceTest.java

Modified: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java?rev=667474&r1=667473&r2=667474&view=diff
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java (original)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/CommonsEmailService.java Fri Jun 13 04:10:29 2008
@@ -34,7 +34,7 @@
 
 /**
  * A service taking care of most of the commons-email configuration such as
- *
+ * 
  * <ul>
  *   <li>authentication</li>
  *   <li>mail session</li>
@@ -47,28 +47,28 @@
 public interface CommonsEmailService
 {
     /**
-     * Determines if any email for the given domain name will
+     * Determines if any email for the given domain name will 
      * be sent or silently consumed by the service without
      * delivering it.
-     *
+     * 
      * @param domainName the domain name
      * @return true if the email will not be sent by the service
      */
     boolean isMailDoNotSend(String domainName);
-
+    
     /**
      * Factory method to create a mail session based on the domain configuration.
-     *
+     * 
      * @param domainName the domain name
      * @return a mail session
      */
     Session createSmtpSession(String domainName);
 
     /**
-     * Factory method to create a mail session based on the domain configuration
+     * Factory method to create a mail session based on the domain configuration 
      * and a user-supplied username and password. We assume that SMTP AUTH is
      * used.
-     *
+     * 
      * @param domainName the domain name
      * @param username the user name used for SMTP authentication
      * @param password the password used for SMTP authentication
@@ -79,7 +79,7 @@
     /**
      * Factory method for creating a SimpleEmail with fully
      * configured mail session based on the domain configuration.
-     *
+     * 
      * @param domainName the sender of the email
      * @return a SimpleEmail
      * @throws EmailException creation failed
@@ -88,8 +88,8 @@
     	throws EmailException;
 
     /**
-     * Factory method for creating a SimpleEmail
-     *
+     * Factory method for creating a SimpleEmail 
+     * 
      * @param domainName the sender of the email
      * @param content the content of the email
      * @return a SimpleEmail
@@ -101,7 +101,7 @@
     /**
      * Factory method for creating a MultiPartEmail with fully
      * configured mail session based on the domain configuration.
-     *
+     * 
      * @param domainName the sender of the email
      * @return a MultiPartEmail
      * @throws EmailException creation failed
@@ -110,8 +110,8 @@
     	throws EmailException;
 
     /**
-     * Factory method for creating a MultiPartEmail
-     *
+     * Factory method for creating a MultiPartEmail 
+     * 
      * @param domainName the sender of the email
      * @param content the content of the email
      * @return a MultiPartEmail
@@ -123,7 +123,7 @@
     /**
      * Factory method for creating a HtmlEmail with fully
      * configured mail session based on the domain configuration.
-     *
+     * 
      * @param domainName the sender of the email
      * @return a MultiPartEmail
      * @throws EmailException creation failed
@@ -132,8 +132,8 @@
     	throws EmailException;
 
     /**
-     * Factory method for creating a HtmlEmail
-     *
+     * Factory method for creating a HtmlEmail 
+     * 
      * @param domainName the sender of the email
      * @param content the content of the email
      * @return a MultiPartEmail
@@ -146,21 +146,21 @@
      * Sends an email using the service instead of calling send()
      * directly on the Email. This allows to overwrite the receivers
      * of the email as an additional security measure for sending
-     * thousands of emails using real-world email addresses.
-     *
+     * thousands of emails using real-world email addresses. 
+     * 
      * @param domainName the sender of the email
      * @param email the email to be sent
      * @return the MimeMessage being sent
      * @throws EmailException sending the email failed
      */
-    MimeMessage send(String domainName, Email email)
+    MimeMessage send(String domainName, Email email) 
     	throws EmailException;
-
+    
     /**
      * Sends an email using the service instead of calling send()
      * directly on the Email. The implementation uses the
      * the from email address as domain name.
-     *
+     * 
      * @param email the email to be sent
      * @return the MimeMessage being sent
      * @throws EmailException sending the email failed
@@ -168,26 +168,26 @@
     MimeMessage send(Email email) throws EmailException;
 
     /**
-     * Sends a MimeMessage using the service instead of calling
+     * Sends a MimeMessage using the service instead of calling 
      * Transport.send(). This allows to overwrite the receivers
      * of the email as an additional security measure for sending
-     * thousands of emails using real-world email addresses.
-     *
+     * thousands of emails using real-world email addresses. 
+     * 
      * @param domainName the sender of the email
      * @param session the email session
      * @param mimeMessage the email to be sent
      * @return the MimeMessage being sent
      * @throws MessagingException sending the email failed
      */
-    MimeMessage send(String domainName, Session session, MimeMessage mimeMessage)
-    	throws MessagingException;
+    MimeMessage send(String domainName, Session session, MimeMessage mimeMessage) 
+    	throws MessagingException;        
 
     /**
-     * Sends a MimeMessage using the service instead of calling
+     * Sends a MimeMessage using the service instead of calling 
      * Transport.send(). This allows to overwrite the receivers
      * of the email as an additional security measure for sending
-     * thousands of emails using real-world email addresses.
-     *
+     * thousands of emails using real-world email addresses. 
+     * 
      * @param domainName the sender of the email
      * @param session the email session
      * @param mimeMessage the email to be sent
@@ -195,20 +195,31 @@
      * @return the MimeMessage being sent
      * @throws MessagingException sending the email failed
      */
-    MimeMessage send(String domainName, Session session, MimeMessage mimeMessage, Address[] recipients)
-    	throws MessagingException;
+    MimeMessage send(String domainName, Session session, MimeMessage mimeMessage, Address[] recipients) 
+    	throws MessagingException;        
 
     /**
-     * Sends a MimeMessage using the service instead of calling
+     * Sends a MimeMessage using the service instead of calling 
      * Transport.send(). This allows to overwrite the receivers
      * of the email as an additional security measure for sending
-     * thousands of emails using real-world email addresses.
-     *
+     * thousands of emails using real-world email addresses. 
+     * 
      * @param session the email session
      * @param mimeMessage the email to be sent
      * @return the MimeMessage being sent
      * @throws MessagingException sending the email failed
      */
-    MimeMessage send(Session session, MimeMessage mimeMessage)
+    MimeMessage send(Session session, MimeMessage mimeMessage) 
     	throws MessagingException;
-}
+
+    /**
+     * Get the delivery status of the previously sent email. This
+     * allows to do something sensible if email delivery failed.
+     *
+     * @param mimeMessage the email sent
+     * @return the delivery status
+     * @throws MessagingException getting the delivery status failed
+     */
+    SendDeliveryStatus getSendDeliveryStatus(MimeMessage mimeMessage)
+        throws MessagingException;
+}
\ No newline at end of file

Added: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/SendDeliveryStatus.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/SendDeliveryStatus.java?rev=667474&view=auto
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/SendDeliveryStatus.java (added)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/SendDeliveryStatus.java Fri Jun 13 04:10:29 2008
@@ -0,0 +1,58 @@
+package org.apache.fulcrum.commonsemail;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.mail.Address;
+
+/**
+ * Allows to access the send delivery status of a previously sent
+ * email.
+ */
+public interface SendDeliveryStatus
+{
+    /**
+     * Returns true only if ALL recipients were accepted by the
+     * mailserver, i.e. everything is okay.
+     *
+     * @return true if message sending was successful
+     */
+    boolean hasSucceeded();
+
+    /**
+     * The list of mail addresses accepted by the mailserver.
+     *
+     * @return list of email addresses
+     */
+    Address[] getValidSentAddresses();
+
+    /**
+     * The list of mail addresses rejected by the mailserver.
+     *
+     * @return list of email addresses
+     */
+    Address[] getValidUnsentAddresses();
+
+    /**
+     * The list of invalid mail addresses.
+     *
+     * @return list of email addresses
+     */        
+    Address[] getInvalidAddresses();
+}
\ No newline at end of file

Modified: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java?rev=667474&r1=667473&r2=667474&view=diff
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java (original)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailDomainEntry.java Fri Jun 13 04:10:29 2008
@@ -19,18 +19,17 @@
  * under the License.
  */
 
-import java.util.Hashtable;
-import java.util.Properties;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
 
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
-
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
+import java.util.Hashtable;
+import java.util.Properties;
 
 /**
  * A service taking care of most of the commons-email configuration such as
- *
+ * 
  * <ul>
  *   <li>authentication</li>
  *   <li>mail session</li>
@@ -44,13 +43,13 @@
 {
     /** use SMTPAUTH */
     public static final String AUTH_SMTP = "smtpauth";
-
+    
     /** use PopBeforeSmtp */
     public static final String AUTH_POPBEFORESMTP = "popbeforesmtp";
-
+    
     /** use no authentication at all */
     public static final String AUTH_NONE = "none";
-
+    
     /** the name of the domain */
     private String domainName;
 
@@ -59,31 +58,31 @@
 
     /** turn the diagnostic features on */
     private boolean mailDump;
-
+    
     /** the bounce address */
     private String mailBounceAddress;
-
+    
     /** debug mode for mail session */
     private boolean mailDebug;
-
+    
     /** the charset being used for the mail */
     private String mailCharset;
-
+    
     /** the address of the mail server */
     private String mailSmtpHost;
 
     /** the port of the mail server */
     private int mailSmtpPort;
-
+    
     /** socket connection timeout value in milliseconds */
     private int mailSmtpConnectionTimeout;
-
+    
 	/** socket I/O timeout value in millisecond */
     private int mailSmtpTimeout;
-
+    
     /** if the message has some valid and some invalid addresses, send the message anyway */
     private boolean mailSmtpSendPartial;
-
+    
     /** the email address of the sender */
     private String mailFromEmail;
 
@@ -95,25 +94,25 @@
 
     /** the email address of the replyTo */
     private String mailReplyToName;
-
+    
     /** the type of authentication */
     private String authType;
-
+    
     /** the username for authentication */
     private String authUsername;
-
+    
     /** the password for authentication */
     private String authPassword;
-
-    /** the POP server being used for popbeforesmtp */
+    
+    /** the POP server being used for popbeforesmtp */    
     private String authPopHost;
-
+    
     /** the mail headers being used */
     private Properties headers;
-
+    
     /** are we overwriting the TO recipients */
     private boolean hasOverwriteTo;
-
+    
     /** the to address to be overwritten during send() */
     private InternetAddress overwriteTo;
 
@@ -128,10 +127,10 @@
 
     /** the bcc address to be overwritten during send() */
     private InternetAddress overwriteBcc;
-
+        
     /** do we skip the sending */
     private boolean mailDoNotSend;
-
+    
     /** is an application hook for onSuccess defined */
     private boolean hasOnSuccessHook;
 
@@ -143,16 +142,16 @@
 
     /** the configuration of the success hook */
     private Configuration onSuccessHookConfiguration;
-
+    
     /** the configuration of the success hook */
-    private Configuration onFailureHookConfiguration;
+    private Configuration onFailureHookConfiguration;    
 
     /** the configuration of the notSend hook */
-    private Configuration onNotSendHookConfiguration;
+    private Configuration onNotSendHookConfiguration;    
 
     /**
-     * Constructor.
-     */
+     * Constructor. 
+     */    
     public CommonsEmailDomainEntry()
     {
         this.headers = new Properties();
@@ -160,78 +159,78 @@
         this.hasOverwriteCc = false;
         this.hasOverwriteBcc = false;
     }
-
+    
     /**
      * Initialize this instance.
-     *
-     * @param conf the domain configuration
+     * 
+     * @param conf the domain configuration 
      * @return the fully configured instance
      * @throws ConfigurationException the configuration failed
      */
     public CommonsEmailDomainEntry initialize( Configuration conf )
     	throws ConfigurationException
-    {
+    {        
         // read the basic parameters
-
-        this.domainName = conf.getChild("domainName").getValue();
+        
+        this.domainName = conf.getChild("domainName").getValue();     
         this.domainMatch = conf.getChild("domainName").getValue(this.domainName);
-
+        
         this.mailBounceAddress = conf.getChild("mailBounceAddress").getValue(null);
         this.mailDebug = conf.getChild("mailDebug").getValueAsBoolean(false);
         this.mailCharset = conf.getChild("mailCharset").getValue(null);
-
+        
         this.mailSmtpHost = conf.getChild("mailSmtpHost").getValue(
             System.getProperty("mail.smtp.host","localhost")
             );
-
+        
         // determine SMTP port either from the configuration or from the system properties
-
-        this.mailSmtpPort = conf.getChild("mailSmtpPort").getValueAsInteger(0);
-
+        
+        this.mailSmtpPort = conf.getChild("mailSmtpPort").getValueAsInteger(0);    
+        
         if( this.mailSmtpPort == 0 )
         {
             this.mailSmtpPort = Integer.parseInt(
                 System.getProperty("mail.smtp.port","25")
                 );
         }
-
+        
         this.mailSmtpConnectionTimeout = conf.getChild("mailSmtpConnectionTimeout").getValueAsInteger(Integer.MAX_VALUE);
         this.mailSmtpTimeout = conf.getChild("mailSmtpConnectionTimeout").getValueAsInteger(Integer.MAX_VALUE);
         this.mailSmtpSendPartial = conf.getChild("mailSmtpSendPartial").getValueAsBoolean(false);
         this.mailFromEmail = conf.getChild("mailFromEmail").getValue(null);
         this.mailFromName = conf.getChild("mailFromName").getValue(null);
         this.mailReplyToEmail = conf.getChild("mailReplyToEmail").getValue(this.mailFromEmail);
-        this.mailReplyToName = conf.getChild("mailReplyToName").getValue(this.mailFromName);
+        this.mailReplyToName = conf.getChild("mailReplyToName").getValue(this.mailFromName);         
         this.mailDump = conf.getChild("mailDump").getValueAsBoolean(false);
         this.mailDoNotSend = conf.getChild("mailDoNotSend").getValueAsBoolean(false);
-
+        
         // parse the authentication related parameters
-
+        
         this.authType = conf.getChild("authentication").getChild("type").getValue(AUTH_NONE);
-
+        
         if( this.hasAuthentication() )
         {
 	        this.authPopHost = conf.getChild("authentication").getChild("popHost").getValue(this.mailSmtpHost);
 	        this.authUsername = conf.getChild("authentication").getChild("username").getValue();
 	        this.authPassword = conf.getChild("authentication").getChild("password").getValue();
         }
-
+        
         // parse the email headers
-
+        
         Configuration[] headersConf = conf.getChild("headers").getChildren("property");
-
+        
         for( int i=0; i<headersConf.length; i++ )
         {
             String name = headersConf[i].getAttribute("name");
             String value = headersConf[i].getValue();
-            this.headers.setProperty(name,value);
+            this.headers.setProperty(name,value);            
         }
-
+                
         // parse the overwrites
-
+        
         String internetAddress = null;
         Configuration overwritesConf = conf.getChild("overwrites");
-
+        
         try
         {
             if( overwritesConf.getChild("mailToEmail",false) != null )
@@ -266,47 +265,47 @@
         }
         catch (AddressException e)
         {
-            String msg = "Unable to parse " + internetAddress;
+            String msg = "Unable to parse " + internetAddress;            
             throw new ConfigurationException(msg,e);
         }
-
+        
         // parse the application hooks
-
+        
         Configuration hookConf = conf.getChild("hooks");
-
+        
         this.hasOnSuccessHook = hookConf.getChild("onSuccess").getAttributeAsBoolean("enabled", false);
-
+        
         if( this.hasOnSuccessHook() )
         {
             this.onSuccessHookConfiguration = hookConf.getChild("onSuccess");
         }
-
+        
         this.hasOnFailureHook = hookConf.getChild("onFailure").getAttributeAsBoolean("enabled", false);
 
         if( this.hasOnFailureHook())
         {
             this.onFailureHookConfiguration = hookConf.getChild("onFailure");
         }
-
+        
         this.hasOnNotSendHook = hookConf.getChild("onNotSend").getAttributeAsBoolean("enabled", false);
 
         if( this.hasOnNotSendHook())
         {
             this.onNotSendHookConfiguration = hookConf.getChild("onNotSend");
         }
-
+        
         return this;
     }
-
+ 
     /**
      * @see java.lang.Object#toString()
      */
     public String toString()
     {
         StringBuffer result = new StringBuffer();
-
+        
         result.append(getClass().getName() + "@" + Integer.toHexString(hashCode()));
-
+        
         result.append('[');
         result.append("authPopHost=" + this.getAuthPopHost());
         result.append(',');
@@ -318,51 +317,51 @@
         result.append(',');
         result.append("domainName=" + this.getDomainName());
         result.append(',');
-        result.append("hasOverwriteCc=" + this.getHasOverwriteBcc());
+        result.append("hasOverwriteCc=" + this.getHasOverwriteBcc());                
         result.append(',');
-        result.append("hasOverwriteBcc=" + this.getHasOverwriteBcc());
+        result.append("hasOverwriteBcc=" + this.getHasOverwriteBcc());                
         result.append(',');
-        result.append("hasOverwriteTo=" + this.getHasOverwriteTo());
+        result.append("hasOverwriteTo=" + this.getHasOverwriteTo());                
         result.append(',');
-        result.append("headers=" + this.getHeaders());
+        result.append("headers=" + this.getHeaders());                
         result.append(',');
-        result.append("mailBounceAddress=" + this.getMailBounceAddress());
+        result.append("mailBounceAddress=" + this.getMailBounceAddress());                
         result.append(',');
-        result.append("mailCharset=" + this.getMailCharset());
+        result.append("mailCharset=" + this.getMailCharset());                
         result.append(',');
-        result.append("mailDebug=" + this.mailDebug);
+        result.append("mailDebug=" + this.mailDebug);                
         result.append(',');
-        result.append("mailDump=" + this.mailDump);
+        result.append("mailDump=" + this.mailDump);                
         result.append(',');
-        result.append("mailFromEmail=" + this.getMailFromEmail());
+        result.append("mailFromEmail=" + this.getMailFromEmail());                
         result.append(',');
-        result.append("mailFromName=" + this.getMailFromName());
+        result.append("mailFromName=" + this.getMailFromName());                
         result.append(',');
-        result.append("mailReplyToEmail=" + this.getMailReplyToEmail());
+        result.append("mailReplyToEmail=" + this.getMailReplyToEmail());                
         result.append(',');
-        result.append("mailReplyToName=" + this.getMailReplyToName());
+        result.append("mailReplyToName=" + this.getMailReplyToName());                
         result.append(',');
-        result.append("mailSmtpHost=" + this.getMailSmtpHost());
+        result.append("mailSmtpHost=" + this.getMailSmtpHost());                
         result.append(',');
-        result.append("mailSmtpPort=" + this.getMailSmtpPort());
+        result.append("mailSmtpPort=" + this.getMailSmtpPort());                
         result.append(',');
-        result.append("mailSmtpConnectionTimeout=" + this.getMailSmtpConnectionTimeout());
+        result.append("mailSmtpConnectionTimeout=" + this.getMailSmtpConnectionTimeout());                
         result.append(',');
-        result.append("mailSmtpTimeout=" + this.getMailSmtpTimeout());
+        result.append("mailSmtpTimeout=" + this.getMailSmtpTimeout());                
         result.append(',');
-        result.append("mailSmtpSendPartial=" + this.isMailSmtpSendPartial());
+        result.append("mailSmtpSendPartial=" + this.isMailSmtpSendPartial());                
         result.append(',');
-        result.append("overwriteBcc=" + this.getOverwriteBcc());
+        result.append("overwriteBcc=" + this.getOverwriteBcc());                
         result.append(',');
-        result.append("overwriteCc=" + this.getOverwriteCc());
+        result.append("overwriteCc=" + this.getOverwriteCc());                
         result.append(',');
-        result.append("overwriteTo=" + this.getOverwriteTo());
+        result.append("overwriteTo=" + this.getOverwriteTo());                                
         result.append(']');
-
-        return result.toString();
+        
+        return result.toString();                
 
     }
-
+    
     /**
      * @return Returns the authPassword.
      */
@@ -370,7 +369,7 @@
     {
         return authPassword;
     }
-
+    
     /**
      * @return Returns the authPopHost.
      */
@@ -378,7 +377,7 @@
     {
         return authPopHost;
     }
-
+    
     /**
      * @return Returns the authType.
      */
@@ -386,7 +385,7 @@
     {
         return authType;
     }
-
+    
     /**
      * @return Returns the authUsername.
      */
@@ -394,7 +393,7 @@
     {
         return authUsername;
     }
-
+    
     /**
      * @return Returns the mailBounceAddress.
      */
@@ -402,7 +401,7 @@
     {
         return mailBounceAddress;
     }
-
+    
     /**
      * @return Returns the domainName.
      */
@@ -410,7 +409,7 @@
     {
         return domainName;
     }
-
+        
     /**
      * @return Returns the domainMatch.
      */
@@ -418,7 +417,7 @@
     {
         return domainMatch;
     }
-
+    
     /**
      * @return Returns the headers.
      */
@@ -426,7 +425,7 @@
     {
         return headers;
     }
-
+        
     /**
      * @return Returns the overwriteBcc.
      */
@@ -434,7 +433,7 @@
     {
         return overwriteBcc;
     }
-
+    
     /**
      * @return Returns the overwriteCc.
      */
@@ -442,7 +441,7 @@
     {
         return overwriteCc;
     }
-
+    
     /**
      * @return Returns the overwriteTo.
      */
@@ -450,7 +449,7 @@
     {
         return overwriteTo;
     }
-
+        
     /**
      * @return Returns the mailCharset.
      */
@@ -458,7 +457,7 @@
     {
         return mailCharset;
     }
-
+    
     /**
      * @return Returns the mailDebug.
      */
@@ -466,7 +465,7 @@
     {
         return mailDebug;
     }
-
+    
     /**
      * @return Returns the mailFromEmail.
      */
@@ -474,7 +473,7 @@
     {
         return mailFromEmail;
     }
-
+    
     /**
      * @return Returns the mailFromName.
      */
@@ -482,7 +481,7 @@
     {
         return mailFromName;
     }
-
+        
     /**
      * @return Returns the mailReplyToEmail.
      */
@@ -490,7 +489,7 @@
     {
         return mailReplyToEmail;
     }
-
+    
     /**
      * @return Returns the mailReplyToName.
      */
@@ -498,7 +497,7 @@
     {
         return mailReplyToName;
     }
-
+    
     /**
      * @return Returns the mailSmtpHost.
      */
@@ -506,7 +505,7 @@
     {
         return mailSmtpHost;
     }
-
+    
     /**
      * @return Returns the mailSmtpPort.
      */
@@ -514,7 +513,7 @@
     {
         return mailSmtpPort;
     }
-
+    
     /**
      * @return Returns the mailSmtpConnectionTimeout.
      */
@@ -522,7 +521,7 @@
     {
         return mailSmtpConnectionTimeout;
     }
-
+    
     /**
      * @return Returns the mailSmtpTimeout.
      */
@@ -530,7 +529,7 @@
     {
         return mailSmtpTimeout;
     }
-
+    
     /**
      * @return Returns the mailSmtpSendPartial.
      */
@@ -538,7 +537,7 @@
     {
         return mailSmtpSendPartial;
     }
-
+    
     /**
      * @return Is any type of authentication used for this domain?
      */
@@ -583,7 +582,7 @@
             return false;
         }
     }
-
+    
     /**
      * @return Returns the mailDump.
      */
@@ -591,7 +590,7 @@
     {
         return mailDump;
     }
-
+        
     /**
      * @return Returns the hasOverwriteBcc.
      */
@@ -599,7 +598,7 @@
     {
         return hasOverwriteBcc;
     }
-
+    
     /**
      * @return Returns the hasOverwriteCc.
      */
@@ -614,15 +613,15 @@
     {
         return hasOverwriteTo;
     }
-
+    
     /**
      * @return Returns the mailDoNotSend.
      */
     public boolean isMailDoNotSend()
     {
         return mailDoNotSend;
-    }
-
+    } 
+        
     /**
      * @return Returns the hasOnFailureHook.
      */
@@ -630,7 +629,7 @@
     {
         return hasOnFailureHook;
     }
-
+    
     /**
      * @return Returns the hasOnSuccessHook.
      */
@@ -638,7 +637,7 @@
     {
         return hasOnSuccessHook;
     }
-
+    
     /**
      * @return Returns the onFailureHookConfiguration.
      */
@@ -646,7 +645,7 @@
     {
         return onFailureHookConfiguration;
     }
-
+    
     /**
      * @return Returns the onSuccessHookConfiguration.
      */
@@ -654,7 +653,7 @@
     {
         return onSuccessHookConfiguration;
     }
-
+        
     /**
      * @return Returns the hasOnNotSendHook.
      */
@@ -662,7 +661,7 @@
     {
         return hasOnNotSendHook;
     }
-
+    
     /**
      * @return Returns the onNotSendHookConfiguration.
      */
@@ -670,4 +669,4 @@
     {
         return onNotSendHookConfiguration;
     }
-}
+}
\ No newline at end of file

Modified: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java?rev=667474&r1=667473&r2=667474&view=diff
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java (original)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailServiceImpl.java Fri Jun 13 04:10:29 2008
@@ -19,28 +19,6 @@
  * under the License.
  */
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Properties;
-
-import javax.activation.DataSource;
-import javax.mail.Address;
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.event.TransportEvent;
-import javax.mail.event.TransportListener;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.configuration.Configuration;
@@ -50,7 +28,7 @@
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.commons.lang.StringUtils;
+import org.apache.avalon.framework.thread.ThreadSafe;
 import org.apache.commons.mail.DefaultAuthenticator;
 import org.apache.commons.mail.Email;
 import org.apache.commons.mail.EmailAttachment;
@@ -59,6 +37,28 @@
 import org.apache.commons.mail.MultiPartEmail;
 import org.apache.commons.mail.SimpleEmail;
 import org.apache.fulcrum.commonsemail.CommonsEmailService;
+import org.apache.fulcrum.commonsemail.SendDeliveryStatus;
+
+import javax.activation.DataSource;
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.event.TransportEvent;
+import javax.mail.event.TransportListener;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.WeakHashMap;
 
 /**
  * A service taking care of most of the commons-email configuration such as
@@ -74,18 +74,21 @@
 
 public class CommonsEmailServiceImpl
     extends AbstractLogEnabled
-    implements CommonsEmailService, Contextualizable, Reconfigurable, Initializable, Disposable,
+    implements CommonsEmailService, Contextualizable, Reconfigurable, Initializable, Disposable, ThreadSafe,
         TransportListener, CommonsEmailConstants
 {
     /** context key for persistent directory */
-    private final static String URN_AVALON_HOME = "urn:avalon:home";
+    private final static String URN_AVALON_HOME = "context-root";
 
     /** context key for temporary directory */
-    private final static String URN_AVALON_TEMP = "urn:avalon:temp";
+    private final static String URN_AVALON_TEMP = "impl.workDir";
+
+    /** the file extension used for a MimeMessage */
+    private final static String MIME_MESSAGE_EXTENSION = "eml";
 
     /** counter for creating a file name */
     private int fileNameCounter;
-
+    
     /** the Avalon home directory */
     private File serviceHomeDir;
 
@@ -98,15 +101,23 @@
     /** the available domains */
     private CommonsEmailDomainEntry[] domainList;
 
+    /** date formatter to create timestamps for debug utput */
+    private final SimpleDateFormat simpleDateFormat;
+
     /** is the service instance initialized */
     private volatile boolean isInitialized;
 
+    /** keep track of the incoming TransportEvents using MimeMessage ==> SendDeliveryStatus */
+    private Map sendDeliveryStatusMap;
+
     /**
      * Constructor
      */
     public CommonsEmailServiceImpl()
     {
-        // nothing to do
+        this.fileNameCounter = (int) System.currentTimeMillis() % 1000;
+        this.simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HHmmssSSS");
+        this.sendDeliveryStatusMap = new WeakHashMap();
     }
 
     /////////////////////////////////////////////////////////////////////////
@@ -168,6 +179,7 @@
         this.domainList = null;
         this.serviceHomeDir = null;
         this.serviceTempDir = null;
+        this.sendDeliveryStatusMap = null;
     }
 
     /////////////////////////////////////////////////////////////////////////
@@ -203,7 +215,7 @@
     public Session createSmtpSession(String domainName, String username,
         String password)
     {
-        Session result = null;
+        Session result;
         CommonsEmailDomainEntry domain = this.getDomain(domainName);
         Properties properties = new Properties(System.getProperties());
         DefaultAuthenticator authenticator = null;
@@ -341,15 +353,13 @@
     public MimeMessage send(String domainName, Session session, MimeMessage mimeMessage)
         throws MessagingException
     {
-        MimeMessage result = null;
-
         // get the configuration of this domain
 
         CommonsEmailDomainEntry domain = this.getDomain(domainName);
 
         //  update the MimeMessage based on the domain configuration
 
-        result = this.updateMimeMessage(domain, mimeMessage);
+        MimeMessage result = this.updateMimeMessage(domain, mimeMessage);
 
         // send the MimeMessage
 
@@ -370,15 +380,13 @@
         MimeMessage mimeMessage, Address [] recipients)
         throws MessagingException
     {
-        MimeMessage result = null;
-
         // get the configuration of this domain
 
         CommonsEmailDomainEntry domain = this.getDomain(domainName);
 
-        //  update the MimeMessage based on the domain configuration
+        // update the MimeMessage based on the domain configuration
 
-        result = this.updateMimeMessage(domain, mimeMessage);
+        MimeMessage result = this.updateMimeMessage(domain, mimeMessage);
 
         // send the MimeMessage
 
@@ -398,8 +406,6 @@
     public MimeMessage send(Session session, MimeMessage mimeMessage)
         throws MessagingException
     {
-         MimeMessage result = null;
-
          // determine the domain name
 
          if( ( mimeMessage.getFrom() == null ) || ( mimeMessage.getFrom().length == 0 ) )
@@ -416,7 +422,7 @@
 
          // update the MimeMessage based on the domain configuration
 
-         result = this.updateMimeMessage(domain, mimeMessage);
+         MimeMessage result = this.updateMimeMessage(domain, mimeMessage);
 
          // send the MimeMessage
 
@@ -463,6 +469,14 @@
         return result;
     }
 
+    /**
+     * @see org.apache.fulcrum.commonsemail.CommonsEmailService#getSendDeliveryStatus(javax.mail.internet.MimeMessage) 
+     */
+    public SendDeliveryStatus getSendDeliveryStatus( MimeMessage mimeMessage ) throws MessagingException
+    {        
+        return (SendDeliveryStatus) this.sendDeliveryStatusMap.get(mimeMessage);
+    }
+
     /////////////////////////////////////////////////////////////////////////
     // Service Implementation
     /////////////////////////////////////////////////////////////////////////
@@ -475,12 +489,32 @@
     {
         if( this.isInitialized() )
         {
-            this.getLogger().info(
-                "The MimeMessage "
-                + this.getMessageID(transportEvent)
-                + " was successfully delivered to the following recipients : "
-                + this.toString(transportEvent.getValidSentAddresses())
-                );
+            try
+            {
+                this.getLogger().info(
+                    "The MimeMessage "
+                    + this.getMessageId(transportEvent.getMessage())
+                    + " was successfully delivered to the following recipients : "
+                    + this.toString(transportEvent.getValidSentAddresses())
+                    );
+
+                SendDeliveryStatusImpl sendDeliveryStatus = this.getSendDeliveryStatus(transportEvent);
+
+                if(sendDeliveryStatus != null)
+                {
+                    sendDeliveryStatus.add(transportEvent);
+                }
+                else
+                {
+                    MimeMessage mimeMessage = (MimeMessage) transportEvent.getMessage();
+                    this.getLogger().error("Found no sendDeliveryStatus for " + mimeMessage.getMessageID());
+                }
+            }
+            catch(Exception e)
+            {
+                String msg = "Unable to update the delivery status for 'messageDelivered'";
+                this.getLogger().error(msg, e);
+            }
         }
     }
 
@@ -491,12 +525,32 @@
     {
         if( this.isInitialized() )
         {
-            this.getLogger().error(
-                "The MimeMessage "
-                + this.getMessageID(transportEvent)
-                + " was not delivered to any recipient due to following invalid addresses : "
-                + this.toString(transportEvent.getInvalidAddresses())
-                );
+            try
+            {
+                this.getLogger().error(
+                    "The MimeMessage "
+                    + this.getMessageId(transportEvent.getMessage())
+                    + " was not delivered to any recipient due to following invalid addresses : "
+                    + this.toString(transportEvent.getInvalidAddresses())
+                    );
+
+                SendDeliveryStatusImpl sendDeliveryStatus = this.getSendDeliveryStatus(transportEvent);
+                
+                if(sendDeliveryStatus != null)
+                {
+                    sendDeliveryStatus.add(transportEvent);
+                }
+                else
+                {
+                    MimeMessage mimeMessage = (MimeMessage) transportEvent.getMessage();
+                    this.getLogger().error("Found no sendDeliveryStatus for " + mimeMessage.getMessageID());
+                }                
+            }
+            catch(Exception e)
+            {
+                String msg = "Unable to update the delivery status for 'messageNotDelivered'";
+                this.getLogger().error(msg, e);
+            }
         }
     }
 
@@ -505,13 +559,35 @@
      */
     public void messagePartiallyDelivered(TransportEvent transportEvent)
     {
+        // write to the logfile
         if( this.isInitialized() )
         {
-            this.getLogger().warn(
-                "The MimeMessage "
-                + this.getMessageID(transportEvent)
-                + "was only partially delivered "
-                );
+            try
+            {
+                this.getLogger().warn(
+                    "The MimeMessage "
+                    + this.getMessageId(transportEvent.getMessage())
+                    + "was only partially delivered "
+                    + this.toString(transportEvent.getValidUnsentAddresses())
+                    );
+
+                SendDeliveryStatusImpl sendDeliveryStatus = this.getSendDeliveryStatus(transportEvent);
+
+                if(sendDeliveryStatus != null)
+                {
+                    sendDeliveryStatus.add(transportEvent);
+                }
+                else
+                {
+                    MimeMessage mimeMessage = (MimeMessage) transportEvent.getMessage();
+                    this.getLogger().error("Found no sendDeliveryStatus for " + mimeMessage.getMessageID());
+                }                
+            }
+            catch(Exception e)
+            {
+                String msg = "Unable to update the delivery status for 'messagePartiallyDelivered'";
+                this.getLogger().error(msg, e);
+            }
         }
     }
 
@@ -533,6 +609,7 @@
 
     /**
      * @return Returns the serviceTempDir.
+     * @noinspection WeakerAccess
      */
     protected File getServiceTempDir()
     {
@@ -546,6 +623,8 @@
      *
      * @param mimeMessage the MimeMessage to be send
      * @return the updated MimeMessage
+     * @throws MessagingException the post-processing failed
+     * @noinspection WeakerAccess
      */
     protected MimeMessage onPostProcessMimeMessage(MimeMessage mimeMessage)
         throws MessagingException
@@ -558,6 +637,8 @@
      *
      * @param email the underlying email for building the MimeMessage
      * @return the resulting MimeMessage
+     * @throws EmailException building the message failed
+     * @throws MessagingException the post-processing failed
      */
     private MimeMessage buildMimeMessage( Email email )
         throws EmailException, MessagingException
@@ -578,6 +659,7 @@
      * @param domain the domain configuration
      * @param mimeMessage the MimeMessage to be updated
      * @return the resulting MimeMessage
+     * @throws MessagingException the operation failed
      */
     private MimeMessage updateMimeMessage( CommonsEmailDomainEntry domain, MimeMessage mimeMessage )
         throws MessagingException
@@ -615,7 +697,7 @@
      * a transport listener to track invalid email addresses.
      *
      * @param domain the domain configuration
-     * @param sesssion the mail sessoin
+     * @param session the mail sessoin
      * @param mimeMessage the MimeMessage to be sent
      * @param recipients the list of recipients
      * @throws MessagingException sending the MimeMessage failed
@@ -632,6 +714,20 @@
                 );
         }
 
+        // get the current recipients for the mail since we allow
+        // overwriting the recipients found in the message
+
+        javax.mail.Address[] currRecipients = null;
+
+        if( (recipients == null) || (recipients.length == 0) )
+        {
+            currRecipients = mimeMessage.getAllRecipients();
+        }
+        else
+        {
+            currRecipients = recipients;
+        }
+
         // dump the MimeMessage to be sent
 
         if( domain.isMailDump() )
@@ -639,26 +735,22 @@
             this.dump(mimeMessage,"send");
         }
 
-        if( domain.isMailDoNotSend() == false )
+        // keep track of the deliver status
+
+        this.createSendDeliveryStatus(mimeMessage, domain.isMailDoNotSend());
+
+        if( !domain.isMailDoNotSend() )
         {
             try
             {
                 long startTime = System.currentTimeMillis();
 
-                Transport transport = session.getTransport("smtp");
+                // do the sending keyboard gymnastics
 
+                Transport transport = session.getTransport("smtp");
                 transport.addTransportListener(this);
                 transport.connect();
-
-                if( (recipients == null) || (recipients.length == 0) )
-                {
-                    transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
-                }
-                else
-                {
-                    transport.sendMessage(mimeMessage, recipients);
-                }
-
+                transport.sendMessage(mimeMessage, currRecipients);
                 transport.close();
 
                 long endTime = System.currentTimeMillis();
@@ -732,29 +824,9 @@
      */
     protected void onSendSucceeded(CommonsEmailDomainEntry domain, Session session, MimeMessage mimeMessage)
     {
-        try
-        {
-            Configuration conf = domain.getOnSuccessHookConfiguration();
-            String directoryName = conf.getChild("directory").getValue(this.getServiceTempDir().getAbsolutePath());
-
-            String messageId = mimeMessage.getMessageID();
-            String messageFileName = this.createMessageFileName(messageId);
-            File directory = this.makeAbsolutePath(directoryName);
-            directory.mkdirs();
-
-            File file = new File( directory, messageFileName);
-            FileOutputStream fos = new FileOutputStream(file);
-            mimeMessage.writeTo(fos);
-            fos.flush();
-            fos.close();
-
-            this.getLogger().info( "Stored the MimeMessage as " + file.getAbsolutePath() );
-        }
-        catch( Throwable t )
-        {
-            String msg = "Failed to store the MimeMessage in " + this.serviceTempDir.getAbsolutePath();
-            this.getLogger().error(msg,t);
-        }
+        Configuration conf = domain.getOnSuccessHookConfiguration();
+        String directoryName = conf.getChild("directory").getValue(this.getServiceTempDir().getAbsolutePath());
+        this.writeMimeMessage(directoryName, mimeMessage);
     }
 
     /**
@@ -766,29 +838,9 @@
      */
     protected void onSendFailed(CommonsEmailDomainEntry domain, Session session, MimeMessage mimeMessage)
     {
-        try
-        {
-            Configuration conf = domain.getOnFailureHookConfiguration();
-            String directoryName = conf.getChild("directory").getValue(this.getServiceTempDir().getAbsolutePath());
-
-            String messageId = mimeMessage.getMessageID();
-            String messageFileName = this.createMessageFileName(messageId);
-            File directory = this.makeAbsolutePath(directoryName);
-            directory.mkdirs();
-
-            File file = new File( directory, messageFileName);
-            FileOutputStream fos = new FileOutputStream(file);
-            mimeMessage.writeTo(fos);
-            fos.flush();
-            fos.close();
-
-            this.getLogger().info( "Stored the MimeMessage as " + file.getAbsolutePath() );
-        }
-        catch( Throwable t )
-        {
-            String msg = "Failed to store the MimeMessage in " + this.serviceTempDir.getAbsolutePath();
-            this.getLogger().error(msg,t);
-        }
+        Configuration conf = domain.getOnFailureHookConfiguration();
+        String directoryName = conf.getChild("directory").getValue(this.getServiceTempDir().getAbsolutePath());
+        this.writeMimeMessage(directoryName, mimeMessage);
     }
 
     /**
@@ -800,29 +852,9 @@
      */
     protected void onSendSupressed(CommonsEmailDomainEntry domain, Session session, MimeMessage mimeMessage)
     {
-        try
-        {
-            Configuration conf = domain.getOnNotSendHookConfiguration();
-            String directoryName = conf.getChild("directory").getValue(this.getServiceTempDir().getAbsolutePath());
-
-            String messageId = mimeMessage.getMessageID();
-            String messageFileName = this.createMessageFileName(messageId);
-            File directory = this.makeAbsolutePath(directoryName);
-            directory.mkdirs();
-
-            File file = new File( directory, messageFileName);
-            FileOutputStream fos = new FileOutputStream(file);
-            mimeMessage.writeTo(fos);
-            fos.flush();
-            fos.close();
-
-            this.getLogger().info( "Stored the MimeMessage as " + file.getAbsolutePath() );
-        }
-        catch( Throwable t )
-        {
-            String msg = "Failed to store the MimeMessage in " + this.serviceTempDir.getAbsolutePath();
-            this.getLogger().error(msg,t);
-        }
+        Configuration conf = domain.getOnNotSendHookConfiguration();
+        String directoryName = conf.getChild("directory").getValue(this.getServiceTempDir().getAbsolutePath());
+        this.writeMimeMessage(directoryName, mimeMessage);
     }
 
     /**
@@ -1011,8 +1043,9 @@
      * Overwrites certain fields of the MimeMessage before sending it.
      *
      * @param domain the domain configuration
-     * @param email the email to configure
-     * @throws EmailException the configuration failed
+     * @param mimeMessage the email to configure
+     * @return the modified message
+     * @throws MessagingException the configuration failed
      */
     private MimeMessage overwrite( CommonsEmailDomainEntry domain, MimeMessage mimeMessage )
         throws MessagingException
@@ -1053,8 +1086,6 @@
      */
     private void dump(MimeMessage mimeMessage, String type)
     {
-        FileOutputStream fos = null;
-
         if( mimeMessage == null )
         {
             return;
@@ -1064,30 +1095,13 @@
         {
             String name = "CommonsEmailService_" + type + ".eml";
             File dumpFile = new File( this.serviceTempDir, name );
-            fos = new FileOutputStream(dumpFile);
-            mimeMessage.writeTo(fos);
-            fos.flush();
+            CommonsEmailUtils.writeMimeMessage(dumpFile, mimeMessage);
         }
         catch (Throwable t)
         {
             String msg = "Unable to dump the MimeMessage";
             this.getLogger().warn(msg,t);
         }
-        finally
-        {
-            if( fos != null )
-            {
-                try
-                {
-                    fos.close();
-                }
-                catch (IOException ioe)
-                {
-                    String msg = "Closing the FileOutputStream failed";
-                    this.getLogger().warn(msg,ioe);
-                }
-            }
-        }
     }
 
     /**
@@ -1101,24 +1115,21 @@
     /**
      * Determines the message id for the TansportEvent
      *
-     * @param transportEvent the transport event
+     * @param message the message
      * @return the message id
+     * @throws MessagingException the operation failed
      */
-    private String getMessageID( TransportEvent transportEvent)
+    private String getMessageId(Message message) throws MessagingException
     {
         String result = "<unknown>";
 
-        if( transportEvent.getMessage() instanceof MimeMessage )
+        if( message instanceof MimeMessage )
         {
-            try
-            {
-                result = ((MimeMessage) transportEvent.getMessage()).getMessageID();
-            }
-            catch (MessagingException e)
-            {
-                String msg = "Unable to retrieve messageID";
-                this.getLogger().warn(msg,e);
-            }
+            result = ((MimeMessage) message).getMessageID();
+        }
+        else
+        {
+            throw new IllegalArgumentException("Don't know how to handle : " + message.getClass());
         }
 
         return result;
@@ -1168,7 +1179,7 @@
      */
     private boolean hasDefaulDomain()
     {
-        return (this.defaultDomainName != null ? true : false );
+        return ( this.defaultDomainName != null );
     }
 
     /**
@@ -1329,7 +1340,9 @@
     }
 
     /**
-     * Creates a meaningful log message for a MimeMessage
+     * Creates a meaningful log message for a MimeMessage.
+     *
+     * @param mimeMessage the mesage to log
      * @return log message
      */
     private String getLogMsg( MimeMessage mimeMessage )
@@ -1366,7 +1379,7 @@
 
     /**
      * Creates a valid file name based on the system time, e.g
-     * "2005-12-28T143216345000
+     * "2005-12-28T143216345-414
      *
      * @param messageId the message id
      * @return a file name
@@ -1374,22 +1387,8 @@
     private synchronized String createMessageFileName(String messageId)
     {
         int currCounter = this.fileNameCounter++ % 1000;
-        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HHmmssSSS");
         String counterString = StringUtils.leftPad( "" + currCounter, 3, '0');
-        String result = dateFormat.format(new Date()) + counterString + ".eml";
-        return result;
-    }
-
-    /**
-     * Creates an absolute path for the given filename based on the application
-     * root directory.
-     *
-     * @param fileName the file name
-     * @return abolsute file
-     */
-    private File makeAbsolutePath( String fileName )
-    {
-        return this.makeAbsolutePath( new File(fileName) );
+        return this.simpleDateFormat.format(new Date()) + "-" + counterString + "." + MIME_MESSAGE_EXTENSION;
     }
 
     /**
@@ -1403,7 +1402,7 @@
     {
         File result = file;
 
-        if( result.isAbsolute() == false )
+        if( !result.isAbsolute() )
         {
             if( file.isDirectory() )
             {
@@ -1418,4 +1417,62 @@
 
         return result;
     }
-}
+
+    /**
+     * Writes a MimeMessage to the given directory.
+     *
+     * @param directory the directory
+     * @param mimeMessage the MimeMessage
+     */
+    protected void writeMimeMessage(File directory, MimeMessage mimeMessage)
+    {
+        File targetDirectory = this.makeAbsolutePath(directory);
+
+        try
+        {
+            String messageId = mimeMessage.getMessageID();
+            String messageFileName = this.createMessageFileName(messageId);
+            targetDirectory.mkdirs();
+            File file = new File(targetDirectory, messageFileName);
+            CommonsEmailUtils.writeMimeMessage(file, mimeMessage);
+            this.getLogger().debug( "Stored the MimeMessage as " + file.getAbsolutePath() );
+        }
+        catch( Throwable t )
+        {
+            String msg = "Failed to store the MimeMessage in " + targetDirectory.getAbsolutePath();
+            this.getLogger().error(msg,t);
+        }
+    }
+
+    /**
+     * Writes a MimeMessage to the given directory.
+     *
+     * @param directory the directory
+     * @param mimeMessage the MimeMessage
+     */
+    protected void writeMimeMessage(String directory, MimeMessage mimeMessage)
+    {
+        this.writeMimeMessage(new File(directory), mimeMessage);
+    }
+
+    private SendDeliveryStatusImpl createSendDeliveryStatus(MimeMessage mimeMessage, boolean isMailDoNotSend)
+        throws MessagingException
+    {
+        SendDeliveryStatusImpl sendDeliveryStatus = new SendDeliveryStatusImpl();
+
+        if(isMailDoNotSend)
+        {
+            sendDeliveryStatus.addSendAddressList(mimeMessage.getAllRecipients());
+        }
+
+        this.sendDeliveryStatusMap.put(mimeMessage, sendDeliveryStatus);
+        return sendDeliveryStatus;
+    }
+
+    private SendDeliveryStatusImpl getSendDeliveryStatus( TransportEvent transportEvent )
+        throws MessagingException
+    {
+        MimeMessage mimeMessage = (MimeMessage) transportEvent.getMessage();
+        return (SendDeliveryStatusImpl) this.getSendDeliveryStatus(mimeMessage);
+    }
+}
\ No newline at end of file

Modified: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java?rev=667474&r1=667473&r2=667474&view=diff
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java (original)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailSmtpConstants.java Fri Jun 13 04:10:29 2008
@@ -19,10 +19,9 @@
  * under the License.
  */
 
-
 /**
  * Contains all SMTP releated session properties for javamail-1.3.3.
- *
+ * 
  * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
  */
 
@@ -34,23 +33,23 @@
     /** The SMTP server to connect to */
     public static final String MAIL_SMTP_HOST = "mail.smtp.host";
 
-    /**
-     * The SMTP server port to connect to, if the connect() method
-     * doesn't explicitly specify one. Defaults to 25
+    /** 	
+     * The SMTP server port to connect to, if the connect() method 
+     * doesn't explicitly specify one. Defaults to 25 
      */
     public static final String MAIL_SMTP_PORT = "mail.smtp.port";
 
-    /**
-     * Socket connection timeout value in milliseconds. Default is
-     * infinite timeout.
+    /** 
+     * Socket connection timeout value in milliseconds. Default is 
+     * infinite timeout. 
      */
     public static final String MAIL_SMTP_CONNECTIONTIMEOUT = "mail.smtp.connectiontimeout";
 
-    /**
-     * Socket I/O timeout value in milliseconds. Default is infinite timeout.
+    /** 
+     * Socket I/O timeout value in milliseconds. Default is infinite timeout. 
      */
     public static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout";
-
+    
     /** Email address to use for SMTP MAIL command */
     public static final String MAIL_SMTP_FROM = "mail.smtp.from";
 
@@ -72,9 +71,9 @@
     /**  The submitter to use in the AUTH tag in the MAIL FROM command */
     public static final String MAIL_SMTP_SUBMITTER = "mail.smtp.submitter";
 
-    /**
-     * The NOTIFY option to the RCPT command. Either NEVER, or some combination of
-     * SUCCESS, FAILURE, and DELAY (separated by commas).
+    /** 
+     * The NOTIFY option to the RCPT command. Either NEVER, or some combination of 
+     * SUCCESS, FAILURE, and DELAY (separated by commas). 
      */
     public static final String MAIL_SMTP_DSN_NOTIFY = "mail.smtp.dsn.notify";
 
@@ -82,17 +81,17 @@
     public static final String MAIL_SMTP_DSN_RET = "mail.smtp.dsn.ret";
 
     /**
-     * If set to true, and the server supports the 8BITMIME extension,
-     * text parts of messages that use the "quoted-printable" or
-     * "base64" encodings are converted to use "8bit" encoding if they
+     * If set to true, and the server supports the 8BITMIME extension, 
+     * text parts of messages that use the "quoted-printable" or 
+     * "base64" encodings are converted to use "8bit" encoding if they 
      * follow the RFC2045 rules for 8bit text.*/
     public static final String MAIL_SMTP_ALLOW8BITMIME = "mail.smtp.allow8bitmime";
 
-    /**
-     * If set to true, and a message has some valid and some invalid
+    /** 
+     * If set to true, and a message has some valid and some invalid 
      * addresses, send the message anyway, reporting the partial failure
-     * with a SendFailedException. If set to false (the default), the
-     * message is not sent to any of the recipients if there is an
+     * with a SendFailedException. If set to false (the default), the 
+     * message is not sent to any of the recipients if there is an 
      * invalid recipient address. */
     public static final String MAIL_SMTP_SENTPARTIAL = "mail.smtp.sendpartial";
 
@@ -103,41 +102,41 @@
     public static final String MAIL_SMTP_QUITWAIT = "mail.smtp.quitwait";
 
     /**
-     * If set to true, causes the transport to include an SMTPAddressSucceededException
-     * for each address that is successful. Note also that this will cause
-     * a SendFailedException to be thrown from the sendMessage method of
-     * SMTPTransport even if all addresses were correct and the message
+     * If set to true, causes the transport to include an SMTPAddressSucceededException 
+     * for each address that is successful. Note also that this will cause 
+     * a SendFailedException to be thrown from the sendMessage method of 
+     * SMTPTransport even if all addresses were correct and the message 
      * was sent successfully.
      */
     public static final String MAIL_SMTP_REPORTSUCCESS = "mail.smtp.reportsuccess";
 
-    /**
-     * If set, specifies the name of a class that implements the
-     * javax.net.SocketFactory interface. This class will be used to create
-     * SMTP sockets.
+    /** 
+     * If set, specifies the name of a class that implements the 
+     * javax.net.SocketFactory interface. This class will be used to create 
+     * SMTP sockets. 
      */
     public static final String MAIL_SMTP_SOCKETFACTORY_CLASS = "mail.smtp.socketFactory.class";
 
-    /**
+    /** 
      *  If set to true, failure to create a socket using the specified
-     *  socket factory class will cause the socket to be created
-     *  using the java.net.Socket class. Defaults to true
+     *  socket factory class will cause the socket to be created 
+     *  using the java.net.Socket class. Defaults to true 
      */
     public static final String MAIL_SMTP_SOCKETFACTORY_FALLBACK = "mail.smtp.socketFactory.fallback";
 
-    /**
-     *  Specifies the port to connect to when using the specified socket factory.
+    /** 
+     *  Specifies the port to connect to when using the specified socket factory. 
      * If not set, the default port will be used.
      */
     public static final String MAIL_SMTP_SOCKETFACTORY_PORT = "mail.smtp.socketFactory.port";
 
     /**
-     * Extension string to append to the MAIL command. The extension string
-     * can be used to specify standard SMTP service extensions as well
-     * as vendor-specific extensions. Typically the application should use
-     * the SMTPTransport method supportsExtension to verify that the server
-     * supports the desired service extension. See RFC 1869 and other RFCs
-     * that define specific extensions.
+     * Extension string to append to the MAIL command. The extension string 
+     * can be used to specify standard SMTP service extensions as well 
+     * as vendor-specific extensions. Typically the application should use 
+     * the SMTPTransport method supportsExtension to verify that the server 
+     * supports the desired service extension. See RFC 1869 and other RFCs 
+     * that define specific extensions.  
      * */
     public static final String MAIL_SMTP_MAILEXTENSION = "mail.smtp.mailextension";
-}
+}
\ No newline at end of file

Added: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailUtils.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailUtils.java?rev=667474&view=auto
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailUtils.java (added)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/CommonsEmailUtils.java Fri Jun 13 04:10:29 2008
@@ -0,0 +1,77 @@
+package org.apache.fulcrum.commonsemail.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import javax.mail.internet.MimeMessage;
+
+/**
+ * Static helper methods.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public class CommonsEmailUtils
+{
+    /**
+     * Convinience method to write a MimeMessage into a file.
+     *
+     * @param resultFile the file containing the MimeMessgae
+     * @param mimeMessage the MimeMessage to write
+     * @throws Exception writing the MimeMessage failed
+     */
+    public static void writeMimeMessage(File resultFile, MimeMessage mimeMessage) throws Exception
+    {
+
+        FileOutputStream fos = null;
+
+        // don't complain about invalid arguments here
+        if( mimeMessage == null || resultFile == null)
+        {
+            return;
+        }
+        
+        try
+        {
+            fos = new FileOutputStream(resultFile);
+            mimeMessage.writeTo(fos);
+            fos.flush();
+            fos.close();
+            fos = null;
+        }
+        finally
+        {
+            if(fos != null)
+            {
+                try
+                {
+                    fos.close();
+                    fos = null;
+                }
+                catch( Exception e )
+                {
+                    // ignore
+                }
+            }
+        }
+    }
+}

Added: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/SendDeliveryStatusImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/SendDeliveryStatusImpl.java?rev=667474&view=auto
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/SendDeliveryStatusImpl.java (added)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/SendDeliveryStatusImpl.java Fri Jun 13 04:10:29 2008
@@ -0,0 +1,144 @@
+package org.apache.fulcrum.commonsemail.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.fulcrum.commonsemail.SendDeliveryStatus;
+
+import javax.mail.Address;
+import javax.mail.event.TransportEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Keep track of the delivery status of a single email.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public class SendDeliveryStatusImpl implements SendDeliveryStatus
+{
+    private List validSentAddressList;
+    private List validUnsentAddressList;
+    private List invalidAddressList;
+
+    /**
+     * Constructor.
+     */
+    SendDeliveryStatusImpl()
+    {
+        this.validSentAddressList = new ArrayList();
+        this.validUnsentAddressList = new ArrayList();
+        this.invalidAddressList = new ArrayList();        
+    }
+
+    /** @see org.apache.fulcrum.commonsemail.SendDeliveryStatus#hasSucceeded()  */
+    public boolean hasSucceeded()
+    {
+        if((this.validSentAddressList.size() > 0) &&
+           (this.validUnsentAddressList.size() == 0) &&
+           (this.invalidAddressList.size() == 0 ))
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    /** @see org.apache.fulcrum.commonsemail.SendDeliveryStatus#getValidSentAddresses()  */
+    public Address[] getValidSentAddresses()
+    {
+        List currList = this.validSentAddressList;
+        return (Address[]) currList.toArray(new Address[currList.size()]);
+    }
+
+    /** @see org.apache.fulcrum.commonsemail.SendDeliveryStatus#getValidUnsentAddresses()  */
+    public Address[] getValidUnsentAddresses()
+    {
+        List currList = this.validUnsentAddressList; 
+        return (Address[]) currList.toArray(new Address[currList.size()]);
+    }
+
+    /** @see org.apache.fulcrum.commonsemail.SendDeliveryStatus#getInvalidAddresses()  */
+    public Address[] getInvalidAddresses()
+    {
+        List currList = this.invalidAddressList; 
+        return (Address[]) currList.toArray(new Address[currList.size()]);
+    }
+
+    /** @see Object#toString() */
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer(128);
+        result.append(this.getClass().getName());
+        result.append('@');
+        result.append(Integer.toHexString(this.hashCode()));
+        result.append(' ');
+        result.append("validSentAddresses:");
+        result.append(this.validSentAddressList.size());
+        result.append(',');
+        result.append("validUnsentAddresses:");
+        result.append(this.validUnsentAddressList.size());
+        result.append(',');
+        result.append("invalidAddresses:");
+        result.append(this.invalidAddressList.size());
+        return result.toString();
+    }
+
+    /**
+     * Store the addresses of the incoming TransportEvents.
+     *
+     * @param transportEvent the transport event
+     */
+    void add( TransportEvent transportEvent )
+    {
+        this.addAddresses(this.validSentAddressList, transportEvent.getValidSentAddresses());
+        this.addAddresses(this.validUnsentAddressList, transportEvent.getValidUnsentAddresses() );
+        this.addAddresses(this.invalidAddressList, transportEvent.getInvalidAddresses());
+    }
+
+    /**
+     * Store the addresses.
+     *
+     * @param sentAddresses of email addresses
+     */
+    void addSendAddressList( Address[] sentAddresses )
+    {
+        this.addAddresses(this.validSentAddressList, sentAddresses);
+    }
+
+    /**
+     * Add a list of addresses to the given target list
+     *
+     * @param target the target list
+     * @param addressList the address list
+     */
+    private void addAddresses(List target, Address[] addressList)
+    {
+        if((addressList != null) && (addressList.length > 0))
+        {
+            for(int i=0; i<addressList.length; i++)
+            {
+                target.add( addressList[i]);
+            }
+        }
+    }
+}

Added: turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/StringUtils.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/StringUtils.java?rev=667474&view=auto
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/StringUtils.java (added)
+++ turbine/fulcrum/trunk/commonsemail/src/java/org/apache/fulcrum/commonsemail/impl/StringUtils.java Fri Jun 13 04:10:29 2008
@@ -0,0 +1,183 @@
+package org.apache.fulcrum.commonsemail.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Taken from commons-lang-2.3 to avoid coupling based on
+ * single convinience methods.
+ *
+ * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
+ */
+
+public class StringUtils
+{
+
+    /**
+     * <p>The maximum size to which the padding constant(s) can expand.</p>
+     */
+    private static final int PAD_LIMIT = 8192;
+
+    // Empty checks
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Checks if a String is empty ("") or null.</p>
+     *
+     * <pre>
+     * StringUtils.isEmpty(null)      = true
+     * StringUtils.isEmpty("")        = true
+     * StringUtils.isEmpty(" ")       = false
+     * StringUtils.isEmpty("bob")     = false
+     * StringUtils.isEmpty("  bob  ") = false
+     * </pre>
+     *
+     * <p>NOTE: This method changed in Lang version 2.0.
+     * It no longer trims the String.
+     * That functionality is available in isBlank().</p>
+     *
+     * @param str  the String to check, may be null
+     * @return <code>true</code> if the String is empty or null
+     */
+    public static boolean isEmpty(String str) {
+        return str == null || str.length() == 0;
+    }
+
+    /**
+     * <p>Returns padding using the specified delimiter repeated
+     * to a given length.</p>
+     *
+     * <pre>
+     * StringUtils.padding(0, 'e')  = ""
+     * StringUtils.padding(3, 'e')  = "eee"
+     * StringUtils.padding(-2, 'e') = IndexOutOfBoundsException
+     * </pre>
+     *
+     * <p>Note: this method doesn't not support padding with
+     * <a href="http://www.unicode.org/glossary/#supplementary_character">Unicode Supplementary Characters</a>
+     * as they require a pair of <code>char</code>s to be represented.
+     * If you are needing to support full I18N of your applications
+     * consider using repeat(String, int)} instead.
+     * </p>
+     *
+     * @param repeat  number of times to repeat delim
+     * @param padChar  character to repeat
+     * @return String with repeated character
+     * @throws IndexOutOfBoundsException if <code>repeat &lt; 0</code>
+     */
+    private static String padding(int repeat, char padChar) throws IndexOutOfBoundsException {
+        if (repeat < 0) {
+            throw new IndexOutOfBoundsException("Cannot pad a negative amount: " + repeat);
+        }
+        final char[] buf = new char[repeat];
+        for (int i = 0; i < buf.length; i++) {
+            buf[i] = padChar;
+        }
+        return new String(buf);
+    }
+
+
+    /**
+     * <p>Left pad a String with a specified character.</p>
+     *
+     * <p>Pad to a size of <code>size</code>.</p>
+     *
+     * <pre>
+     * StringUtils.leftPad(null, *, *)     = null
+     * StringUtils.leftPad("", 3, 'z')     = "zzz"
+     * StringUtils.leftPad("bat", 3, 'z')  = "bat"
+     * StringUtils.leftPad("bat", 5, 'z')  = "zzbat"
+     * StringUtils.leftPad("bat", 1, 'z')  = "bat"
+     * StringUtils.leftPad("bat", -1, 'z') = "bat"
+     * </pre>
+     *
+     * @param str  the String to pad out, may be null
+     * @param size  the size to pad to
+     * @param padChar  the character to pad with
+     * @return left padded String or original String if no padding is necessary,
+     *  <code>null</code> if null String input
+     * @since 2.0
+     */
+    public static String leftPad(String str, int size, char padChar) {
+        if (str == null) {
+            return null;
+        }
+        int pads = size - str.length();
+        if (pads <= 0) {
+            return str; // returns original String when possible
+        }
+        if (pads > PAD_LIMIT ) {
+            return leftPad(str, size, String.valueOf(padChar));
+        }
+        return padding(pads, padChar).concat(str);
+    }
+
+    /**
+     * <p>Left pad a String with a specified String.</p>
+     *
+     * <p>Pad to a size of <code>size</code>.</p>
+     *
+     * <pre>
+     * StringUtils.leftPad(null, *, *)      = null
+     * StringUtils.leftPad("", 3, "z")      = "zzz"
+     * StringUtils.leftPad("bat", 3, "yz")  = "bat"
+     * StringUtils.leftPad("bat", 5, "yz")  = "yzbat"
+     * StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat"
+     * StringUtils.leftPad("bat", 1, "yz")  = "bat"
+     * StringUtils.leftPad("bat", -1, "yz") = "bat"
+     * StringUtils.leftPad("bat", 5, null)  = "  bat"
+     * StringUtils.leftPad("bat", 5, "")    = "  bat"
+     * </pre>
+     *
+     * @param str  the String to pad out, may be null
+     * @param size  the size to pad to
+     * @param padStr  the String to pad with, null or empty treated as single space
+     * @return left padded String or original String if no padding is necessary,
+     *  <code>null</code> if null String input
+     */
+    public static String leftPad(String str, int size, String padStr) {
+        if (str == null) {
+            return null;
+        }
+        if ( isEmpty(padStr)) {
+            padStr = " ";
+        }
+        int padLen = padStr.length();
+        int strLen = str.length();
+        int pads = size - strLen;
+        if (pads <= 0) {
+            return str; // returns original String when possible
+        }
+        if (padLen == 1 && pads <= PAD_LIMIT ) {
+            return leftPad(str, size, padStr.charAt(0));
+        }
+
+        if (pads == padLen) {
+            return padStr.concat(str);
+        } else if (pads < padLen) {
+            return padStr.substring(0, pads).concat(str);
+        } else {
+            char[] padding = new char[pads];
+            char[] padChars = padStr.toCharArray();
+            for (int i = 0; i < pads; i++) {
+                padding[i] = padChars[i % padLen];
+            }
+            return new String(padding).concat(str);
+        }
+    }
+}

Modified: turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml?rev=667474&r1=667473&r2=667474&view=diff
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/commonsemail/src/test/TestComponentConfig.xml Fri Jun 13 04:10:29 2008
@@ -17,7 +17,6 @@
  specific language governing permissions and limitations
  under the License.
 -->
-
 <componentConfig>
 
   <!--
@@ -36,6 +35,7 @@
     domains\domain\mailFromName := the sender name of the email (optional)
     domains\domain\bounceAddress := the bounce address if the email can't be delivered (optional)
     domains\domain\mailDebug := use debuggind mode of javamail (optional)
+    domains\domain\mailCharset := the charset to use for the email (optional)
     domains\domain\mailDump := dump the current MimeMessage into the temp directory (optional)
     domains\domain\mailDoNotSend := skip sending of the email(optional)
     domains\domain\authentication\type := the type of authentication used for sending emails
@@ -92,13 +92,13 @@
         </overwrites>
         <hooks>
           <onSuccess enabled="true">
-            <directory>./temp/archive/out/eml</directory>
+            <directory>./target/archive/out/eml</directory>
           </onSuccess>
           <onFailure enabled="true">
-            <directory>./temp/archive/broken/eml</directory>
+            <directory>./target/archive/broken/eml</directory>
           </onFailure>
           <onNotSend enabled="true">
-            <directory>./temp/archive/broken/eml</directory>
+            <directory>./target/archive/broken/eml</directory>
           </onNotSend>
         </hooks>
       </domain>
@@ -106,6 +106,8 @@
         <domainName>it20one.at</domainName>
         <mailSmtpHost>localhost</mailSmtpHost>
         <mailSmtpPort>6025</mailSmtpPort>
+        <mailFromEmail>demo@it20one.at</mailFromEmail>
+        <mailFromName>E-Billing Test</mailFromName>
         <mailDoNotSend>true</mailDoNotSend>
         <authentication>
           <type>smtpauth</type>

Modified: turbine/fulcrum/trunk/commonsemail/src/test/TestRoleConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/commonsemail/src/test/TestRoleConfig.xml?rev=667474&r1=667473&r2=667474&view=diff
==============================================================================
--- turbine/fulcrum/trunk/commonsemail/src/test/TestRoleConfig.xml (original)
+++ turbine/fulcrum/trunk/commonsemail/src/test/TestRoleConfig.xml Fri Jun 13 04:10:29 2008
@@ -17,7 +17,6 @@
  specific language governing permissions and limitations
  under the License.
 -->
-
 <role-list>
   <role
     name="org.apache.fulcrum.commonsemail.CommonsEmailService"
@@ -25,5 +24,5 @@
     default-class="org.apache.fulcrum.commonsemail.impl.CommonsEmailServiceImpl"
     early-init="true"
     description="Simplifies the usage of commons-email"
-  />
-</role-list>
+  />        
+</role-list>
\ No newline at end of file



Mime
View raw message