Add MIME preamble to all multipart message types, should fix #316

Tidy up format of test messages
This commit is contained in:
Synchro 2015-03-17 18:55:11 +01:00
parent d1c43fe83f
commit c8be94946e
2 changed files with 28 additions and 17 deletions

View File

@ -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] . '"');

View File

@ -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 = '<br/>';
$bullet = '<li>';
$bullet_start = '<ul>';
$bullet_end = '</ul>';
$eol = "<br/>\r\n";
$bullet_start = '<li>';
$bullet_end = "</li>\r\n";
$list_start = '<ul>';
$list_end = "</ul>\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