Reputation: 3108
I have a multi-part message that I would like to decode (see below).
I'm able to use PHP's base64_decode
function to decode normal emails, but it wont work for multi-part emails.
Is anyone aware of how to do this or know of any scripts available?
--_000_FBA91459E616EF4B8C1CCF54B389A283030E5EMX105CL01corpemcc_
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
SGVsbG8sIEkgY2Fu4oCZdCBzZWVtIHRvIGdldCB0aGUgbGluayB0byB3b3JrIGFmZmVjdGl2ZWx5
IHRvIGVudGVyIGluIHRoZSBuYW1lcyBvZiBwZW9wbGUgdG8gc2VuZCB0aGUgc3VydmV5IHRvb+KA
pml0IHdvbuKAmXQgbGV0IG1lIGVudGVyIHRoZSBuYW1lcy4gQmUgZ3JlYXQgaWYgeW91IGNvdWxk
IGhlbHAgb3Igc2hvdWxkIEkganVzdCB3YWl0IGEgbGl0dGxlIHdoaWxlIHRvIGdhaW4gdGhlIGFj
Y2Vzcz8NCg0KUmVnYXJkcw0... etc
--_000_FBA91459E616EF4B8C1CCF54B389A283030E5EMX105CL01corpemcc_
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
PGh0bWwgeG1sbnM6dj0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTp2bWwiIHhtbG5zOm89InVy
bjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSIgeG1sbnM6dz0idXJuOnNjaGVt
YXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6d29yZCIgeG1sbnM6bT0iaHR0cDovL3NjaGVtYXMubWlj
cm9zb2Z0LmNvbS9vZmZpY2UvMjAwNC8xMi9vbW1sIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv
VFIvUkVDLWh0bWw0MCI+DQo8aGVhZD4NCjxtZXRhIGh... etc
--_000_FBA91459E616EF4B8C1CCF54B389A283030E5EMX105CL01corpemcc_--
Upvotes: 1
Views: 1485
Reputation: 134
There is a PHP module called mailparse which can do the heavy lifting for you.
On top of that, check out this wrapper which will make it more easy to access the functions of the library.
We use the php module in our stack at mailparser.io and it works very reliable.
Upvotes: 1
Reputation: 3108
I found this library which does most of what I want (I made a few small customisations).
https://github.com/CaTzil/emailParser
Upvotes: 0