After playing around with the imap_bodystruct() function I found out, that it behaves like imap_fetchstructure, but as I can see only for the body-part of the message, no headers here.
You can do following (is tested):
$bodystruct = imap_bodystruct($mbox,$msgno,$partNumber)
$bodystruct->type
- returns an integer [0 - 7] -
$bodystruct->encoding
- returns an integer [0 - 5] -
$bodystruct->bytes
- return size of message in bytes -
$bodystruct->parameters
- returns an array with pairs of 'attribute' and 'value'
When writing attachment-handling for a mail client you will be able to fetch the filename of the attachment this way.
$struct = imap_fetchstructure($mbox,$msgno);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($i=2;$i<=$contentParts;$i++) {
$att[$i-2] = imap_bodystruct($mbox,$msgno,$i);
}
for ($k=0;$k<sizeof($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$attachments[$k] = $att[$k]->parameters[1]->value;
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
$attachments[$k] = $att[$k]->parameters[0]->value;
}
}
}
I have written a mail client that can handle most attachment-types if anyone interested in the source for the attachment-handling I could mail it to you.
But be warned it's no beauty-code since i've been fighting with lag of the documentation available on this issue.