servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r390209 - in /incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email: MailMarshalerSupport.java MimeMailMarshaler.java
Date Thu, 30 Mar 2006 18:32:47 GMT
Author: gnodet
Date: Thu Mar 30 10:32:45 2006
New Revision: 390209

URL: http://svn.apache.org/viewcvs?rev=390209&view=rev
Log:
SM-373: Add support to MimeMailSender for multipart/alternative email
Patch provided by Marc Tremblay, thx !

Modified:
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
    incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java?rev=390209&r1=390208&r2=390209&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
Thu Mar 30 10:32:45 2006
@@ -47,6 +47,7 @@
     private Expression bcc = new PropertyExpression("org.apache.servicemix.email.bcc");
     private Expression from = new PropertyExpression("org.apache.servicemix.email.from",
"noone@servicemix.org");
     private Expression text = new PropertyExpression("org.apache.servicemix.email.text");
+    private Expression html = new PropertyExpression("org.apache.servicemix.email.html");
     private Expression subject = new PropertyExpression("org.apache.servicemix.email.subject",
"Message from ServiceMix");
     private Expression replyTo = new PropertyExpression("org.apache.servicemix.email.replyTo");
     private Expression sentDate = new PropertyExpression("org.apache.servicemix.email.sentDate");
@@ -90,6 +91,14 @@
     public void setText(Expression text) {
         this.text = text;
     }
+    
+    public Expression getHtml() {
+        return html;
+    }
+
+    public void setHtml(Expression html) {
+        this.html = html;
+    }
 
     public Expression getSubject() {
         return subject;
@@ -143,6 +152,10 @@
             }
         }
         return text;
+    }
+    
+    protected String getHtml(MessageExchange exchange, NormalizedMessage normalizedMessage)
throws MessagingException, TransformerException {
+        return (this.html != null) ? asString(this.html.evaluate(exchange, normalizedMessage))
: null;
     }
 
     protected Address asAddress(Object value) throws AddressException {

Modified: incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java?rev=390209&r1=390208&r2=390209&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
(original)
+++ incubator/servicemix/trunk/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
Thu Mar 30 10:32:45 2006
@@ -25,7 +25,9 @@
 import javax.mail.Message;
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
 import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
 import javax.xml.transform.TransformerException;
 
 import org.apache.servicemix.jbi.jaxp.StringSource;
@@ -103,8 +105,20 @@
                 mimeMessage.setFrom(from);
             }
             String text = getText(exchange, normalizedMessage);
-            if (text != null) {
+            String html = getHtml(exchange, normalizedMessage);
+            if ((text != null) && (html == null)) {
                 mimeMessage.setText(text);
+            }
+            else if ((text != null) && (html != null)) {
+                MimeMultipart content = new MimeMultipart("alternative");
+                MimeBodyPart textBodyPart = new MimeBodyPart();
+                MimeBodyPart htmlBodyPart = new MimeBodyPart();
+                textBodyPart.setText(text);
+                htmlBodyPart.setContent(html, "text/html");
+                content.addBodyPart(textBodyPart);
+                content.addBodyPart(htmlBodyPart);
+                
+                mimeMessage.setContent(content);
             }
             String subject = getSubject(exchange, normalizedMessage);
             if (subject != null) {



Mime
View raw message