Parsing a stdClass Object created with mimeDecode

From: Date: Fri, 12 May 2006 00:42:16 +0000
Subject: Parsing a stdClass Object created with mimeDecode
Groups: php.general 
Request: Send a blank email to php-general+get-236045@lists.php.net to get a copy of this message
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"; } } ?>

« previous php.general (#236045) next »