Parsing a stdClass Object created with mimeDecode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

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 am a bit new to stdClass Object and Mail_mimeDecode so any help is appreciated This script was taken from a previous example on http:// www.troywolf.com/articles/php/class_xml/


The script currently is:

	include('Mail/mimeDecode.php');

	$filename = "email_multi.txt";
	$message  = fread(fopen($filename, 'r'), filesize($filename));

	header('Content-Type: text/plain');
	header('Content-Disposition: inline; filename="stuff.txt"');

	$params = array(
					'input'          => $message,
					'crlf'           => "\r\n",
					'include_bodies' => TRUE,
					'decode_headers' => TRUE,
					'decode_bodies'  => TRUE
					);

	$structure = Mail_mimeDecode::decode($params);

// This only works if you know specifically where there node/Object lives :(
foreach($structure->parts[0]->parts[0]->parts as $part)
{

//for debugging
echo $part->ctype_primary."|".$part->ctype_secondary."\n\r";

// if these conditions are met, we found the right node
if (trim($part->ctype_primary)== "text" && trim($part- >ctype_secondary) == "plain")
{
$body = $part->body;
echo "body is: $body";
}
}

?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux