Mule ESB:如何根据主题或发件人过滤电子邮件?

use*_*188 3 email esb header filter mule

我是Mule 3.3的新手,如果发件人字段和主题字段包含某些关键字,我正尝试使用它从POP3服务器检索电子邮件并下载CSV附件.我使用了Mulesoft网站上提供的示例,我已成功设法扫描我的收件箱中的新电子邮件,并且只下载了CSV附件.但是,我现在卡住了,因为我无法弄清楚如何按主题和发件人字段过滤电子邮件.

做一些研究我遇到了一个可以应用于端点的消息属性过滤器模式标签,但我不确定应用它的哪个端点,传入或传出.这两种方法似乎都不起作用,我找不到一个体面的例子来展示如何使用这个标签.我想实现的基本算法如下:

if email is from "Bob"
  if attachment of type "CSV"
    then download CSV attachment

if email subject field contains "keyword"
  if attachment of type CSV
    then download CSV attachment
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止的Mule xml:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:pop3s="http://www.mulesoft.org/schema/mule/pop3s" xmlns:pop3="http://www.mulesoft.org/schema/mule/pop3" 
xmlns="http://www.mulesoft.org/schema/mule/core" 
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/pop3s http://www.mulesoft.org/schema/mule/pop3s/current/mule-pop3s.xsd 
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/pop3 http://www.mulesoft.org/schema/mule/pop3/current/mule-pop3.xsd ">


<expression-transformer expression="#[attachments-list:*.csv]" 
   name="returnAttachments" doc:name="Expression">
</expression-transformer>

<pop3s:connector name="POP3Connector" 
    checkFrequency="5000" 
    deleteReadMessages="false" 
    defaultProcessMessageAction="RECENT" 
    doc:name="POP3" 
    validateConnections="true">
</pop3s:connector>

<file:connector name="fileName" doc:name="File">
    <file:expression-filename-parser />
</file:connector>

<flow name="incoming-orders" doc:name="incoming-orders">

    <pop3s:inbound-endpoint user="my_username" 
        password="my_password" 
        host="pop.gmail.com" 
        port="995" 
        transformer-refs="returnAttachments"
        doc:name="GetMail" 
        connector-ref="POP3Connector" 
        responseTimeout="10000"/>
    <collection-splitter doc:name="Collection Splitter"/>

    <echo-component doc:name="Echo"/>

    <file:outbound-endpoint path="/attachments" 
        outputPattern="#[function:datestamp].csv"
        doc:name="File" responseTimeout="10000"> 
        <expression-transformer expression="payload.inputStream"/>
        <message-property-filter pattern="from=(.*)(bob@email.com)(.*)" caseSensitive="false"/>
    </file:outbound-endpoint>           
</flow>
Run Code Online (Sandbox Code Playgroud)

解决这个问题的最佳方法是什么?

提前致谢.

Dav*_*sot 8

为了帮助您,这里有两个配置位:

  • 以下过滤器仅接受fromAddress"Bob"和主题包含"keyword"的邮件:

    <expression-filter
        expression="#[message.inboundProperties.fromAddress == 'Bob' || message.inboundProperties.subject contains 'keyword']" />
    
    Run Code Online (Sandbox Code Playgroud)
  • 以下转换器提取名称以".csv"结尾的所有附件:

    <expression-transformer
        expression="#[($.value in message.inboundAttachments.entrySet() if $.key ~= '.*\\.csv')]" />
    
    Run Code Online (Sandbox Code Playgroud)