Author: jstrachan
Date: Tue May  1 03:47:51 2007
New Revision: 534002

URL: http://svn.apache.org/viewvc?view=rev&rev=534002
Log:
added converter from JavaMail message to String

Added:
    
activemq/camel/trunk/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
   (with props)
    
activemq/camel/trunk/camel-mail/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
Modified:
    
activemq/camel/trunk/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java

Added: 
activemq/camel/trunk/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java?view=auto&rev=534002
==============================================================================
--- 
activemq/camel/trunk/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
 (added)
+++ 
activemq/camel/trunk/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
 Tue May  1 03:47:51 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mail;
+
+import org.apache.camel.Converter;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.BodyPart;
+import javax.mail.internet.MimeMultipart;
+import java.io.IOException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
[EMAIL PROTECTED]
+public class MailConverters {
+    /**
+     * Converts the given JavaMail message to a String body
+     *
+     * @param message the message
+     * @return the String content
+     * @throws MessagingException
+     * @throws IOException
+     */
+    @Converter
+    public String toString(Message message) throws MessagingException, 
IOException {
+        Object content = message.getContent();
+        if (content instanceof MimeMultipart) {
+            MimeMultipart multipart = (MimeMultipart) content;
+            if (multipart.getCount() > 0) {
+                BodyPart part = multipart.getBodyPart(0);
+                content = part.getContent();
+            }
+        }
+        if (content != null) {
+            return content.toString();
+        }
+        return null;
+    }
+}

Propchange: 
activemq/camel/trunk/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
activemq/camel/trunk/camel-mail/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mail/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?view=auto&rev=534002
==============================================================================
--- 
activemq/camel/trunk/camel-mail/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
 (added)
+++ 
activemq/camel/trunk/camel-mail/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
 Tue May  1 03:47:51 2007
@@ -0,0 +1 @@
+org.apache.camel.component.mail
\ No newline at end of file

Modified: 
activemq/camel/trunk/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java?view=diff&rev=534002&r1=534001&r2=534002
==============================================================================
--- 
activemq/camel/trunk/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
 (original)
+++ 
activemq/camel/trunk/camel-mail/src/test/java/org/apache/camel/component/mail/MailRouteTest.java
 Tue May  1 03:47:51 2007
@@ -39,7 +39,7 @@
 
     public void testSendAndReceiveMails() throws Exception {
         resultEndpoint = (MockEndpoint) 
resolveMandatoryEndpoint("mock:result");
-        resultEndpoint.expectedMessageCount(1);
+        resultEndpoint.expectedBodiesReceived("hello world!");
 
         client.send("smtp://[EMAIL PROTECTED]", new Processor<Exchange>() {
             public void process(Exchange exchange) {
@@ -71,7 +71,7 @@
             public void configure() {
                 from("smtp://[EMAIL PROTECTED]").to("queue:a");
                 from("queue:a").to("smtp://[EMAIL PROTECTED]", "smtp://[EMAIL 
PROTECTED]");
-                from("smtp://[EMAIL PROTECTED]").to("mock:result");
+                from("smtp://[EMAIL 
PROTECTED]").convertBodyTo(String.class).to("mock:result");
             }
         };
     }


Reply via email to