PHP Mailparse pecl 扩展的任何好的文档/教程

发布于 2024-07-10 08:39:38 字数 186 浏览 15 评论 0原文

我正在寻找有关如何使用 PHP 的 Mailparse pecl 扩展的指南。 PHP 网站上的文档不是很有帮助。

有没有人有这方面的经验并愿意分享一些建议?

I'm looking for guidance on how to use PHP's Mailparse pecl extension. The documentation on the PHP website isn't very helpful.

Does anyone have experience with this and care to share a few pointers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相对绾红妆 2024-07-17 08:39:39

扩展名附带的 README 文件中有补充文档< /a> 包括以下 OO 示例,我发现它很有帮助。

<?php
$file = "/path/to/rfc822/compliant/message";
// 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"];
var_dump($msgpart->data);

echo "The headers are:\n";
// 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 htmlentities($body);
    
    // 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",
            //               );

            printf("UUE[%d] %s (%d bytes)\n",
                $index, $data["filename"],
                $data["filesize"]);

            // 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);
    }
}
}

?>

There is supplementary documentation in the README file that comes with the extension including the following OO example which I found helpful.

<?php
$file = "/path/to/rfc822/compliant/message";
// 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"];
var_dump($msgpart->data);

echo "The headers are:\n";
// 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 htmlentities($body);
    
    // 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",
            //               );

            printf("UUE[%d] %s (%d bytes)\n",
                $index, $data["filename"],
                $data["filesize"]);

            // 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);
    }
}
}

?>
恏ㄋ傷疤忘ㄋ疼 2024-07-17 08:39:39

您可以联系 PECL mailparse 包维护者

You could contact the PECL mailparse package maintainers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文