From c8be94946e996969ff8b126b33596e2f039c47cf Mon Sep 17 00:00:00 2001 From: Synchro Date: Tue, 17 Mar 2015 18:55:11 +0100 Subject: [PATCH] Add MIME preamble to all multipart message types, should fix #316 Tidy up format of test messages --- class.phpmailer.php | 9 +++++++++ test/phpmailerTest.php | 36 +++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/class.phpmailer.php b/class.phpmailer.php index 5c33e585..7fe8b312 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -1873,20 +1873,25 @@ class PHPMailer $altBodyEncoding = '7bit'; $altBodyCharSet = 'us-ascii'; } + //Use this as a preamble in all multipart message types + $mimepre = "This is a multi-part message in MIME format.".$this->LE; switch ($this->message_type) { case 'inline': + $body .= $mimepre; $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding); $body .= $this->encodeString($this->Body, $bodyEncoding); $body .= $this->LE . $this->LE; $body .= $this->attachAll('inline', $this->boundary[1]); break; case 'attach': + $body .= $mimepre; $body .= $this->getBoundary($this->boundary[1], $bodyCharSet, '', $bodyEncoding); $body .= $this->encodeString($this->Body, $bodyEncoding); $body .= $this->LE . $this->LE; $body .= $this->attachAll('attachment', $this->boundary[1]); break; case 'inline_attach': + $body .= $mimepre; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', 'multipart/related;'); $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); @@ -1899,6 +1904,7 @@ class PHPMailer $body .= $this->attachAll('attachment', $this->boundary[1]); break; case 'alt': + $body .= $mimepre; $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding); $body .= $this->encodeString($this->AltBody, $altBodyEncoding); $body .= $this->LE . $this->LE; @@ -1913,6 +1919,7 @@ class PHPMailer $body .= $this->endBoundary($this->boundary[1]); break; case 'alt_inline': + $body .= $mimepre; $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding); $body .= $this->encodeString($this->AltBody, $altBodyEncoding); $body .= $this->LE . $this->LE; @@ -1928,6 +1935,7 @@ class PHPMailer $body .= $this->endBoundary($this->boundary[1]); break; case 'alt_attach': + $body .= $mimepre; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', 'multipart/alternative;'); $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); @@ -1943,6 +1951,7 @@ class PHPMailer $body .= $this->attachAll('attachment', $this->boundary[1]); break; case 'alt_inline_attach': + $body .= $mimepre; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', 'multipart/alternative;'); $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index d10f7302..8016908b 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -146,15 +146,17 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase // Determine line endings for message if ($this->Mail->ContentType == 'text/html' || strlen($this->Mail->AltBody) > 0) { - $eol = '
'; - $bullet = '
  • '; - $bullet_start = ''; + $eol = "
    \r\n"; + $bullet_start = '
  • '; + $bullet_end = "
  • \r\n"; + $list_start = '\r\n"; } else { - $eol = "\n"; - $bullet = ' - '; - $bullet_start = ''; + $eol = "\r\n"; + $bullet_start = ' - '; $bullet_end = ''; + $list_start = ''; + $list_end = ''; } $ReportBody = ''; @@ -173,13 +175,13 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase $attachments = $this->Mail->getAttachments(); if (count($attachments) > 0) { $ReportBody .= 'Attachments:' . $eol; - $ReportBody .= $bullet_start; + $ReportBody .= $list_start; foreach ($attachments as $attachment) { - $ReportBody .= $bullet . 'Name: ' . $attachment[1] . ', '; + $ReportBody .= $bullet_start . 'Name: ' . $attachment[1] . ', '; $ReportBody .= 'Encoding: ' . $attachment[3] . ', '; - $ReportBody .= 'Type: ' . $attachment[4] . $eol; + $ReportBody .= 'Type: ' . $attachment[4] . $bullet_end; } - $ReportBody .= $bullet_end . $eol; + $ReportBody .= $list_end . $eol; } // If there are changes then list them @@ -187,12 +189,12 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase $ReportBody .= 'Changes' . $eol; $ReportBody .= '-------' . $eol; - $ReportBody .= $bullet_start; + $ReportBody .= $list_start; for ($i = 0; $i < count($this->ChangeLog); $i++) { - $ReportBody .= $bullet . $this->ChangeLog[$i][0] . ' was changed to [' . + $ReportBody .= $bullet_start . $this->ChangeLog[$i][0] . ' was changed to [' . $this->ChangeLog[$i][1] . ']' . $eol; } - $ReportBody .= $bullet_end . $eol . $eol; + $ReportBody .= $list_end . $eol . $eol; } // If there are notes then list them @@ -200,11 +202,11 @@ class PHPMailerTest extends PHPUnit_Framework_TestCase $ReportBody .= 'Notes' . $eol; $ReportBody .= '-----' . $eol; - $ReportBody .= $bullet_start; + $ReportBody .= $list_start; for ($i = 0; $i < count($this->NoteLog); $i++) { - $ReportBody .= $bullet . $this->NoteLog[$i] . $eol; + $ReportBody .= $bullet_start . $this->NoteLog[$i] . $eol; } - $ReportBody .= $bullet_end; + $ReportBody .= $list_end; } // Re-attach the original body