Graham Anderson wrote:
I am trying to get the body text from a number of different emails using
mimeDecode [Pear]
Unfortunately, it appears that the body text could be in any number of
locations in the stdClass Object depending on which email is processed.
At this point, I can only access the node by looking at the
print_r($structure) directly :(
Out of the three different emails I parsed, I got three different
locations for the 'body' node
$structure->parts[0]->parts[0]->parts[0]->body;
$structure->body;
$structure->parts[0]->body;
Question:
Is there a way to generically traverse the entire object generated from
Mail_mimeDecode and search for the correct node ?
In my case, these conditions need to be met .
if (trim($part->ctype_primary)== "text" && trim($part->ctype_secondary)
== "plain")
{
$body = $part->body;
echo "the body text is: $body";
}
}
I've recently needed to do this for a site I'm writing. This is what I
came up with to find the first body (for my purposes I don't care about
the type). I've not tested it much, but it will be getting a grilling
over the coming weeks. It shouldn't be too hard to modify it to ensure
it meets your requirements, but bear in mind that an email is not
required to have a text/plain part.
if ($structure->ctype_primary == 'multipart')
{
$part = $structure->parts[0];
while ($part->ctype_primary == 'multipart')
$part = $part->parts[0];
$body = $part->body;
$type = $part->ctype_primary.'/'.$part->ctype_secondary;
}
else
{
$body = $structure->body;
$type = $structure->ctype_primary.'/'.
$structure->ctype_secondary;
}
Hope that helps.
-Stut
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php