Skip to content
Snippets Groups Projects
Commit 1d8036c2 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Mailer: avoid overlong headers in content ids FS#2868

parent d305bc7e
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ class Mailer {
$server = parse_url(DOKU_URL, PHP_URL_HOST);
if(strpos($server,'.') === false) $server = $server.'.localhost';
$this->partid = md5(uniqid(rand(), true)).'@'.$server;
$this->partid = substr(md5(uniqid(rand(), true)),0, 8).'@'.$server;
$this->boundary = '__________'.md5(uniqid(rand(), true));
$listid = join('.', array_reverse(explode('/', DOKU_BASE))).$server;
......@@ -430,14 +430,13 @@ class Mailer {
}
$mime .= '--'.$this->boundary.MAILHEADER_EOL;
$mime .= 'Content-Type: '.$media['mime'].';'.MAILHEADER_EOL.
' id="'.$cid.'"'.MAILHEADER_EOL;
$mime .= 'Content-Transfer-Encoding: base64'.MAILHEADER_EOL;
$mime .= "Content-ID: <$cid>".MAILHEADER_EOL;
$mime .= $this->wrappedHeaderLine('Content-Type', $media['mime'].'; id="'.$cid.'"');
$mime .= $this->wrappedHeaderLine('Content-Transfer-Encoding', 'base64');
$mime .= $this->wrappedHeaderLine('Content-ID',"<$cid>");
if($media['embed']) {
$mime .= 'Content-Disposition: inline; filename='.$media['name'].''.MAILHEADER_EOL;
$mime .= $this->wrappedHeaderLine('Content-Disposition', 'inline; filename='.$media['name']);
} else {
$mime .= 'Content-Disposition: attachment; filename='.$media['name'].''.MAILHEADER_EOL;
$mime .= $this->wrappedHeaderLine('Content-Disposition', 'attachment; filename='.$media['name']);
}
$mime .= MAILHEADER_EOL; //end of headers
$mime .= chunk_split(base64_encode($media['data']), 74, MAILHEADER_EOL);
......@@ -556,10 +555,17 @@ class Mailer {
}
}
// wrap headers
foreach($this->headers as $key => $val) {
$this->headers[$key] = wordwrap($val, 78, MAILHEADER_EOL.' ');
}
}
/**
* Returns a complete, EOL terminated header line, wraps it if necessary
*
* @param $key
* @param $val
* @return string
*/
protected function wrappedHeaderLine($key, $val){
return wordwrap("$key: $val", 78, MAILHEADER_EOL.' ').MAILHEADER_EOL;
}
/**
......@@ -571,7 +577,7 @@ class Mailer {
$headers = '';
foreach($this->headers as $key => $val) {
if ($val === '') continue;
$headers .= "$key: $val".MAILHEADER_EOL;
$headers .= $this->wrappedHeaderLine($key, $val);
}
return $headers;
}
......
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