Author: davsclaus
Date: Sun Oct 12 02:47:06 2008
New Revision: 703775
URL: http://svn.apache.org/viewvc?rev=703775&view=rev
Log:
CAMEL-978: Added type converters from Mail Messages to InputStream
Modified:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
Modified:
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java?rev=703775&r1=703774&r2=703775&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
(original)
+++
activemq/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
Sun Oct 12 02:47:06 2008
@@ -17,6 +17,7 @@
package org.apache.camel.component.mail;
import java.io.IOException;
+import java.io.InputStream;
import javax.mail.BodyPart;
import javax.mail.Message;
@@ -25,6 +26,7 @@
import javax.mail.internet.MimeMultipart;
import org.apache.camel.Converter;
+import org.apache.camel.converter.IOConverter;
/**
* JavaMail specific converters.
@@ -39,7 +41,7 @@
* Can return null.
*/
@Converter
- public String toString(Message message) throws MessagingException,
IOException {
+ public static String toString(Message message) throws MessagingException,
IOException {
Object content = message.getContent();
if (content instanceof MimeMultipart) {
MimeMultipart multipart = (MimeMultipart) content;
@@ -69,4 +71,31 @@
}
return null;
}
+
+ /**
+ * Converts the given JavaMail message to an InputStream.
+ * Can return null.
+ */
+ @Converter
+ public static InputStream toInputStream(Message message) throws
IOException, MessagingException {
+ String s = toString(message);
+ if (s == null) {
+ return null;
+ }
+ return IOConverter.toInputStream(s);
+ }
+
+ /**
+ * Converts the given JavaMail multipart to a InputStream body, where the
contenttype of the multipart
+ * must be text based (ie start with text). Can return null.
+ */
+ @Converter
+ public static InputStream toInputStream(Multipart multipart) throws
IOException, MessagingException {
+ String s = toString(multipart);
+ if (s == null) {
+ return null;
+ }
+ return IOConverter.toInputStream(s);
+ }
+
}