编译安装了php扩展,用php解析eml文件,在浏览器中显示邮件有关信息,如何提取
1.邮件正文内容 2.附件文件名称和大小
获取邮件头信息如发件人,收件人 邮件主题的代码如下
$file = "./log/mailmonitor/2012/03/28/smtp/1225009383.eml";
// parse the message in $file.
// The file MUST remain in existence until you are finished using
// the object, as mailparse does not cache the file in memory.
// You can also use two alternative syntaxes:
// 
// Read the message from a variable:
//   $msg =& new MimeMessage("var", $message);
//
// Read the message from a stream (from fopen).
// The stream MUST be seekable, or things will not work correctly.
// Also, you MUST NOT fclose the stream until you have finished
// using the message object (or any child objects it returns).
//   $msg =& new MimeMessage("stream", $fp);
//
$msg =& new MimeMessage("file", $file);// Process the message.
display_part_info("message", $msg);// Little function to display things
function display_part_info($caption, &$msgpart){
//echo "Message part: $caption\n";// The data member corresponds to the information
// available from the mailparse_msg_get_part_data function.
// You can access a particular header like this:
//   $subject = $msgpart->data["headers"]["subject"];
//print_r($msgpart->data);echo "The headers are:<br>";
// Display the headers (in raw format) to the browser output.
// You can also use:
//   $msgpart->extract_headers(MAILPARSE_EXTRACT_STREAM, $fp);
//     to write the headers to the supplied stream at it's current
//     position.
//
//   $var = $msgpart->extract_headers(MAILPARSE_EXTRACT_RETURN);
//     to return the headers in a variable.
$msgpart->extract_headers(MAILPARSE_EXTRACT_OUTPUT);// Display the body if this part is intended to be displayed:
$n = $msgpart->get_child_count();if ($n == 0) {
    // Return the body as a string (the MAILPARSE_EXTRACT parameter
    // acts just as it does in extract_headers method.
    $body = $msgpart->extract_body(MAILPARSE_EXTRACT_RETURN);
    echo $body;
echo '<br>';    // This function tells you about any uuencoded attachments
    // that are present in this part.
    $uue = $msgpart->enum_uue();
    if ($uue !== false) {
       // var_dump($uue);
        foreach($uue as $index => $data) {
             $data = array("filename" => "original filename",
                            "filesize" => "size of extracted file",
                           );

//print_r($data);
            printf("UUE[%d] %s (%d bytes)\n", $index, $data["filename"], $data["filesize"]);
echo '<br>';            // Display the extracted part to the output.
            $msgpart->extract_uue($index, MAILPARSE_EXTRACT_OUTPUT);        }
    }} else {
    // Recurse and show children of that part
    for ($i = 0; $i < $n; $i++) {
        $part =& $msgpart->get_child($i);
        display_part_info("$caption child $i", $part);
    }
 }
}