mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-29 03:13:40 +01:00
improved parsing of multipart/alternative
This commit is contained in:
parent
8254487a3e
commit
140c700a82
@ -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 $this->htmlOptions."<br>";
|
||||
#require_once('Mail/mimeDecode.php');
|
||||
@ -991,46 +990,10 @@
|
||||
}
|
||||
}
|
||||
#_debug_array($structure);
|
||||
if($structure->type == TYPETEXT) {
|
||||
$bodyPart = array();
|
||||
if (($structure->subtype == 'HTML' || $structure->subtype == 'PLAIN') && $structure->disposition != 'ATTACHMENT') {
|
||||
// only text or html email
|
||||
#print "_patrID = $_partID";
|
||||
if($_partID == '')
|
||||
$_partID=1;
|
||||
#else
|
||||
# $_partID=$_partID.'.1';
|
||||
#$partID = $_partID == '' ? $_partID=1 : $_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;
|
||||
|
||||
} elseif ($structure->type == TYPEMULTIPART && $structure->subtype == 'ALTERNATIVE') {
|
||||
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;
|
||||
switch($structure->type) {
|
||||
case TYPEMESSAGE:
|
||||
switch($structure->subtype) {
|
||||
case 'RFC822':
|
||||
$i=1;
|
||||
foreach($structure->parts as $part) {
|
||||
if($part->type == TYPEMULTIPART &&
|
||||
@ -1042,7 +1005,9 @@
|
||||
$i++;
|
||||
}
|
||||
return $bodyParts;
|
||||
} elseif ($structure->type == TYPEMESSAGE && $structure->subtype == 'DELIVERY-STATUS') {
|
||||
|
||||
break;
|
||||
case 'DELIVERY-STATUS':
|
||||
// only text
|
||||
if($_partID == '') $_partID=1;
|
||||
$mimePartBody = imap_fetchbody($this->mbox, $_uid, $_partID, FT_UID);
|
||||
@ -1053,8 +1018,62 @@
|
||||
'charSet' => $this->getMimePartCharset($structure),
|
||||
)
|
||||
);
|
||||
|
||||
return $bodyPart;
|
||||
} else {
|
||||
|
||||
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(
|
||||
array(
|
||||
'body' => lang('The mimeparser can not parse this message.'),
|
||||
@ -1062,10 +1081,12 @@
|
||||
'charSet' => 'iso-8859-1',
|
||||
)
|
||||
);
|
||||
return $bodyPart;
|
||||
}
|
||||
}
|
||||
|
||||
return $bodyPart;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function getMessageHeader($_uid, $_partID = '')
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user