Skip to content

Commit

Permalink
use CRLF for mail body as discussed in #1101
Browse files Browse the repository at this point in the history
This has to be tested with real world mailers
  • Loading branch information
splitbrain committed Apr 15, 2016
1 parent acb389a commit e05f34f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions _test/tests/inc/mailer.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ function test_simplemail(){

// construct the expected mail body text - include the expected dokuwiki signature
$replacements = $mail->prop('replacements');
$expected_mail_body = chunk_split(base64_encode($mailbody.$replacements['text']['EMAILSIGNATURE']),72,MAILHEADER_EOL);
$expected_mail_body = chunk_split(base64_encode(
str_replace("\n", "\r\n", $mailbody.$replacements['text']['EMAILSIGNATURE'])
),72,MAILHEADER_EOL);

$this->assertNotRegexp('/Content-Type: multipart/',$dump);
$this->assertRegexp('#Content-Type: text/plain; charset=UTF-8#',$dump);
Expand Down Expand Up @@ -222,8 +224,6 @@ function test_lint(){
if(substr($line,0,5) == 'ERROR' || substr($line,0,7) == 'WARNING'){
// ignore some errors
if(strpos($line, "missing mandatory header 'return-path'")) continue; #set by MDA
if(strpos($line, "bare newline in text body decoded")) continue; #we don't send mail bodies as CRLF, yet
if(strpos($line, "last decoded line too long")) continue; #we don't send mail bodies as CRLF, yet

// get the context in which the error occured
$errorin = '';
Expand Down
8 changes: 8 additions & 0 deletions inc/Mailer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ protected function prepareBody() {
return false;
}

// ensure content is CRLF encoded
$this->text = str_replace("\r\n", "\n", $this->text);
$this->text = str_replace("\r", "\n", $this->text);
$this->text = str_replace("\n", "\r\n", $this->text);
$this->html = str_replace("\r\n", "\n", $this->html);
$this->html = str_replace("\r", "\n", $this->html);
$this->html = str_replace("\n", "\r\n", $this->html);

// add general headers
$this->headers['MIME-Version'] = '1.0';

Expand Down

0 comments on commit e05f34f

Please sign in to comment.