note 36386 deleted from function.imap-bodystruct by didou
| From: | didou@php.net | Date: | Mon, 15 Jan 2007 00:35:56 +0000 |
| Subject: | note 36386 deleted from function.imap-bodystruct by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121696@lists.php.net to get a copy of this message | ||
Note Submitter: omeko at dolfijn dot nl
----
The above mentioned suggestions and code for handling attachments have some serious flaws;
especially concering mails containing attachments sent bij PHP-applications [hello Manuel!] or
SteveJobbs-aslongasitlookscool-clients.
After some extended reverse engineering I came to the following conclusions:
1) Don't count on a "inline" or "attachment" disposition to mark a bodypart
containing attachment data.
2) Never assume your attachment is NOT in the first bodypart
(i.e. default [$key]+2 constructions to start a download)
3) Do not assume your filename is in parameters and most certainly not in parameters[0] or
parameters[1]
The way to go is to loop through ALL bodyparts and look for a
parameters-attribute=="NAME" and - if not there - for a
dparameters-attribute=="FILENAME" (note the "d" in front of parameters here!)
and get the value to get the name of the attachment.
Please notice APPLEDOUBLE-encoded emails put its attachments in a parts array inside the parts
array; meaning your loop has to go one level deep if
(stristr($structure->parts[1]->subtype,"appledouble")).
Mark the part where you found the NAME or FILENAME attribute and increase +1 for your download
routine. ie.:
$nr=$partno+1;
imap_fetchbody($mbox,$msgno,$nr);
If appledouble-encoded $nr is constructed like $partno1+1.".".$partno2+1
I won't publish the code here because it's a mess and I'm ashamed of it and I'm
not sure if it covers APPLESINGLE and I don't feel like cleaning it up unless someone wants an
article on it and I'm gonna be bloody payed to write it.
Yes, this IS a hint.
Good luck, lads.