Ejemplo n.º 1
0
 public function testWritingMessageToByteStreamTwiceUsingAFileAttachment()
 {
     $message = new Swift_Message();
     $message->setSubject('test subject');
     $message->setTo('*****@*****.**');
     $message->setCc('*****@*****.**');
     $message->setFrom('*****@*****.**');
     $attachment = Swift_Attachment::fromPath($this->_attFile);
     $message->attach($attachment);
     $message->setBody('HTML part', 'text/html');
     $id = $message->getId();
     $date = preg_quote(date('r', $message->getDate()), '~');
     $boundary = $message->getBoundary();
     $streamA = new Swift_ByteStream_ArrayByteStream();
     $streamB = new Swift_ByteStream_ArrayByteStream();
     $pattern = '~^' . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: user@domain.tld' . "\r\n" . 'To: user@domain.tld' . "\r\n" . 'Cc: other@domain.tld' . "\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=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: ' . $this->_attFileType . '; name=' . $this->_attFileName . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=' . $this->_attFileName . "\r\n" . "\r\n" . preg_quote(base64_encode(file_get_contents($this->_attFile)), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D';
     $message->toByteStream($streamA);
     $message->toByteStream($streamB);
     $this->assertPatternInStream($pattern, $streamA);
     $this->assertPatternInStream($pattern, $streamB);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getDate()
 {
     return $this->message->getDate();
 }
 public function testCreatesPreviewFiles()
 {
     $message = new Swift_Message('Foo subject', '<html>Body</html>', 'text/html');
     $message->setFrom('*****@*****.**', 'Jack Black');
     $message->setTo('*****@*****.**');
     $files = m::mock('Illuminate\\Filesystem\\Filesystem');
     $transport = new PreviewTransport($files, 'framework/emails');
     $files->shouldReceive('exists')->once()->with('framework/emails')->andReturn(true);
     $files->shouldReceive('files')->once()->with('framework/emails')->andReturn([]);
     $files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.html', m::any());
     $files->shouldReceive('put')->with('framework/emails/' . $message->getDate() . '_me_at_example_com_foo_subject.eml', $message->toString());
     $transport->send($message);
 }
Ejemplo n.º 4
-1
 public function testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative()
 {
     $message = new Swift_Message();
     $message->setCharset('utf-8');
     $message->setSubject('test subject');
     $message->addPart('plain part', 'text/plain');
     $image = new Swift_Image('<image data>', 'image.gif', 'image/gif');
     $cid = $message->embed($image);
     $message->setBody('<img src="' . $cid . '" />', 'text/html');
     $message->setTo(array('*****@*****.**' => 'User'));
     $message->setFrom(array('*****@*****.**' => 'Other'));
     $message->setSender(array('*****@*****.**' => 'Other'));
     $id = $message->getId();
     $date = preg_quote(date('r', $message->getDate()), '~');
     $boundary = $message->getBoundary();
     $cidVal = $image->getId();
     $this->assertRegExp('~^' . 'Sender: Other <*****@*****.**>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <*****@*****.**>' . "\r\n" . 'To: User <*****@*****.**>' . "\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=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\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=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . '<img.*?/>' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: inline; filename=image.gif' . "\r\n" . 'Content-ID: <' . $cidVal . '>' . "\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());
 }
Ejemplo n.º 5
-2
 public function testHTMLPartAppearsLastEvenWhenAttachmentsAdded()
 {
     $message = new Swift_Message();
     $message->setCharset('utf-8');
     $message->setSubject('test subject');
     $message->addPart('plain part', 'text/plain');
     $attachment = new Swift_Attachment('<data>', 'image.gif', 'image/gif');
     $message->attach($attachment);
     $message->setBody('HTML part', 'text/html');
     $message->setTo(array('*****@*****.**' => 'User'));
     $message->setFrom(array('*****@*****.**' => 'Other'));
     $message->setSender(array('*****@*****.**' => 'Other'));
     $id = $message->getId();
     $date = preg_quote($message->getDate()->format('r'), '~');
     $boundary = $message->getBoundary();
     $this->assertRegExp('~^' . 'Sender: Other <*****@*****.**>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <*****@*****.**>' . "\r\n" . 'To: User <*****@*****.**>' . "\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=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'plain part' . "\r\n\r\n" . '--\\1' . "\r\n" . 'Content-Type: text/html; charset=utf-8' . "\r\n" . 'Content-Transfer-Encoding: quoted-printable' . "\r\n" . "\r\n" . 'HTML part' . "\r\n\r\n" . '--\\1--' . "\r\n" . "\r\n\r\n" . '--' . $boundary . "\r\n" . 'Content-Type: image/gif; name=image.gif' . "\r\n" . 'Content-Transfer-Encoding: base64' . "\r\n" . 'Content-Disposition: attachment; filename=image.gif' . "\r\n" . "\r\n" . preg_quote(base64_encode('<data>'), '~') . "\r\n\r\n" . '--' . $boundary . '--' . "\r\n" . '$~D', $message->toString());
 }