You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/06/11 07:46:30 UTC

svn commit: r783638 - /camel/branches/camel-1.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java

Author: davsclaus
Date: Thu Jun 11 05:46:30 2009
New Revision: 783638

URL: http://svn.apache.org/viewvc?rev=783638&view=rev
Log:
CAMEL-1645: Fixed setting Content-Type for multipart messages as well.

Modified:
    camel/branches/camel-1.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java

Modified: camel/branches/camel-1.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=783638&r1=783637&r2=783638&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java (original)
+++ camel/branches/camel-1.x/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java Thu Jun 11 05:46:30 2009
@@ -341,11 +341,34 @@
 
     protected void addBodyToMultipart(org.apache.camel.Message camelMessage, MailConfiguration configuration, MimeMultipart activeMultipart) throws MessagingException {
         BodyPart bodyMessage = new MimeBodyPart();
-        bodyMessage.setContent(camelMessage.getBody(String.class), configuration.getContentType());
+
+        // determine the content type
+        String contentType = configuration.getContentType();
+        if (camelMessage.getHeader("contentType") != null) {
+            contentType = camelMessage.getHeader("contentType", String.class);
+        }
+
+        // set the content according to the content type
+        if (contentType == null) {
+            bodyMessage.setText(camelMessage.getBody(String.class));
+        } else if (contentType.startsWith("text/plain")) {
+            bodyMessage.setText(camelMessage.getBody(String.class));
+            bodyMessage.setHeader("Content-Type", contentType);
+        } else {
+            // store content in a byte array data store
+            DataSource ds;
+            try {
+                ds = new ByteArrayDataSource(camelMessage.getBody(String.class), contentType);
+            } catch (IOException e) {
+                throw new MessagingException("Cannot create DataSource", e);
+            }
+            bodyMessage.setDataHandler(new DataHandler(ds));
+            bodyMessage.setHeader("Content-Type", contentType);
+        }
+
         activeMultipart.addBodyPart(bodyMessage);
     }
 
-
     /**
      * Strategy to allow filtering of attachments which are put on the Mail message
      *