title: How to pass mail attachment to POJO object with MULE ESB
body: <p>I'm trying to pass mail attachments from IMAP inbound endpoint to a JAVA component but it fails. The error message says "Message payload is of type: MimeBodyPart$MimePartDataHandler".</p>
  
  <p>The files in the attachments are Excel-files and I'm able to connect a Indound File endpoint but I want to use a IMAP endpoint instead.</p>
  
  <p>How to get the message passed to the JAVA component of the typw FILE?</p>
  
  <p>Here's my Mule config:</p>
  
  <pre><code>&lt;flow name="imaptestflow" doc:name="imaptestflow"&gt;
      &lt;imap:inbound-endpoint user="XXXXXXXX"
          password="XXXXX" host="XXXXXXX" port="143" doc:name="IMAP" disableTransportTransformer="true"/&gt;
      &lt;expression-transformer evaluator="attachments-list" expression="*.xls" doc:name="Expression"/&gt;
  
      &lt;collection-splitter doc:name="Collection Splitter"/&gt;
      &lt;all doc:name="All"&gt;
          &lt;processor-chain&gt;
              &lt;component class="xlsFileRead" doc:name="Java"/&gt;
          &lt;/processor-chain&gt;
          &lt;processor-chain&gt;
              &lt;file:outbound-endpoint path="c:\out" outputPattern="#[groovy:payload.getName()]" doc:name="File"/&gt;
          &lt;/processor-chain&gt;
      &lt;/all&gt;
  &lt;/flow&gt;
  </code></pre>
  
  <p></p>
  
  <p>The Java-Class is:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import java.util.List;
  import jxl.Cell;
  import jxl.CellType;
  import jxl.Sheet;
  import jxl.Workbook;
  import jxl.read.biff.BiffException;
  public class xlsFileRead {
  public void readFromFile(Object input)throws IOException  {
          Workbook w;
          try {
            w = Workbook.getWorkbook((File)input);
            // Get the first sheet
            Sheet sheet = w.getSheet(0);
            // Loop over first 10 column and lines
            for (int i = 5; i &lt; sheet.getRows(); i++) {
            for (int j = 0; j &lt; sheet.getColumns(); j++) {
                Cell cell = sheet.getCell(j, i);
                CellType type = cell.getType();
                if (type == CellType.LABEL) {
                  System.out.print(cell.getContents() + ";");
                }
                if (type == CellType.NUMBER) {
                  System.out.print(cell.getContents() + ";");
                }
              }
            System.out.println(i);
            }
          } catch (BiffException e) {
            e.printStackTrace();
          }
  }
  }
  </code></pre>
  
  <p>And the Exception from the Mule console is:</p>
  
  <pre><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  + Started app 'imaptest'                                   +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  INFO  2013-03-03 19:35:17,592 [[imaptest].imaptestflow.stage1.02] org.mule.api.processor.LoggerMessageProcessor: [rtdata2.xls, rtdata.xlsx]
  INFO  2013-03-03 19:35:17,598 [[imaptest].imaptestflow.stage1.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.file.mule.default.dispatcher.1635258243'. Object is: FileMessageDispatcher
  INFO  2013-03-03 19:35:17,598 [[imaptest].imaptestflow.stage1.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.file.mule.default.dispatcher.1635258243'. Object is: FileMessageDispatcher
  INFO  2013-03-03 19:35:17,601 [[imaptest].imaptestflow.stage1.02] org.mule.transport.file.FileConnector: Writing file to: C:\OUT\18a0c736-8431-11e2-b133-e9e7c6fca1c6rtdata2.xls
  ERROR 2013-03-03 19:35:17,674 [[imaptest].imaptestflow.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
  ********************************************************************************
  Message               : Component that caused exception is: DefaultJavaComponent{imaptestflow.commponent.569080239}. Message payload is of type: MimeBodyPart$MimePartDataHandler
  Code                  : MULE_ERROR--2
  --------------------------------------------------------------------------------
  Exception stack is:
      1. javax.mail.internet.MimeBodyPart$MimePartDataHandler cannot be cast to java.io.File (java.lang.ClassCastException)xlsFileRead:18 (null)
      2. Component that caused exception is: DefaultJavaComponent{imaptestflow.commponent.569080239}. Message payload is of type: MimeBodyPart$MimePartDataHandler (org.mule.component.ComponentException) org.mule.component.DefaultComponentLifecycleAdapter:352 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  java.lang.ClassCastException: javax.mail.internet.MimeBodyPart$MimePartDataHandler cannot be cast to java.io.File
  at xlsFileRead.readFromFile(xlsFileRead.java:18)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  </code></pre>