Be aware of "corporate mails" or users who do not understand character encoding too deeply (or do not care). You may (as we did) face mail where the whole mail body is encoded used i.e. Latin2 (and iso-8859-2 is given in multipart's charset header) but at the same time the body also contains text footer with UTF-8 characters in it... Yes, fu*g Microsoft Exchange V6.5 frontent will show that fine on the screen, but if when receive it:
mailparse_msg_extract_part_file() - filter conversion failed. Input message is probably incorrectly encoded in ....
so be extra careful and deal with all the possible errors to avoid mail loss.
(PECL mailparse >= 0.9.0)
mailparse_msg_extract_part_file — Extracts/decodes a message section
Extracts/decodes a message section from the supplied filename.
The contents of the section will be decoded according to their transfer encoding - base64, quoted-printable and uuencoded text are supported.
A valid MIME resource, created with mailparse_msg_create().
Can be a file name or a valid stream resource.
If set, this must be either a valid callback that will be passed the extracted section, or
NULLto make this function return the extracted section.
If not specified, the contents will be sent to "stdout".
callbackfunc is not
callbackfunc is set to
NULL, returns the
extracted section as a string.
FALSE on error.