Maybe you prefer a short and recursive way to parse a message
and get the part numbers built:
-------------------------------------------------------------
function parse_message($obj, $prefix="") {
/* Here you can process the data of the main "part" of the message, e.g.: */
do_anything_with_message_struct($obj);
if (sizeof($obj->parts) > 0)
foreach ($obj->parts as $count=>$p)
parse_part($p, $prefix.($count+1));
}
function parse_part($obj, $partno) {
/* Here you can process the part number and the data of the parts of the message, e.g.: */
do_anything_with_part_struct($obj,$partno);
if ($obj->type == TYPEMESSAGE)
parse_message($obj->parts[0], $partno.".");
else
if (sizeof($obj->parts) > 0)
foreach ($obj->parts as $count=>$p)
parse_part($p, $partno.".".($count+1));
}
/* Let's say, you have an already opened mailbox stream $mbox
and you like to parse through the first message: */
$msgno = 1;
parse_message(imap_fetchstructure($mbox,$msgno));