PHP Classes

Have trouble with filename with inline attachments

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Have trouble with filename with...  >  (Un) Subscribe thread alerts  
Subject:Have trouble with filename with...
Summary:attachments on email
Messages:7
Author:arnaudroyone
Date:2016-03-08 22:30:49
 

  1. Have trouble with filename with...   Reply   Report abuse  
Picture of arnaudroyone arnaudroyone - 2016-03-08 22:30:49
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

  2. Re: Have trouble with filename with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-03-08 22:36:13 - In reply to message 1 from arnaudroyone
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?

  3. Re: Have trouble with filename with...   Reply   Report abuse  
Picture of arnaudroyone arnaudroyone - 2016-03-08 22:57:43 - In reply to message 2 from Manuel Lemos
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
';


  4. Re: Have trouble with filename with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-03-08 23:32:54 - In reply to message 3 from arnaudroyone
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.

  5. Re: Have trouble with filename with...   Reply   Report abuse  
Picture of arnaudroyone arnaudroyone - 2016-03-08 23:51:17 - In reply to message 4 from Manuel Lemos
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 <royone@free.fr>; Wed, 9 Mar 2016 00:41:58 +0100 (CET)
X-SFR-UUID: 20160308234158166.28969700008B@msfrf2403.sfr.fr
From: leeroxxxx <leeroxxxx@free.fr>
Subject: test pj
Message-Id: <3578B465-6738-41C3-A43B-1C8E3E295666@free.fr>
Date: Wed, 9 Mar 2016 00:41:58 +0100 (CET)
To: "roxxxx@free.fr Arnaud" <roxxxx@free.fr>
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: roxxxx@free.fr
X-Mailer: Zimbra 7.2.0-GA2598
X-Authenticated-User: roxxxx@free.fr

--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--

  6. Re: Have trouble with filename with...   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2016-03-09 01:17:01 - In reply to message 5 from arnaudroyone
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) "leeroxxxx@free.fr"
["name"]=>
string(9) "leeroxxxx"
}
}
["To"]=>
array(1) {
[0]=>
array(2) {
["address"]=>
string(14) "roxxxx@free.fr"
["name"]=>
string(21) "roxxxx@free.fr Arnaud"
}
}
}

  7. Re: Have trouble with filename with...   Reply   Report abuse  
Picture of arnaudroyone arnaudroyone - 2016-03-09 02:53:32 - In reply to message 6 from Manuel Lemos
ok, thanks for your answer, i'll test this.