本文整理汇总了PHP中Swift_Message::getBoundary方法的典型用法代码示例。如果您正苦于以下问题:PHP Swift_Message::getBoundary方法的具体用法?PHP Swift_Message::getBoundary怎么用?PHP Swift_Message::getBoundary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swift_Message
的用法示例。
在下文中一共展示了Swift_Message::getBoundary方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWritingMessageToByteStreamTwiceUsingAFileAttachment
public function testWritingMessageToByteStreamTwiceUsingAFileAttachment()
{
$message = new Swift_Message();
$message->setSubject('test subject');
$message->setTo('user@domain.tld');
$message->setCc('other@domain.tld');
$message->setFrom('user@domain.tld');
$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);
}
示例2: getPart
/**
* TODO Better support of RFC1341
*
* @param \Swift_Message $message
* @param string $contentType
*
* @return null
*/
protected function getPart(\Swift_Message $message, $contentType)
{
$dumpedMessage = explode("\r\n", $message->toString());
// save current line (relative to $key)
foreach ($dumpedMessage as $key => $value) {
if ($value != "Content-Type: " . $contentType) {
continue;
}
$index = 1;
// Detect Transfert Encoding
$encoding = null;
while (true) {
if (strpos($dumpedMessage[$key + $index], "Content-Transfer-Encoding:") !== false) {
$line = trim($dumpedMessage[$key + $index]);
$encoding = substr($line, 27, strlen($line) - 27);
$encoding = explode(';', $encoding);
$encoding = strtolower($encoding[0]);
break;
}
if ($dumpedMessage[$key + $index] == "") {
$index++;
break;
}
$index++;
}
// Skip others header, to get content
while ($dumpedMessage[$key + $index] !== "") {
$index++;
}
$result = [];
// Get all mime/part until boundary is reached
while (isset($dumpedMessage[$key + $index]) && strpos($dumpedMessage[$key + $index], $message->getBoundary()) === false) {
$txt = $dumpedMessage[$key + $index];
// Remove soft break-line
$len = mb_strlen($txt);
if ($encoding == "quoted-printable" && $len > 1 && substr($txt, -1) == "=") {
$txt = substr($txt, 0, $len - 1);
}
$result[] = $txt;
$index++;
}
$resultstr = implode("", $result);
switch ($encoding) {
case 'quoted-printable':
return quoted_printable_decode($resultstr);
case 'base64':
return base64_decode($resultstr);
default:
return $resultstr;
}
}
return null;
}
示例3: getBoundary
/**
* {@inheritdoc}
*/
public function getBoundary()
{
return $this->message->getBoundary();
}
示例4: testEmbeddedFilesWithMultipartDataCreateMultipartRelatedContentAsAnAlternative
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@domain.tld' => 'User'));
$message->setFrom(array('other@domain.tld' => 'Other'));
$message->setSender(array('other@domain.tld' => 'Other'));
$id = $message->getId();
$date = preg_quote(date('r', $message->getDate()), '~');
$boundary = $message->getBoundary();
$cidVal = $image->getId();
$this->assertRegExp('~^' . 'Sender: Other <other@domain.tld>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <other@domain.tld>' . "\r\n" . 'To: User <user@domain.tld>' . "\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());
}
示例5: testHTMLPartAppearsLastEvenWhenAttachmentsAdded
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@domain.tld' => 'User'));
$message->setFrom(array('other@domain.tld' => 'Other'));
$message->setSender(array('other@domain.tld' => 'Other'));
$id = $message->getId();
$date = preg_quote($message->getDate()->format('r'), '~');
$boundary = $message->getBoundary();
$this->assertRegExp('~^' . 'Sender: Other <other@domain.tld>' . "\r\n" . 'Message-ID: <' . $id . '>' . "\r\n" . 'Date: ' . $date . "\r\n" . 'Subject: test subject' . "\r\n" . 'From: Other <other@domain.tld>' . "\r\n" . 'To: User <user@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: 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());
}