我有一個文件包含一個電子郵件在「純文本MIME郵件格式」。我不確定這是否是EML格式。該電子郵件包含附件,我想提取附件並再次創建這些文件。這是附件部分的樣子 -正確的PHP方式來解析EML格式的電子郵件附件
...
...
Receive, deliver details
...
...
From: sac ascsac <[email protected]>
Date: Thu, 20 Jan 2011 18:05:16 +0530
Message-ID: <[email protected]>
Subject: Test attachments
To: [email protected]
Content-Type: multipart/mixed; boundary=20cf3054ac85d97721049a465e12
--20cf3054ac85d97721049a465e12
Content-Type: multipart/alternative; boundary=20cf3054ac85d97717049a465e10
--20cf3054ac85d97717049a465e10
Content-Type: text/plain; charset=ISO-8859-1
hello this is a test mail. It contains two attachments
--20cf3054ac85d97717049a465e10
Content-Type: text/html; charset=ISO-8859-1
hello this is a test mail. It contains two attachments<br>
--20cf3054ac85d97717049a465e10--
--20cf3054ac85d97721049a465e12
Content-Type: text/plain; charset=US-ASCII; name="simple_test.txt"
Content-Disposition: attachment; filename="simple_test.txt"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_gj5n2yx60
aGVsbG8gd29ybGQKYWMgYXNj
...
encoded things here
...
ZyBmZyAKCjIKNDIzCnQ2Mwo=
--20cf3054ac85d97721049a465e12
Content-Type: application/x-httpd-php; name="oscomm_backup_code.php"
Content-Disposition: attachment; filename="oscomm_backup_code.php"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_gj5n5gxn1
PD9waHAKCg ...
...
encoded things here
...
X2xpbmsoRklMRU5BTUVfQkFDS1VQKSk7Cgo/Pgo=
--20cf3054ac85d97721049a465e12--
我可以看到X-Attachment-Id: f_gj5n2yx60
和ZyBmZyAKCjIKNDIzCnQ2Mwo=
,既包括 之間的部分是第一個附件的內容。我想解析這些附件(文件名和內容並創建這些文件)。
我使用PHP類中可用的DBX Parser類解析dbx格式文件後得到了此文件。
我在很多地方搜索過,並沒有在Script to parse emails for attachments以外的其他地方找到關於此的討論。可能是我在搜索時錯過了一些術語。在這個問題的答案中提到 -
可以使用boundries提取 編碼信息
以base64但我不知道這是界限,究竟如何使用的界限?已經必須有一些庫或者一些明確的方法來做到這一點。如果我嘗試在這裏重新發明輪子,我想我會犯很多錯誤。
絕對有幫助。謝謝,我正在嘗試Mailparse擴展。 – 2011-01-28 07:30:28