Mule ESB IMAP questions

2019-08-09 03:16发布

Currently we need fetch mails from an IMAP server using Mule ESB. Once the mails have been fetched, we only need the attachments and save them on the harddrive. So far so good. Now I got a couple of questions:

  1. How do I keep the original name intact using a file:outbound-endpoint?
  2. How can I check how many attachments I got?
  3. How do save a copy of the mail on the IMAP and local drive?

@1: I tried #header:fileName or #originalFileName or even removing the outputpattern (this results in the filename being "35c7dea0-519a-11e1-b8b2-092b658ae008.dat")

@2: I am trying to make a flow where I check how many attachments there are. If there are less then 1 then I want to save the files and no further process them. If it's more then 1, then save it and process it. I tried COUNT but it didn't work.

@3: am trying to MOVE a message when READ to a back-up folder on the IMAP-server. On top of that I'll save a copy on the local server. Problem is that with the current code, the message does not get marked as read nor moved. The messages stay unread and they get copied (over and over, enldess loop) instead of getting moved to the IMAP back-up folder. When enabling the deleteReadMessages then the loop is broken but the message does not get copied on the IMAP.

Here's the code I am currently using:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:spring="http://www.springframework.org/schema/beans"
           xmlns:imap="http://www.mulesoft.org/schema/mule/imap"
           xmlns:file="http://www.mulesoft.org/schema/mule/file"
           xmlns:email="http://www.mulesoft.org/schema/mule/email"
           xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
           http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/3.2/mule-file.xsd
           http://www.mulesoft.org/schema/mule/imap http://www.mulesoft.org/schema/mule/imap/3.2/mule-imap.xsd
           http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/3.2/mule-email.xsd
           http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.2/mule-vm.xsd">

        <imap:connector name="imapConnector" checkFrequency="5000" 
        backupEnabled="true" backupFolder="/home/mark/workspace/Eclipse/RHZ_Project/src/Archive/"
        mailboxFolder="INBOX" moveToFolder="INBOX.Backup" deleteReadMessages="false" 
        defaultProcessMessageAction="SEEN" />
        <expression-transformer name="returnAttachments">
            <return-argument evaluator="attachments-list" expression="*.txt,*.ozb,*.xml" optional="false"/>
        </expression-transformer>

        <flow name="Flow1_IMAP_fetch">
            <imap:inbound-endpoint user="USER" password="PASS" host="IP" 
                         port="143" transformer-refs="returnAttachments" disableTransportTransformer="true"/>               
            <collection-splitter/>          
            <file:outbound-endpoint path="/home/mark/workspace/Eclipse/RHZ_Project/src/Inbox/#[function:datestamp].dat">
                    <expression-transformer>
                        <return-argument expression="payload.inputStream" evaluator="groovy" />
                    </expression-transformer>
            </file:outbound-endpoint>      

        </flow>
</mule>

标签: imap esb mule
1条回答
我只想做你的唯一
2楼-- · 2019-08-09 04:04

1) How do I keep the original name intact using a file:outbound-endpoint?

Attachments are javax.activation.DataHandler instances so you should be able to call getName() on them, with an OGNL or Groovy expression. For example:

#[groovy:payload.name]

Should give you the original attachment name.

2) How can I check how many attachments I got?

Before the splitter, use a choice router and an condition that checks the size() attribute of the attachment list, like:

#[groovy:payload.size()>1]

3) How do save a copy of the mail on the IMAP and local drive?

I do not know what the issue is here. Maybe marking as seen is not supported. Or maybe the fact that you disable the transport transformer prevents a post-read action to kick in.

By the way, I suggest you leave the default transport transformer as-is and move the returnAttachments transformer after the inbound endpoint, before the splitter.

查看更多
登录 后发表回答