I'm using the following code to parse the structure of the mail messages,
function parse($structure)
{
global $type;
global $encoding;

// create an array to hold message sections
$ret = array();

// split structure into parts
$parts = $structure->parts;

/*
iterate through parts
and create an array whose every element
represents one part
each element is itself an associative array
with keys representing the
- part number
- part type
- encoding
- disposition
- size
- filename
*/
for($x=0; $x<sizeof($parts); $x++)
{
$ret[$x]["pid"] = ($x+1);


$this = $parts[$x];
// default to text

if ($this->type == "")
{
    $this->type = 0;
}
$ret[$x]["type"] = $type[$this->type] . "/" . strtolower($this->subtype);

// default to 7bit
if ($this->encoding == "")
{
$this->encoding = 0;
}

$ret[$x]["encoding"] = $encoding[$this->encoding];


$ret[$x]["size"] = strtolower($this->bytes);

$ret[$x]["disposition"] = strtolower($this->disposition);

if (strtolower($this->disposition) == "attachment")
{
$params = $this->dparameters;
foreach ($params as $p)
{
if($p->attribute == "FILENAME")
{
$ret[$x]["name"] = $p->value;
break;
}
}
}
}

return $ret;
}



and when i use to show the the contents with the following code

if(is_array($sections))
{
echo sizeof($sections);
for($x=0; $x<sizeof($sections); $x++)
{
if(($sections[$x]["type"] == "text/plain" || $sections[$x]["type"] ==
"message/rfc822") && ($sections[$x]["disposition"] != "attachment"))
{

$text.= htmlspecialchars(stripslashes(trim(imap_fetchbody($inbox, $id,
$sections[$x]["pid"]))));
$text.= "<br>";
}
}
}
else
{
$text.= htmlspecialchars(stripslashes(trim(imap_body($inbox, $id))));
}

$headers = imap_header($inbox, $id);
$structure = imap_fetchstructure($inbox, $id);

// if multipart, parse
if(sizeof($structure->parts) > 1)
{
$sections = parse($structure);
$attachments = get_attachments($sections);
}

if i only have text it works fine, but if i have attachements it only shows
the attachements and not the body text.

Any thought on why does this happens?

<g>

Thanks in advance,

Sam da Costa





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

Reply via email to