Mail_Mbox() PEAR 脚本 - 从字符串而不是文件加载 mbox 消息

发布于 2024-11-13 12:13:02 字数 1405 浏览 4 评论 0原文

如果我尝试从文件加载,它会很好用,但我正在处理以前存储在 MySQL 表中的 mbox 格式的消息。我已将消息加载到 $variable 中,但出于某种原因它不想接受它。有什么想法吗?

示例代码:

<?php
    // Reads a mbox file
    #$mbox = new Mail_Mbox('test.mbox');        // Works
    $mbox = new Mail_Mbox($data);               // Doesn't work (what the heck?!)
    $mbox->open();

    $message = $mbox->get(0);

    $decodedMessage = new Mail_mimeDecode($message, "\r\n");
    $structuredMessage = $decodedMessage->decode(
        array(
            'include_bodies'    =>  true,
            'decode_bodies'     =>  true
        )
    );
?>

除了从字符串(而不是文件)将消息加载到此脚本中之外,一切正常。完全迷失了这一点。

供参考: http://pear.php.net/package/Mail_Mbox

有效的解决方案示例:

<?php
    // Setup a Stream_Var() to let us use a $variable like a file...so that Mail_Mbox() works
    stream_wrapper_register( "var", "Stream_Var" );

    // Reads a mbox file
    $mbox = new Mail_Mbox('var://GLOBALS/this-is-my-variable');   // Leave the $ off
    $mbox->open();

    $message = $mbox->get(0);

    $decodedMessage = new Mail_mimeDecode($message, "\r\n");
    $structuredMessage = $decodedMessage->decode(
        array(
            'include_bodies'    =>  true,
            'decode_bodies'     =>  true
        )
    );
?>

It works great if I try to load from a file, but I'm working with mbox formatted messages previously stored in a MySQL table. I've loaded the message into a $variable and for whatever reason it doesn't want to accept it. Any ideas?

Sample code:

<?php
    // Reads a mbox file
    #$mbox = new Mail_Mbox('test.mbox');        // Works
    $mbox = new Mail_Mbox($data);               // Doesn't work (what the heck?!)
    $mbox->open();

    $message = $mbox->get(0);

    $decodedMessage = new Mail_mimeDecode($message, "\r\n");
    $structuredMessage = $decodedMessage->decode(
        array(
            'include_bodies'    =>  true,
            'decode_bodies'     =>  true
        )
    );
?>

Everything's working except loading a message into this script from a string, as opposed to a file. Totally lost on this.

For reference:
http://pear.php.net/package/Mail_Mbox

SOLUTION EXAMPLE THAT WORKS:

<?php
    // Setup a Stream_Var() to let us use a $variable like a file...so that Mail_Mbox() works
    stream_wrapper_register( "var", "Stream_Var" );

    // Reads a mbox file
    $mbox = new Mail_Mbox('var://GLOBALS/this-is-my-variable');   // Leave the $ off
    $mbox->open();

    $message = $mbox->get(0);

    $decodedMessage = new Mail_mimeDecode($message, "\r\n");
    $structuredMessage = $decodedMessage->decode(
        array(
            'include_bodies'    =>  true,
            'decode_bodies'     =>  true
        )
    );
?>

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

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

发布评论

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

评论(1

维持三分热 2024-11-20 12:13:02

文档说明 :

void 构造函数 Mail_Mbox::Mail_Mbox ( string $file )

该类接受字符串,只接受文件。

您可能想尝试像 Stream_Var 这样的流包装器,以使变量像文件一样可访问。也许它有效。如果没有,请在 PEAR bugtracker 中提出功能请求。

The documentation states:

void constructor Mail_Mbox::Mail_Mbox ( string $file )

The class does not accept strings, only files.

You might want to try a stream wrapper like Stream_Var to make the variable accessible like a file. Maybe it works. If it does not, open a feature request in the PEAR bugtracker.

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