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{ foreach($parsed->parts as $part){
if ($part->body) { $this->extract_part($part,$msg,$attachments);
$attachment = tmpfile();
fwrite($attachment, $part->body);
$attachments[] = $attachment;
}
} }
} }
} else if ($type == 'text/plain') { } else if ($parsed->ctype_primary == 'text'
&& $parsed->ctype_secondary=='plain') {
$msg = $parsed->body; $msg = $parsed->body;
} else { }else if(!empty($parsed->body)){
$this->unsupported_type($type); $attachment = tmpfile();
fwrite($attachment, $parsed->body);
$attachments[] = $attachment;
} }
return array($from, $to, $msg, $attachments); }
function extract_msg_from_multipart_alternative_part($parsed){
foreach ($parsed->parts as $part) {
$this->extract_part($part,$msg,$attachments);
}
//we don't want any attachments that are a result of this parsing
return $msg;
} }
function unsupported_type($type) function unsupported_type($type)