summaryrefslogtreecommitdiff
path: root/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime')
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/AttachmentAcceptanceTest.php123
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/Base64ContentEncoderAcceptanceTest.php56
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/NativeQpContentEncoderAcceptanceTest.php88
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/PlainContentEncoderAcceptanceTest.php88
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/QpContentEncoderAcceptanceTest.php160
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/EmbeddedFileAcceptanceTest.php136
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/HeaderEncoder/Base64HeaderEncoderAcceptanceTest.php32
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/MimePartAcceptanceTest.php127
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/SimpleMessageAcceptanceTest.php1249
9 files changed, 2059 insertions, 0 deletions
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/AttachmentAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/AttachmentAcceptanceTest.php
new file mode 100644
index 0000000..7353d9d
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/AttachmentAcceptanceTest.php
@@ -0,0 +1,123 @@
+<?php
+
+class Swift_Mime_AttachmentAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_contentEncoder;
+ private $_cache;
+ private $_grammar;
+ private $_headers;
+
+ protected function setUp()
+ {
+ $this->_cache = new Swift_KeyCache_ArrayKeyCache(
+ new Swift_KeyCache_SimpleKeyCacheInputStream()
+ );
+ $factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
+ $this->_contentEncoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
+
+ $headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
+ );
+ $paramEncoder = new Swift_Encoder_Rfc2231Encoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
+ );
+ $this->_grammar = new Swift_Mime_Grammar();
+ $this->_headers = new Swift_Mime_SimpleHeaderSet(
+ new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
+ );
+ }
+
+ public function testDispositionIsSetInHeader()
+ {
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setDisposition('inline');
+ $this->assertEquals(
+ 'Content-Type: application/pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: inline'."\r\n",
+ $attachment->toString()
+ );
+ }
+
+ public function testDispositionIsAttachmentByDefault()
+ {
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $this->assertEquals(
+ 'Content-Type: application/pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment'."\r\n",
+ $attachment->toString()
+ );
+ }
+
+ public function testFilenameIsSetInHeader()
+ {
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $this->assertEquals(
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf'."\r\n",
+ $attachment->toString()
+ );
+ }
+
+ public function testSizeIsSetInHeader()
+ {
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setSize(12340);
+ $this->assertEquals(
+ 'Content-Type: application/pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; size=12340'."\r\n",
+ $attachment->toString()
+ );
+ }
+
+ public function testMultipleParametersInHeader()
+ {
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setSize(12340);
+ $this->assertEquals(
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf; size=12340'."\r\n",
+ $attachment->toString()
+ );
+ }
+
+ public function testEndToEnd()
+ {
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setSize(12340);
+ $attachment->setBody('abcd');
+ $this->assertEquals(
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf; size=12340'."\r\n".
+ "\r\n".
+ base64_encode('abcd'),
+ $attachment->toString()
+ );
+ }
+
+ protected function _createAttachment()
+ {
+ $entity = new Swift_Mime_Attachment(
+ $this->_headers,
+ $this->_contentEncoder,
+ $this->_cache,
+ $this->_grammar
+ );
+
+ return $entity;
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/Base64ContentEncoderAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/Base64ContentEncoderAcceptanceTest.php
new file mode 100644
index 0000000..a72f5ff
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/Base64ContentEncoderAcceptanceTest.php
@@ -0,0 +1,56 @@
+<?php
+
+class Swift_Mime_ContentEncoder_Base64ContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_samplesDir;
+ private $_encoder;
+
+ protected function setUp()
+ {
+ $this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
+ $this->_encoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
+ }
+
+ public function testEncodingAndDecodingSamples()
+ {
+ $sampleFp = opendir($this->_samplesDir);
+ while (false !== $encodingDir = readdir($sampleFp)) {
+ if (substr($encodingDir, 0, 1) == '.') {
+ continue;
+ }
+
+ $sampleDir = $this->_samplesDir.'/'.$encodingDir;
+
+ if (is_dir($sampleDir)) {
+ $fileFp = opendir($sampleDir);
+ while (false !== $sampleFile = readdir($fileFp)) {
+ if (substr($sampleFile, 0, 1) == '.') {
+ continue;
+ }
+
+ $text = file_get_contents($sampleDir.'/'.$sampleFile);
+
+ $os = new Swift_ByteStream_ArrayByteStream();
+ $os->write($text);
+
+ $is = new Swift_ByteStream_ArrayByteStream();
+
+ $this->_encoder->encodeByteStream($os, $is);
+
+ $encoded = '';
+ while (false !== $bytes = $is->read(8192)) {
+ $encoded .= $bytes;
+ }
+
+ $this->assertEquals(
+ base64_decode($encoded), $text,
+ '%s: Encoded string should decode back to original string for sample '.
+ $sampleDir.'/'.$sampleFile
+ );
+ }
+ closedir($fileFp);
+ }
+ }
+ closedir($sampleFp);
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/NativeQpContentEncoderAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/NativeQpContentEncoderAcceptanceTest.php
new file mode 100644
index 0000000..0dfc4e2
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/NativeQpContentEncoderAcceptanceTest.php
@@ -0,0 +1,88 @@
+<?php
+
+class Swift_Mime_ContentEncoder_NativeQpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ protected $_samplesDir;
+
+ /**
+ * @var Swift_Mime_ContentEncoder_NativeQpContentEncoder
+ */
+ protected $_encoder;
+
+ protected function setUp()
+ {
+ $this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
+ $this->_encoder = new Swift_Mime_ContentEncoder_NativeQpContentEncoder();
+ }
+
+ public function testEncodingAndDecodingSamples()
+ {
+ $sampleFp = opendir($this->_samplesDir);
+ while (false !== $encodingDir = readdir($sampleFp)) {
+ if (substr($encodingDir, 0, 1) == '.') {
+ continue;
+ }
+
+ $sampleDir = $this->_samplesDir.'/'.$encodingDir;
+
+ if (is_dir($sampleDir)) {
+ $fileFp = opendir($sampleDir);
+ while (false !== $sampleFile = readdir($fileFp)) {
+ if (substr($sampleFile, 0, 1) == '.') {
+ continue;
+ }
+
+ $text = file_get_contents($sampleDir.'/'.$sampleFile);
+
+ $os = new Swift_ByteStream_ArrayByteStream();
+ $os->write($text);
+
+ $is = new Swift_ByteStream_ArrayByteStream();
+ $this->_encoder->encodeByteStream($os, $is);
+
+ $encoded = '';
+ while (false !== $bytes = $is->read(8192)) {
+ $encoded .= $bytes;
+ }
+
+ $this->assertEquals(
+ quoted_printable_decode($encoded),
+ // CR and LF are converted to CRLF
+ preg_replace('~\r(?!\n)|(?<!\r)\n~', "\r\n", $text),
+ '%s: Encoded string should decode back to original string for sample '.$sampleDir.'/'.$sampleFile
+ );
+ }
+ closedir($fileFp);
+ }
+ }
+ closedir($sampleFp);
+ }
+
+ public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
+ {
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertSame('=C3=A4=C3=B6=C3=BC=C3=9F', $encoder->encodeString('äöüß'));
+ }
+
+ /**
+ * @expectedException \RuntimeException
+ */
+ public function testCharsetChangeNotImplemented()
+ {
+ $this->_encoder->charsetChanged('utf-8');
+ $this->_encoder->charsetChanged('charset');
+ $this->_encoder->encodeString('foo');
+ }
+
+ public function testGetName()
+ {
+ $this->assertSame('quoted-printable', $this->_encoder->getName());
+ }
+
+ private function _createEncoderFromContainer()
+ {
+ return Swift_DependencyContainer::getInstance()
+ ->lookup('mime.nativeqpcontentencoder')
+ ;
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/PlainContentEncoderAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/PlainContentEncoderAcceptanceTest.php
new file mode 100644
index 0000000..5eff4e2
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/PlainContentEncoderAcceptanceTest.php
@@ -0,0 +1,88 @@
+<?php
+
+class Swift_Mime_ContentEncoder_PlainContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_samplesDir;
+ private $_encoder;
+
+ protected function setUp()
+ {
+ $this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
+ $this->_encoder = new Swift_Mime_ContentEncoder_PlainContentEncoder('8bit');
+ }
+
+ public function testEncodingAndDecodingSamplesString()
+ {
+ $sampleFp = opendir($this->_samplesDir);
+ while (false !== $encodingDir = readdir($sampleFp)) {
+ if (substr($encodingDir, 0, 1) == '.') {
+ continue;
+ }
+
+ $sampleDir = $this->_samplesDir.'/'.$encodingDir;
+
+ if (is_dir($sampleDir)) {
+ $fileFp = opendir($sampleDir);
+ while (false !== $sampleFile = readdir($fileFp)) {
+ if (substr($sampleFile, 0, 1) == '.') {
+ continue;
+ }
+
+ $text = file_get_contents($sampleDir.'/'.$sampleFile);
+ $encodedText = $this->_encoder->encodeString($text);
+
+ $this->assertEquals(
+ $encodedText, $text,
+ '%s: Encoded string should be identical to original string for sample '.
+ $sampleDir.'/'.$sampleFile
+ );
+ }
+ closedir($fileFp);
+ }
+ }
+ closedir($sampleFp);
+ }
+
+ public function testEncodingAndDecodingSamplesByteStream()
+ {
+ $sampleFp = opendir($this->_samplesDir);
+ while (false !== $encodingDir = readdir($sampleFp)) {
+ if (substr($encodingDir, 0, 1) == '.') {
+ continue;
+ }
+
+ $sampleDir = $this->_samplesDir.'/'.$encodingDir;
+
+ if (is_dir($sampleDir)) {
+ $fileFp = opendir($sampleDir);
+ while (false !== $sampleFile = readdir($fileFp)) {
+ if (substr($sampleFile, 0, 1) == '.') {
+ continue;
+ }
+
+ $text = file_get_contents($sampleDir.'/'.$sampleFile);
+
+ $os = new Swift_ByteStream_ArrayByteStream();
+ $os->write($text);
+
+ $is = new Swift_ByteStream_ArrayByteStream();
+
+ $this->_encoder->encodeByteStream($os, $is);
+
+ $encoded = '';
+ while (false !== $bytes = $is->read(8192)) {
+ $encoded .= $bytes;
+ }
+
+ $this->assertEquals(
+ $encoded, $text,
+ '%s: Encoded string should be identical to original string for sample '.
+ $sampleDir.'/'.$sampleFile
+ );
+ }
+ closedir($fileFp);
+ }
+ }
+ closedir($sampleFp);
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/QpContentEncoderAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/QpContentEncoderAcceptanceTest.php
new file mode 100644
index 0000000..a383b58
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/ContentEncoder/QpContentEncoderAcceptanceTest.php
@@ -0,0 +1,160 @@
+<?php
+
+class Swift_Mime_ContentEncoder_QpContentEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_samplesDir;
+ private $_factory;
+
+ protected function setUp()
+ {
+ $this->_samplesDir = realpath(__DIR__.'/../../../../_samples/charsets');
+ $this->_factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
+ }
+
+ protected function tearDown()
+ {
+ Swift_Preferences::getInstance()->setQPDotEscape(false);
+ }
+
+ public function testEncodingAndDecodingSamples()
+ {
+ $sampleFp = opendir($this->_samplesDir);
+ while (false !== $encodingDir = readdir($sampleFp)) {
+ if (substr($encodingDir, 0, 1) == '.') {
+ continue;
+ }
+
+ $encoding = $encodingDir;
+ $charStream = new Swift_CharacterStream_NgCharacterStream(
+ $this->_factory, $encoding);
+ $encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream);
+
+ $sampleDir = $this->_samplesDir.'/'.$encodingDir;
+
+ if (is_dir($sampleDir)) {
+ $fileFp = opendir($sampleDir);
+ while (false !== $sampleFile = readdir($fileFp)) {
+ if (substr($sampleFile, 0, 1) == '.') {
+ continue;
+ }
+
+ $text = file_get_contents($sampleDir.'/'.$sampleFile);
+
+ $os = new Swift_ByteStream_ArrayByteStream();
+ $os->write($text);
+
+ $is = new Swift_ByteStream_ArrayByteStream();
+ $encoder->encodeByteStream($os, $is);
+
+ $encoded = '';
+ while (false !== $bytes = $is->read(8192)) {
+ $encoded .= $bytes;
+ }
+
+ $this->assertEquals(
+ quoted_printable_decode($encoded), $text,
+ '%s: Encoded string should decode back to original string for sample '.
+ $sampleDir.'/'.$sampleFile
+ );
+ }
+ closedir($fileFp);
+ }
+ }
+ closedir($sampleFp);
+ }
+
+ public function testEncodingAndDecodingSamplesFromDiConfiguredInstance()
+ {
+ $sampleFp = opendir($this->_samplesDir);
+ while (false !== $encodingDir = readdir($sampleFp)) {
+ if (substr($encodingDir, 0, 1) == '.') {
+ continue;
+ }
+
+ $encoding = $encodingDir;
+ $encoder = $this->_createEncoderFromContainer();
+
+ $sampleDir = $this->_samplesDir.'/'.$encodingDir;
+
+ if (is_dir($sampleDir)) {
+ $fileFp = opendir($sampleDir);
+ while (false !== $sampleFile = readdir($fileFp)) {
+ if (substr($sampleFile, 0, 1) == '.') {
+ continue;
+ }
+
+ $text = file_get_contents($sampleDir.'/'.$sampleFile);
+
+ $os = new Swift_ByteStream_ArrayByteStream();
+ $os->write($text);
+
+ $is = new Swift_ByteStream_ArrayByteStream();
+ $encoder->encodeByteStream($os, $is);
+
+ $encoded = '';
+ while (false !== $bytes = $is->read(8192)) {
+ $encoded .= $bytes;
+ }
+
+ $this->assertEquals(
+ str_replace("\r\n", "\n", quoted_printable_decode($encoded)), str_replace("\r\n", "\n", $text),
+ '%s: Encoded string should decode back to original string for sample '.
+ $sampleDir.'/'.$sampleFile
+ );
+ }
+ closedir($fileFp);
+ }
+ }
+ closedir($sampleFp);
+ }
+
+ public function testEncodingLFTextWithDiConfiguredInstance()
+ {
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\nb\nc"));
+ }
+
+ public function testEncodingCRTextWithDiConfiguredInstance()
+ {
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\rb\rc"));
+ }
+
+ public function testEncodingLFCRTextWithDiConfiguredInstance()
+ {
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertEquals("a\r\n\r\nb\r\n\r\nc", $encoder->encodeString("a\n\rb\n\rc"));
+ }
+
+ public function testEncodingCRLFTextWithDiConfiguredInstance()
+ {
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertEquals("a\r\nb\r\nc", $encoder->encodeString("a\r\nb\r\nc"));
+ }
+
+ public function testEncodingDotStuffingWithDiConfiguredInstance()
+ {
+ // Enable DotEscaping
+ Swift_Preferences::getInstance()->setQPDotEscape(true);
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertEquals("a=2E\r\n=2E\r\n=2Eb\r\nc", $encoder->encodeString("a.\r\n.\r\n.b\r\nc"));
+ // Return to default
+ Swift_Preferences::getInstance()->setQPDotEscape(false);
+ $encoder = $this->_createEncoderFromContainer();
+ $this->assertEquals("a.\r\n.\r\n.b\r\nc", $encoder->encodeString("a.\r\n.\r\n.b\r\nc"));
+ }
+
+ public function testDotStuffingEncodingAndDecodingSamplesFromDiConfiguredInstance()
+ {
+ // Enable DotEscaping
+ Swift_Preferences::getInstance()->setQPDotEscape(true);
+ $this->testEncodingAndDecodingSamplesFromDiConfiguredInstance();
+ }
+
+ private function _createEncoderFromContainer()
+ {
+ return Swift_DependencyContainer::getInstance()
+ ->lookup('mime.qpcontentencoder')
+ ;
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/EmbeddedFileAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/EmbeddedFileAcceptanceTest.php
new file mode 100644
index 0000000..0f7aa72
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/EmbeddedFileAcceptanceTest.php
@@ -0,0 +1,136 @@
+<?php
+
+class Swift_Mime_EmbeddedFileAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_contentEncoder;
+ private $_cache;
+ private $_grammar;
+ private $_headers;
+
+ protected function setUp()
+ {
+ $this->_cache = new Swift_KeyCache_ArrayKeyCache(
+ new Swift_KeyCache_SimpleKeyCacheInputStream()
+ );
+ $factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
+ $this->_contentEncoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder();
+
+ $headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
+ );
+ $paramEncoder = new Swift_Encoder_Rfc2231Encoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
+ );
+ $this->_grammar = new Swift_Mime_Grammar();
+ $this->_headers = new Swift_Mime_SimpleHeaderSet(
+ new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
+ );
+ }
+
+ public function testContentIdIsSetInHeader()
+ {
+ $file = $this->_createEmbeddedFile();
+ $file->setContentType('application/pdf');
+ $file->setId('foo@bar');
+ $this->assertEquals(
+ 'Content-Type: application/pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <foo@bar>'."\r\n".
+ 'Content-Disposition: inline'."\r\n",
+ $file->toString()
+ );
+ }
+
+ public function testDispositionIsSetInHeader()
+ {
+ $file = $this->_createEmbeddedFile();
+ $id = $file->getId();
+ $file->setContentType('application/pdf');
+ $file->setDisposition('attachment');
+ $this->assertEquals(
+ 'Content-Type: application/pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$id.'>'."\r\n".
+ 'Content-Disposition: attachment'."\r\n",
+ $file->toString()
+ );
+ }
+
+ public function testFilenameIsSetInHeader()
+ {
+ $file = $this->_createEmbeddedFile();
+ $id = $file->getId();
+ $file->setContentType('application/pdf');
+ $file->setFilename('foo.pdf');
+ $this->assertEquals(
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$id.'>'."\r\n".
+ 'Content-Disposition: inline; filename=foo.pdf'."\r\n",
+ $file->toString()
+ );
+ }
+
+ public function testSizeIsSetInHeader()
+ {
+ $file = $this->_createEmbeddedFile();
+ $id = $file->getId();
+ $file->setContentType('application/pdf');
+ $file->setSize(12340);
+ $this->assertEquals(
+ 'Content-Type: application/pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$id.'>'."\r\n".
+ 'Content-Disposition: inline; size=12340'."\r\n",
+ $file->toString()
+ );
+ }
+
+ public function testMultipleParametersInHeader()
+ {
+ $file = $this->_createEmbeddedFile();
+ $id = $file->getId();
+ $file->setContentType('application/pdf');
+ $file->setFilename('foo.pdf');
+ $file->setSize(12340);
+
+ $this->assertEquals(
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$id.'>'."\r\n".
+ 'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n",
+ $file->toString()
+ );
+ }
+
+ public function testEndToEnd()
+ {
+ $file = $this->_createEmbeddedFile();
+ $id = $file->getId();
+ $file->setContentType('application/pdf');
+ $file->setFilename('foo.pdf');
+ $file->setSize(12340);
+ $file->setBody('abcd');
+ $this->assertEquals(
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$id.'>'."\r\n".
+ 'Content-Disposition: inline; filename=foo.pdf; size=12340'."\r\n".
+ "\r\n".
+ base64_encode('abcd'),
+ $file->toString()
+ );
+ }
+
+ protected function _createEmbeddedFile()
+ {
+ $entity = new Swift_Mime_EmbeddedFile(
+ $this->_headers,
+ $this->_contentEncoder,
+ $this->_cache,
+ $this->_grammar
+ );
+
+ return $entity;
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/HeaderEncoder/Base64HeaderEncoderAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/HeaderEncoder/Base64HeaderEncoderAcceptanceTest.php
new file mode 100644
index 0000000..e3fad6d
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/HeaderEncoder/Base64HeaderEncoderAcceptanceTest.php
@@ -0,0 +1,32 @@
+<?php
+
+class Swift_Mime_HeaderEncoder_Base64HeaderEncoderAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_encoder;
+
+ protected function setUp()
+ {
+ $this->_encoder = new Swift_Mime_HeaderEncoder_Base64HeaderEncoder();
+ }
+
+ public function testEncodingJIS()
+ {
+ if (function_exists('mb_convert_encoding')) {
+ // base64_encode and split cannot handle long JIS text to fold
+ $subject = '長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い長い件名';
+
+ $encodedWrapperLength = strlen('=?iso-2022-jp?'.$this->_encoder->getName().'??=');
+
+ $old = mb_internal_encoding();
+ mb_internal_encoding('utf-8');
+ $newstring = mb_encode_mimeheader($subject, 'iso-2022-jp', 'B', "\r\n");
+ mb_internal_encoding($old);
+
+ $encoded = $this->_encoder->encodeString($subject, 0, 75 - $encodedWrapperLength, 'iso-2022-jp');
+ $this->assertEquals(
+ $encoded, $newstring,
+ 'Encoded string should decode back to original string for sample '
+ );
+ }
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/MimePartAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/MimePartAcceptanceTest.php
new file mode 100644
index 0000000..a7f6fc5
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/MimePartAcceptanceTest.php
@@ -0,0 +1,127 @@
+<?php
+
+class Swift_Mime_MimePartAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ private $_contentEncoder;
+ private $_cache;
+ private $_grammar;
+ private $_headers;
+
+ protected function setUp()
+ {
+ $this->_cache = new Swift_KeyCache_ArrayKeyCache(
+ new Swift_KeyCache_SimpleKeyCacheInputStream()
+ );
+ $factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory();
+ $this->_contentEncoder = new Swift_Mime_ContentEncoder_QpContentEncoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8'),
+ new Swift_StreamFilters_ByteArrayReplacementFilter(
+ array(array(0x0D, 0x0A), array(0x0D), array(0x0A)),
+ array(array(0x0A), array(0x0A), array(0x0D, 0x0A))
+ )
+ );
+
+ $headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
+ );
+ $paramEncoder = new Swift_Encoder_Rfc2231Encoder(
+ new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')
+ );
+ $this->_grammar = new Swift_Mime_Grammar();
+ $this->_headers = new Swift_Mime_SimpleHeaderSet(
+ new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $this->_grammar)
+ );
+ }
+
+ public function testCharsetIsSetInHeader()
+ {
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setCharset('utf-8');
+ $part->setBody('foobar');
+ $this->assertEquals(
+ 'Content-Type: text/plain; charset=utf-8'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foobar',
+ $part->toString()
+ );
+ }
+
+ public function testFormatIsSetInHeaders()
+ {
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setFormat('flowed');
+ $part->setBody('> foobar');
+ $this->assertEquals(
+ 'Content-Type: text/plain; format=flowed'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ '> foobar',
+ $part->toString()
+ );
+ }
+
+ public function testDelSpIsSetInHeaders()
+ {
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setDelSp(true);
+ $part->setBody('foobar');
+ $this->assertEquals(
+ 'Content-Type: text/plain; delsp=yes'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foobar',
+ $part->toString()
+ );
+ }
+
+ public function testAll3ParamsInHeaders()
+ {
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setCharset('utf-8');
+ $part->setFormat('fixed');
+ $part->setDelSp(true);
+ $part->setBody('foobar');
+ $this->assertEquals(
+ 'Content-Type: text/plain; charset=utf-8; format=fixed; delsp=yes'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foobar',
+ $part->toString()
+ );
+ }
+
+ public function testBodyIsCanonicalized()
+ {
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setCharset('utf-8');
+ $part->setBody("foobar\r\rtest\ning\r");
+ $this->assertEquals(
+ 'Content-Type: text/plain; charset=utf-8'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ "foobar\r\n".
+ "\r\n".
+ "test\r\n".
+ "ing\r\n",
+ $part->toString()
+ );
+ }
+
+ protected function _createMimePart()
+ {
+ $entity = new Swift_Mime_MimePart(
+ $this->_headers,
+ $this->_contentEncoder,
+ $this->_cache,
+ $this->_grammar
+ );
+
+ return $entity;
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/SimpleMessageAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/SimpleMessageAcceptanceTest.php
new file mode 100644
index 0000000..912768e
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/SimpleMessageAcceptanceTest.php
@@ -0,0 +1,1249 @@
+<?php
+
+class Swift_Mime_SimpleMessageAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ protected function setUp()
+ {
+ Swift_Preferences::getInstance()->setCharset(null); //TODO: Test with the charset defined
+ }
+
+ public function testBasicHeaders()
+ {
+ /* -- RFC 2822, 3.6.
+ */
+
+ $message = $this->_createMessage();
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString(),
+ '%s: Only required headers, and non-empty headers should be displayed'
+ );
+ }
+
+ public function testSubjectIsDisplayedIfSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testDateCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $id = $message->getId();
+ $message->setDate(1234);
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', 1234)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testMessageIdCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setId('foo@bar');
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <foo@bar>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testContentTypeCanBeChanged()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setContentType('text/html');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/html'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testCharsetCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setContentType('text/html');
+ $message->setCharset('iso-8859-1');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testFormatCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFormat('flowed');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain; format=flowed'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testEncoderCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setContentType('text/html');
+ $message->setEncoder(
+ new Swift_Mime_ContentEncoder_PlainContentEncoder('7bit')
+ );
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/html'."\r\n".
+ 'Content-Transfer-Encoding: 7bit'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testFromAddressCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom('chris.corbyn@swiftmailer.org');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: chris.corbyn@swiftmailer.org'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testFromAddressCanBeSetWithName()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris Corbyn'));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testMultipleFromAddressesCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn',
+ 'mark@swiftmailer.org',
+ ));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>, mark@swiftmailer.org'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testReturnPathAddressCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testEmptyReturnPathHeaderCanBeUsed()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Return-Path: <>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testSenderCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setSender('chris.corbyn@swiftmailer.org');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Sender: chris.corbyn@swiftmailer.org'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testSenderCanBeSetWithName()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setSender(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Sender: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: '."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testReplyToCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array('chris@w3style.co.uk' => 'Myself'));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testMultipleReplyAddressCanBeUsed()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testToAddressCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $message->setTo('mark@swiftmailer.org');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'To: mark@swiftmailer.org'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testMultipleToAddressesCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $message->setTo(array(
+ 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
+ ));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testCcAddressCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $message->setTo(array(
+ 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
+ ));
+ $message->setCc('john@some-site.com');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
+ 'Cc: john@some-site.com'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testMultipleCcAddressesCanBeSet()
+ {
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $message->setTo(array(
+ 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
+ ));
+ $message->setCc(array(
+ 'john@some-site.com' => 'John West',
+ 'fred@another-site.co.uk' => 'Big Fred',
+ ));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
+ 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testBccAddressCanBeSet()
+ {
+ //Obviously Transports need to setBcc(array()) and send to each Bcc recipient
+ // separately in accordance with RFC 2822/2821
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $message->setTo(array(
+ 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
+ ));
+ $message->setCc(array(
+ 'john@some-site.com' => 'John West',
+ 'fred@another-site.co.uk' => 'Big Fred',
+ ));
+ $message->setBcc('x@alphabet.tld');
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
+ 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
+ 'Bcc: x@alphabet.tld'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testMultipleBccAddressesCanBeSet()
+ {
+ //Obviously Transports need to setBcc(array()) and send to each Bcc recipient
+ // separately in accordance with RFC 2822/2821
+ $message = $this->_createMessage();
+ $message->setSubject('just a test subject');
+ $message->setFrom(array('chris.corbyn@swiftmailer.org' => 'Chris'));
+ $message->setReplyTo(array(
+ 'chris@w3style.co.uk' => 'Myself',
+ 'my.other@address.com' => 'Me',
+ ));
+ $message->setTo(array(
+ 'mark@swiftmailer.org', 'chris@swiftmailer.org' => 'Chris Corbyn',
+ ));
+ $message->setCc(array(
+ 'john@some-site.com' => 'John West',
+ 'fred@another-site.co.uk' => 'Big Fred',
+ ));
+ $message->setBcc(array('x@alphabet.tld', 'a@alphabet.tld' => 'A'));
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."\r\n".
+ 'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."\r\n".
+ 'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."\r\n".
+ 'Bcc: x@alphabet.tld, A <a@alphabet.tld>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testStringBodyIsAppended()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $message->setBody(
+ 'just a test body'."\r\n".
+ 'with a new line'
+ );
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'just a test body'."\r\n".
+ 'with a new line',
+ $message->toString()
+ );
+ }
+
+ public function testStringBodyIsEncoded()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $message->setBody(
+ 'Just s'.pack('C*', 0xC2, 0x01, 0x01).'me multi-'."\r\n".
+ 'line message!'
+ );
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'Just s=C2=01=01me multi-'."\r\n".
+ 'line message!',
+ $message->toString()
+ );
+ }
+
+ public function testChildrenCanBeAttached()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = $message->getDate();
+ $boundary = $message->getBoundary();
+
+ $part1 = $this->_createMimePart();
+ $part1->setContentType('text/plain');
+ $part1->setCharset('iso-8859-1');
+ $part1->setBody('foo');
+
+ $message->attach($part1);
+
+ $part2 = $this->_createMimePart();
+ $part2->setContentType('text/html');
+ $part2->setCharset('iso-8859-1');
+ $part2->setBody('test <b>foo</b>');
+
+ $message->attach($part2);
+
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'test <b>foo</b>'.
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testAttachmentsBeingAttached()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = preg_quote(date('r', $message->getDate()), '~');
+ $boundary = $message->getBoundary();
+
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setCharset('iso-8859-1');
+ $part->setBody('foo');
+
+ $message->attach($part);
+
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setBody('<pdf data>');
+
+ $message->attach($attachment);
+
+ $this->assertRegExp(
+ '~^'.
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/mixed;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="(.*?)"'."\r\n".
+ "\r\n\r\n".
+ '--\\1'."\r\n".
+ 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--\\1--'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
+ "\r\n".
+ preg_quote(base64_encode('<pdf data>'), '~').
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n".
+ '$~D',
+ $message->toString()
+ );
+ }
+
+ public function testAttachmentsAndEmbeddedFilesBeingAttached()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = preg_quote(date('r', $message->getDate()), '~');
+ $boundary = $message->getBoundary();
+
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setCharset('iso-8859-1');
+ $part->setBody('foo');
+
+ $message->attach($part);
+
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setBody('<pdf data>');
+
+ $message->attach($attachment);
+
+ $file = $this->_createEmbeddedFile();
+ $file->setContentType('image/jpeg');
+ $file->setFilename('myimage.jpg');
+ $file->setBody('<image data>');
+
+ $message->attach($file);
+
+ $cid = $file->getId();
+
+ $this->assertRegExp(
+ '~^'.
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/mixed;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="(.*?)"'."\r\n".
+ "\r\n\r\n".
+ '--\\1'."\r\n".
+ 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+
+ "\r\n\r\n".
+ '--\\1'."\r\n".
+ 'Content-Type: multipart/related;'."\r\n".
+ ' boundary="(.*?)"'."\r\n".
+ "\r\n\r\n".
+ '--\\2'."\r\n".
+ 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$cid.'>'."\r\n".
+ 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
+ "\r\n".
+ preg_quote(base64_encode('<image data>'), '~').
+ "\r\n\r\n".
+ '--\\2--'."\r\n".
+ "\r\n\r\n".
+ '--\\1--'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
+ "\r\n".
+ preg_quote(base64_encode('<pdf data>'), '~').
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n".
+ '$~D',
+ $message->toString()
+ );
+ }
+
+ public function testComplexEmbeddingOfContent()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = preg_quote(date('r', $message->getDate()), '~');
+ $boundary = $message->getBoundary();
+
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setBody('<pdf data>');
+
+ $message->attach($attachment);
+
+ $file = $this->_createEmbeddedFile();
+ $file->setContentType('image/jpeg');
+ $file->setFilename('myimage.jpg');
+ $file->setBody('<image data>');
+
+ $part = $this->_createMimePart();
+ $part->setContentType('text/html');
+ $part->setCharset('iso-8859-1');
+ $part->setBody('foo <img src="'.$message->embed($file).'" />');
+
+ $message->attach($part);
+
+ $cid = $file->getId();
+
+ $this->assertRegExp(
+ '~^'.
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/mixed;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: multipart/related;'."\r\n".
+ ' boundary="(.*?)"'."\r\n".
+ "\r\n\r\n".
+ '--\\1'."\r\n".
+ 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo <img src=3D"cid:'.$cid.'" />'.//=3D is just = in QP
+ "\r\n\r\n".
+ '--\\1'."\r\n".
+ 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$cid.'>'."\r\n".
+ 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
+ "\r\n".
+ preg_quote(base64_encode('<image data>'), '~').
+ "\r\n\r\n".
+ '--\\1--'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
+ "\r\n".
+ preg_quote(base64_encode('<pdf data>'), '~').
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n".
+ '$~D',
+ $message->toString()
+ );
+ }
+
+ public function testAttachingAndDetachingContent()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = preg_quote(date('r', $message->getDate()), '~');
+ $boundary = $message->getBoundary();
+
+ $part = $this->_createMimePart();
+ $part->setContentType('text/plain');
+ $part->setCharset('iso-8859-1');
+ $part->setBody('foo');
+
+ $message->attach($part);
+
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setBody('<pdf data>');
+
+ $message->attach($attachment);
+
+ $file = $this->_createEmbeddedFile();
+ $file->setContentType('image/jpeg');
+ $file->setFilename('myimage.jpg');
+ $file->setBody('<image data>');
+
+ $message->attach($file);
+
+ $cid = $file->getId();
+
+ $message->detach($attachment);
+
+ $this->assertRegExp(
+ '~^'.
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: multipart/related;'."\r\n".
+ ' boundary="(.*?)"'."\r\n".
+ "\r\n\r\n".
+ '--\\1'."\r\n".
+ 'Content-Type: image/jpeg; name=myimage.jpg'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-ID: <'.$cid.'>'."\r\n".
+ 'Content-Disposition: inline; filename=myimage.jpg'."\r\n".
+ "\r\n".
+ preg_quote(base64_encode('<image data>'), '~').
+ "\r\n\r\n".
+ '--\\1--'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n".
+ '$~D',
+ $message->toString(),
+ '%s: Attachment should have been detached'
+ );
+ }
+
+ public function testBoundaryDoesNotAppearAfterAllPartsAreDetached()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = $message->getDate();
+ $boundary = $message->getBoundary();
+
+ $part1 = $this->_createMimePart();
+ $part1->setContentType('text/plain');
+ $part1->setCharset('iso-8859-1');
+ $part1->setBody('foo');
+
+ $message->attach($part1);
+
+ $part2 = $this->_createMimePart();
+ $part2->setContentType('text/html');
+ $part2->setCharset('iso-8859-1');
+ $part2->setBody('test <b>foo</b>');
+
+ $message->attach($part2);
+
+ $message->detach($part1);
+ $message->detach($part2);
+
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n",
+ $message->toString(),
+ '%s: Message should be restored to orignal state after parts are detached'
+ );
+ }
+
+ public function testCharsetFormatOrDelSpAreNotShownWhenBoundaryIsSet()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $message->setCharset('utf-8');
+ $message->setFormat('flowed');
+ $message->setDelSp(true);
+
+ $id = $message->getId();
+ $date = $message->getDate();
+ $boundary = $message->getBoundary();
+
+ $part1 = $this->_createMimePart();
+ $part1->setContentType('text/plain');
+ $part1->setCharset('iso-8859-1');
+ $part1->setBody('foo');
+
+ $message->attach($part1);
+
+ $part2 = $this->_createMimePart();
+ $part2->setContentType('text/html');
+ $part2->setCharset('iso-8859-1');
+ $part2->setBody('test <b>foo</b>');
+
+ $message->attach($part2);
+
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/plain; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'test <b>foo</b>'.
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testBodyCanBeSetWithAttachments()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $message->setContentType('text/html');
+ $message->setCharset('iso-8859-1');
+ $message->setBody('foo');
+
+ $id = $message->getId();
+ $date = date('r', $message->getDate());
+ $boundary = $message->getBoundary();
+
+ $attachment = $this->_createAttachment();
+ $attachment->setContentType('application/pdf');
+ $attachment->setFilename('foo.pdf');
+ $attachment->setBody('<pdf data>');
+
+ $message->attach($attachment);
+
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/mixed;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/html; charset=iso-8859-1'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: application/pdf; name=foo.pdf'."\r\n".
+ 'Content-Transfer-Encoding: base64'."\r\n".
+ 'Content-Disposition: attachment; filename=foo.pdf'."\r\n".
+ "\r\n".
+ base64_encode('<pdf data>').
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testHtmlPartAlwaysAppearsLast()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+
+ $id = $message->getId();
+ $date = date('r', $message->getDate());
+ $boundary = $message->getBoundary();
+
+ $part1 = $this->_createMimePart();
+ $part1->setContentType('text/html');
+ $part1->setBody('foo');
+
+ $part2 = $this->_createMimePart();
+ $part2->setContentType('text/plain');
+ $part2->setBody('bar');
+
+ $message->attach($part1);
+ $message->attach($part2);
+
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'bar'.
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/html'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testBodyBecomesPartIfOtherPartsAttached()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $message->setContentType('text/html');
+ $message->setBody('foo');
+
+ $id = $message->getId();
+ $date = date('r', $message->getDate());
+ $boundary = $message->getBoundary();
+
+ $part2 = $this->_createMimePart();
+ $part2->setContentType('text/plain');
+ $part2->setBody('bar');
+
+ $message->attach($part2);
+
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.$date."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: multipart/alternative;'."\r\n".
+ ' boundary="'.$boundary.'"'."\r\n".
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'bar'.
+ "\r\n\r\n".
+ '--'.$boundary."\r\n".
+ 'Content-Type: text/html'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'foo'.
+ "\r\n\r\n".
+ '--'.$boundary.'--'."\r\n",
+ $message->toString()
+ );
+ }
+
+ public function testBodyIsCanonicalized()
+ {
+ $message = $this->_createMessage();
+ $message->setReturnPath('chris@w3style.co.uk');
+ $message->setSubject('just a test subject');
+ $message->setFrom(array(
+ 'chris.corbyn@swiftmailer.org' => 'Chris Corbyn', ));
+ $message->setBody(
+ 'just a test body'."\n".
+ 'with a new line'
+ );
+ $id = $message->getId();
+ $date = $message->getDate();
+ $this->assertEquals(
+ 'Return-Path: <chris@w3style.co.uk>'."\r\n".
+ 'Message-ID: <'.$id.'>'."\r\n".
+ 'Date: '.date('r', $date)."\r\n".
+ 'Subject: just a test subject'."\r\n".
+ 'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."\r\n".
+ 'MIME-Version: 1.0'."\r\n".
+ 'Content-Type: text/plain'."\r\n".
+ 'Content-Transfer-Encoding: quoted-printable'."\r\n".
+ "\r\n".
+ 'just a test body'."\r\n".
+ 'with a new line',
+ $message->toString()
+ );
+ }
+
+ protected function _createMessage()
+ {
+ return new Swift_Message();
+ }
+
+ protected function _createMimePart()
+ {
+ return new Swift_MimePart();
+ }
+
+ protected function _createAttachment()
+ {
+ return new Swift_Attachment();
+ }
+
+ protected function _createEmbeddedFile()
+ {
+ return new Swift_EmbeddedFile();
+ }
+}