2012-02-08 212 views
1

目前我們需要使用Mule ESB從IMAP服務器獲取郵件。一旦郵件被提取,我們只需要附件並將它們保存在硬盤上。到現在爲止還挺好。現在我遇到了幾個問題:Mule ESB IMAP問題

  1. 如何使用文件保持原始名稱不變:outbound-endpoint?
  2. 如何檢查我獲得的附件數量?
  3. 如何將郵件副本保存在IMAP和本地驅動器上?

@ 1:我嘗試的#header:文件名或#originalFileName或甚至除去outputpattern(這導致在文件名是 「35c7dea0-519a-11e1的-b8b2-092b658ae008.dat」)

@ 2 :我正在嘗試做一個流程,檢查有多少附件。如果少於1,那麼我想保存這些文件,不再進一步處理它們。如果它超過1,則保存並處理它。我試過COUNT,但沒有奏效。

@ 3:正在嘗試在讀取到IMAP服務器上的備份文件夾時移動消息。最重要的是,我將在本地服務器上保存一份副本。問題是,對於當前的代碼,消息不會被標記爲已讀或移動。消息保持未讀狀態,並且它們被複制(反覆,循環)而不是移動到IMAP備份文件夾。當啓用deleteReadMessages時,循環被打破,但消息不會被複制到IMAP上。

這裏是我目前使用的代碼:

<?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> 

回答

0

1)我怎樣使用文件保持原名稱不變:出站終點?

附件是javax.activation.DataHandler實例,因此您應該可以使用OGNL或Groovy表達式對它們調用getName()。例如:

#[groovy:payload.name] 

應該給你原始的附件名稱。

2)如何檢查我得到的附件數量?

分離器之前,用choice路由器和條件檢查附件列表的大小()的屬性,如:

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

3)如何保存郵件的副本在IMAP和本地驅動器上?

我不知道問題在這裏。也許標記爲看到不支持。或者,也許事實上,你禁用運輸變壓器,防止讀後行動踢in。

順便說一下,我建議你離開默認的運輸變壓器,並在入站端點之前移動returnAttachments變壓器,之前分配器。

+0

嗯...... groovy:payload.name在路徑中工作,但不在outputPattern中。它將其視爲純文本,因此在使用file:outbound-endpoint時命名文件#[groovy:payload.name]。它在outputPattern之前的記錄器1行中工作正常。 – user1132229 2012-02-09 10:52:54

+0

沒關係,通過將文件名放入與message-properties-transform的會話中來獲得它。這個名字仍然很奇怪。關於IMAP郵件服務器的事情,我對此表示懷疑。我試着改變設置,但沒有運氣。我們使用的測試服務器是Cyrus IMAP v2.3.13服務器。 – user1132229 2012-02-09 12:44:18

+0

Ow也是一個新問題,我在進站後立即將有效載荷存儲在會話中。那麼如何從有效載荷中獲取消息呢?記錄器顯示它,但是當它放在一個文件中時,它顯示了類型等。這是用於記錄原始消息的錯誤部分。 – user1132229 2012-02-09 14:26:15