Browse Source

SwiftMailer message updated to setup charset for alternative body correctly.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
232a223c17
  1. 8
      extensions/yii/swiftmailer/Message.php
  2. 19
      tests/unit/extensions/swiftmailer/MessageTest.php

8
extensions/yii/swiftmailer/Message.php

@ -188,6 +188,7 @@ class Message extends BaseMessage
{
$message = $this->getSwiftMessage();
$oldBody = $message->getBody();
$charset = $message->getCharset();
if (empty($oldBody)) {
$parts = $message->getChildren();
$partFound = false;
@ -195,6 +196,7 @@ class Message extends BaseMessage
if (!($part instanceof \Swift_Mime_Attachment)) {
/* @var \Swift_Mime_MimePart $part */
if ($part->getContentType() == $contentType) {
$charset = $part->getCharset();
unset($parts[$key]);
$partFound = true;
break;
@ -204,7 +206,7 @@ class Message extends BaseMessage
if ($partFound) {
reset($parts);
$message->setChildren($parts);
$message->addPart($body, $contentType);
$message->addPart($body, $contentType, $charset);
} else {
$message->setBody($body, $contentType);
}
@ -215,8 +217,8 @@ class Message extends BaseMessage
} else {
$message->setBody(null);
$message->setContentType(null);
$message->addPart($oldBody, $oldContentType);
$message->addPart($body, $contentType);
$message->addPart($oldBody, $oldContentType, $charset);
$message->addPart($body, $contentType, $charset);
}
}
}

19
tests/unit/extensions/swiftmailer/MessageTest.php

@ -341,4 +341,23 @@ class MessageTest extends VendorTestCase
$unserializedMessaage = unserialize($serializedMessage);
$this->assertEquals($message, $unserializedMessaage, 'Unable to unserialize message!');
}
/**
* @depends testSendAlternativeBody
*/
public function testAlternativeBodyCharset()
{
$message = $this->createTestMessage();
$charset = 'windows-1251';
$message->setCharset($charset);
$message->setTextBody('some text');
$message->setHtmlBody('some html');
$content = $message->toString();
$this->assertEquals(2, substr_count($content, $charset), 'Wrong charset for alternative body.');
$message->setTextBody('some text override');
$content = $message->toString();
$this->assertEquals(2, substr_count($content, $charset), 'Wrong charset for alternative body override.');
}
}

Loading…
Cancel
Save