Файл: gapps/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Mime/SimpleMessageAcceptanceTest.php
Строк: 1588
<?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.'>'."rn".
'Date: '.date('r', $date)."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', 1234)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/html'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/html; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain; format=flowed'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/html'."rn".
'Content-Transfer-Encoding: 7bit'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: chris.corbyn@swiftmailer.org'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>, mark@swiftmailer.org'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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: <>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: '."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'To: mark@swiftmailer.org'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."rn".
'Cc: john@some-site.com'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."rn".
'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."rn".
'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."rn".
'Bcc: x@alphabet.tld'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris <chris.corbyn@swiftmailer.org>'."rn".
'Reply-To: Myself <chris@w3style.co.uk>, Me <my.other@address.com>'."rn".
'To: mark@swiftmailer.org, Chris Corbyn <chris@swiftmailer.org>'."rn".
'Cc: John West <john@some-site.com>, Big Fred <fred@another-site.co.uk>'."rn".
'Bcc: x@alphabet.tld, A <a@alphabet.tld>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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'."rn".
'with a new line'
);
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'just a test body'."rn".
'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-'."rn".
'line message!'
);
$id = $message->getId();
$date = $message->getDate();
$this->assertEquals(
'Return-Path: <chris@w3style.co.uk>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'Just s=C2=01=01me multi-'."rn".
'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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/plain; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/html; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'test <b>foo</b>'.
"rnrn".
'--'.$boundary.'--'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/mixed;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="(.*?)"'."rn".
"rnrn".
'--\1'."rn".
'Content-Type: text/plain; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--\1--'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: application/pdf; name=foo.pdf'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-Disposition: attachment; filename=foo.pdf'."rn".
"rn".
preg_quote(base64_encode('<pdf data>'), '~').
"rnrn".
'--'.$boundary.'--'."rn".
'$~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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/mixed;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="(.*?)"'."rn".
"rnrn".
'--\1'."rn".
'Content-Type: text/plain; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--\1'."rn".
'Content-Type: multipart/related;'."rn".
' boundary="(.*?)"'."rn".
"rnrn".
'--\2'."rn".
'Content-Type: image/jpeg; name=myimage.jpg'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-ID: <'.$cid.'>'."rn".
'Content-Disposition: inline; filename=myimage.jpg'."rn".
"rn".
preg_quote(base64_encode('<image data>'), '~').
"rnrn".
'--\2--'."rn".
"rnrn".
'--\1--'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: application/pdf; name=foo.pdf'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-Disposition: attachment; filename=foo.pdf'."rn".
"rn".
preg_quote(base64_encode('<pdf data>'), '~').
"rnrn".
'--'.$boundary.'--'."rn".
'$~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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/mixed;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: multipart/related;'."rn".
' boundary="(.*?)"'."rn".
"rnrn".
'--\1'."rn".
'Content-Type: text/html; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo <img src=3D"cid:'.$cid.'" />'.//=3D is just = in QP
"rnrn".
'--\1'."rn".
'Content-Type: image/jpeg; name=myimage.jpg'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-ID: <'.$cid.'>'."rn".
'Content-Disposition: inline; filename=myimage.jpg'."rn".
"rn".
preg_quote(base64_encode('<image data>'), '~').
"rnrn".
'--\1--'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: application/pdf; name=foo.pdf'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-Disposition: attachment; filename=foo.pdf'."rn".
"rn".
preg_quote(base64_encode('<pdf data>'), '~').
"rnrn".
'--'.$boundary.'--'."rn".
'$~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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/plain; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--'.$boundary."rn".
'Content-Type: multipart/related;'."rn".
' boundary="(.*?)"'."rn".
"rnrn".
'--\1'."rn".
'Content-Type: image/jpeg; name=myimage.jpg'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-ID: <'.$cid.'>'."rn".
'Content-Disposition: inline; filename=myimage.jpg'."rn".
"rn".
preg_quote(base64_encode('<image data>'), '~').
"rnrn".
'--\1--'."rn".
"rnrn".
'--'.$boundary.'--'."rn".
'$~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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/plain; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/html; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'test <b>foo</b>'.
"rnrn".
'--'.$boundary.'--'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/mixed;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/html; charset=iso-8859-1'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--'.$boundary."rn".
'Content-Type: application/pdf; name=foo.pdf'."rn".
'Content-Transfer-Encoding: base64'."rn".
'Content-Disposition: attachment; filename=foo.pdf'."rn".
"rn".
base64_encode('<pdf data>').
"rnrn".
'--'.$boundary.'--'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'bar'.
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/html'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--'.$boundary.'--'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.$date."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: multipart/alternative;'."rn".
' boundary="'.$boundary.'"'."rn".
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'bar'.
"rnrn".
'--'.$boundary."rn".
'Content-Type: text/html'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'foo'.
"rnrn".
'--'.$boundary.'--'."rn",
$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>'."rn".
'Message-ID: <'.$id.'>'."rn".
'Date: '.date('r', $date)."rn".
'Subject: just a test subject'."rn".
'From: Chris Corbyn <chris.corbyn@swiftmailer.org>'."rn".
'MIME-Version: 1.0'."rn".
'Content-Type: text/plain'."rn".
'Content-Transfer-Encoding: quoted-printable'."rn".
"rn".
'just a test body'."rn".
'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();
}
}