1 10 11 package org.mule.providers.email.transformers; 12 13 import javax.mail.Message ; 14 import javax.mail.internet.MimeMultipart ; 15 16 import org.mule.transformers.AbstractTransformer; 17 import org.mule.umo.transformer.TransformerException; 18 19 23 public class EmailMessageToString extends AbstractTransformer 24 { 25 28 private static final long serialVersionUID = 8940364998861971795L; 29 30 public EmailMessageToString() 31 { 32 registerSourceType(Message .class); 33 registerSourceType(String .class); 34 setReturnClass(String .class); 35 } 36 37 42 public Object doTransform(Object src, String encoding) throws TransformerException 43 { 44 Message msg = (Message )src; 45 try 46 { 47 55 Object result = msg.getContent(); 57 if (result instanceof String ) 58 { 59 return result; 60 } 61 else 62 { 63 MimeMultipart part = (MimeMultipart )result; 65 String transMsg = (String )part.getBodyPart(0).getContent(); 66 return transMsg; 67 } 68 } 69 catch (Exception e) 70 { 71 throw new TransformerException(this, e); 72 } 73 } 74 } 75 | Popular Tags |