improved parsing of multipart/alternative

This commit is contained in:
Lars Kneschke 2006-07-22 13:46:09 +00:00
parent 8254487a3e
commit 140c700a82

View File

@ -962,8 +962,7 @@
} }
function getMessageBody($_uid, $_htmlOptions='', $_partID='', $_structure='') function getMessageBody($_uid, $_htmlOptions='', $_partID='', $_structure='') {
{
#print "UID: $_uid HTML: $_htmlOptions PART: $_partID<br>"; #print "UID: $_uid HTML: $_htmlOptions PART: $_partID<br>";
#print $this->htmlOptions."<br>"; #print $this->htmlOptions."<br>";
#require_once('Mail/mimeDecode.php'); #require_once('Mail/mimeDecode.php');
@ -991,82 +990,104 @@
} }
} }
#_debug_array($structure); #_debug_array($structure);
if($structure->type == TYPETEXT) { switch($structure->type) {
$bodyPart = array(); case TYPEMESSAGE:
if (($structure->subtype == 'HTML' || $structure->subtype == 'PLAIN') && $structure->disposition != 'ATTACHMENT') { switch($structure->subtype) {
// only text or html email case 'RFC822':
#print "_patrID = $_partID"; $i=1;
if($_partID == '') foreach($structure->parts as $part) {
$_partID=1; if($part->type == TYPEMULTIPART &&
#else ($part->subtype == 'RELATED' || $part->subtype == 'MIXED' || $part->subtype == 'ALTERNATIVE' || $part->subtype == 'REPORT') ) {
# $_partID=$_partID.'.1'; $bodyParts = $this->getMessageBody($_uid, $this->htmlOptions, $_partID, $part);
#$partID = $_partID == '' ? $_partID=1 : $_partID=$_partID.'.1'; } else {
$partID = $_partID; $bodyParts = $this->getMessageBody($_uid, $this->htmlOptions, $_partID.'.'.$i, $part);
$mimePartBody = imap_fetchbody($this->mbox, $_uid, $partID, FT_UID); }
$i++;
}
return $bodyParts;
break;
case 'DELIVERY-STATUS':
// only text
if($_partID == '') $_partID=1;
$mimePartBody = imap_fetchbody($this->mbox, $_uid, $_partID, FT_UID);
$bodyPart = array(
array(
'body' => $this->decodeMimePart($mimePartBody, $structure->encoding),
'mimeType' => 'text/plain',
'charSet' => $this->getMimePartCharset($structure),
)
);
return $bodyPart;
break;
}
break;
case TYPEMULTIPART:
switch($structure->subtype) {
case 'ALTERNATIVE':
return $this->getMultipartAlternative($_uid, $_partID, $structure, $this->htmlOptions);
break;
default:
$i = 1;
$parentPartID = ($_partID != '') ? $_partID.'.' : '';
$bodyParts = array();
foreach($structure->parts as $part) {
if($part->type == TYPETEXT || $part->type == TYPEMULTIPART || $part->type == TYPEMESSAGE) {
$bodyParts = array_merge($bodyParts, $this->getMessageBody($_uid, $this->htmlOptions, $parentPartID.$i, $part));
}
$i++;
}
return $bodyParts;
break;
}
break;
case TYPETEXT:
$bodyPart = array();
#_debug_array($structure);
if (($structure->subtype == 'HTML' || $structure->subtype == 'PLAIN') && $structure->disposition != 'ATTACHMENT') {
if($_partID == '') {
$_partID=1;
}
$partID = $_partID;
$mimePartBody = imap_fetchbody($this->mbox, $_uid, $partID, FT_UID);
$bodyPart = array(
array(
'body' => $this->decodeMimePart($mimePartBody, $structure->encoding),
'mimeType' => $structure->subtype == 'HTML' ? 'text/html' : 'text/plain',
'charSet' => $this->getMimePartCharset($structure),
)
);
}
return $bodyPart;
break;
default:
$bodyPart = array( $bodyPart = array(
array( array(
'body' => $this->decodeMimePart($mimePartBody, $structure->encoding), 'body' => lang('The mimeparser can not parse this message.'),
'mimeType' => $structure->subtype == 'HTML' ? 'text/html' : 'text/plain', 'mimeType' => 'text/plain',
'charSet' => $this->getMimePartCharset($structure), 'charSet' => 'iso-8859-1',
) )
); );
}
return $bodyPart; return $bodyPart;
} elseif ($structure->type == TYPEMULTIPART && $structure->subtype == 'ALTERNATIVE') { break;
return $this->getMultipartAlternative($_uid, $_partID, $structure, $this->htmlOptions);
#} elseif (($structure->type == TYPEMULTIPART && ($structure->subtype == 'MIXED' || $structure->subtype == 'REPORT' || $structure->subtype == 'SIGNED'))) {
} elseif ($structure->type == TYPEMULTIPART) {
$i = 1;
$parentPartID = ($_partID != '') ? $_partID.'.' : '';
$bodyParts = array();
foreach($structure->parts as $part) {
if($part->type == TYPETEXT || ($part->type == TYPEMULTIPART && $part->subtype == 'ALTERNATIVE')) {
$bodyParts = array_merge($bodyParts, $this->getMessageBody($_uid, $this->htmlOptions, $parentPartID.$i, $part));
}
$i++;
}
return $bodyParts;
} elseif ($structure->type == TYPEMESSAGE && $structure->subtype == 'RFC822') {
#$bodyParts = $this->getMessageBody($_uid, $this->htmlOptions, $_partID, $structure->parts[0]);
#return $bodyParts;
$i=1;
foreach($structure->parts as $part) {
if($part->type == TYPEMULTIPART &&
($part->subtype == 'RELATED' || $part->subtype == 'MIXED' || $part->subtype == 'ALTERNATIVE' || $part->subtype == 'REPORT') ) {
$bodyParts = $this->getMessageBody($_uid, $this->htmlOptions, $_partID, $part);
} else {
$bodyParts = $this->getMessageBody($_uid, $this->htmlOptions, $_partID.'.'.$i, $part);
}
$i++;
}
return $bodyParts;
} elseif ($structure->type == TYPEMESSAGE && $structure->subtype == 'DELIVERY-STATUS') {
// only text
if($_partID == '') $_partID=1;
$mimePartBody = imap_fetchbody($this->mbox, $_uid, $_partID, FT_UID);
$bodyPart = array(
array(
'body' => $this->decodeMimePart($mimePartBody, $structure->encoding),
'mimeType' => 'text/plain',
'charSet' => $this->getMimePartCharset($structure),
)
);
return $bodyPart;
} else {
$bodyPart = array(
array(
'body' => lang('The mimeparser can not parse this message.'),
'mimeType' => 'text/plain',
'charSet' => 'iso-8859-1',
)
);
return $bodyPart;
} }
} }
function getMessageHeader($_uid, $_partID = '') function getMessageHeader($_uid, $_partID = '')
{ {
$msgno = imap_msgno($this->mbox, $_uid); $msgno = imap_msgno($this->mbox, $_uid);