Skip to content

Commit

Permalink
Corrections to ISO text test
Browse files Browse the repository at this point in the history
Only test ICS configs that are actually supported!
Fix missing headers when using signed messages
  • Loading branch information
Synchro committed Apr 29, 2015
1 parent 0635bf6 commit 9164e6d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
8 changes: 6 additions & 2 deletions class.phpmailer.php
Expand Up @@ -1030,16 +1030,20 @@ public function preSend()
$this->ContentType = 'multipart/alternative';
}

$this->error_count = 0; // reset errors
$this->error_count = 0; // Reset errors
$this->setMessageType();
// Refuse to send an empty message unless we are specifically allowing it
if (!$this->AllowEmpty and empty($this->Body)) {
throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
}

//Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
// Create body before headers in case body makes changes to headers (e.g. altering transfer encoding)
$this->MIMEHeader = '';
$this->MIMEBody = $this->createBody();
// createBody may have added some headers, so retain them
$tempheaders = $this->MIMEHeader;
$this->MIMEHeader = $this->createHeader();
$this->MIMEHeader .= $tempheaders;

// To capture the complete message when using mail(), create
// an extra header list which createHeader() doesn't fold in
Expand Down
38 changes: 12 additions & 26 deletions test/phpmailerTest.php
Expand Up @@ -806,21 +806,29 @@ public function testHtml()
*/
public function testHtmlIso8859()
{
$this->Mail->isHTML(false);
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": ISO-8859-1 HTML";
$this->Mail->CharSet = 'iso-8859-1';

//This file is in ISO-8859-1 charset
//Needs to be external because this file is in UTF-8
$content = file_get_contents('../examples/contents.html');
// This is the string 'éèîüçÅñæß' in ISO-8859-1, base-64 encoded
$check = base64_decode('6eju/OfF8ebf');
//Make sure it really is in ISO-8859-1!
$this->Mail->Body =
$this->Mail->msgHTML(
mb_convert_encoding(
$content,
"ISO-8859-1",
mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true)
);
),
'../examples'
);
$this->buildBody();
$this->assertTrue(
strpos($this->Mail->Body, $check) !== false,
'ISO message body does not contain expected text'
);
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}

Expand Down Expand Up @@ -1095,36 +1103,14 @@ public function testIcal()
//Need to test generated output but PHPUnit isn't playing nice
//$rendered = $ICS->render();

//Now test sending an ICS
//Test sending an ICS
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->AltBody = 'This is the text part of the email.';
$this->Mail->Subject .= ': iCal';
$this->Mail->isHTML(true);
$this->buildBody();
$ICS = new EasyPeasyICS("PHPMailer test calendar");
$ICS->addEvent(
strtotime('tomorrow 10:00 Europe/Paris'),
strtotime('tomorrow 11:00 Europe/Paris'),
'PHPMailer iCal test',
'A test of PHPMailer iCal support',
'https://github.com/PHPMailer/PHPMailer'
);
$this->Mail->Ical = $ICS->render(false);
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
'Here is an image!</a>.';
$this->Mail->AltBody = 'This is the text part of the email.';
$this->Mail->Subject .= ': iCal + inline';
$this->Mail->isHTML(true);
$this->Mail->addEmbeddedImage(
'../examples/images/phpmailer.png',
'my-attach',
'phpmailer.png',
'base64',
'image/png'
);
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}

/**
Expand Down

0 comments on commit 9164e6d

Please sign in to comment.