Voting

: eight minus four?
(Example: nine)

The Note You're Voting On

caevan at amkd dot com dot au
13 years ago
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);
}
}
}
}
?>

<< Back to user notes page

To Top