diff options
author | Anika Henke <anika@selfthinker.org> | 2014-01-05 16:25:21 +0000 |
---|---|---|
committer | Anika Henke <anika@selfthinker.org> | 2014-01-05 16:25:21 +0000 |
commit | 8491e52805a9aaef90168f1417c6e0806fb7c5d7 (patch) | |
tree | 536ad50878f0ac6f6815db91f8bcb4819bc092ae /inc/Mailer.class.php | |
parent | 6fdd11e032b654dd27de346f7e54231ee043d7ef (diff) | |
parent | dfaf5f6c54597f81b1a8b777f55b89c93f87a345 (diff) | |
download | rpg-8491e52805a9aaef90168f1417c6e0806fb7c5d7.tar.gz rpg-8491e52805a9aaef90168f1417c6e0806fb7c5d7.tar.bz2 |
Merge remote-tracking branch 'origin/master' into extension_manager
Diffstat (limited to 'inc/Mailer.class.php')
-rw-r--r-- | inc/Mailer.class.php | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/inc/Mailer.class.php b/inc/Mailer.class.php index 0f3321bb9..2ac2c1d60 100644 --- a/inc/Mailer.class.php +++ b/inc/Mailer.class.php @@ -41,9 +41,10 @@ class Mailer { global $conf; $server = parse_url(DOKU_URL, PHP_URL_HOST); + if(strpos($server,'.') === false) $server = $server.'.localhost'; - $this->partid = md5(uniqid(rand(), true)).'@'.$server; - $this->boundary = '----------'.md5(uniqid(rand(), true)); + $this->partid = substr(md5(uniqid(rand(), true)),0, 8).'@'.$server; + $this->boundary = '__________'.md5(uniqid(rand(), true)); $listid = join('.', array_reverse(explode('/', DOKU_BASE))).$server; $listid = strtolower(trim($listid, '.')); @@ -57,6 +58,7 @@ class Mailer { $this->setHeader('X-DokuWiki-Server', $server); $this->setHeader('X-Auto-Response-Suppress', 'OOF'); $this->setHeader('List-Id', $conf['title'].' <'.$listid.'>'); + $this->setHeader('Date', date('r'), false); } /** @@ -417,6 +419,8 @@ class Mailer { $part = 1; // embedded attachments foreach($this->attach as $media) { + $media['name'] = str_replace(':', '_', cleanID($media['name'], true)); + // create content id $cid = 'part'.$part.'.'.$this->partid; @@ -426,13 +430,13 @@ class Mailer { } $mime .= '--'.$this->boundary.MAILHEADER_EOL; - $mime .= 'Content-Type: '.$media['mime'].';'.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); @@ -469,7 +473,7 @@ class Mailer { if(!$this->html && !count($this->attach)) { // we can send a simple single part message $this->headers['Content-Type'] = 'text/plain; charset=UTF-8'; $this->headers['Content-Transfer-Encoding'] = 'base64'; - $body .= chunk_split(base64_encode($this->text), 74, MAILHEADER_EOL); + $body .= chunk_split(base64_encode($this->text), 72, MAILHEADER_EOL); } else { // multi part it is $body .= "This is a multi-part message in MIME format.".MAILHEADER_EOL; @@ -484,10 +488,11 @@ class Mailer { $body .= 'Content-Type: text/plain; charset=UTF-8'.MAILHEADER_EOL; $body .= 'Content-Transfer-Encoding: base64'.MAILHEADER_EOL; $body .= MAILHEADER_EOL; - $body .= chunk_split(base64_encode($this->text), 74, MAILHEADER_EOL); + $body .= chunk_split(base64_encode($this->text), 72, MAILHEADER_EOL); $body .= '--'.$this->boundary.'XX'.MAILHEADER_EOL; $body .= 'Content-Type: multipart/related;'.MAILHEADER_EOL. - ' boundary="'.$this->boundary.'"'.MAILHEADER_EOL; + ' boundary="'.$this->boundary.'";'.MAILHEADER_EOL. + ' type="text/html"'.MAILHEADER_EOL; $body .= MAILHEADER_EOL; } @@ -495,7 +500,7 @@ class Mailer { $body .= 'Content-Type: text/html; charset=UTF-8'.MAILHEADER_EOL; $body .= 'Content-Transfer-Encoding: base64'.MAILHEADER_EOL; $body .= MAILHEADER_EOL; - $body .= chunk_split(base64_encode($this->html), 74, MAILHEADER_EOL); + $body .= chunk_split(base64_encode($this->html), 72, MAILHEADER_EOL); $body .= MAILHEADER_EOL; $body .= $attachments; $body .= '--'.$this->boundary.'--'.MAILHEADER_EOL; @@ -550,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; } /** @@ -564,8 +576,8 @@ class Mailer { protected function prepareHeaders() { $headers = ''; foreach($this->headers as $key => $val) { - if ($val === '') continue; - $headers .= "$key: $val".MAILHEADER_EOL; + if ($val === '' || is_null($val)) continue; + $headers .= $this->wrappedHeaderLine($key, $val); } return $headers; } @@ -628,16 +640,16 @@ class Mailer { ) return false; // The To: header is special - if(isset($this->headers['To'])) { - $to = $this->headers['To']; + if(array_key_exists('To', $this->headers)) { + $to = (string)$this->headers['To']; unset($this->headers['To']); } else { $to = ''; } // so is the subject - if(isset($this->headers['Subject'])) { - $subject = $this->headers['Subject']; + if(array_key_exists('Subject', $this->headers)) { + $subject = (string)$this->headers['Subject']; unset($this->headers['Subject']); } else { $subject = ''; |