Mail_Mbox() PEAR 脚本 - 从字符串而不是文件加载 mbox 消息
如果我尝试从文件加载,它会很好用,但我正在处理以前存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文档说明 :
该类不接受字符串,只接受文件。
您可能想尝试像 Stream_Var 这样的流包装器,以使变量像文件一样可访问。也许它有效。如果没有,请在 PEAR bugtracker 中提出功能请求。
The documentation states:
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.