Better handle multipart emails (especially those with multipart/alternative contents)

This commit is contained in:
Craig Andrews 2009-07-20 14:02:42 -04:00
parent 31307e6cdd
commit 6313cf5bfe

View File

@ -299,25 +299,37 @@ class MailerDaemon
$attachments = array(); $attachments = array();
$this->extract_part($parsed,$msg,$attachments);
return array($from, $to, $msg, $attachments);
}
function extract_part($parsed,&$msg,&$attachments){
if ($parsed->ctype_primary == 'multipart') { if ($parsed->ctype_primary == 'multipart') {
foreach ($parsed->parts as $part) { if($parsed->ctype_secondary == 'alternative'){
if ($part->ctype_primary == 'text' && $altmsg = $this->extract_msg_from_multipart_alternative_part($parsed);
$part->ctype_secondary == 'plain') { if(!empty($altmsg)) $msg = $altmsg;
$msg = $part->body;
}else{ }else{
if ($part->body) { foreach($parsed->parts as $part){
$this->extract_part($part,$msg,$attachments);
}
}
} else if ($parsed->ctype_primary == 'text'
&& $parsed->ctype_secondary=='plain') {
$msg = $parsed->body;
}else if(!empty($parsed->body)){
$attachment = tmpfile(); $attachment = tmpfile();
fwrite($attachment, $part->body); fwrite($attachment, $parsed->body);
$attachments[] = $attachment; $attachments[] = $attachment;
} }
} }
function extract_msg_from_multipart_alternative_part($parsed){
foreach ($parsed->parts as $part) {
$this->extract_part($part,$msg,$attachments);
} }
} else if ($type == 'text/plain') { //we don't want any attachments that are a result of this parsing
$msg = $parsed->body; return $msg;
} else {
$this->unsupported_type($type);
}
return array($from, $to, $msg, $attachments);
} }
function unsupported_type($type) function unsupported_type($type)