在WSO2 ESB / WSO2 EI中是否有从gmail下载附件的解决方案?

问题描述 投票:1回答:1

自最近6个月以来,我一直在从事wso2 esb的研究。我想从wso2 esb / ei中的gmail下载附件并将其保存到本地文件夹中。Google对其获取解决方案,仅使用gmail连接器发送附件,而不下载附件。注意:已经看到,但无法通过参考以下链接获得解决方案-WSO2 esb get attach files from email代码:ProxyService

<proxy name="GmailConfigAttachment-TaskProxy" startOnLoad="true"
transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
    <inSequence>
        <log level="custom">
            <property name="Log Text"
                value="Inside GmailConfigAttachment-TaskProxy Service"></property>
        </log>
        <property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING"
            value="true" />
        <property description="serviceName" name="serviceName"
            scope="operation" type="STRING"
            value="TaskScheduler_ASG_Read_Email_Body_Dummy_Service" />
        <property description="messageId" expression="get-property('MessageID')"
            name="messageId" scope="operation" type="STRING" />
        <sequence key="Load_Gmail_Configuration" />
        <gmail.init>
            <userId>{$ctx:userId}</userId>
            <accessToken>{$ctx:accessToken}</accessToken>
            <apiUrl>{$ctx:apiUrl}</apiUrl>
            <clientId>{$ctx:clientId}</clientId>
            <clientSecret>{$ctx:clientSecret}</clientSecret>
            <refreshToken>{$ctx:refreshToken}</refreshToken>
            <accessTokenRegistryPath>{$ctx:registryPath}</accessTokenRegistryPath>
        </gmail.init>
        <gmail.listAllMails>
            <labelIds>INBOX</labelIds>
            <q>is:unread</q>
        </gmail.listAllMails>
        <log level="full" />
        <iterate description="MailIterator" expression="//jsonObject/messages" sequential="true" id="listUnread">
            <target>
                <sequence>
                    <log description="Iterate Logger" level="custom" separator=",**, ">
                        <property expression="fn:concat('GmailConfigAttachment-TaskProxy_Service ESB-MessageId:',get-property('operation','messageId'))" name="LogText" />
                        <property expression="//id/text()" name="Gmail-MessageId" />
                   </log>
                   <property description="emailMsgId" expression="//id/text()" name="emailMsgId" scope="default" type="STRING" />
                   <property description="emailSubject" expression="//headers/name[text()='Subject']/../value/text()" name="emailSubject" scope="default" type="STRING"/>
                    <property description="emailDate" expression="//headers/name[text()='Date']/../value/text()" name="emailDate" scope="operation" type="STRING"/>
                <property description="toAddress" expression="//headers/name[text()='To']/../value/text()" name="toAddress" scope="operation" type="STRING"/> 
                   <header expression="fn:concat('Bearer ', $ctx:uri.var.gmail.accessToken)" name="Authorization" scope="transport" />
                    <gmail.readMail>
                        <id>{$ctx:emailMsgId}</id>
                    </gmail.readMail>
                    <payloadFactory media-type="xml">
                                <format>
                                    <htmlProcessEmailBody xmlns="">
                                        <emailMessageId>$1</emailMessageId>
                                        <emailSubject>$2</emailSubject>
                                        <emailBody>$3</emailBody>
                                    </htmlProcessEmailBody>
                                </format>
                                <args>
                                    <arg evaluator="xml" expression="get-property('emailMsgId')"/>
                                    <arg evaluator="xml" expression="get-property('emailSubject')"/>
                                    <arg evaluator="xml" expression="//payload"/>
                                </args>
                            </payloadFactory>
                            <log level="custom">
                                <property description="emailMsgId" expression="get-property('emailMsgId')" name="emailMsgId" scope="default" type="STRING" />
                                <property description="emailSubject" expression="//headers/name[text()='Subject']/../value/text()" name="emailSubject" scope="default" type="STRING"/>
                                <property description="emailDate" expression="//headers/name[text()='Date']/../value/text()" name="emailDate" scope="default" type="STRING"/>
                                <property description="toAddress" expression="//headers/name[text()='To']/../value/text()" name="toAddress" scope="default" type="STRING"/> 
                            </log>
                               <!-- here i need further process to download attachment from gmail  -->
                </sequence>
            </target>
        </iterate>
    </inSequence>
    <outSequence />
    <faultSequence />
</target>

Output of ESB所以有人可以帮助我提供解决方案吗?

等待您的回复。谢谢。

wso2esb gmail-api wso2ei
1个回答
0
投票
想法:

迭代每个部分,然后获取电子邮件附件ID,该附件将传递给gmail api,以获得base64编码格式。

  • 代码段:

<iterate continueParent="true" description="MailIterator" expression="//parts" id="listUnread" sequential="true"> <target> <sequence> <property expression="//filename[text()!=' ']" name="AttachedFileName" scope="default" type="STRING"/> <property expression="substring-after(get-property('AttachedFileName'),'.')" name="Attachmentextension" scope="default" type="STRING"/> <filter description="check emailSubject" regex="jpg|jpeg|png|gif|webp|tiff|tif|psd|raw|bmp|dib|heif|heic|indd|ind|jp2" source="lower-case(get-property('Attachmentextension'))"> <then> <property description="emailAttachmentId" expression="//attachmentId/text()" name="uri.var.attachmentId" scope="default" type="STRING"/> <log level="custom"> <property expression="get-property('AttachedFileName')" name="=====ValidAttachmentFileName===="/> <property expression="get-property('uri.var.attachmentId')" name="====emailAttachmentId====="/> </log> <header expression="fn:concat('Bearer ', $ctx:uri.var.gmail.accessToken)" name="Authorization" scope="transport"/> <call> <endpoint> <http method="get" uri-template="{+uri.var.gmail.apiUrl}/{+uri.var.gmail.apiVersion}/users/{+uri.var.gmail.userId}/messages/{+uri.var.id}/attachments/{+uri.var.attachmentId}"/> </endpoint> </call> <property description="emailAttachment" expression="//data/text()" name="emailAttachment" scope="default" type="STRING"/> <!-- ==========Script for Base64 url to Base64 Encoding Format ========== --> <script language="js"><![CDATA[var log=mc.getServiceLog(); var emailAttachment = mc.getProperty('emailAttachment'); emailAttachment=emailAttachment.replaceAll("_","/").replaceAll("-","+"); mc.setProperty("modifiedemailAttachment",emailAttachment)]]></script> <log level="custom"> <property expression="get-property('modifiedemailAttachment')" name="========modifiedemailAttachment========"/> </log>

© www.soinside.com 2019 - 2024. All rights reserved.