I am trying to build an webmail client, and, not suprisingly, I am stuck regarding the various MIME types and how to display them.
I have a mail, which has contect types of both plain text and text / html, as well as an attachment.
The attachment can be dealt with and is produced nicely, however the body message isn't.
Is there a way of breaking down the main body into different subsections that can be dealt with and parsed differently according to the content type ?
(The answer is yes, but I don't know how to do it !!)
I have looked extensively at the imap functions within [url]http://www.php.net,[/url] but no joy as yet...
Any help / links (apart from Rogering the French Maid) would be helpful...
edited to add code...
if ($struct->type == 1) /* this is multipart body message time */
{
while(list($index, $sub_structure) = each($struct->parts))
{
for($i=0; $i< count($struct->parts); $i++) {
$prefix=$i.".";
if ($struct->parts[$prefix.($index+1)]->encoding ==3) {
$arr["body"] = imap_base64(imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID));
if(strtolower($struct->parts[$prefix.($index+1)]->subtype) == 'html') $html = 1;
}
else if ($struct->parts[$prefix.($index+1)]->encoding ==4) {
$arr["body"] = imap_qprint(imap_fetchbody($this->stream, $this->msg_uid, 1, FT_UID));
if(strtolower($struct->parts[$prefix.($index+1)]->subtype) == 'html') $html = 1;
}
}
}
}
Hmmm...
This works - splits multipart body mail out, decodes the right section and leaves the plain text bit alone...
if ($struct->type == 1) /* this is multipart body message time */
{
while(list($index, $sub_structure) = each($struct->parts))
{
for($i=0; $i< count($struct->parts); $i++) {
$prefix=$i.".";
echo "part ".$prefix.($index+1)." aka ".$struct->parts[$i]->parts[($index)]->encoding;
if ($struct->parts[$i]->parts[($index)]->encoding ==3) {
$arr["body"] = imap_base64(imap_fetchbody($this->stream, $this->msg_uid, ($prefix.$index), FT_UID));
if(strtolower($struct->parts[$prefix.($index+1)]->subtype) == 'html') $html = 1;
}
else if ($struct->parts[$i]->parts[($index)]->encoding ==4) {
$arr["body"] = imap_qprint(imap_fetchbody($this->stream, $this->msg_uid, ($prefix.$index), FT_UID));
if(strtolower($struct->parts[$prefix.($index+1)]->subtype) == 'html') $html = 1;
}
else {
$arr["body"] = imap_fetchbody($this->stream, $this->msg_uid, ($prefix.$index), FT_UID);
if(strtolower($struct->subtype) == 'html') $html = 1;
}
}
}
}
Hope it helps someone....
Some ideas came fromhere which helped - look at the user notes..