| Recommend this page to a friend! |
| PHP MIME Email Message Parser | > | All threads | > | Have trouble with filename with... | > | (Un) Subscribe thread alerts |
| |||||||||||||
Hi,
with the class, i use this script to have the filename of the attachments, but, it dont work when : - it's inline attachment - it's classiq attachment but with html charset It only work when it's classiq attachment in text/plain format. Here is my little script, what do you think of it ? Can you help me ? foreach($decoded[0]['Parts'] as $part){ //check for attachments inline or attachment - utile ?? if (($part['FileDisposition'] == 'attachment') XOR ($part['FileDisposition'] == 'inline')) { //format file name (change spaces to underscore then remove anything that isn't a letter, number or underscore) $filename = preg_replace('/[^0-9,a-z,\.,_]*/i','',str_replace(' ','_', $part['FileName'])); //add file to attachments array $attachments[] = $filename; } } Thanks Arnaud
I am not sure what you mean.
Can you please post an example message complete with body and headers so I can see what is the problem you are facing?
Thanks for your answer.
it's just a part of my parse script. I just want to select the filename of the attachment. The files are always in the email after the filename=" in the $body. For the moment, i use this, it's ok, but i think that your class do this very much ;) preg_match('#filename="(.+)"#Usi', $body, $output); $filenamefin = htmlentities($output[1]); Here is the body of the message : $body = ' --Apple-Mail=_380D7683-C2AA-4F13-8B31-93C43592D154 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Cordialement. Non prenom --Apple-Mail=_380D7683-C2AA-4F13-8B31-93C43592D154 Content-Disposition: attachment; filename="mes candidatures.txt" Content-Type: text/plain; name="mes candidatures.txt" Content-Transfer-Encoding: quoted-printable ici la piece jointe en texte B64 ';
This is not the complete message. It seems to be just the body. It still needs the headers to appear at the top of the message data passed.
Please include the missing message headers as that seems to be causing the problem of the class not parsing the message the way you expected.
ok, here it's one of the complet email, hope than you'll can help me
The array $attachments[] (script in my first message) is empty, i dont understand why. for <[email protected]>; Wed, 9 Mar 2016 00:41:58 +0100 (CET) X-SFR-UUID: [email protected] From: leeroxxxx <[email protected]> Subject: test pj Message-Id: <[email protected]> Date: Wed, 9 Mar 2016 00:41:58 +0100 (CET) To: "[email protected] Arnaud" <[email protected]> MIME-Version: 1.0 X-Mailer: Apple Mail (2.3112) Content-Type: multipart/alternative; boundary="Apple-Mail=_07AC20CF-8C13-4B2A-A854-2FE47511F8EB" X-Zimbra-Forwarded: [email protected] X-Mailer: Zimbra 7.2.0-GA2598 X-Authenticated-User: [email protected] --Apple-Mail=_07AC20CF-8C13-4B2A-A854-2FE47511F8EB Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii test PJ Cordialement. Arnaud Perrot --Apple-Mail=_07AC20CF-8C13-4B2A-A854-2FE47511F8EB Content-Type: multipart/related; type="text/html"; boundary="Apple-Mail=_E82A8F40-27EF-458D-8C84-7552D1A7868B" --Apple-Mail=_E82A8F40-27EF-458D-8C84-7552D1A7868B Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii <html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">test PJ<br class=""><div class=""> <br class="">Cordialement.<br class=""><br class="">Arnaud Perrot </div> <img height="21" width="100" apple-width="yes" apple-height="yes" apple-inline="yes" id="E34113A6-0902-4E64-8CBC-7B348D749FFB" src="cid:7A032742-9CD8-4B32-B3B5-19AC063A8267" class=""></body></html> --Apple-Mail=_E82A8F40-27EF-458D-8C84-7552D1A7868B Content-Transfer-Encoding: base64 Content-Disposition: inline; filename="gmail-filtre 2.tiff" Content-Type: image/tiff; x-unix-mode=0644; name="gmail-filtre 2.tiff" Content-Id: <7A032742-9CD8-4B32-B3B5-19AC063A8267> TU0AKgAAFBCAP6BP8AwUAQeEQmFQuGQ2HQ+IRGJROKRWLReMRmFP8ARwAgB7O1wAB+vRogABAQER 1/v6MR+DxyFzCOxqHzSZACcS+ETmIzubz2ITSEz6EUCdUKZweYP9+PkAAMGC8AAsJiCYzKDTauV2 vV+wWGxWOyRh8WeQPZ7SgBAKFQWP3AAPW6VUFguWUaiv+jXyOXe8X5/u3CABxYcACTFAAG4202t5 ZG8gAH5UAATMAAC5sAPnPZfM37QASdVuy6fUambXymR99Z96vN4VmmarbbeLUjcRWcwYFg0IAADA... --Apple-Mail=_E82A8F40-27EF-458D-8C84-7552D1A7868B-- --Apple-Mail=_07AC20CF-8C13-4B2A-A854-2FE47511F8EB--
There is some data missing in the beggining but I could parse the message with the test_message_decoder.php script.
The results that I post below says it is a HTML message with an alternative text part. It has a related TIFF image with ID 7A032742-9CD8-4B32-B3B5-19AC063A8267 . This image should be linked in the HTML where it says cid:7A032742-9CD8-4B32-B3B5-19AC063A8267 . So this is not an attachment, it is an image that should be displayed inline with HTML part of the message. array(10) { ["Type"]=> string(4) "html" ["Description"]=> string(12) "HTML message" ["Encoding"]=> string(8) "us-ascii" ["DataFile"]=> string(7) "/tmp/25" ["Related"]=> array(1) { [0]=> array(7) { ["Type"]=> string(5) "image" ["SubType"]=> string(4) "tiff" ["Description"]=> string(29) "Image file in the TIFF format" ["DataFile"]=> string(7) "/tmp/35" ["FileName"]=> string(19) "gmail-filtre 2.tiff" ["FileDisposition"]=> string(6) "inline" ["ContentID"]=> string(36) "7A032742-9CD8-4B32-B3B5-19AC063A8267" } } ["Alternative"]=> array(1) { [0]=> array(4) { ["Type"]=> string(4) "text" ["Description"]=> string(12) "Text message" ["Encoding"]=> string(8) "us-ascii" ["DataFile"]=> string(7) "/tmp/15" } } ["Subject"]=> string(7) "test pj" ["Date"]=> string(36) "Wed, 9 Mar 2016 00:41:58 +0100 (CET)" ["From"]=> array(1) { [0]=> array(2) { ["address"]=> string(17) "[email protected]" ["name"]=> string(9) "leeroxxxx" } } ["To"]=> array(1) { [0]=> array(2) { ["address"]=> string(14) "[email protected]" ["name"]=> string(21) "[email protected] Arnaud" } } }
ok, thanks for your answer, i'll test this.
|
info at phpclasses dot org.
