title: Apache Camel: MailMessage email Headers are empty
body: <p>I am new to Apache camel. we are using Apache camel 2.11.0 to poll a microsoft exchange Indox, using POP3 as FROM endpoint and created a bean class to process the email message in the route before sending it to target endpoint. The issue i have is MailMessage object return from Exchange.getIn(MailMessage.class).getMessage() in Processor method does not have any email headers. When i put a Debug option on FROM endpoint i can see the email headers of receiving email in the Apache camel trace. Your help is much appreciated.</p>
  
  <p><strong>Route Config</strong></p>
  
  <pre><code>&lt;!-- Route email exchange--&gt;
      &lt;route id="gateMail"&gt;
          &lt;from uri="pop3://MyUser@MyMailServer.com?password=MyPassword&amp;amp;debugMode=true&amp;amp;contentType=multipart/alternative" /&gt;
          &lt;bean ref="MailProcessor" /&gt;            
          &lt;to uri="file:D:/Mail" /&gt;&lt;/route&gt;
  </code></pre>
  
  <p><strong>Output in console of Tomcat v7.0 Server at localhost [Apache Tomcat] c:\Program Files\Java\jdk1.7.0_21\bin\Javaw.exe</strong></p>
  
  <p><code>DEBUG POP3: pipeline message size 2243
      S: +OK
      Received: by MyMailServer.com id &lt;01CF1183.AA71B3C0@MyMailServer.com&gt;; Wed, 15 Jan 2014 10:52:21 +1100
  x-protective-marking: VER=2005.6, NS=com.au, SEC=UNCLASSIFIED:AUDIT, ORIGIN=MyUser@MyMailServer.com
  x-titus-version: 3.3.8.1
  x-tituslabs-classifications-30: TLPropertyRoot=Titus;Classification=UNCLASSIFIED;Precedence=ROUTINE;Privacy=AUDIT;
  x-tituslabs-classificationhash-30: YifyyqlCDo9l8ySQLTGzHX5c15nHvPqznjIb8keFNu8UEVGWAssd6R0LjeoelHoKfBmfwLv3tDicWe12NsuQFLTSJLlcdr56aL59f1GzpTBosa6XLoHlIutAnNQcPA+xRA5fzirrVFmPv2jTtl8Bqp30thtdKQvwpzqD/KcGI3vS033ldtUOzAF1+/gwx9zL+SBDwxSwUor1ihlW6uCx36tFLjtDF7M9GjKi5Cd/jUFyjCypZnCyZkCmSjvL9iG/
  Content-class: urn:content-classes:message
  Subject: Test Design [SEC=UNCLASSIFIED:AUDIT]
  MIME-Version: 1.0
  Content-Type: multipart/alternative;
  </code>    </p>
  
  <p><strong>Bean Class Code</strong></p>
  
  <pre><code> public class MailProcessor implements Processor {
  
  public void process(Exchange exch) throws Exception {
      String filename = exch.getIn().getHeader(Exchange.BREADCRUMB_ID,String.class);
      POP3Message mailMSG = (POP3Message)exch.getIn(MailMessage.class).getMessage();
      String mailTo = getRecipients(mailMSG);
      String from = this.getFrom(mailMSG);`enter code here`
      String subject = mailMSG.getSubject();
      String headers = GetHeaders(mailMSG);
      String body = this.getText(mailMSG);
      Map&lt;String, DataHandler&gt; attachments = exch.getIn().getAttachments();
      String attFileName = "";
      if(attachments.size() &gt; 0)
      {
          for(String name: attachments.keySet())
          {
              DataHandler dh = attachments.get(name);
              attFileName = attFileName + "; " + dh.getName();
          }
      }
      String strMessage = (" ----------- From:" + from  + " ----------- To:" + mailTo  
              + " ----------- Subject:" + subject + " ----------- Attchements:" + attFileName + 
              " ----------- Header:" + headers +" ----------- Body:" + body);
      File mailFile = new File("D:\\IOI\\Mail\\" + filename + ".txt");
      BufferedWriter writer = new BufferedWriter(new FileWriter(mailFile));
      writer.write(strMessage);
      writer.close();
  }
  
  private String getText(Part p) throws
      MessagingException, IOException 
  {
  
  if (p.isMimeType("text/*")) {
  String s = (String)p.getContent();
  return s;
  }
  
  if (p.isMimeType("multipart/alternative")) {
  // prefer html text over plain text
  Multipart mp = (Multipart)p.getContent();
  String text = null;
  Part bp = null; 
  for (int i = 0; i &lt; mp.getCount(); i++) {
      bp = mp.getBodyPart(i);
      if (bp.isMimeType("text/plain")) {
          if (text == null)
              text = getText(bp);
          continue;
      } else if (bp.isMimeType("text/html")) {
          String s = getText(bp);
          if (s != null)
              return s;
      } else {
          return getText(bp);
      }
  }
  return text;
  } else if (p.isMimeType("multipart/*")) {
  Multipart mp = (Multipart)p.getContent();
  for (int i = 0; i &lt; mp.getCount(); i++) {
      String s = getText(mp.getBodyPart(i));
      if (s != null)
          return s;
  }
  }
  return null;
  }
  
  private String GetHeaders(Part p) 
          throws MessagingException
  {
      Enumeration&lt;?&gt; headers = p.getAllHeaders();
          //Get the mail Header
          String strHeader = "";
          while(headers.hasMoreElements())
              {
                  Header h = (Header)headers.nextElement();   
                  strHeader = strHeader + "-" + h.getName() + " : " + h.getValue();
              }
          return strHeader;
  }
  private String getRecipients(Message msg)
          throws MessagingException
        {
          javax.mail.Address[] addrs = msg.getRecipients(Message.RecipientType.TO);
          if (addrs == null || addrs.length == 0)
              return null;
  
          String str = "";
          for (int i = 0; i &lt; addrs.length; i++) {
              if (i != 0)
                  str += ", ";
              String text = addrs[i].toString();
              str += removeChars(text);
          }
  
          return str;
        }
  private String getFrom(Message msg)
          throws MessagingException
        {
          javax.mail.Address[] addrs = msg.getFrom();
          if (addrs == null || addrs.length == 0)
              return null;
  
          String str = "";
          for (int i = 0; i &lt; addrs.length; i++) {
              if (i != 0)
                  str += ", ";
              String text = addrs[i].toString();
              str += removeChars(text);
          }
  
          return str;
        }
  private String removeChars(String text)
    {
      if (text == null)
          return null;
  
      StringBuffer buf = new StringBuffer();
      for (int i = 0; i &lt; text.length(); i++) {
          char c = text.charAt(i);
          if (c == '&lt;' || c == '&gt;' || c == '\'' || c == '\"' || c == '&amp;')
              buf.append(' ');
          else
              buf.append(c);
      }
      return buf.toString();
    }}
  </code></pre>
  
  <p>Thanks
  Sunil      </p>