Mail_Mbox() PEAR script - load mbox message from string instead of file
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
)
);
?>
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.
精彩评论