Coverage Report - org.mule.providers.email.transformers.Rfc822ByteArraytoMimeMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
Rfc822ByteArraytoMimeMessage
0%
0/14
0%
0/4
3.333
 
 1  
 /*
 2  
  * $Id: Rfc822ByteArraytoMimeMessage.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.providers.email.AbstractMailConnector;
 14  
 import org.mule.transformers.AbstractTransformer;
 15  
 import org.mule.umo.provider.UMOConnector;
 16  
 import org.mule.umo.transformer.TransformerException;
 17  
 
 18  
 import java.io.ByteArrayInputStream;
 19  
 
 20  
 import javax.mail.MessagingException;
 21  
 import javax.mail.Session;
 22  
 import javax.mail.internet.MimeMessage;
 23  
 
 24  
 public class Rfc822ByteArraytoMimeMessage extends AbstractTransformer
 25  
 {
 26  
 
 27  
     public Rfc822ByteArraytoMimeMessage()
 28  0
     {
 29  0
         registerSourceType(byte[].class);
 30  0
         setReturnClass(MimeMessage.class);
 31  0
     }
 32  
 
 33  
     protected Object doTransform(Object src, String encoding) throws TransformerException
 34  
     {
 35  
         try
 36  
         {
 37  0
             byte[] bytes = (byte[]) src;
 38  0
             return new MimeMessage(getSession(), new ByteArrayInputStream(bytes));
 39  
         }
 40  0
         catch (MessagingException e)
 41  
         {
 42  0
             throw new TransformerException(this, e);
 43  
         }
 44  
     }
 45  
 
 46  
     protected Session getSession() throws TransformerException
 47  
     {
 48  0
         if (null == endpoint)
 49  
         {
 50  0
             throw new TransformerException(this,
 51  
                     new IllegalStateException("The transformer is no associated with an endpoint."));
 52  
         }
 53  0
         UMOConnector connector = endpoint.getConnector();
 54  0
         if (!(connector instanceof AbstractMailConnector))
 55  
         {
 56  0
             throw new TransformerException(this,
 57  
                     new IllegalStateException("The transformer is not associated with an email endpoint."));
 58  
         }
 59  0
         return ((AbstractMailConnector) connector).getSessionDetails(endpoint).getSession();
 60  
     }
 61  
 
 62  
 }