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/17 12:54:19 UTC
svn commit: r785549 -
/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
Author: davsclaus
Date: Wed Jun 17 10:54:18 2009
New Revision: 785549
URL: http://svn.apache.org/viewvc?rev=785549&view=rev
Log:
CAMEL-1724: Always use a ByteArrayDataSource for mail content to avoid all kind of content type and charset issues.
Modified:
camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
Modified: camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java?rev=785549&r1=785548&r2=785549&view=diff
==============================================================================
--- camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java (original)
+++ camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailBinding.java Wed Jun 17 10:54:18 2009
@@ -127,40 +127,35 @@
protected String populateContentOnMimeMessage(MimeMessage part, MailConfiguration configuration, Exchange exchange) throws MessagingException, IOException {
String contentType = determineContentType(configuration, exchange);
- if (contentType == null) {
- part.setText(exchange.getIn().getBody(String.class));
- } else {
- if (contentType.startsWith("text/plain")) {
- String charset = ObjectHelper.after(contentType, "charset=");
- if (charset != null) {
- part.setText(exchange.getIn().getBody(String.class), charset.trim());
- } else {
- part.setText(exchange.getIn().getBody(String.class));
- }
- } else {
- // store content in a byte array data store
- DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
- part.setDataHandler(new DataHandler(ds));
- }
- part.setHeader("Content-Type", contentType);
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Using Content-Type " + contentType + " for MimeMessage: " + part);
}
+
+ // always store content in a byte array data store to avoid various content type and charset issues
+ DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
+ part.setDataHandler(new DataHandler(ds));
+
+ // set the content type header afterwards
+ part.setHeader("Content-Type", contentType);
+
return contentType;
}
protected String populateContentOnBodyPart(BodyPart part, MailConfiguration configuration, Exchange exchange) throws MessagingException, IOException {
String contentType = determineContentType(configuration, exchange);
- if (contentType == null) {
- part.setText(exchange.getIn().getBody(String.class));
- } else {
- if (contentType.startsWith("text/plain")) {
- part.setText(exchange.getIn().getBody(String.class));
- } else {
- // store content in a byte array data store
- DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
- part.setDataHandler(new DataHandler(ds));
- }
- part.setHeader("Content-Type", contentType);
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Using Content-Type " + contentType + " for BodyPart: " + part);
}
+
+ // always store content in a byte array data store to avoid various content type and charset issues
+ DataSource ds = new ByteArrayDataSource(exchange.getIn().getBody(String.class), contentType);
+ part.setDataHandler(new DataHandler(ds));
+
+ // set the content type header afterwards
+ part.setHeader("Content-Type", contentType);
+
return contentType;
}