note 36386 added to function.imap-bodystruct

From: Date: Wed, 08 Oct 2003 09:58:53 +0000
Subject: note 36386 added to function.imap-bodystruct
Groups: php.notes 
Request: Send a blank email to php-notes+get-58034@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.imap-bodystruct.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36386 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36386&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36386&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58034) next »