forked from Wavyzz/dolibarr
swiftmailer
This commit is contained in:
@@ -16,23 +16,23 @@
|
||||
class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
{
|
||||
/** Recognized MIME types */
|
||||
private $_mimeTypes = array();
|
||||
private $mimeTypes = array();
|
||||
|
||||
/**
|
||||
* Create a new Attachment with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_HeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param array $mimeTypes optional
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param array $mimeTypes
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $mimeTypes = array())
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = array())
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $grammar);
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator);
|
||||
$this->setDisposition('attachment');
|
||||
$this->setContentType('application/octet-stream');
|
||||
$this->_mimeTypes = $mimeTypes;
|
||||
$this->mimeTypes = $mimeTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getDisposition()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Content-Disposition');
|
||||
return $this->getHeaderFieldModel('Content-Disposition');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,11 +64,11 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
*
|
||||
* @param string $disposition
|
||||
*
|
||||
* @return Swift_Mime_Attachment
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisposition($disposition)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Content-Disposition', $disposition)) {
|
||||
if (!$this->setHeaderFieldModel('Content-Disposition', $disposition)) {
|
||||
$this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->_getHeaderParameter('Content-Disposition', 'filename');
|
||||
return $this->getHeaderParameter('Content-Disposition', 'filename');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,12 +90,12 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return Swift_Mime_Attachment
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
{
|
||||
$this->_setHeaderParameter('Content-Disposition', 'filename', $filename);
|
||||
$this->_setHeaderParameter('Content-Type', 'name', $filename);
|
||||
$this->setHeaderParameter('Content-Disposition', 'filename', $filename);
|
||||
$this->setHeaderParameter('Content-Type', 'name', $filename);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getSize()
|
||||
{
|
||||
return $this->_getHeaderParameter('Content-Disposition', 'size');
|
||||
return $this->getHeaderParameter('Content-Disposition', 'size');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,11 +115,11 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
*
|
||||
* @param int $size
|
||||
*
|
||||
* @return Swift_Mime_Attachment
|
||||
* @return $this
|
||||
*/
|
||||
public function setSize($size)
|
||||
{
|
||||
$this->_setHeaderParameter('Content-Disposition', 'size', $size);
|
||||
$this->setHeaderParameter('Content-Disposition', 'size', $size);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
* @param Swift_FileStream $file
|
||||
* @param string $contentType optional
|
||||
*
|
||||
* @return Swift_Mime_Attachment
|
||||
* @return $this
|
||||
*/
|
||||
public function setFile(Swift_FileStream $file, $contentType = null)
|
||||
{
|
||||
@@ -139,8 +139,8 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
if (!isset($contentType)) {
|
||||
$extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
|
||||
|
||||
if (array_key_exists($extension, $this->_mimeTypes)) {
|
||||
$this->setContentType($this->_mimeTypes[$extension]);
|
||||
if (array_key_exists($extension, $this->mimeTypes)) {
|
||||
$this->setContentType($this->mimeTypes[$extension]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
|
||||
sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
|
||||
}
|
||||
|
||||
return $this->_standardize(quoted_printable_encode($string));
|
||||
return $this->standardize(quoted_printable_encode($string));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +102,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _standardize($string)
|
||||
protected function standardize($string)
|
||||
{
|
||||
// transform CR or LF to CRLF
|
||||
$string = preg_replace('~=0D(?!=0A)|(?<!=0D)=0A~', '=0D=0A', $string);
|
||||
|
||||
@@ -20,14 +20,14 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_name;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* True if canonical transformations should be done.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_canonical;
|
||||
private $canonical;
|
||||
|
||||
/**
|
||||
* Creates a new PlainContentEncoder with $name (probably 7bit or 8bit).
|
||||
@@ -37,8 +37,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
*/
|
||||
public function __construct($name, $canonical = false)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->_canonical = $canonical;
|
||||
$this->name = $name;
|
||||
$this->canonical = $canonical;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,11 +52,11 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
*/
|
||||
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
if ($this->_canonical) {
|
||||
$string = $this->_canonicalize($string);
|
||||
if ($this->canonical) {
|
||||
$string = $this->canonicalize($string);
|
||||
}
|
||||
|
||||
return $this->_safeWordWrap($string, $maxLineLength, "\r\n");
|
||||
return $this->safeWordwrap($string, $maxLineLength, "\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,10 +72,10 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
$leftOver = '';
|
||||
while (false !== $bytes = $os->read(8192)) {
|
||||
$toencode = $leftOver.$bytes;
|
||||
if ($this->_canonical) {
|
||||
$toencode = $this->_canonicalize($toencode);
|
||||
if ($this->canonical) {
|
||||
$toencode = $this->canonicalize($toencode);
|
||||
}
|
||||
$wrapped = $this->_safeWordWrap($toencode, $maxLineLength, "\r\n");
|
||||
$wrapped = $this->safeWordwrap($toencode, $maxLineLength, "\r\n");
|
||||
$lastLinePos = strrpos($wrapped, "\r\n");
|
||||
$leftOver = substr($wrapped, $lastLinePos);
|
||||
$wrapped = substr($wrapped, 0, $lastLinePos);
|
||||
@@ -94,7 +94,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _safeWordwrap($string, $length = 75, $le = "\r\n")
|
||||
private function safeWordwrap($string, $length = 75, $le = "\r\n")
|
||||
{
|
||||
if (0 >= $length) {
|
||||
return $string;
|
||||
@@ -151,7 +151,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _canonicalize($string)
|
||||
private function canonicalize($string)
|
||||
{
|
||||
return str_replace(
|
||||
array("\r\n", "\r", "\n"),
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
/**
|
||||
* Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_ContentEncoder
|
||||
{
|
||||
protected $_dotEscape;
|
||||
protected $dotEscape;
|
||||
|
||||
/**
|
||||
* Creates a new QpContentEncoder for the given CharacterStream.
|
||||
@@ -26,26 +26,26 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
*/
|
||||
public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null, $dotEscape = false)
|
||||
{
|
||||
$this->_dotEscape = $dotEscape;
|
||||
$this->dotEscape = $dotEscape;
|
||||
parent::__construct($charStream, $filter);
|
||||
}
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return array('_charStream', '_filter', '_dotEscape');
|
||||
return array('charStream', 'filter', 'dotEscape');
|
||||
}
|
||||
|
||||
protected function getSafeMapShareId()
|
||||
{
|
||||
return get_class($this).($this->_dotEscape ? '.dotEscape' : '');
|
||||
return get_class($this).($this->dotEscape ? '.dotEscape' : '');
|
||||
}
|
||||
|
||||
protected function initSafeMap()
|
||||
{
|
||||
parent::initSafeMap();
|
||||
if ($this->_dotEscape) {
|
||||
if ($this->dotEscape) {
|
||||
/* Encode . as =2e for buggy remote servers */
|
||||
unset($this->_safeMap[0x2e]);
|
||||
unset($this->safeMap[0x2e]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,20 +69,20 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
|
||||
$thisLineLength = $maxLineLength - $firstLineOffset;
|
||||
|
||||
$this->_charStream->flushContents();
|
||||
$this->_charStream->importByteStream($os);
|
||||
$this->charStream->flushContents();
|
||||
$this->charStream->importByteStream($os);
|
||||
|
||||
$currentLine = '';
|
||||
$prepend = '';
|
||||
$size = $lineLen = 0;
|
||||
|
||||
while (false !== $bytes = $this->_nextSequence()) {
|
||||
while (false !== $bytes = $this->nextSequence()) {
|
||||
// If we're filtering the input
|
||||
if (isset($this->_filter)) {
|
||||
if (isset($this->filter)) {
|
||||
// If we can't filter because we need more bytes
|
||||
while ($this->_filter->shouldBuffer($bytes)) {
|
||||
while ($this->filter->shouldBuffer($bytes)) {
|
||||
// Then collect bytes into the buffer
|
||||
if (false === $moreBytes = $this->_nextSequence(1)) {
|
||||
if (false === $moreBytes = $this->nextSequence(1)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -91,16 +91,16 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
}
|
||||
}
|
||||
// And filter them
|
||||
$bytes = $this->_filter->filter($bytes);
|
||||
$bytes = $this->filter->filter($bytes);
|
||||
}
|
||||
|
||||
$enc = $this->_encodeByteSequence($bytes, $size);
|
||||
$enc = $this->encodeByteSequence($bytes, $size);
|
||||
|
||||
$i = strpos($enc, '=0D=0A');
|
||||
$newLineLength = $lineLen + ($i === false ? $size : $i);
|
||||
|
||||
if ($currentLine && $newLineLength >= $thisLineLength) {
|
||||
$is->write($prepend.$this->_standardize($currentLine));
|
||||
$is->write($prepend.$this->standardize($currentLine));
|
||||
$currentLine = '';
|
||||
$prepend = "=\r\n";
|
||||
$thisLineLength = $maxLineLength;
|
||||
@@ -117,7 +117,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
}
|
||||
}
|
||||
if (strlen($currentLine)) {
|
||||
$is->write($prepend.$this->_standardize($currentLine));
|
||||
$is->write($prepend.$this->standardize($currentLine));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,15 +18,15 @@ class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment
|
||||
/**
|
||||
* Creates a new Attachment with $headers and $encoder.
|
||||
*
|
||||
* @param Swift_Mime_HeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param array $mimeTypes optional
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param array $mimeTypes optional
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $mimeTypes = array())
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = array())
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $grammar, $mimeTypes);
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator, $mimeTypes);
|
||||
$this->setDisposition('inline');
|
||||
$this->setId($this->getId());
|
||||
}
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines the grammar to use for validation, implements the RFC 2822 (and friends) ABNF grammar definitions.
|
||||
*
|
||||
* @author Fabien Potencier
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_Grammar
|
||||
{
|
||||
/**
|
||||
* Special characters used in the syntax which need to be escaped.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private static $_specials = array();
|
||||
|
||||
/**
|
||||
* Tokens defined in RFC 2822 (and some related RFCs).
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private static $_grammar = array();
|
||||
|
||||
/**
|
||||
* Initialize some RFC 2822 (and friends) ABNF grammar definitions.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
if (count(self::$_specials) > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$_specials = array(
|
||||
'(', ')', '<', '>', '[', ']',
|
||||
':', ';', '@', ',', '.', '"',
|
||||
);
|
||||
|
||||
/*** Refer to RFC 2822 for ABNF grammar ***/
|
||||
|
||||
// All basic building blocks
|
||||
self::$_grammar['NO-WS-CTL'] = '[\x01-\x08\x0B\x0C\x0E-\x19\x7F]';
|
||||
self::$_grammar['WSP'] = '[ \t]';
|
||||
self::$_grammar['CRLF'] = '(?:\r\n)';
|
||||
self::$_grammar['FWS'] = '(?:(?:'.self::$_grammar['WSP'].'*'.
|
||||
self::$_grammar['CRLF'].')?'.self::$_grammar['WSP'].')';
|
||||
self::$_grammar['text'] = '[\x00-\x08\x0B\x0C\x0E-\x7F]';
|
||||
self::$_grammar['quoted-pair'] = '(?:\\\\'.self::$_grammar['text'].')';
|
||||
self::$_grammar['ctext'] = '(?:'.self::$_grammar['NO-WS-CTL'].
|
||||
'|[\x21-\x27\x2A-\x5B\x5D-\x7E])';
|
||||
// Uses recursive PCRE (?1) -- could be a weak point??
|
||||
self::$_grammar['ccontent'] = '(?:'.self::$_grammar['ctext'].'|'.
|
||||
self::$_grammar['quoted-pair'].'|(?1))';
|
||||
self::$_grammar['comment'] = '(\((?:'.self::$_grammar['FWS'].'|'.
|
||||
self::$_grammar['ccontent'].')*'.self::$_grammar['FWS'].'?\))';
|
||||
self::$_grammar['CFWS'] = '(?:(?:'.self::$_grammar['FWS'].'?'.
|
||||
self::$_grammar['comment'].')*(?:(?:'.self::$_grammar['FWS'].'?'.
|
||||
self::$_grammar['comment'].')|'.self::$_grammar['FWS'].'))';
|
||||
self::$_grammar['qtext'] = '(?:'.self::$_grammar['NO-WS-CTL'].
|
||||
'|[\x21\x23-\x5B\x5D-\x7E])';
|
||||
self::$_grammar['qcontent'] = '(?:'.self::$_grammar['qtext'].'|'.
|
||||
self::$_grammar['quoted-pair'].')';
|
||||
self::$_grammar['quoted-string'] = '(?:'.self::$_grammar['CFWS'].'?"'.
|
||||
'('.self::$_grammar['FWS'].'?'.self::$_grammar['qcontent'].')*'.
|
||||
self::$_grammar['FWS'].'?"'.self::$_grammar['CFWS'].'?)';
|
||||
self::$_grammar['atext'] = '[a-zA-Z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\}\|~]';
|
||||
self::$_grammar['atom'] = '(?:'.self::$_grammar['CFWS'].'?'.
|
||||
self::$_grammar['atext'].'+'.self::$_grammar['CFWS'].'?)';
|
||||
self::$_grammar['dot-atom-text'] = '(?:'.self::$_grammar['atext'].'+'.
|
||||
'(\.'.self::$_grammar['atext'].'+)*)';
|
||||
self::$_grammar['dot-atom'] = '(?:'.self::$_grammar['CFWS'].'?'.
|
||||
self::$_grammar['dot-atom-text'].'+'.self::$_grammar['CFWS'].'?)';
|
||||
self::$_grammar['word'] = '(?:'.self::$_grammar['atom'].'|'.
|
||||
self::$_grammar['quoted-string'].')';
|
||||
self::$_grammar['phrase'] = '(?:'.self::$_grammar['word'].'+?)';
|
||||
self::$_grammar['no-fold-quote'] = '(?:"(?:'.self::$_grammar['qtext'].
|
||||
'|'.self::$_grammar['quoted-pair'].')*")';
|
||||
self::$_grammar['dtext'] = '(?:'.self::$_grammar['NO-WS-CTL'].
|
||||
'|[\x21-\x5A\x5E-\x7E])';
|
||||
self::$_grammar['no-fold-literal'] = '(?:\[(?:'.self::$_grammar['dtext'].
|
||||
'|'.self::$_grammar['quoted-pair'].')*\])';
|
||||
|
||||
// Message IDs
|
||||
self::$_grammar['id-left'] = '(?:'.self::$_grammar['dot-atom-text'].'|'.
|
||||
self::$_grammar['no-fold-quote'].')';
|
||||
self::$_grammar['id-right'] = '(?:'.self::$_grammar['dot-atom-text'].'|'.
|
||||
self::$_grammar['no-fold-literal'].')';
|
||||
|
||||
// Addresses, mailboxes and paths
|
||||
self::$_grammar['local-part'] = '(?:'.self::$_grammar['dot-atom'].'|'.
|
||||
self::$_grammar['quoted-string'].')';
|
||||
self::$_grammar['dcontent'] = '(?:'.self::$_grammar['dtext'].'|'.
|
||||
self::$_grammar['quoted-pair'].')';
|
||||
self::$_grammar['domain-literal'] = '(?:'.self::$_grammar['CFWS'].'?\[('.
|
||||
self::$_grammar['FWS'].'?'.self::$_grammar['dcontent'].')*?'.
|
||||
self::$_grammar['FWS'].'?\]'.self::$_grammar['CFWS'].'?)';
|
||||
self::$_grammar['domain'] = '(?:'.self::$_grammar['dot-atom'].'|'.
|
||||
self::$_grammar['domain-literal'].')';
|
||||
self::$_grammar['addr-spec'] = '(?:'.self::$_grammar['local-part'].'@'.
|
||||
self::$_grammar['domain'].')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the grammar defined for $name token.
|
||||
*
|
||||
* @param string $name exactly as written in the RFC
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefinition($name)
|
||||
{
|
||||
if (array_key_exists($name, self::$_grammar)) {
|
||||
return self::$_grammar[$name];
|
||||
}
|
||||
|
||||
throw new Swift_RfcComplianceException(
|
||||
"No such grammar '".$name."' defined."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the tokens defined in RFC 2822 (and some related RFCs).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGrammarDefinitions()
|
||||
{
|
||||
return self::$_grammar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current special characters used in the syntax which need to be escaped.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSpecials()
|
||||
{
|
||||
return self::$_specials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape special characters in a string (convert to quoted-pairs).
|
||||
*
|
||||
* @param string $token
|
||||
* @param string[] $include additional chars to escape
|
||||
* @param string[] $exclude chars from escaping
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function escapeSpecials($token, $include = array(), $exclude = array())
|
||||
{
|
||||
foreach (array_merge(array('\\'), array_diff(self::$_specials, $exclude), $include) as $char) {
|
||||
$token = str_replace($char, '\\'.$char, $token);
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i
|
||||
range(0x61, 0x7A), range(0x41, 0x5A),
|
||||
range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
|
||||
) as $byte) {
|
||||
$this->_safeMap[$byte] = chr($byte);
|
||||
$this->safeMap[$byte] = chr($byte);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates MIME headers.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
interface Swift_Mime_HeaderFactory extends Swift_Mime_CharsetObserver
|
||||
{
|
||||
/**
|
||||
* Create a new Mailbox Header with a list of $addresses.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array|string $addresses
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function createMailboxHeader($name, $addresses = null);
|
||||
|
||||
/**
|
||||
* Create a new Date header using $timestamp (UNIX time).
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $timestamp
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function createDateHeader($name, $timestamp = null);
|
||||
|
||||
/**
|
||||
* Create a new basic text header with $name and $value.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function createTextHeader($name, $value = null);
|
||||
|
||||
/**
|
||||
* Create a new ParameterizedHeader with $name, $value and $params.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param array $params
|
||||
*
|
||||
* @return Swift_Mime_ParameterizedHeader
|
||||
*/
|
||||
public function createParameterizedHeader($name, $value = null, $params = array());
|
||||
|
||||
/**
|
||||
* Create a new ID header for Message-ID or Content-ID.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|array $ids
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function createIdHeader($name, $ids = null);
|
||||
|
||||
/**
|
||||
* Create a new Path header with an address (path) in it.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function createPathHeader($name, $path = null);
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A collection of MIME headers.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver
|
||||
{
|
||||
/**
|
||||
* Add a new Mailbox Header with a list of $addresses.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array|string $addresses
|
||||
*/
|
||||
public function addMailboxHeader($name, $addresses = null);
|
||||
|
||||
/**
|
||||
* Add a new Date header using $timestamp (UNIX time).
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $timestamp
|
||||
*/
|
||||
public function addDateHeader($name, $timestamp = null);
|
||||
|
||||
/**
|
||||
* Add a new basic text header with $name and $value.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function addTextHeader($name, $value = null);
|
||||
|
||||
/**
|
||||
* Add a new ParameterizedHeader with $name, $value and $params.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
* @param array $params
|
||||
*/
|
||||
public function addParameterizedHeader($name, $value = null, $params = array());
|
||||
|
||||
/**
|
||||
* Add a new ID header for Message-ID or Content-ID.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|array $ids
|
||||
*/
|
||||
public function addIdHeader($name, $ids = null);
|
||||
|
||||
/**
|
||||
* Add a new Path header with an address (path) in it.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $path
|
||||
*/
|
||||
public function addPathHeader($name, $path = null);
|
||||
|
||||
/**
|
||||
* Returns true if at least one header with the given $name exists.
|
||||
*
|
||||
* If multiple headers match, the actual one may be specified by $index.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $index
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has($name, $index = 0);
|
||||
|
||||
/**
|
||||
* Set a header in the HeaderSet.
|
||||
*
|
||||
* The header may be a previously fetched header via {@link get()} or it may
|
||||
* be one that has been created separately.
|
||||
*
|
||||
* If $index is specified, the header will be inserted into the set at this
|
||||
* offset.
|
||||
*
|
||||
* @param Swift_Mime_Header $header
|
||||
* @param int $index
|
||||
*/
|
||||
public function set(Swift_Mime_Header $header, $index = 0);
|
||||
|
||||
/**
|
||||
* Get the header with the given $name.
|
||||
* If multiple headers match, the actual one may be specified by $index.
|
||||
* Returns NULL if none present.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $index
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function get($name, $index = 0);
|
||||
|
||||
/**
|
||||
* Get all headers with the given $name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll($name = null);
|
||||
|
||||
/**
|
||||
* Return the name of all Headers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listAll();
|
||||
|
||||
/**
|
||||
* Remove the header with the given $name if it's set.
|
||||
*
|
||||
* If multiple headers match, the actual one may be specified by $index.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $index
|
||||
*/
|
||||
public function remove($name, $index = 0);
|
||||
|
||||
/**
|
||||
* Remove all headers with the given $name.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function removeAll($name);
|
||||
|
||||
/**
|
||||
* Create a new instance of this HeaderSet.
|
||||
*
|
||||
* @return Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function newInstance();
|
||||
|
||||
/**
|
||||
* Define a list of Header names as an array in the correct order.
|
||||
*
|
||||
* These Headers will be output in the given order where present.
|
||||
*
|
||||
* @param array $sequence
|
||||
*/
|
||||
public function defineOrdering(array $sequence);
|
||||
|
||||
/**
|
||||
* Set a list of header names which must always be displayed when set.
|
||||
*
|
||||
* Usually headers without a field value won't be output unless set here.
|
||||
*
|
||||
* @param array $names
|
||||
*/
|
||||
public function setAlwaysDisplayed(array $names);
|
||||
|
||||
/**
|
||||
* Returns a string with a representation of all headers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString();
|
||||
}
|
||||
@@ -11,68 +11,53 @@
|
||||
/**
|
||||
* An abstract base MIME Header.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
{
|
||||
const PHRASE_PATTERN = '(?:(?:(?:(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?[a-zA-Z0-9!#\$%&\'\*\+\-\/=\?\^_`\{\}\|~]+(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?)|(?:(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?"((?:(?:[ \t]*(?:\r\n))?[ \t])?(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21\x23-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])))*(?:(?:[ \t]*(?:\r\n))?[ \t])?"(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?))+?)';
|
||||
|
||||
/**
|
||||
* The name of this Header.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_name;
|
||||
|
||||
/**
|
||||
* The Grammar used for this Header.
|
||||
*
|
||||
* @var Swift_Mime_Grammar
|
||||
*/
|
||||
private $_grammar;
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* The Encoder used to encode this Header.
|
||||
*
|
||||
* @var Swift_Encoder
|
||||
*/
|
||||
private $_encoder;
|
||||
private $encoder;
|
||||
|
||||
/**
|
||||
* The maximum length of a line in the header.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_lineLength = 78;
|
||||
private $lineLength = 78;
|
||||
|
||||
/**
|
||||
* The language used in this Header.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_lang;
|
||||
private $lang;
|
||||
|
||||
/**
|
||||
* The character set of the text in this Header.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_charset = 'utf-8';
|
||||
private $charset = 'utf-8';
|
||||
|
||||
/**
|
||||
* The value of this Header, cached.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_cachedValue = null;
|
||||
|
||||
/**
|
||||
* Creates a new Header.
|
||||
*
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
*/
|
||||
public function __construct(Swift_Mime_Grammar $grammar)
|
||||
{
|
||||
$this->setGrammar($grammar);
|
||||
}
|
||||
private $cachedValue = null;
|
||||
|
||||
/**
|
||||
* Set the character set used in this Header.
|
||||
@@ -81,10 +66,10 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function setCharset($charset)
|
||||
{
|
||||
$this->clearCachedValueIf($charset != $this->_charset);
|
||||
$this->_charset = $charset;
|
||||
if (isset($this->_encoder)) {
|
||||
$this->_encoder->charsetChanged($charset);
|
||||
$this->clearCachedValueIf($charset != $this->charset);
|
||||
$this->charset = $charset;
|
||||
if (isset($this->encoder)) {
|
||||
$this->encoder->charsetChanged($charset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +80,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getCharset()
|
||||
{
|
||||
return $this->_charset;
|
||||
return $this->charset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +93,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function setLanguage($lang)
|
||||
{
|
||||
$this->clearCachedValueIf($this->_lang != $lang);
|
||||
$this->_lang = $lang;
|
||||
$this->clearCachedValueIf($this->lang != $lang);
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +104,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
return $this->_lang;
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +114,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function setEncoder(Swift_Mime_HeaderEncoder $encoder)
|
||||
{
|
||||
$this->_encoder = $encoder;
|
||||
$this->encoder = $encoder;
|
||||
$this->setCachedValue(null);
|
||||
}
|
||||
|
||||
@@ -140,28 +125,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getEncoder()
|
||||
{
|
||||
return $this->_encoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the grammar used for the header.
|
||||
*
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
*/
|
||||
public function setGrammar(Swift_Mime_Grammar $grammar)
|
||||
{
|
||||
$this->_grammar = $grammar;
|
||||
$this->setCachedValue(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the grammar used for this Header.
|
||||
*
|
||||
* @return Swift_Mime_Grammar
|
||||
*/
|
||||
public function getGrammar()
|
||||
{
|
||||
return $this->_grammar;
|
||||
return $this->encoder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +135,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getFieldName()
|
||||
{
|
||||
return $this->_name;
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,8 +145,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function setMaxLineLength($lineLength)
|
||||
{
|
||||
$this->clearCachedValueIf($this->_lineLength != $lineLength);
|
||||
$this->_lineLength = $lineLength;
|
||||
$this->clearCachedValueIf($this->lineLength != $lineLength);
|
||||
$this->lineLength = $lineLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,19 +156,19 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getMaxLineLength()
|
||||
{
|
||||
return $this->_lineLength;
|
||||
return $this->lineLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this Header rendered as a RFC 2822 compliant string.
|
||||
*
|
||||
* @throws Swift_RfcComplianceException
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws Swift_RfcComplianceException
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return $this->_tokensToString($this->toTokens());
|
||||
return $this->tokensToString($this->toTokens());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,8 +183,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
return $this->toString();
|
||||
}
|
||||
|
||||
// -- Points of extension
|
||||
|
||||
/**
|
||||
* Set the name of this Header field.
|
||||
*
|
||||
@@ -228,7 +190,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
protected function setFieldName($name)
|
||||
{
|
||||
$this->_name = $name;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,13 +209,12 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
// Treat token as exactly what was given
|
||||
$phraseStr = $string;
|
||||
// If it's not valid
|
||||
if (!preg_match('/^'.$this->getGrammar()->getDefinition('phrase').'$/D', $phraseStr)) {
|
||||
|
||||
if (!preg_match('/^'.self::PHRASE_PATTERN.'$/D', $phraseStr)) {
|
||||
// .. but it is just ascii text, try escaping some characters
|
||||
// and make it a quoted-string
|
||||
if (preg_match('/^'.$this->getGrammar()->getDefinition('text').'*$/D', $phraseStr)) {
|
||||
$phraseStr = $this->getGrammar()->escapeSpecials(
|
||||
$phraseStr, array('"'), $this->getGrammar()->getSpecials()
|
||||
);
|
||||
if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) {
|
||||
$phraseStr = $this->escapeSpecials($phraseStr, array('"'));
|
||||
$phraseStr = '"'.$phraseStr.'"';
|
||||
} else {
|
||||
// ... otherwise it needs encoding
|
||||
@@ -270,6 +231,23 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
return $phraseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape special characters in a string (convert to quoted-pairs).
|
||||
*
|
||||
* @param string $token
|
||||
* @param string[] $include additional chars to escape
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function escapeSpecials($token, $include = array())
|
||||
{
|
||||
foreach (array_merge(array('\\'), $include) as $char) {
|
||||
$token = str_replace($char, '\\'.$char, $token);
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode needed word tokens within a string of input.
|
||||
*
|
||||
@@ -365,12 +343,12 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
protected function getTokenAsEncodedWord($token, $firstLineOffset = 0)
|
||||
{
|
||||
// Adjust $firstLineOffset to account for space needed for syntax
|
||||
$charsetDecl = $this->_charset;
|
||||
if (isset($this->_lang)) {
|
||||
$charsetDecl .= '*'.$this->_lang;
|
||||
$charsetDecl = $this->charset;
|
||||
if (isset($this->lang)) {
|
||||
$charsetDecl .= '*'.$this->lang;
|
||||
}
|
||||
$encodingWrapperLength = strlen(
|
||||
'=?'.$charsetDecl.'?'.$this->_encoder->getName().'??='
|
||||
'=?'.$charsetDecl.'?'.$this->encoder->getName().'??='
|
||||
);
|
||||
|
||||
if ($firstLineOffset >= 75) {
|
||||
@@ -379,16 +357,16 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
}
|
||||
|
||||
$encodedTextLines = explode("\r\n",
|
||||
$this->_encoder->encodeString(
|
||||
$token, $firstLineOffset, 75 - $encodingWrapperLength, $this->_charset
|
||||
$this->encoder->encodeString(
|
||||
$token, $firstLineOffset, 75 - $encodingWrapperLength, $this->charset
|
||||
)
|
||||
);
|
||||
|
||||
if (strtolower($this->_charset) !== 'iso-2022-jp') {
|
||||
if (strtolower($this->charset) !== 'iso-2022-jp') {
|
||||
// special encoding for iso-2022-jp using mb_encode_mimeheader
|
||||
foreach ($encodedTextLines as $lineNum => $line) {
|
||||
$encodedTextLines[$lineNum] = '=?'.$charsetDecl.
|
||||
'?'.$this->_encoder->getName().
|
||||
'?'.$this->encoder->getName().
|
||||
'?'.$line.'?=';
|
||||
}
|
||||
}
|
||||
@@ -415,7 +393,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
protected function setCachedValue($value)
|
||||
{
|
||||
$this->_cachedValue = $value;
|
||||
$this->cachedValue = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -425,7 +403,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
protected function getCachedValue()
|
||||
{
|
||||
return $this->_cachedValue;
|
||||
return $this->cachedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -449,7 +427,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
protected function toTokens($string = null)
|
||||
{
|
||||
if (is_null($string)) {
|
||||
if (null === $string) {
|
||||
$string = $this->getFieldBody();
|
||||
}
|
||||
|
||||
@@ -474,18 +452,18 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _tokensToString(array $tokens)
|
||||
private function tokensToString(array $tokens)
|
||||
{
|
||||
$lineCount = 0;
|
||||
$headerLines = array();
|
||||
$headerLines[] = $this->_name.': ';
|
||||
$headerLines[] = $this->name.': ';
|
||||
$currentLine = &$headerLines[$lineCount++];
|
||||
|
||||
// Build all tokens back into compliant header
|
||||
foreach ($tokens as $i => $token) {
|
||||
// Line longer than specified maximum or token was just a new line
|
||||
if (("\r\n" == $token) ||
|
||||
($i > 0 && strlen($currentLine.$token) > $this->_lineLength)
|
||||
($i > 0 && strlen($currentLine.$token) > $this->lineLength)
|
||||
&& 0 < strlen($currentLine)) {
|
||||
$headerLines[] = '';
|
||||
$currentLine = &$headerLines[$lineCount++];
|
||||
|
||||
@@ -16,29 +16,20 @@
|
||||
class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
{
|
||||
/**
|
||||
* The UNIX timestamp value of this Header.
|
||||
* Date-time value of this Header.
|
||||
*
|
||||
* @var int
|
||||
* @var DateTimeImmutable
|
||||
*/
|
||||
private $_timestamp;
|
||||
private $dateTime;
|
||||
|
||||
/**
|
||||
* Creates a new DateHeader with $name and $timestamp.
|
||||
* Creates a new DateHeader with $name.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* <?php
|
||||
* $header = new Swift_Mime_Headers_DateHeader('Date', time());
|
||||
* ?>
|
||||
* </code>
|
||||
*
|
||||
* @param string $name of Header
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $name of Header
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
parent::__construct($grammar);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,49 +48,48 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
/**
|
||||
* Set the model for the field body.
|
||||
*
|
||||
* This method takes a UNIX timestamp.
|
||||
*
|
||||
* @param int $model
|
||||
* @param DateTimeInterface $model
|
||||
*/
|
||||
public function setFieldBodyModel($model)
|
||||
{
|
||||
$this->setTimestamp($model);
|
||||
$this->setDateTime($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the model for the field body.
|
||||
*
|
||||
* This method returns a UNIX timestamp.
|
||||
*
|
||||
* @return mixed
|
||||
* @return DateTimeImmutable
|
||||
*/
|
||||
public function getFieldBodyModel()
|
||||
{
|
||||
return $this->getTimestamp();
|
||||
return $this->getDateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UNIX timestamp of the Date in this Header.
|
||||
* Get the date-time representing the Date in this Header.
|
||||
*
|
||||
* @return int
|
||||
* @return DateTimeImmutable
|
||||
*/
|
||||
public function getTimestamp()
|
||||
public function getDateTime()
|
||||
{
|
||||
return $this->_timestamp;
|
||||
return $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the UNIX timestamp of the Date in this Header.
|
||||
* Set the date-time of the Date in this Header.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* If a DateTime instance is provided, it is converted to DateTimeImmutable.
|
||||
*
|
||||
* @param DateTimeInterface $dateTime
|
||||
*/
|
||||
public function setTimestamp($timestamp)
|
||||
public function setDateTime(DateTimeInterface $dateTime)
|
||||
{
|
||||
if (!is_null($timestamp)) {
|
||||
$timestamp = (int) $timestamp;
|
||||
$this->clearCachedValueIf($this->getCachedValue() != $dateTime->format(DateTime::RFC2822));
|
||||
if ($dateTime instanceof DateTime) {
|
||||
$immutable = new DateTimeImmutable('@'.$dateTime->getTimestamp());
|
||||
$dateTime = $immutable->setTimezone($dateTime->getTimezone());
|
||||
}
|
||||
$this->clearCachedValueIf($this->_timestamp != $timestamp);
|
||||
$this->_timestamp = $timestamp;
|
||||
$this->dateTime = $dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,8 +105,8 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
public function getFieldBody()
|
||||
{
|
||||
if (!$this->getCachedValue()) {
|
||||
if (isset($this->_timestamp)) {
|
||||
$this->setCachedValue(date('r', $this->_timestamp));
|
||||
if (isset($this->dateTime)) {
|
||||
$this->setCachedValue($this->dateTime->format(DateTime::RFC2822));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
/**
|
||||
* An ID MIME Header for something like Message-ID or Content-ID.
|
||||
*
|
||||
@@ -22,18 +25,25 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_ids = array();
|
||||
private $ids = array();
|
||||
|
||||
/**
|
||||
* The strict EmailValidator.
|
||||
*
|
||||
* @var EmailValidator
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
/**
|
||||
* Creates a new IdentificationHeader with the given $name and $id.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $name
|
||||
* @param EmailValidator $emailValidator
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name, EmailValidator $emailValidator)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
parent::__construct($grammar);
|
||||
$this->emailValidator = $emailValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,8 +106,8 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (count($this->_ids) > 0) {
|
||||
return $this->_ids[0];
|
||||
if (count($this->ids) > 0) {
|
||||
return $this->ids[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,12 +123,12 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
$actualIds = array();
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$this->_assertValidId($id);
|
||||
$this->assertValidId($id);
|
||||
$actualIds[] = $id;
|
||||
}
|
||||
|
||||
$this->clearCachedValueIf($this->_ids != $actualIds);
|
||||
$this->_ids = $actualIds;
|
||||
$this->clearCachedValueIf($this->ids != $actualIds);
|
||||
$this->ids = $actualIds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +138,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return $this->_ids;
|
||||
return $this->ids;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +158,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
if (!$this->getCachedValue()) {
|
||||
$angleAddrs = array();
|
||||
|
||||
foreach ($this->_ids as $id) {
|
||||
foreach ($this->ids as $id) {
|
||||
$angleAddrs[] = '<'.$id.'>';
|
||||
}
|
||||
|
||||
@@ -165,16 +175,10 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*
|
||||
* @throws Swift_RfcComplianceException
|
||||
*/
|
||||
private function _assertValidId($id)
|
||||
private function assertValidId($id)
|
||||
{
|
||||
if (!preg_match(
|
||||
'/^'.$this->getGrammar()->getDefinition('id-left').'@'.
|
||||
$this->getGrammar()->getDefinition('id-right').'$/D',
|
||||
$id
|
||||
)) {
|
||||
throw new Swift_RfcComplianceException(
|
||||
'Invalid ID given <'.$id.'>'
|
||||
);
|
||||
if (!$this->emailValidator->isValid($id, new RFCValidation())) {
|
||||
throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
/**
|
||||
* A Mailbox Address MIME Header for something like From or Sender.
|
||||
*
|
||||
@@ -20,20 +23,27 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_mailboxes = array();
|
||||
private $mailboxes = array();
|
||||
|
||||
/**
|
||||
* The strict EmailValidator.
|
||||
*
|
||||
* @var EmailValidator
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
/**
|
||||
* Creates a new MailboxHeader with $name.
|
||||
*
|
||||
* @param string $name of Header
|
||||
* @param string $name of Header
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param EmailValidator $emailValidator
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
$this->setEncoder($encoder);
|
||||
parent::__construct($grammar);
|
||||
$this->emailValidator = $emailValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +113,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function setNameAddresses($mailboxes)
|
||||
{
|
||||
$this->_mailboxes = $this->normalizeMailboxes((array) $mailboxes);
|
||||
$this->mailboxes = $this->normalizeMailboxes((array) $mailboxes);
|
||||
$this->setCachedValue(null); //Clear any cached value
|
||||
}
|
||||
|
||||
@@ -134,7 +144,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function getNameAddressStrings()
|
||||
{
|
||||
return $this->_createNameAddressStrings($this->getNameAddresses());
|
||||
return $this->createNameAddressStrings($this->getNameAddresses());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +173,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function getNameAddresses()
|
||||
{
|
||||
return $this->_mailboxes;
|
||||
return $this->mailboxes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +210,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function getAddresses()
|
||||
{
|
||||
return array_keys($this->_mailboxes);
|
||||
return array_keys($this->mailboxes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,7 +222,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
{
|
||||
$this->setCachedValue(null);
|
||||
foreach ((array) $addresses as $address) {
|
||||
unset($this->_mailboxes[$address]);
|
||||
unset($this->mailboxes[$address]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,15 +241,13 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
public function getFieldBody()
|
||||
{
|
||||
// Compute the string value of the header only if needed
|
||||
if (is_null($this->getCachedValue())) {
|
||||
$this->setCachedValue($this->createMailboxListString($this->_mailboxes));
|
||||
if (null === $this->getCachedValue()) {
|
||||
$this->setCachedValue($this->createMailboxListString($this->mailboxes));
|
||||
}
|
||||
|
||||
return $this->getCachedValue();
|
||||
}
|
||||
|
||||
// -- Points of extension
|
||||
|
||||
/**
|
||||
* Normalizes a user-input list of mailboxes into consistent key=>value pairs.
|
||||
*
|
||||
@@ -260,7 +268,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
$address = $value;
|
||||
$name = null;
|
||||
}
|
||||
$this->_assertValidAddress($address);
|
||||
$this->assertValidAddress($address);
|
||||
$actualMailboxes[$address] = $name;
|
||||
}
|
||||
|
||||
@@ -277,9 +285,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
protected function createDisplayNameString($displayName, $shorten = false)
|
||||
{
|
||||
return $this->createPhrase($this, $displayName,
|
||||
$this->getCharset(), $this->getEncoder(), $shorten
|
||||
);
|
||||
return $this->createPhrase($this, $displayName, $this->getCharset(), $this->getEncoder(), $shorten);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,14 +299,15 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
protected function createMailboxListString(array $mailboxes)
|
||||
{
|
||||
return implode(', ', $this->_createNameAddressStrings($mailboxes));
|
||||
return implode(', ', $this->createNameAddressStrings($mailboxes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the encoding requirements for mailboxes.
|
||||
*
|
||||
* Commas and semicolons are used to separate
|
||||
* multiple addresses, and should therefore be encoded
|
||||
* All "specials" must be encoded as the full header value will not be quoted
|
||||
*
|
||||
* @see RFC 2822 3.2.1
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
@@ -308,7 +315,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
protected function tokenNeedsEncoding($token)
|
||||
{
|
||||
return preg_match('/[,;]/', $token) || parent::tokenNeedsEncoding($token);
|
||||
return preg_match('/[()<>\[\]:;@\,."]/', $token) || parent::tokenNeedsEncoding($token);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,13 +325,13 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function _createNameAddressStrings(array $mailboxes)
|
||||
private function createNameAddressStrings(array $mailboxes)
|
||||
{
|
||||
$strings = array();
|
||||
|
||||
foreach ($mailboxes as $email => $name) {
|
||||
$mailboxStr = $email;
|
||||
if (!is_null($name)) {
|
||||
if (null !== $name) {
|
||||
$nameStr = $this->createDisplayNameString($name, empty($strings));
|
||||
$mailboxStr = $nameStr.' <'.$mailboxStr.'>';
|
||||
}
|
||||
@@ -341,14 +348,12 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @throws Swift_RfcComplianceException If invalid.
|
||||
*/
|
||||
private function _assertValidAddress($address)
|
||||
private function assertValidAddress($address)
|
||||
{
|
||||
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
|
||||
$address)) {
|
||||
if (!$this->emailValidator->isValid($address, new RFCValidation())) {
|
||||
throw new Swift_RfcComplianceException(
|
||||
'Address in mailbox given ['.$address.
|
||||
'] does not comply with RFC 2822, 3.6.2.'
|
||||
);
|
||||
'Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,25 +20,21 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_value;
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* The name of this Header.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_fieldName;
|
||||
private $fieldName;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleHeader with $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->_fieldName = $name;
|
||||
$this->fieldName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +81,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +91,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->_value = $value;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +101,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getFieldBody()
|
||||
{
|
||||
return $this->_value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +111,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return $this->_fieldName.': '.$this->_value;
|
||||
return $this->fieldName.': '.$this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +121,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function getFieldName()
|
||||
{
|
||||
return $this->_fieldName;
|
||||
return $this->fieldName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_UnstructuredHeader implements Swift_Mime_ParameterizedHeader
|
||||
class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_UnstructuredHeader
|
||||
{
|
||||
/**
|
||||
* RFC 2231's definition of a token.
|
||||
@@ -27,14 +27,14 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*
|
||||
* @var Swift_Encoder
|
||||
*/
|
||||
private $_paramEncoder;
|
||||
private $paramEncoder;
|
||||
|
||||
/**
|
||||
* The parameters as an associative array.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $_params = array();
|
||||
private $params = array();
|
||||
|
||||
/**
|
||||
* Creates a new ParameterizedHeader with $name.
|
||||
@@ -42,12 +42,11 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
* @param string $name
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Encoder $paramEncoder, optional
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder = null, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder = null)
|
||||
{
|
||||
parent::__construct($name, $encoder, $grammar);
|
||||
$this->_paramEncoder = $paramEncoder;
|
||||
parent::__construct($name, $encoder);
|
||||
$this->paramEncoder = $paramEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,8 +70,8 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
public function setCharset($charset)
|
||||
{
|
||||
parent::setCharset($charset);
|
||||
if (isset($this->_paramEncoder)) {
|
||||
$this->_paramEncoder->charsetChanged($charset);
|
||||
if (isset($this->paramEncoder)) {
|
||||
$this->paramEncoder->charsetChanged($charset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
{
|
||||
$params = $this->getParameters();
|
||||
|
||||
return array_key_exists($parameter, $params) ? $params[$parameter] : null;
|
||||
return $params[$parameter] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +107,8 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*/
|
||||
public function setParameters(array $parameters)
|
||||
{
|
||||
$this->clearCachedValueIf($this->_params != $parameters);
|
||||
$this->_params = $parameters;
|
||||
$this->clearCachedValueIf($this->params != $parameters);
|
||||
$this->params = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +118,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->_params;
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,10 +129,10 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
public function getFieldBody() //TODO: Check caching here
|
||||
{
|
||||
$body = parent::getFieldBody();
|
||||
foreach ($this->_params as $name => $value) {
|
||||
if (!is_null($value)) {
|
||||
foreach ($this->params as $name => $value) {
|
||||
if (null !== $value) {
|
||||
// Add the parameter
|
||||
$body .= '; '.$this->_createParameter($name, $value);
|
||||
$body .= '; '.$this->createParameter($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,12 +154,12 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
$tokens = parent::toTokens(parent::getFieldBody());
|
||||
|
||||
// Try creating any parameters
|
||||
foreach ($this->_params as $name => $value) {
|
||||
if (!is_null($value)) {
|
||||
foreach ($this->params as $name => $value) {
|
||||
if (null !== $value) {
|
||||
// Add the semi-colon separator
|
||||
$tokens[count($tokens) - 1] .= ';';
|
||||
$tokens = array_merge($tokens, $this->generateTokenLines(
|
||||
' '.$this->_createParameter($name, $value)
|
||||
' '.$this->createParameter($name, $value)
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -176,7 +175,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _createParameter($name, $value)
|
||||
private function createParameter($name, $value)
|
||||
{
|
||||
$origValue = $value;
|
||||
|
||||
@@ -189,7 +188,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
|
||||
// TODO: text, or something else??
|
||||
// ... and it's not ascii
|
||||
if (!preg_match('/^'.$this->getGrammar()->getDefinition('text').'*$/D', $value)) {
|
||||
if (!preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $value)) {
|
||||
$encoded = true;
|
||||
// Allow space for the indices, charset and language
|
||||
$maxValueLength = $this->getMaxLineLength() - strlen($name.'*N*="";') - 1;
|
||||
@@ -201,8 +200,8 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
|
||||
// Encode if we need to
|
||||
if ($encoded || strlen($value) > $maxValueLength) {
|
||||
if (isset($this->_paramEncoder)) {
|
||||
$value = $this->_paramEncoder->encodeString(
|
||||
if (isset($this->paramEncoder)) {
|
||||
$value = $this->paramEncoder->encodeString(
|
||||
$origValue, $firstLineOffset, $maxValueLength, $this->getCharset()
|
||||
);
|
||||
} else {
|
||||
@@ -212,19 +211,19 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
}
|
||||
}
|
||||
|
||||
$valueLines = isset($this->_paramEncoder) ? explode("\r\n", $value) : array($value);
|
||||
$valueLines = isset($this->paramEncoder) ? explode("\r\n", $value) : array($value);
|
||||
|
||||
// Need to add indices
|
||||
if (count($valueLines) > 1) {
|
||||
$paramLines = array();
|
||||
foreach ($valueLines as $i => $line) {
|
||||
$paramLines[] = $name.'*'.$i.
|
||||
$this->_getEndOfParameterValue($line, true, $i == 0);
|
||||
$this->getEndOfParameterValue($line, true, $i == 0);
|
||||
}
|
||||
|
||||
return implode(";\r\n ", $paramLines);
|
||||
} else {
|
||||
return $name.$this->_getEndOfParameterValue(
|
||||
return $name.$this->getEndOfParameterValue(
|
||||
$valueLines[0], $encoded, true
|
||||
);
|
||||
}
|
||||
@@ -239,7 +238,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getEndOfParameterValue($value, $encoded = false, $firstLine = false)
|
||||
private function getEndOfParameterValue($value, $encoded = false, $firstLine = false)
|
||||
{
|
||||
if (!preg_match('/^'.self::TOKEN_REGEX.'$/D', $value)) {
|
||||
$value = '"'.$value.'"';
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
/**
|
||||
* A Path Header in Swift Mailer, such a Return-Path.
|
||||
*
|
||||
@@ -20,18 +23,25 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_address;
|
||||
private $address;
|
||||
|
||||
/**
|
||||
* The strict EmailValidator.
|
||||
*
|
||||
* @var EmailValidator
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
/**
|
||||
* Creates a new PathHeader with the given $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $name
|
||||
* @param EmailValidator $emailValidator
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name, EmailValidator $emailValidator)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
parent::__construct($grammar);
|
||||
$this->emailValidator = $emailValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,13 +90,13 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function setAddress($address)
|
||||
{
|
||||
if (is_null($address)) {
|
||||
$this->_address = null;
|
||||
if (null === $address) {
|
||||
$this->address = null;
|
||||
} elseif ('' == $address) {
|
||||
$this->_address = '';
|
||||
$this->address = '';
|
||||
} else {
|
||||
$this->_assertValidAddress($address);
|
||||
$this->_address = $address;
|
||||
$this->assertValidAddress($address);
|
||||
$this->address = $address;
|
||||
}
|
||||
$this->setCachedValue(null);
|
||||
}
|
||||
@@ -100,7 +110,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->_address;
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,8 +126,8 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
public function getFieldBody()
|
||||
{
|
||||
if (!$this->getCachedValue()) {
|
||||
if (isset($this->_address)) {
|
||||
$this->setCachedValue('<'.$this->_address.'>');
|
||||
if (isset($this->address)) {
|
||||
$this->setCachedValue('<'.$this->address.'>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,13 +141,12 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @throws Swift_RfcComplianceException If address is invalid
|
||||
*/
|
||||
private function _assertValidAddress($address)
|
||||
private function assertValidAddress($address)
|
||||
{
|
||||
if (!preg_match('/^'.$this->getGrammar()->getDefinition('addr-spec').'$/D',
|
||||
$address)) {
|
||||
if (!$this->emailValidator->isValid($address, new RFCValidation())) {
|
||||
throw new Swift_RfcComplianceException(
|
||||
'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,20 +20,18 @@ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractH
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_value;
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleHeader with $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Mime_Grammar $grammar)
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
$this->setEncoder($encoder);
|
||||
parent::__construct($grammar);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +78,7 @@ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractH
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->_value;
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +88,8 @@ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractH
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->clearCachedValueIf($this->_value != $value);
|
||||
$this->_value = $value;
|
||||
$this->clearCachedValueIf($this->value != $value);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +101,7 @@ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractH
|
||||
{
|
||||
if (!$this->getCachedValue()) {
|
||||
$this->setCachedValue(
|
||||
$this->encodeWords($this, $this->_value)
|
||||
$this->encodeWords($this, $this->value)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message ID generator.
|
||||
*/
|
||||
class Swift_Mime_IdGenerator implements Swift_IdGenerator
|
||||
{
|
||||
/**
|
||||
* @param string $idRight
|
||||
*/
|
||||
public function __construct($idRight)
|
||||
{
|
||||
$this->idRight = $idRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the right-hand side of the "@" used in all generated IDs.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIdRight()
|
||||
{
|
||||
return $this->idRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the right-hand side of the "@" to use in all generated IDs.
|
||||
*
|
||||
* @param string $idRight
|
||||
*/
|
||||
public function setIdRight($idRight)
|
||||
{
|
||||
$this->idRight = $idRight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function generateId()
|
||||
{
|
||||
$idLeft = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
|
||||
return $idLeft.'@'.$this->idRight;
|
||||
}
|
||||
}
|
||||
@@ -1,223 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Message (RFC 2822) object.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
interface Swift_Mime_Message extends Swift_Mime_MimeEntity
|
||||
{
|
||||
/**
|
||||
* Generates a valid Message-ID and switches to it.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateId();
|
||||
|
||||
/**
|
||||
* Set the subject of the message.
|
||||
*
|
||||
* @param string $subject
|
||||
*/
|
||||
public function setSubject($subject);
|
||||
|
||||
/**
|
||||
* Get the subject of the message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubject();
|
||||
|
||||
/**
|
||||
* Set the origination date of the message as a UNIX timestamp.
|
||||
*
|
||||
* @param int $date
|
||||
*/
|
||||
public function setDate($date);
|
||||
|
||||
/**
|
||||
* Get the origination date of the message as a UNIX timestamp.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDate();
|
||||
|
||||
/**
|
||||
* Set the return-path (bounce-detect) address.
|
||||
*
|
||||
* @param string $address
|
||||
*/
|
||||
public function setReturnPath($address);
|
||||
|
||||
/**
|
||||
* Get the return-path (bounce-detect) address.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReturnPath();
|
||||
|
||||
/**
|
||||
* Set the sender of this message.
|
||||
*
|
||||
* If multiple addresses are present in the From field, this SHOULD be set.
|
||||
*
|
||||
* According to RFC 2822 it is a requirement when there are multiple From
|
||||
* addresses, but Swift itself does not require it directly.
|
||||
*
|
||||
* An associative array (with one element!) can be used to provide a display-
|
||||
* name: i.e. array('email@address' => 'Real Name').
|
||||
*
|
||||
* If the second parameter is provided and the first is a string, then $name
|
||||
* is associated with the address.
|
||||
*
|
||||
* @param mixed $address
|
||||
* @param string $name optional
|
||||
*/
|
||||
public function setSender($address, $name = null);
|
||||
|
||||
/**
|
||||
* Get the sender address for this message.
|
||||
*
|
||||
* This has a higher significance than the From address.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSender();
|
||||
|
||||
/**
|
||||
* Set the From address of this message.
|
||||
*
|
||||
* It is permissible for multiple From addresses to be set using an array.
|
||||
*
|
||||
* If multiple From addresses are used, you SHOULD set the Sender address and
|
||||
* according to RFC 2822, MUST set the sender address.
|
||||
*
|
||||
* An array can be used if display names are to be provided: i.e.
|
||||
* array('email@address.com' => 'Real Name').
|
||||
*
|
||||
* If the second parameter is provided and the first is a string, then $name
|
||||
* is associated with the address.
|
||||
*
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*/
|
||||
public function setFrom($addresses, $name = null);
|
||||
|
||||
/**
|
||||
* Get the From address(es) of this message.
|
||||
*
|
||||
* This method always returns an associative array where the keys are the
|
||||
* addresses.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getFrom();
|
||||
|
||||
/**
|
||||
* Set the Reply-To address(es).
|
||||
*
|
||||
* Any replies from the receiver will be sent to this address.
|
||||
*
|
||||
* It is permissible for multiple reply-to addresses to be set using an array.
|
||||
*
|
||||
* This method has the same synopsis as {@link setFrom()} and {@link setTo()}.
|
||||
*
|
||||
* If the second parameter is provided and the first is a string, then $name
|
||||
* is associated with the address.
|
||||
*
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*/
|
||||
public function setReplyTo($addresses, $name = null);
|
||||
|
||||
/**
|
||||
* Get the Reply-To addresses for this message.
|
||||
*
|
||||
* This method always returns an associative array where the keys provide the
|
||||
* email addresses.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getReplyTo();
|
||||
|
||||
/**
|
||||
* Set the To address(es).
|
||||
*
|
||||
* Recipients set in this field will receive a copy of this message.
|
||||
*
|
||||
* This method has the same synopsis as {@link setFrom()} and {@link setCc()}.
|
||||
*
|
||||
* If the second parameter is provided and the first is a string, then $name
|
||||
* is associated with the address.
|
||||
*
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*/
|
||||
public function setTo($addresses, $name = null);
|
||||
|
||||
/**
|
||||
* Get the To addresses for this message.
|
||||
*
|
||||
* This method always returns an associative array, whereby the keys provide
|
||||
* the actual email addresses.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getTo();
|
||||
|
||||
/**
|
||||
* Set the Cc address(es).
|
||||
*
|
||||
* Recipients set in this field will receive a 'carbon-copy' of this message.
|
||||
*
|
||||
* This method has the same synopsis as {@link setFrom()} and {@link setTo()}.
|
||||
*
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*/
|
||||
public function setCc($addresses, $name = null);
|
||||
|
||||
/**
|
||||
* Get the Cc addresses for this message.
|
||||
*
|
||||
* This method always returns an associative array, whereby the keys provide
|
||||
* the actual email addresses.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCc();
|
||||
|
||||
/**
|
||||
* Set the Bcc address(es).
|
||||
*
|
||||
* Recipients set in this field will receive a 'blind-carbon-copy' of this
|
||||
* message.
|
||||
*
|
||||
* In other words, they will get the message, but any other recipients of the
|
||||
* message will have no such knowledge of their receipt of it.
|
||||
*
|
||||
* This method has the same synopsis as {@link setFrom()} and {@link setTo()}.
|
||||
*
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*/
|
||||
public function setBcc($addresses, $name = null);
|
||||
|
||||
/**
|
||||
* Get the Bcc addresses for this message.
|
||||
*
|
||||
* This method always returns an associative array, whereby the keys provide
|
||||
* the actual email addresses.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getBcc();
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A MIME entity, such as an attachment.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_EncodingObserver
|
||||
{
|
||||
/** Main message document; there can only be one of these */
|
||||
const LEVEL_TOP = 16;
|
||||
|
||||
/** An entity which nests with the same precedence as an attachment */
|
||||
const LEVEL_MIXED = 256;
|
||||
|
||||
/** An entity which nests with the same precedence as a mime part */
|
||||
const LEVEL_ALTERNATIVE = 4096;
|
||||
|
||||
/** An entity which nests with the same precedence as embedded content */
|
||||
const LEVEL_RELATED = 65536;
|
||||
|
||||
/**
|
||||
* Get the level at which this entity shall be nested in final document.
|
||||
*
|
||||
* The lower the value, the more outermost the entity will be nested.
|
||||
*
|
||||
* @see LEVEL_TOP, LEVEL_MIXED, LEVEL_RELATED, LEVEL_ALTERNATIVE
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNestingLevel();
|
||||
|
||||
/**
|
||||
* Get the qualified content-type of this mime entity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContentType();
|
||||
|
||||
/**
|
||||
* Returns a unique ID for this entity.
|
||||
*
|
||||
* For most entities this will likely be the Content-ID, though it has
|
||||
* no explicit semantic meaning and can be considered an identifier for
|
||||
* programming logic purposes.
|
||||
*
|
||||
* If a Content-ID header is present, this value SHOULD match the value of
|
||||
* the header.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId();
|
||||
|
||||
/**
|
||||
* Get all children nested inside this entity.
|
||||
*
|
||||
* These are not just the immediate children, but all children.
|
||||
*
|
||||
* @return Swift_Mime_MimeEntity[]
|
||||
*/
|
||||
public function getChildren();
|
||||
|
||||
/**
|
||||
* Set all children nested inside this entity.
|
||||
*
|
||||
* This includes grandchildren.
|
||||
*
|
||||
* @param Swift_Mime_MimeEntity[] $children
|
||||
*/
|
||||
public function setChildren(array $children);
|
||||
|
||||
/**
|
||||
* Get the collection of Headers in this Mime entity.
|
||||
*
|
||||
* @return Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function getHeaders();
|
||||
|
||||
/**
|
||||
* Get the body content of this entity as a string.
|
||||
*
|
||||
* Returns NULL if no body has been set.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getBody();
|
||||
|
||||
/**
|
||||
* Set the body content of this entity as a string.
|
||||
*
|
||||
* @param string $body
|
||||
* @param string $contentType optional
|
||||
*/
|
||||
public function setBody($body, $contentType = null);
|
||||
|
||||
/**
|
||||
* Get this entire entity in its string form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString();
|
||||
|
||||
/**
|
||||
* Get this entire entity as a ByteStream.
|
||||
*
|
||||
* @param Swift_InputByteStream $is to write to
|
||||
*/
|
||||
public function toByteStream(Swift_InputByteStream $is);
|
||||
}
|
||||
@@ -16,31 +16,31 @@
|
||||
class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
{
|
||||
/** The format parameter last specified by the user */
|
||||
protected $_userFormat;
|
||||
protected $userFormat;
|
||||
|
||||
/** The charset last specified by the user */
|
||||
protected $_userCharset;
|
||||
protected $userCharset;
|
||||
|
||||
/** The delsp parameter last specified by the user */
|
||||
protected $_userDelSp;
|
||||
protected $userDelSp;
|
||||
|
||||
/** The nesting level of this MimePart */
|
||||
private $_nestingLevel = self::LEVEL_ALTERNATIVE;
|
||||
private $nestingLevel = self::LEVEL_ALTERNATIVE;
|
||||
|
||||
/**
|
||||
* Create a new MimePart with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_HeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $charset
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $charset = null)
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null)
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $grammar);
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator);
|
||||
$this->setContentType('text/plain');
|
||||
if (!is_null($charset)) {
|
||||
if (null !== $charset) {
|
||||
$this->setCharset($charset);
|
||||
}
|
||||
}
|
||||
@@ -53,14 +53,14 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
* @param string $contentType optional
|
||||
* @param string $charset optional
|
||||
*
|
||||
* @return Swift_Mime_MimePart
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body, $contentType = null, $charset = null)
|
||||
{
|
||||
if (isset($charset)) {
|
||||
$this->setCharset($charset);
|
||||
}
|
||||
$body = $this->_convertString($body);
|
||||
$body = $this->convertString($body);
|
||||
|
||||
parent::setBody($body, $contentType);
|
||||
|
||||
@@ -74,7 +74,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getCharset()
|
||||
{
|
||||
return $this->_getHeaderParameter('Content-Type', 'charset');
|
||||
return $this->getHeaderParameter('Content-Type', 'charset');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,15 +82,15 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*
|
||||
* @param string $charset
|
||||
*
|
||||
* @return Swift_Mime_MimePart
|
||||
* @return $this
|
||||
*/
|
||||
public function setCharset($charset)
|
||||
{
|
||||
$this->_setHeaderParameter('Content-Type', 'charset', $charset);
|
||||
if ($charset !== $this->_userCharset) {
|
||||
$this->_clearCache();
|
||||
$this->setHeaderParameter('Content-Type', 'charset', $charset);
|
||||
if ($charset !== $this->userCharset) {
|
||||
$this->clearCache();
|
||||
}
|
||||
$this->_userCharset = $charset;
|
||||
$this->userCharset = $charset;
|
||||
parent::charsetChanged($charset);
|
||||
|
||||
return $this;
|
||||
@@ -103,7 +103,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getFormat()
|
||||
{
|
||||
return $this->_getHeaderParameter('Content-Type', 'format');
|
||||
return $this->getHeaderParameter('Content-Type', 'format');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,12 +111,12 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return Swift_Mime_MimePart
|
||||
* @return $this
|
||||
*/
|
||||
public function setFormat($format)
|
||||
{
|
||||
$this->_setHeaderParameter('Content-Type', 'format', $format);
|
||||
$this->_userFormat = $format;
|
||||
$this->setHeaderParameter('Content-Type', 'format', $format);
|
||||
$this->userFormat = $format;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getDelSp()
|
||||
{
|
||||
return 'yes' == $this->_getHeaderParameter('Content-Type', 'delsp') ? true : false;
|
||||
return 'yes' === $this->getHeaderParameter('Content-Type', 'delsp');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,12 +136,12 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*
|
||||
* @param bool $delsp
|
||||
*
|
||||
* @return Swift_Mime_MimePart
|
||||
* @return $this
|
||||
*/
|
||||
public function setDelSp($delsp = true)
|
||||
{
|
||||
$this->_setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null);
|
||||
$this->_userDelSp = $delsp;
|
||||
$this->setHeaderParameter('Content-Type', 'delsp', $delsp ? 'yes' : null);
|
||||
$this->userDelSp = $delsp;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
*/
|
||||
public function getNestingLevel()
|
||||
{
|
||||
return $this->_nestingLevel;
|
||||
return $this->nestingLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,31 +170,31 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
}
|
||||
|
||||
/** Fix the content-type and encoding of this entity */
|
||||
protected function _fixHeaders()
|
||||
protected function fixHeaders()
|
||||
{
|
||||
parent::_fixHeaders();
|
||||
parent::fixHeaders();
|
||||
if (count($this->getChildren())) {
|
||||
$this->_setHeaderParameter('Content-Type', 'charset', null);
|
||||
$this->_setHeaderParameter('Content-Type', 'format', null);
|
||||
$this->_setHeaderParameter('Content-Type', 'delsp', null);
|
||||
$this->setHeaderParameter('Content-Type', 'charset', null);
|
||||
$this->setHeaderParameter('Content-Type', 'format', null);
|
||||
$this->setHeaderParameter('Content-Type', 'delsp', null);
|
||||
} else {
|
||||
$this->setCharset($this->_userCharset);
|
||||
$this->setFormat($this->_userFormat);
|
||||
$this->setDelSp($this->_userDelSp);
|
||||
$this->setCharset($this->userCharset);
|
||||
$this->setFormat($this->userFormat);
|
||||
$this->setDelSp($this->userDelSp);
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the nesting level of this entity */
|
||||
protected function _setNestingLevel($level)
|
||||
protected function setNestingLevel($level)
|
||||
{
|
||||
$this->_nestingLevel = $level;
|
||||
$this->nestingLevel = $level;
|
||||
}
|
||||
|
||||
/** Encode charset when charset is not utf-8 */
|
||||
protected function _convertString($string)
|
||||
protected function convertString($string)
|
||||
{
|
||||
$charset = strtolower($this->getCharset());
|
||||
if (!in_array($charset, array('utf-8', 'iso-8859-1', ''))) {
|
||||
if (!in_array($charset, array('utf-8', 'iso-8859-1', 'iso-8859-15', ''))) {
|
||||
// mb_convert_encoding must be the first one to check, since iconv cannot convert some words.
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
$string = mb_convert_encoding($string, $charset, 'utf-8');
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of SwiftMailer.
|
||||
* (c) 2004-2009 Chris Corbyn
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A MIME Header with parameters.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
interface Swift_Mime_ParameterizedHeader extends Swift_Mime_Header
|
||||
{
|
||||
/**
|
||||
* Set the value of $parameter.
|
||||
*
|
||||
* @param string $parameter
|
||||
* @param string $value
|
||||
*/
|
||||
public function setParameter($parameter, $value);
|
||||
|
||||
/**
|
||||
* Get the value of $parameter.
|
||||
*
|
||||
* @param string $parameter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getParameter($parameter);
|
||||
}
|
||||
@@ -8,39 +8,44 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
/**
|
||||
* Creates MIME headers.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
|
||||
{
|
||||
/** The HeaderEncoder used by these headers */
|
||||
private $_encoder;
|
||||
private $encoder;
|
||||
|
||||
/** The Encoder used by parameters */
|
||||
private $_paramEncoder;
|
||||
private $paramEncoder;
|
||||
|
||||
/** The Grammar */
|
||||
private $_grammar;
|
||||
private $grammar;
|
||||
|
||||
/** Strict EmailValidator */
|
||||
private $emailValidator;
|
||||
|
||||
/** The charset of created Headers */
|
||||
private $_charset;
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleHeaderFactory using $encoder and $paramEncoder.
|
||||
*
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Encoder $paramEncoder
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param EmailValidator $emailValidator
|
||||
* @param string|null $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, Swift_Mime_Grammar $grammar, $charset = null)
|
||||
public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, EmailValidator $emailValidator, $charset = null)
|
||||
{
|
||||
$this->_encoder = $encoder;
|
||||
$this->_paramEncoder = $paramEncoder;
|
||||
$this->_grammar = $grammar;
|
||||
$this->_charset = $charset;
|
||||
$this->encoder = $encoder;
|
||||
$this->paramEncoder = $paramEncoder;
|
||||
$this->emailValidator = $emailValidator;
|
||||
$this->charset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,30 +58,30 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
*/
|
||||
public function createMailboxHeader($name, $addresses = null)
|
||||
{
|
||||
$header = new Swift_Mime_Headers_MailboxHeader($name, $this->_encoder, $this->_grammar);
|
||||
$header = new Swift_Mime_Headers_MailboxHeader($name, $this->encoder, $this->emailValidator);
|
||||
if (isset($addresses)) {
|
||||
$header->setFieldBodyModel($addresses);
|
||||
}
|
||||
$this->_setHeaderCharset($header);
|
||||
$this->setHeaderCharset($header);
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Date header using $timestamp (UNIX time).
|
||||
* Create a new Date header using $dateTime.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int|null $timestamp
|
||||
* @param string $name
|
||||
* @param DateTimeInterface|null $dateTime
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
public function createDateHeader($name, $timestamp = null)
|
||||
public function createDateHeader($name, DateTimeInterface $dateTime = null)
|
||||
{
|
||||
$header = new Swift_Mime_Headers_DateHeader($name, $this->_grammar);
|
||||
if (isset($timestamp)) {
|
||||
$header->setFieldBodyModel($timestamp);
|
||||
$header = new Swift_Mime_Headers_DateHeader($name);
|
||||
if (isset($dateTime)) {
|
||||
$header->setFieldBodyModel($dateTime);
|
||||
}
|
||||
$this->_setHeaderCharset($header);
|
||||
$this->setHeaderCharset($header);
|
||||
|
||||
return $header;
|
||||
}
|
||||
@@ -91,11 +96,11 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
*/
|
||||
public function createTextHeader($name, $value = null)
|
||||
{
|
||||
$header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->_encoder, $this->_grammar);
|
||||
$header = new Swift_Mime_Headers_UnstructuredHeader($name, $this->encoder);
|
||||
if (isset($value)) {
|
||||
$header->setFieldBodyModel($value);
|
||||
}
|
||||
$this->_setHeaderCharset($header);
|
||||
$this->setHeaderCharset($header);
|
||||
|
||||
return $header;
|
||||
}
|
||||
@@ -107,19 +112,18 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
* @param string $value
|
||||
* @param array $params
|
||||
*
|
||||
* @return Swift_Mime_ParameterizedHeader
|
||||
* @return Swift_Mime_Headers_ParameterizedHeader
|
||||
*/
|
||||
public function createParameterizedHeader($name, $value = null,
|
||||
$params = array())
|
||||
public function createParameterizedHeader($name, $value = null, $params = array())
|
||||
{
|
||||
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->_encoder, strtolower($name) == 'content-disposition' ? $this->_paramEncoder : null, $this->_grammar);
|
||||
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, (strtolower($name) == 'content-disposition') ? $this->paramEncoder : null);
|
||||
if (isset($value)) {
|
||||
$header->setFieldBodyModel($value);
|
||||
}
|
||||
foreach ($params as $k => $v) {
|
||||
$header->setParameter($k, $v);
|
||||
}
|
||||
$this->_setHeaderCharset($header);
|
||||
$this->setHeaderCharset($header);
|
||||
|
||||
return $header;
|
||||
}
|
||||
@@ -134,11 +138,11 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
*/
|
||||
public function createIdHeader($name, $ids = null)
|
||||
{
|
||||
$header = new Swift_Mime_Headers_IdentificationHeader($name, $this->_grammar);
|
||||
$header = new Swift_Mime_Headers_IdentificationHeader($name, $this->emailValidator);
|
||||
if (isset($ids)) {
|
||||
$header->setFieldBodyModel($ids);
|
||||
}
|
||||
$this->_setHeaderCharset($header);
|
||||
$this->setHeaderCharset($header);
|
||||
|
||||
return $header;
|
||||
}
|
||||
@@ -153,11 +157,11 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
*/
|
||||
public function createPathHeader($name, $path = null)
|
||||
{
|
||||
$header = new Swift_Mime_Headers_PathHeader($name, $this->_grammar);
|
||||
$header = new Swift_Mime_Headers_PathHeader($name, $this->emailValidator);
|
||||
if (isset($path)) {
|
||||
$header->setFieldBodyModel($path);
|
||||
}
|
||||
$this->_setHeaderCharset($header);
|
||||
$this->setHeaderCharset($header);
|
||||
|
||||
return $header;
|
||||
}
|
||||
@@ -169,9 +173,9 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
*/
|
||||
public function charsetChanged($charset)
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_encoder->charsetChanged($charset);
|
||||
$this->_paramEncoder->charsetChanged($charset);
|
||||
$this->charset = $charset;
|
||||
$this->encoder->charsetChanged($charset);
|
||||
$this->paramEncoder->charsetChanged($charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,15 +183,15 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->_encoder = clone $this->_encoder;
|
||||
$this->_paramEncoder = clone $this->_paramEncoder;
|
||||
$this->encoder = clone $this->encoder;
|
||||
$this->paramEncoder = clone $this->paramEncoder;
|
||||
}
|
||||
|
||||
/** Apply the charset to the Header */
|
||||
private function _setHeaderCharset(Swift_Mime_Header $header)
|
||||
private function setHeaderCharset(Swift_Mime_Header $header)
|
||||
{
|
||||
if (isset($this->_charset)) {
|
||||
$header->setCharset($this->_charset);
|
||||
if (isset($this->charset)) {
|
||||
$header->setCharset($this->charset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,37 +13,42 @@
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
{
|
||||
/** HeaderFactory */
|
||||
private $_factory;
|
||||
private $factory;
|
||||
|
||||
/** Collection of set Headers */
|
||||
private $_headers = array();
|
||||
private $headers = array();
|
||||
|
||||
/** Field ordering details */
|
||||
private $_order = array();
|
||||
private $order = array();
|
||||
|
||||
/** List of fields which are required to be displayed */
|
||||
private $_required = array();
|
||||
private $required = array();
|
||||
|
||||
/** The charset used by Headers */
|
||||
private $_charset;
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* Create a new SimpleHeaderSet with the given $factory.
|
||||
*
|
||||
* @param Swift_Mime_HeaderFactory $factory
|
||||
* @param string $charset
|
||||
* @param Swift_Mime_SimpleHeaderFactory $factory
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderFactory $factory, $charset = null)
|
||||
public function __construct(Swift_Mime_SimpleHeaderFactory $factory, $charset = null)
|
||||
{
|
||||
$this->_factory = $factory;
|
||||
$this->factory = $factory;
|
||||
if (isset($charset)) {
|
||||
$this->setCharset($charset);
|
||||
}
|
||||
}
|
||||
|
||||
public function newInstance()
|
||||
{
|
||||
return new self($this->factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the charset used by these headers.
|
||||
*
|
||||
@@ -51,9 +56,9 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function setCharset($charset)
|
||||
{
|
||||
$this->_charset = $charset;
|
||||
$this->_factory->charsetChanged($charset);
|
||||
$this->_notifyHeadersOfCharset($charset);
|
||||
$this->charset = $charset;
|
||||
$this->factory->charsetChanged($charset);
|
||||
$this->notifyHeadersOfCharset($charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,20 +69,20 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function addMailboxHeader($name, $addresses = null)
|
||||
{
|
||||
$this->_storeHeader($name,
|
||||
$this->_factory->createMailboxHeader($name, $addresses));
|
||||
$this->storeHeader($name,
|
||||
$this->factory->createMailboxHeader($name, $addresses));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Date header using $timestamp (UNIX time).
|
||||
* Add a new Date header using $dateTime.
|
||||
*
|
||||
* @param string $name
|
||||
* @param int $timestamp
|
||||
* @param string $name
|
||||
* @param DateTimeInterface $dateTime
|
||||
*/
|
||||
public function addDateHeader($name, $timestamp = null)
|
||||
public function addDateHeader($name, DateTimeInterface $dateTime = null)
|
||||
{
|
||||
$this->_storeHeader($name,
|
||||
$this->_factory->createDateHeader($name, $timestamp));
|
||||
$this->storeHeader($name,
|
||||
$this->factory->createDateHeader($name, $dateTime));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,8 +93,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function addTextHeader($name, $value = null)
|
||||
{
|
||||
$this->_storeHeader($name,
|
||||
$this->_factory->createTextHeader($name, $value));
|
||||
$this->storeHeader($name,
|
||||
$this->factory->createTextHeader($name, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +106,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function addParameterizedHeader($name, $value = null, $params = array())
|
||||
{
|
||||
$this->_storeHeader($name, $this->_factory->createParameterizedHeader($name, $value, $params));
|
||||
$this->storeHeader($name, $this->factory->createParameterizedHeader($name, $value, $params));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +117,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function addIdHeader($name, $ids = null)
|
||||
{
|
||||
$this->_storeHeader($name, $this->_factory->createIdHeader($name, $ids));
|
||||
$this->storeHeader($name, $this->factory->createIdHeader($name, $ids));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,7 +128,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function addPathHeader($name, $path = null)
|
||||
{
|
||||
$this->_storeHeader($name, $this->_factory->createPathHeader($name, $path));
|
||||
$this->storeHeader($name, $this->factory->createPathHeader($name, $path));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,7 +145,16 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
{
|
||||
$lowerName = strtolower($name);
|
||||
|
||||
return array_key_exists($lowerName, $this->_headers) && array_key_exists($index, $this->_headers[$lowerName]);
|
||||
if (!array_key_exists($lowerName, $this->headers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (func_num_args() < 2) {
|
||||
// index was not specified, so we only need to check that there is at least one header value set
|
||||
return (bool) count($this->headers[$lowerName]);
|
||||
}
|
||||
|
||||
return array_key_exists($index, $this->headers[$lowerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +171,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function set(Swift_Mime_Header $header, $index = 0)
|
||||
{
|
||||
$this->_storeHeader($header->getFieldName(), $header, $index);
|
||||
$this->storeHeader($header->getFieldName(), $header, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,10 +187,18 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function get($name, $index = 0)
|
||||
{
|
||||
if ($this->has($name, $index)) {
|
||||
$lowerName = strtolower($name);
|
||||
$name = strtolower($name);
|
||||
|
||||
return $this->_headers[$lowerName][$index];
|
||||
if (func_num_args() < 2) {
|
||||
if ($this->has($name)) {
|
||||
$values = array_values($this->headers[$name]);
|
||||
|
||||
return array_shift($values);
|
||||
}
|
||||
} else {
|
||||
if ($this->has($name, $index)) {
|
||||
return $this->headers[$name][$index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +213,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
{
|
||||
if (!isset($name)) {
|
||||
$headers = array();
|
||||
foreach ($this->_headers as $collection) {
|
||||
foreach ($this->headers as $collection) {
|
||||
$headers = array_merge($headers, $collection);
|
||||
}
|
||||
|
||||
@@ -199,11 +221,11 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
}
|
||||
|
||||
$lowerName = strtolower($name);
|
||||
if (!array_key_exists($lowerName, $this->_headers)) {
|
||||
if (!array_key_exists($lowerName, $this->headers)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $this->_headers[$lowerName];
|
||||
return $this->headers[$lowerName];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,9 +235,9 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function listAll()
|
||||
{
|
||||
$headers = $this->_headers;
|
||||
if ($this->_canSort()) {
|
||||
uksort($headers, array($this, '_sortHeaders'));
|
||||
$headers = $this->headers;
|
||||
if ($this->canSort()) {
|
||||
uksort($headers, array($this, 'sortHeaders'));
|
||||
}
|
||||
|
||||
return array_keys($headers);
|
||||
@@ -232,7 +254,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
public function remove($name, $index = 0)
|
||||
{
|
||||
$lowerName = strtolower($name);
|
||||
unset($this->_headers[$lowerName][$index]);
|
||||
unset($this->headers[$lowerName][$index]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,17 +265,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
public function removeAll($name)
|
||||
{
|
||||
$lowerName = strtolower($name);
|
||||
unset($this->_headers[$lowerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of this HeaderSet.
|
||||
*
|
||||
* @return Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function newInstance()
|
||||
{
|
||||
return new self($this->_factory);
|
||||
unset($this->headers[$lowerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,7 +277,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function defineOrdering(array $sequence)
|
||||
{
|
||||
$this->_order = array_flip(array_map('strtolower', $sequence));
|
||||
$this->order = array_flip(array_map('strtolower', $sequence));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +289,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function setAlwaysDisplayed(array $names)
|
||||
{
|
||||
$this->_required = array_flip(array_map('strtolower', $names));
|
||||
$this->required = array_flip(array_map('strtolower', $names));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,13 +310,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
public function toString()
|
||||
{
|
||||
$string = '';
|
||||
$headers = $this->_headers;
|
||||
if ($this->_canSort()) {
|
||||
uksort($headers, array($this, '_sortHeaders'));
|
||||
$headers = $this->headers;
|
||||
if ($this->canSort()) {
|
||||
uksort($headers, array($this, 'sortHeaders'));
|
||||
}
|
||||
foreach ($headers as $collection) {
|
||||
foreach ($collection as $header) {
|
||||
if ($this->_isDisplayed($header) || $header->getFieldBody() != '') {
|
||||
if ($this->isDisplayed($header) || $header->getFieldBody() != '') {
|
||||
$string .= $header->toString();
|
||||
}
|
||||
}
|
||||
@@ -326,31 +338,31 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
}
|
||||
|
||||
/** Save a Header to the internal collection */
|
||||
private function _storeHeader($name, Swift_Mime_Header $header, $offset = null)
|
||||
private function storeHeader($name, Swift_Mime_Header $header, $offset = null)
|
||||
{
|
||||
if (!isset($this->_headers[strtolower($name)])) {
|
||||
$this->_headers[strtolower($name)] = array();
|
||||
if (!isset($this->headers[strtolower($name)])) {
|
||||
$this->headers[strtolower($name)] = array();
|
||||
}
|
||||
if (!isset($offset)) {
|
||||
$this->_headers[strtolower($name)][] = $header;
|
||||
$this->headers[strtolower($name)][] = $header;
|
||||
} else {
|
||||
$this->_headers[strtolower($name)][$offset] = $header;
|
||||
$this->headers[strtolower($name)][$offset] = $header;
|
||||
}
|
||||
}
|
||||
|
||||
/** Test if the headers can be sorted */
|
||||
private function _canSort()
|
||||
private function canSort()
|
||||
{
|
||||
return count($this->_order) > 0;
|
||||
return count($this->order) > 0;
|
||||
}
|
||||
|
||||
/** uksort() algorithm for Header ordering */
|
||||
private function _sortHeaders($a, $b)
|
||||
private function sortHeaders($a, $b)
|
||||
{
|
||||
$lowerA = strtolower($a);
|
||||
$lowerB = strtolower($b);
|
||||
$aPos = array_key_exists($lowerA, $this->_order) ? $this->_order[$lowerA] : -1;
|
||||
$bPos = array_key_exists($lowerB, $this->_order) ? $this->_order[$lowerB] : -1;
|
||||
$aPos = array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1;
|
||||
$bPos = array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1;
|
||||
|
||||
if (-1 === $aPos && -1 === $bPos) {
|
||||
// just be sure to be determinist here
|
||||
@@ -367,15 +379,15 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
}
|
||||
|
||||
/** Test if the given Header is always displayed */
|
||||
private function _isDisplayed(Swift_Mime_Header $header)
|
||||
private function isDisplayed(Swift_Mime_Header $header)
|
||||
{
|
||||
return array_key_exists(strtolower($header->getFieldName()), $this->_required);
|
||||
return array_key_exists(strtolower($header->getFieldName()), $this->required);
|
||||
}
|
||||
|
||||
/** Notify all Headers of the new charset */
|
||||
private function _notifyHeadersOfCharset($charset)
|
||||
private function notifyHeadersOfCharset($charset)
|
||||
{
|
||||
foreach ($this->_headers as $headerGroup) {
|
||||
foreach ($this->headers as $headerGroup) {
|
||||
foreach ($headerGroup as $header) {
|
||||
$header->setCharset($charset);
|
||||
}
|
||||
@@ -387,10 +399,10 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->_factory = clone $this->_factory;
|
||||
foreach ($this->_headers as $groupKey => $headerGroup) {
|
||||
$this->factory = clone $this->factory;
|
||||
foreach ($this->headers as $groupKey => $headerGroup) {
|
||||
foreach ($headerGroup as $key => $header) {
|
||||
$this->_headers[$groupKey][$key] = clone $header;
|
||||
$this->headers[$groupKey][$key] = clone $header;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,20 +13,26 @@
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime_Message
|
||||
class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
{
|
||||
const PRIORITY_HIGHEST = 1;
|
||||
const PRIORITY_HIGH = 2;
|
||||
const PRIORITY_NORMAL = 3;
|
||||
const PRIORITY_LOW = 4;
|
||||
const PRIORITY_LOWEST = 5;
|
||||
|
||||
/**
|
||||
* Create a new SimpleMessage with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_HeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param string $charset
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar, $charset = null)
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null)
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $grammar, $charset);
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator, $charset);
|
||||
$this->getHeaders()->defineOrdering(array(
|
||||
'Return-Path',
|
||||
'Received',
|
||||
@@ -47,7 +53,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
));
|
||||
$this->getHeaders()->setAlwaysDisplayed(array('Date', 'Message-ID', 'From'));
|
||||
$this->getHeaders()->addTextHeader('MIME-Version', '1.0');
|
||||
$this->setDate(time());
|
||||
$this->setDate(new DateTimeImmutable());
|
||||
$this->setId($this->getId());
|
||||
$this->getHeaders()->addMailboxHeader('From');
|
||||
}
|
||||
@@ -67,11 +73,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*
|
||||
* @param string $subject
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setSubject($subject)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Subject', $subject)) {
|
||||
if (!$this->setHeaderFieldModel('Subject', $subject)) {
|
||||
$this->getHeaders()->addTextHeader('Subject', $subject);
|
||||
}
|
||||
|
||||
@@ -85,20 +91,20 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Subject');
|
||||
return $this->getHeaderFieldModel('Subject');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date at which this message was created.
|
||||
*
|
||||
* @param int $date
|
||||
* @param DateTimeInterface $dateTime
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setDate($date)
|
||||
public function setDate(DateTimeInterface $dateTime)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Date', $date)) {
|
||||
$this->getHeaders()->addDateHeader('Date', $date);
|
||||
if (!$this->setHeaderFieldModel('Date', $dateTime)) {
|
||||
$this->getHeaders()->addDateHeader('Date', $dateTime);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -107,11 +113,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
/**
|
||||
* Get the date at which this message was created.
|
||||
*
|
||||
* @return int
|
||||
* @return DateTimeInterface
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Date');
|
||||
return $this->getHeaderFieldModel('Date');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,11 +125,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*
|
||||
* @param string $address
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setReturnPath($address)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Return-Path', $address)) {
|
||||
if (!$this->setHeaderFieldModel('Return-Path', $address)) {
|
||||
$this->getHeaders()->addPathHeader('Return-Path', $address);
|
||||
}
|
||||
|
||||
@@ -137,7 +143,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getReturnPath()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Return-Path');
|
||||
return $this->getHeaderFieldModel('Return-Path');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +154,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string $address
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setSender($address, $name = null)
|
||||
{
|
||||
@@ -156,7 +162,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
$address = array($address => $name);
|
||||
}
|
||||
|
||||
if (!$this->_setHeaderFieldModel('Sender', (array) $address)) {
|
||||
if (!$this->setHeaderFieldModel('Sender', (array) $address)) {
|
||||
$this->getHeaders()->addMailboxHeader('Sender', (array) $address);
|
||||
}
|
||||
|
||||
@@ -170,7 +176,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getSender()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Sender');
|
||||
return $this->getHeaderFieldModel('Sender');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,7 +187,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string $address
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function addFrom($address, $name = null)
|
||||
{
|
||||
@@ -202,7 +208,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string|array $addresses
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setFrom($addresses, $name = null)
|
||||
{
|
||||
@@ -210,7 +216,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
$addresses = array($addresses => $name);
|
||||
}
|
||||
|
||||
if (!$this->_setHeaderFieldModel('From', (array) $addresses)) {
|
||||
if (!$this->setHeaderFieldModel('From', (array) $addresses)) {
|
||||
$this->getHeaders()->addMailboxHeader('From', (array) $addresses);
|
||||
}
|
||||
|
||||
@@ -224,7 +230,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('From');
|
||||
return $this->getHeaderFieldModel('From');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,7 +241,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string $address
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function addReplyTo($address, $name = null)
|
||||
{
|
||||
@@ -256,7 +262,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setReplyTo($addresses, $name = null)
|
||||
{
|
||||
@@ -264,7 +270,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
$addresses = array($addresses => $name);
|
||||
}
|
||||
|
||||
if (!$this->_setHeaderFieldModel('Reply-To', (array) $addresses)) {
|
||||
if (!$this->setHeaderFieldModel('Reply-To', (array) $addresses)) {
|
||||
$this->getHeaders()->addMailboxHeader('Reply-To', (array) $addresses);
|
||||
}
|
||||
|
||||
@@ -278,7 +284,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getReplyTo()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Reply-To');
|
||||
return $this->getHeaderFieldModel('Reply-To');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,7 +295,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string $address
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function addTo($address, $name = null)
|
||||
{
|
||||
@@ -311,7 +317,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setTo($addresses, $name = null)
|
||||
{
|
||||
@@ -319,7 +325,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
$addresses = array($addresses => $name);
|
||||
}
|
||||
|
||||
if (!$this->_setHeaderFieldModel('To', (array) $addresses)) {
|
||||
if (!$this->setHeaderFieldModel('To', (array) $addresses)) {
|
||||
$this->getHeaders()->addMailboxHeader('To', (array) $addresses);
|
||||
}
|
||||
|
||||
@@ -333,7 +339,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getTo()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('To');
|
||||
return $this->getHeaderFieldModel('To');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +350,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string $address
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function addCc($address, $name = null)
|
||||
{
|
||||
@@ -363,7 +369,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setCc($addresses, $name = null)
|
||||
{
|
||||
@@ -371,7 +377,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
$addresses = array($addresses => $name);
|
||||
}
|
||||
|
||||
if (!$this->_setHeaderFieldModel('Cc', (array) $addresses)) {
|
||||
if (!$this->setHeaderFieldModel('Cc', (array) $addresses)) {
|
||||
$this->getHeaders()->addMailboxHeader('Cc', (array) $addresses);
|
||||
}
|
||||
|
||||
@@ -385,7 +391,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getCc()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Cc');
|
||||
return $this->getHeaderFieldModel('Cc');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,7 +402,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param string $address
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function addBcc($address, $name = null)
|
||||
{
|
||||
@@ -415,7 +421,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
* @param mixed $addresses
|
||||
* @param string $name optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setBcc($addresses, $name = null)
|
||||
{
|
||||
@@ -423,7 +429,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
$addresses = array($addresses => $name);
|
||||
}
|
||||
|
||||
if (!$this->_setHeaderFieldModel('Bcc', (array) $addresses)) {
|
||||
if (!$this->setHeaderFieldModel('Bcc', (array) $addresses)) {
|
||||
$this->getHeaders()->addMailboxHeader('Bcc', (array) $addresses);
|
||||
}
|
||||
|
||||
@@ -437,7 +443,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getBcc()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Bcc');
|
||||
return $this->getHeaderFieldModel('Bcc');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -447,16 +453,16 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*
|
||||
* @param int $priority
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setPriority($priority)
|
||||
{
|
||||
$priorityMap = array(
|
||||
1 => 'Highest',
|
||||
2 => 'High',
|
||||
3 => 'Normal',
|
||||
4 => 'Low',
|
||||
5 => 'Lowest',
|
||||
self::PRIORITY_HIGHEST => 'Highest',
|
||||
self::PRIORITY_HIGH => 'High',
|
||||
self::PRIORITY_NORMAL => 'Normal',
|
||||
self::PRIORITY_LOW => 'Low',
|
||||
self::PRIORITY_LOWEST => 'Lowest',
|
||||
);
|
||||
$pMapKeys = array_keys($priorityMap);
|
||||
if ($priority > max($pMapKeys)) {
|
||||
@@ -464,7 +470,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
} elseif ($priority < min($pMapKeys)) {
|
||||
$priority = min($pMapKeys);
|
||||
}
|
||||
if (!$this->_setHeaderFieldModel('X-Priority',
|
||||
if (!$this->setHeaderFieldModel('X-Priority',
|
||||
sprintf('%d (%s)', $priority, $priorityMap[$priority]))) {
|
||||
$this->getHeaders()->addTextHeader('X-Priority',
|
||||
sprintf('%d (%s)', $priority, $priorityMap[$priority]));
|
||||
@@ -483,11 +489,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getPriority()
|
||||
{
|
||||
list($priority) = sscanf($this->_getHeaderFieldModel('X-Priority'),
|
||||
list($priority) = sscanf($this->getHeaderFieldModel('X-Priority'),
|
||||
'%[1-5]'
|
||||
);
|
||||
|
||||
return isset($priority) ? $priority : 3;
|
||||
return $priority ?? 3;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,11 +501,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*
|
||||
* @param array $addresses
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function setReadReceiptTo($addresses)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Disposition-Notification-To', $addresses)) {
|
||||
if (!$this->setHeaderFieldModel('Disposition-Notification-To', $addresses)) {
|
||||
$this->getHeaders()
|
||||
->addMailboxHeader('Disposition-Notification-To', $addresses);
|
||||
}
|
||||
@@ -514,17 +520,17 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
*/
|
||||
public function getReadReceiptTo()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Disposition-Notification-To');
|
||||
return $this->getHeaderFieldModel('Disposition-Notification-To');
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a {@link Swift_Mime_MimeEntity} such as an Attachment or MimePart.
|
||||
* Attach a {@link Swift_Mime_SimpleMimeEntity} such as an Attachment or MimePart.
|
||||
*
|
||||
* @param Swift_Mime_MimeEntity $entity
|
||||
* @param Swift_Mime_SimpleMimeEntity $entity
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function attach(Swift_Mime_MimeEntity $entity)
|
||||
public function attach(Swift_Mime_SimpleMimeEntity $entity)
|
||||
{
|
||||
$this->setChildren(array_merge($this->getChildren(), array($entity)));
|
||||
|
||||
@@ -534,11 +540,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
/**
|
||||
* Remove an already attached entity.
|
||||
*
|
||||
* @param Swift_Mime_MimeEntity $entity
|
||||
* @param Swift_Mime_SimpleMimeEntity $entity
|
||||
*
|
||||
* @return Swift_Mime_SimpleMessage
|
||||
* @return $this
|
||||
*/
|
||||
public function detach(Swift_Mime_MimeEntity $entity)
|
||||
public function detach(Swift_Mime_SimpleMimeEntity $entity)
|
||||
{
|
||||
$newChildren = array();
|
||||
foreach ($this->getChildren() as $child) {
|
||||
@@ -552,14 +558,14 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a {@link Swift_Mime_MimeEntity} and return it's CID source.
|
||||
* Attach a {@link Swift_Mime_SimpleMimeEntity} and return it's CID source.
|
||||
* This method should be used when embedding images or other data in a message.
|
||||
*
|
||||
* @param Swift_Mime_MimeEntity $entity
|
||||
* @param Swift_Mime_SimpleMimeEntity $entity
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function embed(Swift_Mime_MimeEntity $entity)
|
||||
public function embed(Swift_Mime_SimpleMimeEntity $entity)
|
||||
{
|
||||
$this->attach($entity);
|
||||
|
||||
@@ -574,7 +580,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
public function toString()
|
||||
{
|
||||
if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') {
|
||||
$this->setChildren(array_merge(array($this->_becomeMimePart()), $children));
|
||||
$this->setChildren(array_merge(array($this->becomeMimePart()), $children));
|
||||
$string = parent::toString();
|
||||
$this->setChildren($children);
|
||||
} else {
|
||||
@@ -604,7 +610,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
public function toByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') {
|
||||
$this->setChildren(array_merge(array($this->_becomeMimePart()), $children));
|
||||
$this->setChildren(array_merge(array($this->becomeMimePart()), $children));
|
||||
parent::toByteStream($is);
|
||||
$this->setChildren($children);
|
||||
} else {
|
||||
@@ -612,29 +618,29 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime
|
||||
}
|
||||
}
|
||||
|
||||
/** @see Swift_Mime_SimpleMimeEntity::_getIdField() */
|
||||
protected function _getIdField()
|
||||
/** @see Swift_Mime_SimpleMimeEntity::getIdField() */
|
||||
protected function getIdField()
|
||||
{
|
||||
return 'Message-ID';
|
||||
}
|
||||
|
||||
/** Turn the body of this message into a child of itself if needed */
|
||||
protected function _becomeMimePart()
|
||||
protected function becomeMimePart()
|
||||
{
|
||||
$part = new parent($this->getHeaders()->newInstance(), $this->getEncoder(),
|
||||
$this->_getCache(), $this->_getGrammar(), $this->_userCharset
|
||||
$this->getCache(), $this->getIdGenerator(), $this->userCharset
|
||||
);
|
||||
$part->setContentType($this->_userContentType);
|
||||
$part->setContentType($this->userContentType);
|
||||
$part->setBody($this->getBody());
|
||||
$part->setFormat($this->_userFormat);
|
||||
$part->setDelSp($this->_userDelSp);
|
||||
$part->_setNestingLevel($this->_getTopNestingLevel());
|
||||
$part->setFormat($this->userFormat);
|
||||
$part->setDelSp($this->userDelSp);
|
||||
$part->setNestingLevel($this->getTopNestingLevel());
|
||||
|
||||
return $part;
|
||||
}
|
||||
|
||||
/** Get the highest nesting level nested inside this message */
|
||||
private function _getTopNestingLevel()
|
||||
private function getTopNestingLevel()
|
||||
{
|
||||
$highestLevel = $this->getNestingLevel();
|
||||
foreach ($this->getChildren() as $child) {
|
||||
|
||||
@@ -13,79 +13,91 @@
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_Mime_EncodingObserver
|
||||
{
|
||||
/** Main message document; there can only be one of these */
|
||||
const LEVEL_TOP = 16;
|
||||
|
||||
/** An entity which nests with the same precedence as an attachment */
|
||||
const LEVEL_MIXED = 256;
|
||||
|
||||
/** An entity which nests with the same precedence as a mime part */
|
||||
const LEVEL_ALTERNATIVE = 4096;
|
||||
|
||||
/** An entity which nests with the same precedence as embedded content */
|
||||
const LEVEL_RELATED = 65536;
|
||||
|
||||
/** A collection of Headers for this mime entity */
|
||||
private $_headers;
|
||||
private $headers;
|
||||
|
||||
/** The body as a string, or a stream */
|
||||
private $_body;
|
||||
private $body;
|
||||
|
||||
/** The encoder that encodes the body into a streamable format */
|
||||
private $_encoder;
|
||||
private $encoder;
|
||||
|
||||
/** The grammar to use for id validation */
|
||||
private $_grammar;
|
||||
/** Message ID generator */
|
||||
private $idGenerator;
|
||||
|
||||
/** A mime boundary, if any is used */
|
||||
private $_boundary;
|
||||
private $boundary;
|
||||
|
||||
/** Mime types to be used based on the nesting level */
|
||||
private $_compositeRanges = array(
|
||||
private $compositeRanges = array(
|
||||
'multipart/mixed' => array(self::LEVEL_TOP, self::LEVEL_MIXED),
|
||||
'multipart/alternative' => array(self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE),
|
||||
'multipart/related' => array(self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED),
|
||||
);
|
||||
|
||||
/** A set of filter rules to define what level an entity should be nested at */
|
||||
private $_compoundLevelFilters = array();
|
||||
private $compoundLevelFilters = array();
|
||||
|
||||
/** The nesting level of this entity */
|
||||
private $_nestingLevel = self::LEVEL_ALTERNATIVE;
|
||||
private $nestingLevel = self::LEVEL_ALTERNATIVE;
|
||||
|
||||
/** A KeyCache instance used during encoding and streaming */
|
||||
private $_cache;
|
||||
private $cache;
|
||||
|
||||
/** Direct descendants of this entity */
|
||||
private $_immediateChildren = array();
|
||||
private $immediateChildren = array();
|
||||
|
||||
/** All descendants of this entity */
|
||||
private $_children = array();
|
||||
private $children = array();
|
||||
|
||||
/** The maximum line length of the body of this entity */
|
||||
private $_maxLineLength = 78;
|
||||
private $maxLineLength = 78;
|
||||
|
||||
/** The order in which alternative mime types should appear */
|
||||
private $_alternativePartOrder = array(
|
||||
private $alternativePartOrder = array(
|
||||
'text/plain' => 1,
|
||||
'text/html' => 2,
|
||||
'multipart/related' => 3,
|
||||
);
|
||||
|
||||
/** The CID of this entity */
|
||||
private $_id;
|
||||
private $id;
|
||||
|
||||
/** The key used for accessing the cache */
|
||||
private $_cacheKey;
|
||||
private $cacheKey;
|
||||
|
||||
protected $_userContentType;
|
||||
protected $userContentType;
|
||||
|
||||
/**
|
||||
* Create a new SimpleMimeEntity with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_HeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_Mime_Grammar $grammar
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_Mime_Grammar $grammar)
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator)
|
||||
{
|
||||
$this->_cacheKey = md5(uniqid(getmypid().mt_rand(), true));
|
||||
$this->_cache = $cache;
|
||||
$this->_headers = $headers;
|
||||
$this->_grammar = $grammar;
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$this->cache = $cache;
|
||||
$this->headers = $headers;
|
||||
$this->idGenerator = $idGenerator;
|
||||
$this->setEncoder($encoder);
|
||||
$this->_headers->defineOrdering(array('Content-Type', 'Content-Transfer-Encoding'));
|
||||
$this->headers->defineOrdering(array('Content-Type', 'Content-Transfer-Encoding'));
|
||||
|
||||
// This array specifies that, when the entire MIME document contains
|
||||
// $compoundLevel, then for each child within $level, if its Content-Type
|
||||
@@ -100,7 +112,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
// )
|
||||
// )
|
||||
|
||||
$this->_compoundLevelFilters = array(
|
||||
$this->compoundLevelFilters = array(
|
||||
(self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => array(
|
||||
self::LEVEL_ALTERNATIVE => array(
|
||||
'text/plain' => self::LEVEL_ALTERNATIVE,
|
||||
@@ -109,7 +121,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
),
|
||||
);
|
||||
|
||||
$this->_id = $this->getRandomId();
|
||||
$this->id = $this->idGenerator->generateId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,19 +131,19 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function generateId()
|
||||
{
|
||||
$this->setId($this->getRandomId());
|
||||
$this->setId($this->idGenerator->generateId());
|
||||
|
||||
return $this->_id;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Swift_Mime_HeaderSet} for this entity.
|
||||
* Get the {@link Swift_Mime_SimpleHeaderSet} for this entity.
|
||||
*
|
||||
* @return Swift_Mime_HeaderSet
|
||||
* @return Swift_Mime_SimpleHeaderSet
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,7 +155,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getNestingLevel()
|
||||
{
|
||||
return $this->_nestingLevel;
|
||||
return $this->nestingLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +165,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getContentType()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Content-Type');
|
||||
return $this->getHeaderFieldModel('Content-Type');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,14 +173,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setContentType($type)
|
||||
{
|
||||
$this->_setContentTypeInHeaders($type);
|
||||
$this->setContentTypeInHeaders($type);
|
||||
// Keep track of the value so that if the content-type changes automatically
|
||||
// due to added child entities, it can be restored if they are later removed
|
||||
$this->_userContentType = $type;
|
||||
$this->userContentType = $type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -182,9 +194,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
$tmp = (array) $this->_getHeaderFieldModel($this->_getIdField());
|
||||
$tmp = (array) $this->getHeaderFieldModel($this->getIdField());
|
||||
|
||||
return $this->_headers->has($this->_getIdField()) ? current($tmp) : $this->_id;
|
||||
return $this->headers->has($this->getIdField()) ? current($tmp) : $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,14 +204,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel($this->_getIdField(), $id)) {
|
||||
$this->_headers->addIdHeader($this->_getIdField(), $id);
|
||||
if (!$this->setHeaderFieldModel($this->getIdField(), $id)) {
|
||||
$this->headers->addIdHeader($this->getIdField(), $id);
|
||||
}
|
||||
$this->_id = $id;
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -213,7 +225,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->_getHeaderFieldModel('Content-Description');
|
||||
return $this->getHeaderFieldModel('Content-Description');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,12 +235,12 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @param string $description
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Content-Description', $description)) {
|
||||
$this->_headers->addTextHeader('Content-Description', $description);
|
||||
if (!$this->setHeaderFieldModel('Content-Description', $description)) {
|
||||
$this->headers->addTextHeader('Content-Description', $description);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -241,7 +253,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getMaxLineLength()
|
||||
{
|
||||
return $this->_maxLineLength;
|
||||
return $this->maxLineLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,11 +263,11 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @param int $length
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setMaxLineLength($length)
|
||||
{
|
||||
$this->_maxLineLength = $length;
|
||||
$this->maxLineLength = $length;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -263,37 +275,36 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
/**
|
||||
* Get all children added to this entity.
|
||||
*
|
||||
* @return Swift_Mime_MimeEntity[]
|
||||
* @return Swift_Mime_SimpleMimeEntity[]
|
||||
*/
|
||||
public function getChildren()
|
||||
{
|
||||
return $this->_children;
|
||||
return $this->children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all children of this entity.
|
||||
*
|
||||
* @param Swift_Mime_MimeEntity[] $children
|
||||
* @param int $compoundLevel For internal use only
|
||||
* @param Swift_Mime_SimpleMimeEntity[] $children
|
||||
* @param int $compoundLevel For internal use only
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setChildren(array $children, $compoundLevel = null)
|
||||
{
|
||||
// TODO: Try to refactor this logic
|
||||
|
||||
$compoundLevel = isset($compoundLevel) ? $compoundLevel : $this->_getCompoundLevel($children);
|
||||
$compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
|
||||
$immediateChildren = array();
|
||||
$grandchildren = array();
|
||||
$newContentType = $this->_userContentType;
|
||||
$newContentType = $this->userContentType;
|
||||
|
||||
foreach ($children as $child) {
|
||||
$level = $this->_getNeededChildLevel($child, $compoundLevel);
|
||||
$level = $this->getNeededChildLevel($child, $compoundLevel);
|
||||
if (empty($immediateChildren)) {
|
||||
//first iteration
|
||||
$immediateChildren = array($child);
|
||||
} else {
|
||||
$nextLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel);
|
||||
$nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
|
||||
if ($nextLevel == $level) {
|
||||
$immediateChildren[] = $child;
|
||||
} elseif ($level < $nextLevel) {
|
||||
@@ -308,11 +319,11 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
}
|
||||
|
||||
if ($immediateChildren) {
|
||||
$lowestLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel);
|
||||
$lowestLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
|
||||
|
||||
// Determine which composite media type is needed to accommodate the
|
||||
// immediate children
|
||||
foreach ($this->_compositeRanges as $mediaType => $range) {
|
||||
foreach ($this->compositeRanges as $mediaType => $range) {
|
||||
if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) {
|
||||
$newContentType = $mediaType;
|
||||
|
||||
@@ -322,18 +333,18 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
|
||||
// Put any grandchildren in a subpart
|
||||
if (!empty($grandchildren)) {
|
||||
$subentity = $this->_createChild();
|
||||
$subentity->_setNestingLevel($lowestLevel);
|
||||
$subentity = $this->createChild();
|
||||
$subentity->setNestingLevel($lowestLevel);
|
||||
$subentity->setChildren($grandchildren, $compoundLevel);
|
||||
array_unshift($immediateChildren, $subentity);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_immediateChildren = $immediateChildren;
|
||||
$this->_children = $children;
|
||||
$this->_setContentTypeInHeaders($newContentType);
|
||||
$this->_fixHeaders();
|
||||
$this->_sortChildren();
|
||||
$this->immediateChildren = $immediateChildren;
|
||||
$this->children = $children;
|
||||
$this->setContentTypeInHeaders($newContentType);
|
||||
$this->fixHeaders();
|
||||
$this->sortChildren();
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -345,7 +356,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->_body instanceof Swift_OutputByteStream ? $this->_readStream($this->_body) : $this->_body;
|
||||
return $this->body instanceof Swift_OutputByteStream ? $this->readStream($this->body) : $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,15 +366,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
* @param mixed $body
|
||||
* @param string $contentType optional
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setBody($body, $contentType = null)
|
||||
{
|
||||
if ($body !== $this->_body) {
|
||||
$this->_clearCache();
|
||||
if ($body !== $this->body) {
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
$this->_body = $body;
|
||||
$this->body = $body;
|
||||
if (isset($contentType)) {
|
||||
$this->setContentType($contentType);
|
||||
}
|
||||
@@ -378,7 +389,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getEncoder()
|
||||
{
|
||||
return $this->_encoder;
|
||||
return $this->encoder;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,17 +397,17 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoder(Swift_Mime_ContentEncoder $encoder)
|
||||
{
|
||||
if ($encoder !== $this->_encoder) {
|
||||
$this->_clearCache();
|
||||
if ($encoder !== $this->encoder) {
|
||||
$this->clearCache();
|
||||
}
|
||||
|
||||
$this->_encoder = $encoder;
|
||||
$this->_setEncoding($encoder->getName());
|
||||
$this->_notifyEncoderChanged($encoder);
|
||||
$this->encoder = $encoder;
|
||||
$this->setEncoding($encoder->getName());
|
||||
$this->notifyEncoderChanged($encoder);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -408,11 +419,11 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function getBoundary()
|
||||
{
|
||||
if (!isset($this->_boundary)) {
|
||||
$this->_boundary = '_=_swift_v4_'.time().'_'.md5(getmypid().mt_rand().uniqid('', true)).'_=_';
|
||||
if (!isset($this->boundary)) {
|
||||
$this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
|
||||
}
|
||||
|
||||
return $this->_boundary;
|
||||
return $this->boundary;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -422,12 +433,12 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @throws Swift_RfcComplianceException
|
||||
*
|
||||
* @return Swift_Mime_SimpleMimeEntity
|
||||
* @return $this
|
||||
*/
|
||||
public function setBoundary($boundary)
|
||||
{
|
||||
$this->_assertValidBoundary($boundary);
|
||||
$this->_boundary = $boundary;
|
||||
$this->assertValidBoundary($boundary);
|
||||
$this->boundary = $boundary;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -440,7 +451,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function charsetChanged($charset)
|
||||
{
|
||||
$this->_notifyCharsetChanged($charset);
|
||||
$this->notifyCharsetChanged($charset);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -451,7 +462,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function encoderChanged(Swift_Mime_ContentEncoder $encoder)
|
||||
{
|
||||
$this->_notifyEncoderChanged($encoder);
|
||||
$this->notifyEncoderChanged($encoder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -461,8 +472,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
$string = $this->_headers->toString();
|
||||
$string .= $this->_bodyToString();
|
||||
$string = $this->headers->toString();
|
||||
$string .= $this->bodyToString();
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -472,22 +483,22 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _bodyToString()
|
||||
protected function bodyToString()
|
||||
{
|
||||
$string = '';
|
||||
|
||||
if (isset($this->_body) && empty($this->_immediateChildren)) {
|
||||
if ($this->_cache->hasKey($this->_cacheKey, 'body')) {
|
||||
$body = $this->_cache->getString($this->_cacheKey, 'body');
|
||||
if (isset($this->body) && empty($this->immediateChildren)) {
|
||||
if ($this->cache->hasKey($this->cacheKey, 'body')) {
|
||||
$body = $this->cache->getString($this->cacheKey, 'body');
|
||||
} else {
|
||||
$body = "\r\n".$this->_encoder->encodeString($this->getBody(), 0, $this->getMaxLineLength());
|
||||
$this->_cache->setString($this->_cacheKey, 'body', $body, Swift_KeyCache::MODE_WRITE);
|
||||
$body = "\r\n".$this->encoder->encodeString($this->getBody(), 0, $this->getMaxLineLength());
|
||||
$this->cache->setString($this->cacheKey, 'body', $body, Swift_KeyCache::MODE_WRITE);
|
||||
}
|
||||
$string .= $body;
|
||||
}
|
||||
|
||||
if (!empty($this->_immediateChildren)) {
|
||||
foreach ($this->_immediateChildren as $child) {
|
||||
if (!empty($this->immediateChildren)) {
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$string .= "\r\n\r\n--".$this->getBoundary()."\r\n";
|
||||
$string .= $child->toString();
|
||||
}
|
||||
@@ -516,10 +527,10 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function toByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
$is->write($this->_headers->toString());
|
||||
$is->write($this->headers->toString());
|
||||
$is->commit();
|
||||
|
||||
$this->_bodyToByteStream($is);
|
||||
$this->bodyToByteStream($is);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -527,26 +538,26 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @param Swift_InputByteStream
|
||||
*/
|
||||
protected function _bodyToByteStream(Swift_InputByteStream $is)
|
||||
protected function bodyToByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
if (empty($this->_immediateChildren)) {
|
||||
if (isset($this->_body)) {
|
||||
if ($this->_cache->hasKey($this->_cacheKey, 'body')) {
|
||||
$this->_cache->exportToByteStream($this->_cacheKey, 'body', $is);
|
||||
if (empty($this->immediateChildren)) {
|
||||
if (isset($this->body)) {
|
||||
if ($this->cache->hasKey($this->cacheKey, 'body')) {
|
||||
$this->cache->exportToByteStream($this->cacheKey, 'body', $is);
|
||||
} else {
|
||||
$cacheIs = $this->_cache->getInputByteStream($this->_cacheKey, 'body');
|
||||
$cacheIs = $this->cache->getInputByteStream($this->cacheKey, 'body');
|
||||
if ($cacheIs) {
|
||||
$is->bind($cacheIs);
|
||||
}
|
||||
|
||||
$is->write("\r\n");
|
||||
|
||||
if ($this->_body instanceof Swift_OutputByteStream) {
|
||||
$this->_body->setReadPointer(0);
|
||||
if ($this->body instanceof Swift_OutputByteStream) {
|
||||
$this->body->setReadPointer(0);
|
||||
|
||||
$this->_encoder->encodeByteStream($this->_body, $is, 0, $this->getMaxLineLength());
|
||||
$this->encoder->encodeByteStream($this->body, $is, 0, $this->getMaxLineLength());
|
||||
} else {
|
||||
$is->write($this->_encoder->encodeString($this->getBody(), 0, $this->getMaxLineLength()));
|
||||
$is->write($this->encoder->encodeString($this->getBody(), 0, $this->getMaxLineLength()));
|
||||
}
|
||||
|
||||
if ($cacheIs) {
|
||||
@@ -556,8 +567,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_immediateChildren)) {
|
||||
foreach ($this->_immediateChildren as $child) {
|
||||
if (!empty($this->immediateChildren)) {
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$is->write("\r\n\r\n--".$this->getBoundary()."\r\n");
|
||||
$child->toByteStream($is);
|
||||
}
|
||||
@@ -568,7 +579,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
/**
|
||||
* Get the name of the header that provides the ID of this entity.
|
||||
*/
|
||||
protected function _getIdField()
|
||||
protected function getIdField()
|
||||
{
|
||||
return 'Content-ID';
|
||||
}
|
||||
@@ -576,20 +587,20 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
/**
|
||||
* Get the model data (usually an array or a string) for $field.
|
||||
*/
|
||||
protected function _getHeaderFieldModel($field)
|
||||
protected function getHeaderFieldModel($field)
|
||||
{
|
||||
if ($this->_headers->has($field)) {
|
||||
return $this->_headers->get($field)->getFieldBodyModel();
|
||||
if ($this->headers->has($field)) {
|
||||
return $this->headers->get($field)->getFieldBodyModel();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the model data for $field.
|
||||
*/
|
||||
protected function _setHeaderFieldModel($field, $model)
|
||||
protected function setHeaderFieldModel($field, $model)
|
||||
{
|
||||
if ($this->_headers->has($field)) {
|
||||
$this->_headers->get($field)->setFieldBodyModel($model);
|
||||
if ($this->headers->has($field)) {
|
||||
$this->headers->get($field)->setFieldBodyModel($model);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -600,20 +611,20 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
/**
|
||||
* Get the parameter value of $parameter on $field header.
|
||||
*/
|
||||
protected function _getHeaderParameter($field, $parameter)
|
||||
protected function getHeaderParameter($field, $parameter)
|
||||
{
|
||||
if ($this->_headers->has($field)) {
|
||||
return $this->_headers->get($field)->getParameter($parameter);
|
||||
if ($this->headers->has($field)) {
|
||||
return $this->headers->get($field)->getParameter($parameter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parameter value of $parameter on $field header.
|
||||
*/
|
||||
protected function _setHeaderParameter($field, $parameter, $value)
|
||||
protected function setHeaderParameter($field, $parameter, $value)
|
||||
{
|
||||
if ($this->_headers->has($field)) {
|
||||
$this->_headers->get($field)->setParameter($parameter, $value);
|
||||
if ($this->headers->has($field)) {
|
||||
$this->headers->get($field)->setParameter($parameter, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -624,16 +635,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
/**
|
||||
* Re-evaluate what content type and encoding should be used on this entity.
|
||||
*/
|
||||
protected function _fixHeaders()
|
||||
protected function fixHeaders()
|
||||
{
|
||||
if (count($this->_immediateChildren)) {
|
||||
$this->_setHeaderParameter('Content-Type', 'boundary',
|
||||
if (count($this->immediateChildren)) {
|
||||
$this->setHeaderParameter('Content-Type', 'boundary',
|
||||
$this->getBoundary()
|
||||
);
|
||||
$this->_headers->remove('Content-Transfer-Encoding');
|
||||
$this->headers->remove('Content-Transfer-Encoding');
|
||||
} else {
|
||||
$this->_setHeaderParameter('Content-Type', 'boundary', null);
|
||||
$this->_setEncoding($this->_encoder->getName());
|
||||
$this->setHeaderParameter('Content-Type', 'boundary', null);
|
||||
$this->setEncoding($this->encoder->getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,50 +653,30 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*
|
||||
* @return Swift_KeyCache
|
||||
*/
|
||||
protected function _getCache()
|
||||
protected function getCache()
|
||||
{
|
||||
return $this->_cache;
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the grammar used for validation.
|
||||
* Get the ID generator.
|
||||
*
|
||||
* @return Swift_Mime_Grammar
|
||||
* @return Swift_IdGenerator
|
||||
*/
|
||||
protected function _getGrammar()
|
||||
protected function getIdGenerator()
|
||||
{
|
||||
return $this->_grammar;
|
||||
return $this->idGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty the KeyCache for this entity.
|
||||
*/
|
||||
protected function _clearCache()
|
||||
protected function clearCache()
|
||||
{
|
||||
$this->_cache->clearKey($this->_cacheKey, 'body');
|
||||
$this->cache->clearKey($this->cacheKey, 'body');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random Content-ID or Message-ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getRandomId()
|
||||
{
|
||||
$idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
|
||||
$idRight = !empty($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'swift.generated';
|
||||
$id = $idLeft.'@'.$idRight;
|
||||
|
||||
try {
|
||||
$this->_assertValidId($id);
|
||||
} catch (Swift_RfcComplianceException $e) {
|
||||
$id = $idLeft.'@swift.generated';
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function _readStream(Swift_OutputByteStream $os)
|
||||
private function readStream(Swift_OutputByteStream $os)
|
||||
{
|
||||
$string = '';
|
||||
while (false !== $bytes = $os->read(8192)) {
|
||||
@@ -697,33 +688,33 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
return $string;
|
||||
}
|
||||
|
||||
private function _setEncoding($encoding)
|
||||
private function setEncoding($encoding)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Content-Transfer-Encoding', $encoding)) {
|
||||
$this->_headers->addTextHeader('Content-Transfer-Encoding', $encoding);
|
||||
if (!$this->setHeaderFieldModel('Content-Transfer-Encoding', $encoding)) {
|
||||
$this->headers->addTextHeader('Content-Transfer-Encoding', $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
private function _assertValidBoundary($boundary)
|
||||
private function assertValidBoundary($boundary)
|
||||
{
|
||||
if (!preg_match('/^[a-z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-z0-9\'\(\)\+_\-,\.\/:=\?]$/Di', $boundary)) {
|
||||
throw new Swift_RfcComplianceException('Mime boundary set is not RFC 2046 compliant.');
|
||||
}
|
||||
}
|
||||
|
||||
private function _setContentTypeInHeaders($type)
|
||||
private function setContentTypeInHeaders($type)
|
||||
{
|
||||
if (!$this->_setHeaderFieldModel('Content-Type', $type)) {
|
||||
$this->_headers->addParameterizedHeader('Content-Type', $type);
|
||||
if (!$this->setHeaderFieldModel('Content-Type', $type)) {
|
||||
$this->headers->addParameterizedHeader('Content-Type', $type);
|
||||
}
|
||||
}
|
||||
|
||||
private function _setNestingLevel($level)
|
||||
private function setNestingLevel($level)
|
||||
{
|
||||
$this->_nestingLevel = $level;
|
||||
$this->nestingLevel = $level;
|
||||
}
|
||||
|
||||
private function _getCompoundLevel($children)
|
||||
private function getCompoundLevel($children)
|
||||
{
|
||||
$level = 0;
|
||||
foreach ($children as $child) {
|
||||
@@ -733,10 +724,10 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
return $level;
|
||||
}
|
||||
|
||||
private function _getNeededChildLevel($child, $compoundLevel)
|
||||
private function getNeededChildLevel($child, $compoundLevel)
|
||||
{
|
||||
$filter = array();
|
||||
foreach ($this->_compoundLevelFilters as $bitmask => $rules) {
|
||||
foreach ($this->compoundLevelFilters as $bitmask => $rules) {
|
||||
if (($compoundLevel & $bitmask) === $bitmask) {
|
||||
$filter = $rules + $filter;
|
||||
}
|
||||
@@ -752,31 +743,31 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
return $realLevel;
|
||||
}
|
||||
|
||||
private function _createChild()
|
||||
private function createChild()
|
||||
{
|
||||
return new self($this->_headers->newInstance(), $this->_encoder, $this->_cache, $this->_grammar);
|
||||
return new self($this->headers->newInstance(), $this->encoder, $this->cache, $this->idGenerator);
|
||||
}
|
||||
|
||||
private function _notifyEncoderChanged(Swift_Mime_ContentEncoder $encoder)
|
||||
private function notifyEncoderChanged(Swift_Mime_ContentEncoder $encoder)
|
||||
{
|
||||
foreach ($this->_immediateChildren as $child) {
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$child->encoderChanged($encoder);
|
||||
}
|
||||
}
|
||||
|
||||
private function _notifyCharsetChanged($charset)
|
||||
private function notifyCharsetChanged($charset)
|
||||
{
|
||||
$this->_encoder->charsetChanged($charset);
|
||||
$this->_headers->charsetChanged($charset);
|
||||
foreach ($this->_immediateChildren as $child) {
|
||||
$this->encoder->charsetChanged($charset);
|
||||
$this->headers->charsetChanged($charset);
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$child->charsetChanged($charset);
|
||||
}
|
||||
}
|
||||
|
||||
private function _sortChildren()
|
||||
private function sortChildren()
|
||||
{
|
||||
$shouldSort = false;
|
||||
foreach ($this->_immediateChildren as $child) {
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
// NOTE: This include alternative parts moved into a related part
|
||||
if ($child->getNestingLevel() == self::LEVEL_ALTERNATIVE) {
|
||||
$shouldSort = true;
|
||||
@@ -786,43 +777,32 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
|
||||
// Sort in order of preference, if there is one
|
||||
if ($shouldSort) {
|
||||
usort($this->_immediateChildren, array($this, '_childSortAlgorithm'));
|
||||
// Group the messages by order of preference
|
||||
$sorted = array();
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$type = $child->getContentType();
|
||||
$level = array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
|
||||
|
||||
if (empty($sorted[$level])) {
|
||||
$sorted[$level] = array();
|
||||
}
|
||||
|
||||
$sorted[$level][] = $child;
|
||||
}
|
||||
|
||||
ksort($sorted);
|
||||
|
||||
$this->immediateChildren = array_reduce($sorted, 'array_merge', array());
|
||||
}
|
||||
}
|
||||
|
||||
private function _childSortAlgorithm($a, $b)
|
||||
{
|
||||
$typePrefs = array();
|
||||
$types = array(strtolower($a->getContentType()), strtolower($b->getContentType()));
|
||||
|
||||
foreach ($types as $type) {
|
||||
$typePrefs[] = array_key_exists($type, $this->_alternativePartOrder) ? $this->_alternativePartOrder[$type] : max($this->_alternativePartOrder) + 1;
|
||||
}
|
||||
|
||||
return $typePrefs[0] >= $typePrefs[1] ? 1 : -1;
|
||||
}
|
||||
|
||||
// -- Destructor
|
||||
|
||||
/**
|
||||
* Empties it's own contents from the cache.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->_cache->clearAll($this->_cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an Exception if the id passed does not comply with RFC 2822.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @throws Swift_RfcComplianceException
|
||||
*/
|
||||
private function _assertValidId($id)
|
||||
{
|
||||
if (!preg_match('/^'.$this->_grammar->getDefinition('id-left').'@'.$this->_grammar->getDefinition('id-right').'$/D', $id)) {
|
||||
throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>');
|
||||
if ($this->cache instanceof Swift_KeyCache) {
|
||||
$this->cache->clearAll($this->cacheKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -831,11 +811,11 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$this->_headers = clone $this->_headers;
|
||||
$this->_encoder = clone $this->_encoder;
|
||||
$this->_cacheKey = uniqid();
|
||||
$this->headers = clone $this->headers;
|
||||
$this->encoder = clone $this->encoder;
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$children = array();
|
||||
foreach ($this->_children as $pos => $child) {
|
||||
foreach ($this->children as $pos => $child) {
|
||||
$children[$pos] = clone $child;
|
||||
}
|
||||
$this->setChildren($children);
|
||||
|
||||
Reference in New Issue
Block a user