commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject svn commit: r264911 - in /jakarta/commons/proper/email/trunk: src/java/org/apache/commons/mail/MultiPartEmail.java xdocs/changes.xml
Date Wed, 31 Aug 2005 01:30:33 GMT
Author: epugh
Date: Tue Aug 30 18:30:28 2005
New Revision: 264911

URL: http://svn.apache.org/viewcvs?rev=264911&view=rev
Log:
Bug 34056 Improve MultiPartEmail to ease extending

Modified:
    jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
    jakarta/commons/proper/email/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java?rev=264911&r1=264910&r2=264911&view=diff
==============================================================================
--- jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
(original)
+++ jakarta/commons/proper/email/trunk/src/java/org/apache/commons/mail/MultiPartEmail.java
Tue Aug 30 18:30:28 2005
@@ -19,13 +19,17 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
 import javax.activation.FileDataSource;
 import javax.activation.URLDataSource;
+import javax.mail.BodyPart;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMultipart;
+import javax.mail.internet.MimePart;
+
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -53,7 +57,7 @@
     private MimeMultipart container;
 
     /** The message container. */
-    private MimeBodyPart primaryBodyPart;
+    private BodyPart primaryBodyPart = null;
 
     /** The MIME subtype. */
     private String subType;
@@ -99,7 +103,7 @@
     public Email addPart(String partContent, String partContentType)
         throws EmailException
     {
-        MimeBodyPart bodyPart = new MimeBodyPart();
+    	    BodyPart bodyPart = createBodyPart();
         try
         {
             bodyPart.setContent(partContent, partContentType);
@@ -145,7 +149,7 @@
      */
     public Email addPart(MimeMultipart multipart, int index) throws EmailException
     {
-        MimeBodyPart bodyPart = new MimeBodyPart();
+    	    BodyPart bodyPart = createBodyPart();
         try
         {
             bodyPart.setContent(multipart);
@@ -170,7 +174,7 @@
             throw new IllegalStateException("Already initialized");
         }
 
-        container = new MimeMultipart();
+        container = createMimeMultipart();
         super.setContent(container);
 
         initialized = true;
@@ -196,7 +200,13 @@
         {
             if (StringUtils.isNotEmpty(charset))
             {
-                getPrimaryBodyPart().setText(msg, charset);
+                BodyPart primary = getPrimaryBodyPart();
+
+                if ((primary instanceof MimePart) && StringUtils.isNotEmpty(charset))
{
+                    ((MimePart) primary).setText(msg, charset);
+                } else {
+                    primary.setText(msg);
+                }
             }
             else
             {
@@ -227,7 +237,7 @@
                 // the content for the main body part was actually set.  If not,
                 // an IOException will be thrown during super.send().
 
-                MimeBodyPart body = this.getPrimaryBodyPart();
+            	   BodyPart body = this.getPrimaryBodyPart();
                 try
                 {
                     body.getContent();
@@ -419,21 +429,21 @@
         {
             name = ds.getName();
         }
-        MimeBodyPart mbp = new MimeBodyPart();
+        BodyPart bodyPart = createBodyPart();
         try
         {
-            getContainer().addBodyPart(mbp);
+            getContainer().addBodyPart(bodyPart);
 
-            mbp.setDisposition(disposition);
-            mbp.setFileName(name);
-            mbp.setDescription(description);
-            mbp.setDataHandler(new DataHandler(ds));
+            bodyPart.setDisposition(disposition);
+            bodyPart.setFileName(name);
+            bodyPart.setDescription(description);
+            bodyPart.setDataHandler(new DataHandler(ds));
         }
         catch (MessagingException me)
         {
             throw new EmailException(me);
         }
-        this.boolHasAttachments = true;
+        setBoolHasAttachments(true);
 
         return this;
     }
@@ -445,7 +455,7 @@
      * @throws MessagingException An error occured while getting the primary body part.
      * @since 1.0
      */
-    protected MimeBodyPart getPrimaryBodyPart() throws MessagingException
+    protected BodyPart getPrimaryBodyPart() throws MessagingException
     {
         if (!initialized)
         {
@@ -455,7 +465,7 @@
         // Add the first body part to the message.  The fist body part must be
         if (this.primaryBodyPart == null)
         {
-            primaryBodyPart = new MimeBodyPart();
+            primaryBodyPart = createBodyPart();
             getContainer().addBodyPart(primaryBodyPart, 0);
         }
 
@@ -477,7 +487,26 @@
         return container;
     }
 
-
+    /**
+     * Method that can be overridden if you don't
+     * want to create a MimeBodyPart.
+     * @return
+     */
+    protected BodyPart createBodyPart()
+    {
+        BodyPart bodyPart = new MimeBodyPart();
+        return bodyPart;
+    }
+    /**
+     * 
+     * @return 
+     */
+    protected MimeMultipart createMimeMultipart()
+    {
+        MimeMultipart mmp = new MimeMultipart();
+        return mmp;
+    }
+    
     /**
      * @return boolHasAttachments
      * @since 1.0
@@ -495,4 +524,23 @@
     {
         boolHasAttachments = b;
     }
+    
+    /**
+     * 
+     * @return
+     */
+    protected boolean isInitialized()
+    {
+        return initialized;
+    }
+    
+    /**
+     * 
+     * @param b
+     */
+    protected void setInitialized(boolean b)
+    {
+        initialized = b;
+    }
+
 }

Modified: jakarta/commons/proper/email/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/xdocs/changes.xml?rev=264911&r1=264910&r2=264911&view=diff
==============================================================================
--- jakarta/commons/proper/email/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/email/trunk/xdocs/changes.xml Tue Aug 30 18:30:28 2005
@@ -22,6 +22,9 @@
 
   <body>
     <release version="1.0-rc6-SNAPSHOT" date="IN Subversion">
+      <action dev="epugh" type="update" due-to="Troy Poppe" issue="34056">
+        Improve MultiPartEmail to ease extending it.
+      </action>
       <action dev="sgoeschl" type="update">
         Refactoring the code to seperate creation of a MimeMessage and sending it.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message