Coverage Report - org.mule.providers.email.transformers.EmailMessageToString
 
Classes in this File Line Coverage Branch Coverage Complexity
EmailMessageToString
0%
0/13
0%
0/3
3.5
 
 1  
 /*
 2  
  * $Id: EmailMessageToString.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.providers.email.transformers;
 12  
 
 13  
 import org.mule.transformers.AbstractTransformer;
 14  
 import org.mule.umo.transformer.TransformerException;
 15  
 
 16  
 import javax.mail.Message;
 17  
 import javax.mail.internet.MimeMultipart;
 18  
 
 19  
 /**
 20  
  * <code>EmailMessageToString</code> extracts a java mail Message contents and
 21  
  * returns a string.
 22  
  */
 23  
 public class EmailMessageToString extends AbstractTransformer
 24  
 {
 25  
 
 26  
     public EmailMessageToString()
 27  0
     {
 28  0
         registerSourceType(Message.class);
 29  0
         setReturnClass(String.class);
 30  0
     }
 31  
 
 32  
     /*
 33  
      * (non-Javadoc)
 34  
      * 
 35  
      * @see org.mule.transformers.AbstractTransformer#doTransform(java.lang.Object)
 36  
      */
 37  
     public Object doTransform(Object src, String encoding) throws TransformerException
 38  
     {
 39  0
         Message msg = (Message) src;
 40  
         try
 41  
         {
 42  
             /*
 43  
              * Other information about the message such as cc addresses, attachments
 44  
              * are handled by the mail message adapter. If Transformers need access
 45  
              * to these properties they should extends from
 46  
              * AbstractEventAwareTransformer and extract these properties from the
 47  
              * passed UMOEventContext
 48  
              */
 49  
 
 50  
             // For this impl we just pass back the email content
 51  0
             Object result = msg.getContent();
 52  0
             if (result instanceof String)
 53  
             {
 54  0
                 return result;
 55  
             }
 56  
             else
 57  
             {
 58  
                 // very simplisitic, only gets first part
 59  0
                 MimeMultipart part = (MimeMultipart)result;
 60  0
                 String transMsg = (String) part.getBodyPart(0).getContent();
 61  0
                 return transMsg;
 62  
             }
 63  
         }
 64  0
         catch (Exception e)
 65  
         {
 66  0
             throw new TransformerException(this, e);
 67  
         }
 68  
     }
 69  
 }