Write this message to a {@link Swift_InputByteStream}.
public toByteStream ( Swift_InputByteStream $is ) | ||
$is | Swift_InputByteStream |
/** * Write this message to a {@link Swift_InputByteStream}. * * @param Swift_InputByteStream $is */ public function toByteStream(Swift_InputByteStream $is) { $this->saveMessage(); $this->doSign(); parent::toByteStream($is); $this->restoreMessage(); }
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); }
/** * Append a message to a mailbox * * @param string $mailbox * @param string|\Swift_Message $data * @param string $flags See set_message_flag * @return boolean */ public function append_message($mailbox, $data, $flags = "") { if ($data instanceof \Swift_Message) { $tmpfile = \GO\Base\Fs\File::tempFile(); $is = new \Swift_ByteStream_FileByteStream($tmpfile->path(), true); $data->toByteStream($is); unset($data); unset($is); if (!$this->append_start($mailbox, $tmpfile->size(), $flags)) { return false; } $fp = fopen($tmpfile->path(), 'r'); while ($line = fgets($fp, 1024)) { if (!$this->append_feed($line)) { return false; } } fclose($fp); $tmpfile->delete(); } else { if (!$this->append_start($mailbox, strlen($data), $flags)) { return false; } if (!$this->append_feed($data)) { return false; } } $this->append_feed("\r\n"); return $this->append_end(); }