<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ESB: Extract email attachment with cProcessor and CAMEL code in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234567#M23887</link>
    <description>&lt;P&gt;Some times have passed since I've open the case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've made a new route with same configuration and it works well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;-Jacob&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jul 2019 06:51:17 GMT</pubDate>
    <dc:creator>FMV_IT</dc:creator>
    <dc:date>2019-07-24T06:51:17Z</dc:date>
    <item>
      <title>ESB: Extract email attachment with cProcessor and CAMEL code</title>
      <link>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234565#M23885</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt; 
&lt;P&gt;My scenario is the following:&lt;/P&gt; 
&lt;P&gt;Fetch email on POP3 every 10 seconds. If email, split into separate Message for every attachment. Save attachment locally.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I'm using the following recommendation from CAMEL:&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Consuming mails with attachment sample&lt;/P&gt; 
&lt;P&gt;In this sample we poll a mailbox and store all attachments from the mails as files. First, we define a route to poll the mailbox. As this sample is based on google mail, it uses the same route as shown in the SSL sample:&lt;/P&gt; 
&lt;P&gt;from("imaps://imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;amp;password=YOUR_PASSWORD" + "&amp;amp;delete=false&amp;amp;unseen=true&amp;amp;consumer.delay=60000").process(new MyMailProcessor());&lt;/P&gt; 
&lt;P&gt;Instead of logging the mail we use a processor where we can process the mail from java code:&lt;/P&gt; 
&lt;P&gt;public void process(Exchange exchange) throws Exception { // the API is a bit clunky so we need to loop Map&amp;lt;String, DataHandler&amp;gt; attachments = exchange.getIn().getAttachments(); if (attachments.size() &amp;gt; 0) { for (String name : attachments.keySet()) { DataHandler dh = attachments.get(name); // get the file name String filename = dh.getName(); // get the content and convert it to byte[] byte[] data = exchange.getContext().getTypeConverter() .convertTo(byte[].class, dh.getInputStream()); // write the data to a file FileOutputStream out = new FileOutputStream(filename); out.write(data); out.flush(); out.close(); } } }&lt;/P&gt; 
&lt;P&gt;As you can see the API to handle attachments is a bit clunky but it's there so you can get the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;javax.activation.DataHandler&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;so you can handle the attachments using standard API.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;How to split a mail message with attachments&lt;/P&gt; 
&lt;P&gt;In this example we consume mail messages which may have a number of attachments. What we want to do is to use the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://camel.apache.org/splitter.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Splitter&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;EIP per individual attachment, to process the attachments separately. For example if the mail message has 5 attachments, we want the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://camel.apache.org/splitter.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Splitter&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to process five messages, each having a single attachment. To do this we need to provide a custom&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://camel.apache.org/expression.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Expression&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://camel.apache.org/splitter.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Splitter&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;where we provide a List&amp;lt;Message&amp;gt; that contains the five messages with the single attachment.&lt;/P&gt; 
&lt;P&gt;The code is provided out of the box in Camel 2.10 onwards in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;camel-mail&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;component. The code is in the class:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;org.apache.camel.component.mail.SplitAttachmentsExpression, which you can find the source code&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/SplitAttachmentsExpression.java" target="_blank" rel="nofollow noopener noreferrer"&gt;here&lt;/A&gt;&lt;/P&gt; 
&lt;P&gt;In the Camel route you then need to use this&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://camel.apache.org/expression.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Expression&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in the route as shown below:{snippet:id=e1|lang=java|url=camel/trunk/components/camel-mail/src/test/java/org/apache/camel/component/mail/MailSplitAttachmentsTest.java}If you use XML DSL then you need to declare a method call expression in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://camel.apache.org/splitter.html" target="_blank" rel="nofollow noopener noreferrer"&gt;Splitter&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;as shown below&lt;/P&gt; 
&lt;P&gt;xml&amp;lt;split&amp;gt; &amp;lt;method beanType="org.apache.camel.component.mail.SplitAttachmentsExpression"/&amp;gt; &amp;lt;to uri="mock:split"/&amp;gt; &amp;lt;/split&amp;gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;From Camel 2.16 onwards you can also split the attachments as byte[] to be stored as the message body. This is done by creating the expression with boolean true&lt;/P&gt; 
&lt;P&gt;SplitAttachmentsExpression split = SplitAttachmentsExpression(true);&lt;/P&gt; 
&lt;P&gt;And then use the expression with the splitter eip.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Putting the code in my cProcessor make my route unusable (Java Error). Does anyone already do this on his system? I don't want to make a job, really want a route.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks for your help,&lt;/P&gt; 
&lt;P&gt;-Jacob&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 07:32:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234565#M23885</guid>
      <dc:creator>FMV_IT</dc:creator>
      <dc:date>2024-11-16T07:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: ESB: Extract email attachment with cProcessor and CAMEL code</title>
      <link>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234566#M23886</link>
      <description>&lt;P&gt;Hello Jacob,&lt;/P&gt;
&lt;P&gt;Could you please let us kow what's java error you are getting?&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;
&lt;P&gt;Sabrina&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 03:19:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234566#M23886</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-10-22T03:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: ESB: Extract email attachment with cProcessor and CAMEL code</title>
      <link>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234567#M23887</link>
      <description>&lt;P&gt;Some times have passed since I've open the case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've made a new route with same configuration and it works well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;-Jacob&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 06:51:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/ESB-Extract-email-attachment-with-cProcessor-and-CAMEL-code/m-p/2234567#M23887</guid>
      <dc:creator>FMV_IT</dc:creator>
      <dc:date>2019-07-24T06:51:17Z</dc:date>
    </item>
  </channel>
</rss>

