note 108884 added to function.imap-fetchbody
| From: | caevan at amkd dot com dot au | Date: | Fri, 01 Jun 2012 02:52:26 +0000 |
| Subject: | note 108884 added to function.imap-fetchbody | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188353@lists.php.net to get a copy of this message | ||
I tried using the function add_part_to_array below and noticed a few errors were thrown. If there
are no 'parts' in the structure then if (sizeof($obj->parts) > 0) will throw an
error. As well $prefix is not defined here is the code I have updated. I have left the original
lines commented out. I have tested reading emails from a gmail account and so far so good.
<?php
// Sub function for create_part_array(). Only called by create_part_array() and itself.
function add_part_to_array($obj, $partno, & $part_array) {
$part_array[] = array('part_number' => $partno, 'part_object' =>
$obj);
if ($obj->type == 2) { // Check to see if the part is an attached email message, as in the
RFC-822 type
// if (sizeof($obj->parts) > 0) { // Check to see if the email has parts
if(array_key_exists('parts',$obj){
foreach ($obj->parts as $count => $part) {
// Iterate here again to compensate for the broken way that imap_fetchbody() handles
attachments
if (sizeof($part->parts) > 0) {
foreach ($part->parts as $count2 => $part2) {
add_part_to_array($part2, $partno.".".($count2+1), $part_array);
}
}else{ // Attached email does not have a seperate mime attachment for text
$part_array[] = array('part_number' =>
$partno.'.'.($count+1), 'part_object' => $obj);
}
}
}else{ // Not sure if this is possible
// $part_array[] = array('part_number' => $prefix.'.1',
'part_object' => $obj);
$part_array[] = array('part_number' => $partno.'.1',
'part_object' => $obj);
}
}else{ // If there are more sub-parts, expand them out.
// if (sizeof($obj->parts) > 0) {
if(array_key_exists('parts',$obj)){
foreach ($obj->parts as $count => $p) {
add_part_to_array($p, $partno.".".($count+1), $part_array);
}
}
}
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 115.64.15.202
----
Manual Page -- http://www.php.net/manual/en/function.imap-fetchbody.php
Edit -- https://master.php.net/note/edit/108884
Del: integrated -- https://master.php.net/note/delete/108884/integrated
Del: useless -- https://master.php.net/note/delete/108884/useless
Del: bad code -- https://master.php.net/note/delete/108884/bad+code
Del: spam -- https://master.php.net/note/delete/108884/spam
Del: non-english -- https://master.php.net/note/delete/108884/non-english
Del: in docs -- https://master.php.net/note/delete/108884/in+docs
Del: other reasons-- https://master.php.net/note/delete/108884
Reject -- https://master.php.net/note/reject/108884
Search -- https://master.php.net/manage/user-notes.php