I try post the code i wrote to read the message body
the function to get the message and break it up
function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) {
if (!$structure) {
$structure = imap_fetchstructure($stream, $msg_number);
}
if ($structure) {
if($mime_type == get_mime_type($structure)) {
if(!$part_number) {
$part_number = "1";
}
$text = imap_fetchbody($stream, $msg_number, $part_number);
if($structure->encoding == 3) {
return imap_base64($text);
} else if($structure->encoding == 4) {
return imap_qprint($text);
} else {
return $text;
}
}
if($structure->type == 1) /* multipart */ {
while(list($index, $sub_structure) = each($structure->parts)) {
if($part_number) {
$prefix = $part_number . '.';
}
$data = get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
if($data) {
return $data;
}
} // end while
} // end multipart
} // end structure
return false;
}
this is to call it and display it
$dataTxt = get_part($mbox, $id, "TEXT/PLAIN");
// GET HTML BODY
$dataHtml = get_part($mbox, $id, "TEXT/HTML");
if ($dataHtml != "") {
$dataHtml_lines = explode("\n", $dataHtml);
unset($dataHtml);
foreach ($dataHtml_lines as $x => $line) {
$dataHtml .= $line . "\n";
}
$dataHtml = eregi_replace("<body[^>.]*>","<body>",$dataHtml);
$msgBody = $dataHtml;
}
else {
$dataTxt_lines = explode("\n", $dataTxt);
unset($dataTxt);
foreach ($dataTxt_lines as $x => $line) {
$dataTxt .= htmlspecialchars($line) . "<br />\n";
}
$msgBody = $dataTxt;
}
if($v2 == 'reply' || $v2 == 'forward')
{
$text = htmlspecialchars($msgBody);
echo $text;
}
else
{
echo $msgBody;
}
Hope this helps
I wrote a mail system for my clients. They can log in and check there mail and reply forward and download attachments.
is that what you are doing?