如何從PHP中的各種電子郵件源獲取XML / TXT附件?

[英]How to get XML/TXT attachments from diverse email sources in PHP?


Once the SMTP/MIME text is obtained, it is hard to tell how complex it can be to parse/handle emails coming from all kind of random SMTP/MIME programs.

獲得SMTP / MIME文本后,很難說解析/處理來自各種隨機SMTP / MIME程序的電子郵件有多復雜。

For the particular pose of this question, obtaining header information is completly irrelevant. Only attachments are needed.

對於該問題的特定姿勢,獲得標題信息是完全不相關的。只需要附件。

¿Is out there any bullet proof solution for this?

¿有沒有針對此的防彈解決方案?

Thank you

1 个解决方案

#1


You will need a MIME parser to process MIME data. In PHP, the Mailparse extension can do this for you. It's a fairly basic library, so a wrapper like php-mime-mail-parser can greatly simplify things. In any case, assuming Mailparse, the basic outline of the process is the following: load/parse the email, then enumate all parts and subparts where the following conditions are met:

您將需要一個MIME解析器來處理MIME數據。在PHP中,Mailparse擴展可以為您執行此操作。它是一個相當基礎的庫,所以像php-mime-mail-parser這樣的包裝器可以大大簡化一些事情。在任何情況下,假設Mailparse,該過程的基本概要如下:加載/解析電子郵件,然后啟用滿足以下條件的所有部分和子部分:

  • The Content-Disposition header for the part is attachment.
  • 零件的Content-Disposition標頭是附件。

  • The decoded filename parameter of the Content-Dispositon header ends with the literal .xml or .txt. Alternatively, you can rely on the Content-Type header for type detection (text/XML and text/plain, respectively), but that will be less reliable, because it depends on the email sender finding out the right MIME type for the attached document.
  • Content-Dispositon標頭的已解碼文件名參數以文字.xml或.txt結尾。或者,您可以依賴Content-Type標頭進行類型檢測(分別是text / XML和text / plain),但這樣會不太可靠,因為它依賴於電子郵件發件人找到所附文檔的正確MIME類型。

Once the attachments parts are found, they can be decoded from MIME representation using the PHP-provided functions for BASE64 or quoted-printable decoding.

找到附件部分后,可以使用PHP提供的BASE64函數或引用可打印解碼從MIME表示中對它們進行解碼。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/08/1908484838eebc56881cf45804b846d3.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com