Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Commit

Permalink
Fixing crlf for subject using mail
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederik Vosberg authored and fabpot committed Aug 30, 2015
1 parent caf94ee commit cff72ef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/classes/Swift/Transport/MailTransport.php
Expand Up @@ -156,10 +156,12 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
if ("\r\n" != PHP_EOL) {
// Non-windows (not using SMTP)
$headers = str_replace("\r\n", PHP_EOL, $headers);
$subject = str_replace("\r\n", PHP_EOL, $subject);
$body = str_replace("\r\n", PHP_EOL, $body);
} else {
// Windows, using SMTP
$headers = str_replace("\r\n.", "\r\n..", $headers);
$subject = str_replace("\r\n.", "\r\n..", $subject);
$body = str_replace("\r\n.", "\r\n..", $body);
}

Expand Down
39 changes: 39 additions & 0 deletions tests/unit/Swift/Transport/MailTransportTest.php
Expand Up @@ -249,6 +249,45 @@ public function testSubjectHeaderIsPutBackAfterSending()
$transport->send($message);
}

public function testMessageHeadersOnlyHavePHPEolsDuringSending()
{
$invoker = $this->_createInvoker();
$dispatcher = $this->_createEventDispatcher();
$transport = $this->_createTransport($invoker, $dispatcher);

$subject = $this->_createHeader();
$subject->shouldReceive('getFieldBody')->andReturn("Foo\r\nBar");

$headers = $this->_createHeaders(array(
'Subject' => $subject,
));
$message = $this->_createMessage($headers);
$message->shouldReceive('toString')
->zeroOrMoreTimes()
->andReturn(
"From: Foo\r\n<foo@bar>\r\n".
"\r\n".
"This\r\n".
'body'
);

if("\r\n" != PHP_EOL) {
$expectedHeaders = "From: Foo\n<foo@bar>\n";
$expectedSubject = "Foo\nBar";
$expectedBody = "This\nbody";
} else {
$expectedHeaders = "From: Foo\r\n<foo@bar>\r\n";
$expectedSubject = "Foo\r\nBar";
$expectedBody = "This\r\nbody";
}

$invoker->shouldReceive('mail')
->once()
->with(\Mockery::any(), $expectedSubject, $expectedBody, $expectedHeaders, \Mockery::any());

$transport->send($message);
}

// -- Creation Methods

private function _createTransport($invoker, $dispatcher)
Expand Down

0 comments on commit cff72ef

Please sign in to comment.