你能在mulesoft上的每个语句中获得附件文件名吗?

你能在mulesoft上的每个语句中获得附件文件名吗?,mule,filenames,email-attachments,Mule,Filenames,Email Attachments,我有一封电子邮件要归档。该电子邮件包含多个附件,我需要逐一处理它们以传递到另一个流,我需要原始文件名。我可以在每个作用域的之前获取附件名称,但我不能将其用作目标文件的文件名。任何帮助或建议都将不胜感激 <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:file="http://www.mulesoft.org/sc

我有一封电子邮件要归档。该电子邮件包含多个附件,我需要逐一处理它们以传递到另一个流,我需要原始文件名。我可以在每个作用域的之前获取附件名称,但我不能将其用作目标文件的文件名。任何帮助或建议都将不胜感激

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

<mule xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" 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" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="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
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd">
    <file:connector name="File" autoDelete="true" streaming="true" validateConnections="true" doc:name="File"/>
    <flow name="Knauf_Load_List">
        <pop3:inbound-endpoint host="mailhost" user="exampleuser" password="examplepass" responseTimeout="10000" doc:name="Poll Email PDF"/>
        <set-session-variable variableName="State" value="#[message.inboundProperties.To]" doc:name="Session Variable"/>
        <set-variable variableName="filename()" value="#[message.inboundAttachments.keySet()]" doc:name="Variable"/>
        <expression-transformer doc:name="Expression">
            <return-argument evaluator="attachments-list" expression="*.pdf"/>
        </expression-transformer>
        <foreach doc:name="For Each">
            <set-payload value="#[payload.getContent()]" doc:name="Set Payload"/>
            <logger message="#[flowVars.filename]" level="INFO" doc:name="Logger"/>
            <file:outbound-endpoint path="\\HO-AWH-OCRPROD1\CustomerOrders\Knauff" outputPattern="Knauf_Bunnings_Orders-#[message.id].pdf" connector-ref="File" responseTimeout="10000" doc:name="File"/>
            <set-session-variable variableName="PDF" value="#[flowVars.counter]" doc:name="Session Variable"/>
        </foreach>
        <logger message="#[sessionVars.PDF] for #[sessionVars.State]" level="INFO" doc:name="Logger"/>
    </flow>
    <flow name="ocr_app_test_edi_flow">
        <file:inbound-endpoint path="\\HO-AWH-OCRPROD1\Output\Knauff\EDIEnterprise" moveToPattern="OCR_Archive-#[server.dateTime.format('dd-MM-yy_HH-mm-ss')].xml" moveToDirectory="S:\AWHMan\IT\IT Middleware Project\Ocr To EDI Archive" responseTimeout="10000" doc:name="File" connector-ref="File"/>
        <file:file-to-string-transformer doc:name="File to String"/>
        <set-variable variableName="order" value="#[xpath3('/Payload/WhsDockets/WhsDocket/Reference')]" doc:name="Variable"/>
        <logger level="INFO" doc:name="Logger"/>
        <file:outbound-endpoint path="\\HO-AWH-FS6\ediEnterprise Import Files" outputPattern="Knauf-#[flowVars.order].xml" connector-ref="File" responseTimeout="10000" doc:name="File"/>
    </flow>
</mule>

很好

不知道这是否有用,但我已经为IMAP帐户实现了以下代码:

    <choice doc:name="Choice between mail with and without attachments">
        <when expression="#[message.dataType.mimeType == &quot;multipart/alternative&quot;]">
            <set-variable variableName="hasAttachment" value="false" doc:name="Set hasAttachment"/>
            <set-payload value="#[message.inboundAttachments['0'].getContent()]" doc:name="Set Payload from Body"></set-payload>
            <set-variable variableName="fileName" value="" doc:name="Set fileName"/>
        </when>
        <when expression="#[message.dataType.mimeType == &quot;multipart/mixed&quot;]">
            <set-variable variableName="hasAttachment" value="true" doc:name="Set hasAttachment"/>
            <expression-transformer doc:name="Set Payload from Attachments">
                <return-argument evaluator="attachments" expression="*.*"/>
            </expression-transformer>
            <set-variable variableName="fileName" value="#[payload.keySet().iterator().next()]" doc:name="Set fileName"/>
            <set-payload value="#[payload[flowVars.fileName].getContent()]" doc:name="Set Payload from firts Attachment content"></set-payload>
            <object-to-byte-array-transformer doc:name="Object to Byte Array"></object-to-byte-array-transformer>
        </when>
        <when expression="#[message.dataType.mimeType == &quot;text/plain&quot;]">
            <set-variable variableName="hasAttachment" value="false" doc:name="Set hasAttachment"/>
            <set-payload value="#[payload.getContent()]" doc:name="Set Payload from Text"/>
            <set-variable variableName="fileName" value="" doc:name="Set fileName"/>
        </when>
        <otherwise>
            <logger message="La informaci&#243;n del EMail no es v&#225;lida" level="INFO" doc:name="Logger"/>
        </otherwise>
    </choice>
使用此名称,您可以直接访问此附件的内容,也可以使用相应的密钥访问所有附件

问候语。

使用#[key],这将在foreach语句中给出文件名。
我使用的是3.8版本

您能更好地说明您的问题吗?如果你能在foreach之前得到它,这意味着你可以存储它们,那么为什么不能在foreach之后使用它呢?嗨,Mauro,我需要分配相同的文件名来输出一个文件,同时将其与数据库并行处理。
#[payload.keySet().iterator().next()]