commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott <sc...@minutestopost.com>
Subject Re: [mail] html email with attachments
Date Tue, 31 Aug 2004 14:56:32 GMT
Hi,

Leandro Rodrigo Saad Cruz wrote:
> You don't have to commit it.. just send the new patch against CVS HEAD
> to the list !
> 

Sorry if I'm missing something here, but I thought the patch I sent was against HEAD (rev.
1.6).

Scott

[scott@localhost mail]$ cat CVS/Tag
NHEAD
[scott@localhost mail]$ patch < mp.patch
patching file MultiPartEmail.java
[scott@localhost mail]$ cvs diff -u MultiPartEmail.java
Index: MultiPartEmail.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/MultiPartEmail.java,v
retrieving revision 1.6
diff -u -r1.6 MultiPartEmail.java
--- MultiPartEmail.java 19 Feb 2004 22:38:07 -0000      1.6
+++ MultiPartEmail.java 31 Aug 2004 14:45:40 -0000
@@ -52,6 +52,9 @@
      /** The message container. */
      private MimeBodyPart primaryBodyPart = null;

+    /** The MIME subtype. */
+    private String subType = null;
+
      /** Indicates if the message has been initialized */
      private boolean initialized = false;

@@ -70,14 +73,57 @@
          container = new MimeMultipart();
          super.setContent(container);

-        // Add the first body part to the message.  The fist body part must be
-        primaryBodyPart = new MimeBodyPart();
-        container.addBodyPart(primaryBodyPart);
-
          initialized = true;
      }

      /**
+     * Set the MIME subtype of the email.
+     */
+    public void setSubType(String subType)
+    {
+        this.subType = subType;
+    }
+
+    /**
+     * Get the MIME subtype of the email.
+     */
+    public String getSubType()
+    {
+        return subType;
+    }
+
+    /**
+     * Add a new part to the email.
+     * @param content The content.
+     * @param contentType The content type.
+     * @return An Email.
+     * @exception MessagingException
+     */
+    public Email addPart(String content, String contentType) throws MessagingException
+    {
+        MimeBodyPart bodyPart = new MimeBodyPart();
+        bodyPart.setContent(content, contentType);
+        getContainer().addBodyPart(bodyPart);
+
+        return this;
+    }
+
+    /**
+     * Add a new part to the email.
+     * @param part The MimeMultipart.
+     * @return An Email.
+     * @exception MessagingException
+     */
+    public Email addPart(MimeMultipart multipart) throws MessagingException
+    {
+        MimeBodyPart bodyPart = new MimeBodyPart();
+        bodyPart.setContent(multipart);
+        getContainer().addBodyPart(bodyPart);
+
+        return this;
+    }
+
+    /**
       * Set the message of the email.
       *
       * @param msg A String.
@@ -104,24 +150,33 @@
       */
      public void send() throws MessagingException
      {
-        // before a multipart message can be sent, we must make sure that
-        // the content for the main body part was actually set.  If not,
-        // an IOException will be thrown during super.send().
-
-        MimeBodyPart body = this.getPrimaryBodyPart();
-        Object content = null;
-        try
-        {
-            content = body.getContent();
-        }
-        catch (IOException e)
+        if (primaryBodyPart != null)
          {
-            // do nothing here.  content will be set to an empty string
-            // as a result.
+            // before a multipart message can be sent, we must make sure that
+            // the content for the main body part was actually set.  If not,
+            // an IOException will be thrown during super.send().
+
+            MimeBodyPart body = this.getPrimaryBodyPart();
+            Object content = null;
+            try
+            {
+                content = body.getContent();
+            }
+            catch (IOException e)
+            {
+                // do nothing here.  content will be set to an empty string
+                // as a result.
+            }
+
+            if (content == null)
+            {
+                body.setContent("", TEXT_PLAIN);
+            }
          }
-        if(content == null)
+
+        if (subType != null)
          {
-            body.setContent("", TEXT_PLAIN);
+            getContainer().setSubType(subType);
          }

          super.send();
@@ -259,6 +314,13 @@
          if(!initialized) {
              init();
          }
+
+        if (primaryBodyPart == null)
+        {
+            primaryBodyPart = new MimeBodyPart();
+            container.addBodyPart(primaryBodyPart);
+        }
+
          return primaryBodyPart;
      }

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


Mime
View raw message