epugh 2004/10/24 10:27:21 Modified: email/src/java/org/apache/commons/mail MultiPartEmail.java email/xdocs changes.xml Log: Bug 30973 HTML email with plain text alternative and attachments Revision Changes Path 1.7 +85 -18 jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/MultiPartEmail.java Index: MultiPartEmail.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/MultiPartEmail.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- MultiPartEmail.java 19 Feb 2004 22:38:07 -0000 1.6 +++ MultiPartEmail.java 24 Oct 2004 17:27:21 -0000 1.7 @@ -52,10 +52,62 @@ /** 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; /** + * 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; + } + + + /** * Initialize the multipart email. * * @exception MessagingException @@ -104,25 +156,34 @@ */ 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 (subType != null) + { + getContainer().setSubType(subType); + } + } - if(content == null) + if (subType != null) { - body.setContent("", TEXT_PLAIN); - } + getContainer().setSubType(subType); + } super.send(); } @@ -258,7 +319,13 @@ { if(!initialized) { init(); - } + } + + if (primaryBodyPart == null) + { + primaryBodyPart = new MimeBodyPart(); + container.addBodyPart(primaryBodyPart); + } return primaryBodyPart; } 1.4 +3 -0 jakarta-commons-sandbox/email/xdocs/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/email/xdocs/changes.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- changes.xml 24 Oct 2004 17:10:09 -0000 1.3 +++ changes.xml 24 Oct 2004 17:27:21 -0000 1.4 @@ -7,6 +7,9 @@ <body> <release version="1.0" date="IN CVS"> + <action dev="epugh" type="add" issue="30973" due-to="Corey Scott"> + HTML email with plain text alternative and attachments + </action> <action dev="epugh" type="add" issue="31762" due-to="Corey Scott"> Integrate use of Dumbster to supply a fake SMTP server. </action>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]