Skip to content
Snippets Groups Projects
Commit 784c67f4 authored by Jared Hancock's avatar Jared Hancock
Browse files

pipe: Use Delivered-To and Message-Id from outer

If a wrapped mail is sent, copy the Delivered-To header into the nested
message so it will be clear(er) how the mail arrived into the system. Also,
copy the Message-Id into the nested mail if there is none to help against
mails delivered repeatedly.
parent 65de0c49
No related branches found
No related tags found
No related merge requests found
...@@ -53,18 +53,39 @@ class Mail_Parse { ...@@ -53,18 +53,39 @@ class Mail_Parse {
'include_bodies'=> $this->include_bodies, 'include_bodies'=> $this->include_bodies,
'decode_headers'=> $this->decode_headers, 'decode_headers'=> $this->decode_headers,
'decode_bodies' => $this->decode_bodies); 'decode_bodies' => $this->decode_bodies);
$this->splitBodyHeader();
$this->struct=Mail_mimeDecode::decode($params); $this->struct=Mail_mimeDecode::decode($params);
if (PEAR::isError($this->struct)) if (PEAR::isError($this->struct))
return false; return false;
$this->splitBodyHeader();
// Handle wrapped emails when forwarded // Handle wrapped emails when forwarded
if ($this->struct && $this->struct->parts) { if ($this->struct && $this->struct->parts) {
$outer = $this->struct; $outer = $this->struct;
$ctype = $outer->ctype_primary.'/'.$outer->ctype_secondary; $ctype = $outer->ctype_primary.'/'.$outer->ctype_secondary;
if (strcasecmp($ctype, 'message/rfc822') === 0) if (strcasecmp($ctype, 'message/rfc822') === 0) {
// Capture Delivered-To header from the outer mail
$dt = $this->struct->headers['delivered-to'];
// Capture Message-Id from outer mail
$mid = $this->struct->headers['message-id'];
$this->struct = $outer->parts[0]; $this->struct = $outer->parts[0];
// Add (clobber) delivered to header from the outer mail
if ($dt)
$this->struct->headers['delivered-to'] = $dt;
// Ensure the nested mail has a Message-Id
if (!isset($this->struct->headers['message-id']))
$this->struct->headers['message-id'] = $mid;
// Use headers of the wrapped message
$headers = array();
foreach ($this->struct->headers as $h=>$v)
$headers[mb_convert_case($h, MB_CASE_TITLE)] = $v;
$this->header = Format::array_implode(
": ", "\n", $headers);
}
} }
return (count($this->struct->headers) > 1); return (count($this->struct->headers) > 1);
...@@ -166,7 +187,9 @@ class Mail_Parse { ...@@ -166,7 +187,9 @@ class Mail_Parse {
} }
function getMessageId(){ function getMessageId(){
return $this->struct->headers['message-id']; if (!($mid = $this->struct->headers['message-id']))
$mid = sprintf('<%s@local>', md5($this->getHeader()));
return $mid;
} }
function getSubject(){ function getSubject(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment