mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-14 13:31:28 +01:00
FIX: Update swiftmailer librairies
This commit is contained in:
@@ -16,18 +16,14 @@
|
||||
class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
{
|
||||
/** Recognized MIME types */
|
||||
private $mimeTypes = array();
|
||||
private $mimeTypes = [];
|
||||
|
||||
/**
|
||||
* Create a new Attachment with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param array $mimeTypes
|
||||
* @param array $mimeTypes
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = array())
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = [])
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator);
|
||||
$this->setDisposition('attachment');
|
||||
@@ -127,8 +123,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
|
||||
/**
|
||||
* Set the file that this attachment is for.
|
||||
*
|
||||
* @param Swift_FileStream $file
|
||||
* @param string $contentType optional
|
||||
* @param string $contentType optional
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
@@ -139,7 +134,7 @@ 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)) {
|
||||
if (\array_key_exists($extension, $this->mimeTypes)) {
|
||||
$this->setContentType($this->mimeTypes[$extension]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
|
||||
/**
|
||||
* Encode stream $in to stream $out.
|
||||
*
|
||||
* @param Swift_OutputByteStream $os
|
||||
* @param Swift_InputByteStream $is
|
||||
* @param int $firstLineOffset
|
||||
* @param int $maxLineLength, optional, 0 indicates the default of 76 bytes
|
||||
* @param int $firstLineOffset
|
||||
*/
|
||||
public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
@@ -30,7 +27,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
|
||||
}
|
||||
|
||||
$remainder = 0;
|
||||
$base64ReadBufferRemainderBytes = null;
|
||||
$base64ReadBufferRemainderBytes = '';
|
||||
|
||||
// To reduce memory usage, the output buffer is streamed to the input buffer like so:
|
||||
// Output Stream => base64encode => wrap line length => Input Stream
|
||||
@@ -41,17 +38,17 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
|
||||
// When the OutputStream is empty, we must flush any remainder bytes.
|
||||
while (true) {
|
||||
$readBytes = $os->read(8192);
|
||||
$atEOF = ($readBytes === false);
|
||||
$atEOF = (false === $readBytes);
|
||||
|
||||
if ($atEOF) {
|
||||
$streamTheseBytes = $base64ReadBufferRemainderBytes;
|
||||
} else {
|
||||
$streamTheseBytes = $base64ReadBufferRemainderBytes.$readBytes;
|
||||
}
|
||||
$base64ReadBufferRemainderBytes = null;
|
||||
$bytesLength = strlen($streamTheseBytes);
|
||||
$base64ReadBufferRemainderBytes = '';
|
||||
$bytesLength = \strlen($streamTheseBytes);
|
||||
|
||||
if ($bytesLength === 0) { // no data left to encode
|
||||
if (0 === $bytesLength) { // no data left to encode
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -59,7 +56,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
|
||||
// and carry over remainder 1-2 bytes to the next loop iteration
|
||||
if (!$atEOF) {
|
||||
$excessBytes = $bytesLength % 3;
|
||||
if ($excessBytes !== 0) {
|
||||
if (0 !== $excessBytes) {
|
||||
$base64ReadBufferRemainderBytes = substr($streamTheseBytes, -$excessBytes);
|
||||
$streamTheseBytes = substr($streamTheseBytes, 0, $bytesLength - $excessBytes);
|
||||
}
|
||||
@@ -69,7 +66,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
|
||||
$encodedTransformed = '';
|
||||
$thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset;
|
||||
|
||||
while ($thisMaxLineLength < strlen($encoded)) {
|
||||
while ($thisMaxLineLength < \strlen($encoded)) {
|
||||
$encodedTransformed .= substr($encoded, 0, $thisMaxLineLength)."\r\n";
|
||||
$firstLineOffset = 0;
|
||||
$encoded = substr($encoded, $thisMaxLineLength);
|
||||
@@ -77,7 +74,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
|
||||
$remainder = 0;
|
||||
}
|
||||
|
||||
if (0 < $remainingLength = strlen($encoded)) {
|
||||
if (0 < $remainingLength = \strlen($encoded)) {
|
||||
$remainder += $remainingLength;
|
||||
$encodedTransformed .= $encoded;
|
||||
$encoded = null;
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder
|
||||
{
|
||||
/**
|
||||
* @var null|string
|
||||
* @var string|null
|
||||
*/
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* @param null|string $charset
|
||||
* @param string|null $charset
|
||||
*/
|
||||
public function __construct($charset = null)
|
||||
{
|
||||
$this->charset = $charset ? $charset : 'utf-8';
|
||||
$this->charset = $charset ?: 'utf-8';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,9 +50,8 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
|
||||
*/
|
||||
public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
if ($this->charset !== 'utf-8') {
|
||||
throw new RuntimeException(
|
||||
sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
|
||||
if ('utf-8' !== $this->charset) {
|
||||
throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
|
||||
}
|
||||
|
||||
$string = '';
|
||||
@@ -87,9 +86,8 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
|
||||
*/
|
||||
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
if ($this->charset !== 'utf-8') {
|
||||
throw new RuntimeException(
|
||||
sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
|
||||
if ('utf-8' !== $this->charset) {
|
||||
throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
|
||||
}
|
||||
|
||||
return $this->standardize(quoted_printable_encode($string));
|
||||
@@ -107,9 +105,9 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
|
||||
// transform CR or LF to CRLF
|
||||
$string = preg_replace('~=0D(?!=0A)|(?<!=0D)=0A~', '=0D=0A', $string);
|
||||
// transform =0D=0A to CRLF
|
||||
$string = str_replace(array("\t=0D=0A", ' =0D=0A', '=0D=0A'), array("=09\r\n", "=20\r\n", "\r\n"), $string);
|
||||
$string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A'], ["=09\r\n", "=20\r\n", "\r\n"], $string);
|
||||
|
||||
switch ($end = ord(substr($string, -1))) {
|
||||
switch (\ord(substr($string, -1))) {
|
||||
case 0x09:
|
||||
$string = substr_replace($string, '=09', -1);
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handles the case where the email body is already encoded and you just need specify the correct
|
||||
* encoding without actually changing the encoding of the body.
|
||||
*
|
||||
* @author Jan Flora <jf@penneo.com>
|
||||
*/
|
||||
class Swift_Mime_ContentEncoder_NullContentEncoder implements Swift_Mime_ContentEncoder
|
||||
{
|
||||
/**
|
||||
* The name of this encoding scheme (probably 7bit or 8bit).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Creates a new NullContentEncoder with $name (probably 7bit or 8bit).
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a given string to produce an encoded string.
|
||||
*
|
||||
* @param string $string
|
||||
* @param int $firstLineOffset ignored
|
||||
* @param int $maxLineLength ignored
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode stream $in to stream $out.
|
||||
*
|
||||
* @param int $firstLineOffset ignored
|
||||
* @param int $maxLineLength ignored
|
||||
*/
|
||||
public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
while (false !== ($bytes = $os->read(8192))) {
|
||||
$is->write($bytes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this encoding scheme.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Not used.
|
||||
*/
|
||||
public function charsetChanged($charset)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@
|
||||
/**
|
||||
* Handles binary/7/8-bit Transfer Encoding in Swift Mailer.
|
||||
*
|
||||
* When sending 8-bit content over SMTP, you should use
|
||||
* Swift_Transport_Esmtp_EightBitMimeHandler to enable the 8BITMIME SMTP
|
||||
* extension.
|
||||
*
|
||||
* @author Chris Corbyn
|
||||
*/
|
||||
class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_ContentEncoder
|
||||
@@ -33,7 +37,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
* Creates a new PlainContentEncoder with $name (probably 7bit or 8bit).
|
||||
*
|
||||
* @param string $name
|
||||
* @param bool $canonical If canonicalization transformation should be done.
|
||||
* @param bool $canonical if canonicalization transformation should be done
|
||||
*/
|
||||
public function __construct($name, $canonical = false)
|
||||
{
|
||||
@@ -62,10 +66,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
/**
|
||||
* Encode stream $in to stream $out.
|
||||
*
|
||||
* @param Swift_OutputByteStream $os
|
||||
* @param Swift_InputByteStream $is
|
||||
* @param int $firstLineOffset ignored
|
||||
* @param int $maxLineLength optional, 0 means no wrapping will occur
|
||||
* @param int $firstLineOffset ignored
|
||||
* @param int $maxLineLength optional, 0 means no wrapping will occur
|
||||
*/
|
||||
public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
@@ -82,7 +84,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
|
||||
$is->write($wrapped);
|
||||
}
|
||||
if (strlen($leftOver)) {
|
||||
if (\strlen($leftOver)) {
|
||||
$is->write($leftOver);
|
||||
}
|
||||
}
|
||||
@@ -121,7 +123,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
|
||||
$originalLines = explode($le, $string);
|
||||
|
||||
$lines = array();
|
||||
$lines = [];
|
||||
$lineCount = 0;
|
||||
|
||||
foreach ($originalLines as $originalLine) {
|
||||
@@ -132,8 +134,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
$chunks = preg_split('/(?<=\s)/', $originalLine);
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
if (0 != strlen($currentLine)
|
||||
&& strlen($currentLine.$chunk) > $length) {
|
||||
if (0 != \strlen($currentLine)
|
||||
&& \strlen($currentLine.$chunk) > $length) {
|
||||
$lines[] = '';
|
||||
$currentLine = &$lines[$lineCount++];
|
||||
}
|
||||
@@ -154,8 +156,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
|
||||
private function canonicalize($string)
|
||||
{
|
||||
return str_replace(
|
||||
array("\r\n", "\r", "\n"),
|
||||
array("\n", "\n", "\r\n"),
|
||||
["\r\n", "\r", "\n"],
|
||||
["\n", "\n", "\r\n"],
|
||||
$string
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,12 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
|
||||
public function __sleep()
|
||||
{
|
||||
return array('charStream', 'filter', 'dotEscape');
|
||||
return ['charStream', 'filter', 'dotEscape'];
|
||||
}
|
||||
|
||||
protected function getSafeMapShareId()
|
||||
{
|
||||
return get_class($this).($this->dotEscape ? '.dotEscape' : '');
|
||||
return static::class.($this->dotEscape ? '.dotEscape' : '');
|
||||
}
|
||||
|
||||
protected function initSafeMap()
|
||||
@@ -97,7 +97,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
$enc = $this->encodeByteSequence($bytes, $size);
|
||||
|
||||
$i = strpos($enc, '=0D=0A');
|
||||
$newLineLength = $lineLen + ($i === false ? $size : $i);
|
||||
$newLineLength = $lineLen + (false === $i ? $size : $i);
|
||||
|
||||
if ($currentLine && $newLineLength >= $thisLineLength) {
|
||||
$is->write($prepend.$this->standardize($currentLine));
|
||||
@@ -109,14 +109,14 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
|
||||
|
||||
$currentLine .= $enc;
|
||||
|
||||
if ($i === false) {
|
||||
if (false === $i) {
|
||||
$lineLen += $size;
|
||||
} else {
|
||||
// 6 is the length of '=0D=0A'.
|
||||
$lineLen = $size - strrpos($enc, '=0D=0A') - 6;
|
||||
}
|
||||
}
|
||||
if (strlen($currentLine)) {
|
||||
if (\strlen($currentLine)) {
|
||||
$is->write($prepend.$this->standardize($currentLine));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,16 +28,14 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont
|
||||
private $nativeEncoder;
|
||||
|
||||
/**
|
||||
* @var null|string
|
||||
* @var string|null
|
||||
*/
|
||||
private $charset;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder
|
||||
* @param Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder
|
||||
* @param string|null $charset
|
||||
* @param string|null $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder, Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder, $charset)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
/**
|
||||
* Handles raw Transfer Encoding in Swift Mailer.
|
||||
*
|
||||
* When sending 8-bit content over SMTP, you should use
|
||||
* Swift_Transport_Esmtp_EightBitMimeHandler to enable the 8BITMIME SMTP
|
||||
* extension.
|
||||
*
|
||||
* @author Sebastiaan Stok <s.stok@rollerscapes.net>
|
||||
*/
|
||||
@@ -33,10 +36,8 @@ class Swift_Mime_ContentEncoder_RawContentEncoder implements Swift_Mime_ContentE
|
||||
/**
|
||||
* Encode stream $in to stream $out.
|
||||
*
|
||||
* @param Swift_OutputByteStream $in
|
||||
* @param Swift_InputByteStream $out
|
||||
* @param int $firstLineOffset ignored
|
||||
* @param int $maxLineLength ignored
|
||||
* @param int $firstLineOffset ignored
|
||||
* @param int $maxLineLength ignored
|
||||
*/
|
||||
public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
|
||||
@@ -18,13 +18,9 @@ class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment
|
||||
/**
|
||||
* Creates a new Attachment with $headers and $encoder.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param array $mimeTypes optional
|
||||
* @param array $mimeTypes optional
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = array())
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = [])
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator, $mimeTypes);
|
||||
$this->setDisposition('inline');
|
||||
|
||||
@@ -17,8 +17,6 @@ interface Swift_Mime_EncodingObserver
|
||||
{
|
||||
/**
|
||||
* Notify this observer that the observed entity's ContentEncoder has changed.
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
*/
|
||||
public function encoderChanged(Swift_Mime_ContentEncoder $encoder);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ interface Swift_Mime_Header
|
||||
public function getFieldBody();
|
||||
|
||||
/**
|
||||
* Get this Header rendered as a compliant string.
|
||||
* Get this Header rendered as a compliant string, including trailing CRLF.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -41,7 +41,7 @@ class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64E
|
||||
*/
|
||||
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8')
|
||||
{
|
||||
if (strtolower($charset) === 'iso-2022-jp') {
|
||||
if ('iso-2022-jp' === strtolower($charset ?? '')) {
|
||||
$old = mb_internal_encoding();
|
||||
mb_internal_encoding('utf-8');
|
||||
$newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n");
|
||||
|
||||
@@ -29,9 +29,9 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i
|
||||
{
|
||||
foreach (array_merge(
|
||||
range(0x61, 0x7A), range(0x41, 0x5A),
|
||||
range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
|
||||
range(0x30, 0x39), [0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F]
|
||||
) as $byte) {
|
||||
$this->safeMap[$byte] = chr($byte);
|
||||
$this->safeMap[$byte] = \chr($byte);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i
|
||||
*/
|
||||
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
|
||||
{
|
||||
return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
|
||||
return str_replace([' ', '=20', "=\r\n"], ['_', '_', "\r\n"],
|
||||
parent::encodeString($string, $firstLineOffset, $maxLineLength)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,8 +109,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
|
||||
/**
|
||||
* Set the encoder used for encoding the header.
|
||||
*
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
*/
|
||||
public function setEncoder(Swift_Mime_HeaderEncoder $encoder)
|
||||
{
|
||||
@@ -196,11 +194,9 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
/**
|
||||
* Produces a compliant, formatted RFC 2822 'phrase' based on the string given.
|
||||
*
|
||||
* @param Swift_Mime_Header $header
|
||||
* @param string $string as displayed
|
||||
* @param string $charset of the text
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param bool $shorten the first line to make remove for header name
|
||||
* @param string $string as displayed
|
||||
* @param string $charset of the text
|
||||
* @param bool $shorten the first line to make remove for header name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -214,13 +210,13 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
// .. but it is just ascii text, try escaping some characters
|
||||
// and make it a quoted-string
|
||||
if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) {
|
||||
$phraseStr = $this->escapeSpecials($phraseStr, array('"'));
|
||||
$phraseStr = $this->escapeSpecials($phraseStr, ['"']);
|
||||
$phraseStr = '"'.$phraseStr.'"';
|
||||
} else {
|
||||
// ... otherwise it needs encoding
|
||||
// Determine space remaining on line if first line
|
||||
if ($shorten) {
|
||||
$usedLength = strlen($header->getFieldName().': ');
|
||||
$usedLength = \strlen($header->getFieldName().': ');
|
||||
} else {
|
||||
$usedLength = 0;
|
||||
}
|
||||
@@ -239,9 +235,9 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function escapeSpecials($token, $include = array())
|
||||
private function escapeSpecials($token, $include = [])
|
||||
{
|
||||
foreach (array_merge(array('\\'), $include) as $char) {
|
||||
foreach (array_merge(['\\'], $include) as $char) {
|
||||
$token = str_replace($char, '\\'.$char, $token);
|
||||
}
|
||||
|
||||
@@ -251,9 +247,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
/**
|
||||
* Encode needed word tokens within a string of input.
|
||||
*
|
||||
* @param Swift_Mime_Header $header
|
||||
* @param string $input
|
||||
* @param string $usedLength optional
|
||||
* @param string $input
|
||||
* @param string $usedLength optional
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -276,7 +271,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
}
|
||||
|
||||
if (-1 == $usedLength) {
|
||||
$usedLength = strlen($header->getFieldName().': ') + strlen($value);
|
||||
$usedLength = \strlen($header->getFieldName().': ') + \strlen($value);
|
||||
}
|
||||
$value .= $this->getTokenAsEncodedWord($token, $usedLength);
|
||||
|
||||
@@ -310,22 +305,22 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
protected function getEncodableWordTokens($string)
|
||||
{
|
||||
$tokens = array();
|
||||
$tokens = [];
|
||||
|
||||
$encodedToken = '';
|
||||
// Split at all whitespace boundaries
|
||||
foreach (preg_split('~(?=[\t ])~', $string) as $token) {
|
||||
foreach (preg_split('~(?=[\t ])~', $string ?? '') as $token) {
|
||||
if ($this->tokenNeedsEncoding($token)) {
|
||||
$encodedToken .= $token;
|
||||
} else {
|
||||
if (strlen($encodedToken) > 0) {
|
||||
if (\strlen($encodedToken) > 0) {
|
||||
$tokens[] = $encodedToken;
|
||||
$encodedToken = '';
|
||||
}
|
||||
$tokens[] = $token;
|
||||
}
|
||||
}
|
||||
if (strlen($encodedToken)) {
|
||||
if (\strlen($encodedToken)) {
|
||||
$tokens[] = $encodedToken;
|
||||
}
|
||||
|
||||
@@ -347,7 +342,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
if (isset($this->lang)) {
|
||||
$charsetDecl .= '*'.$this->lang;
|
||||
}
|
||||
$encodingWrapperLength = strlen(
|
||||
$encodingWrapperLength = \strlen(
|
||||
'=?'.$charsetDecl.'?'.$this->encoder->getName().'??='
|
||||
);
|
||||
|
||||
@@ -359,10 +354,10 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
$encodedTextLines = explode("\r\n",
|
||||
$this->encoder->encodeString(
|
||||
$token, $firstLineOffset, 75 - $encodingWrapperLength, $this->charset
|
||||
)
|
||||
) ?? ''
|
||||
);
|
||||
|
||||
if (strtolower($this->charset) !== 'iso-2022-jp') {
|
||||
if ('iso-2022-jp' !== strtolower($this->charset ?? '')) {
|
||||
// special encoding for iso-2022-jp using mb_encode_mimeheader
|
||||
foreach ($encodedTextLines as $lineNum => $line) {
|
||||
$encodedTextLines[$lineNum] = '=?'.$charsetDecl.
|
||||
@@ -383,7 +378,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
*/
|
||||
protected function generateTokenLines($token)
|
||||
{
|
||||
return preg_split('~(\r\n)~', $token, -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
return preg_split('~(\r\n)~', $token ?? '', -1, PREG_SPLIT_DELIM_CAPTURE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,10 +426,10 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
$string = $this->getFieldBody();
|
||||
}
|
||||
|
||||
$tokens = array();
|
||||
$tokens = [];
|
||||
|
||||
// Generate atoms; split at all invisible boundaries followed by WSP
|
||||
foreach (preg_split('~(?=[ \t])~', $string) as $token) {
|
||||
foreach (preg_split('~(?=[ \t])~', $string ?? '') as $token) {
|
||||
$newTokens = $this->generateTokenLines($token);
|
||||
foreach ($newTokens as $newToken) {
|
||||
$tokens[] = $newToken;
|
||||
@@ -455,7 +450,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
private function tokensToString(array $tokens)
|
||||
{
|
||||
$lineCount = 0;
|
||||
$headerLines = array();
|
||||
$headerLines = [];
|
||||
$headerLines[] = $this->name.': ';
|
||||
$currentLine = &$headerLines[$lineCount++];
|
||||
|
||||
@@ -463,8 +458,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_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)
|
||||
&& 0 < strlen($currentLine)) {
|
||||
($i > 0 && \strlen($currentLine.$token) > $this->lineLength)
|
||||
&& 0 < \strlen($currentLine)) {
|
||||
$headerLines[] = '';
|
||||
$currentLine = &$headerLines[$lineCount++];
|
||||
}
|
||||
@@ -478,4 +473,14 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
|
||||
// Implode with FWS (RFC 2822, 2.2.3)
|
||||
return implode("\r\n", $headerLines)."\r\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a deep copy of object.
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
if ($this->encoder) {
|
||||
$this->encoder = clone $this->encoder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,6 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
* Set the date-time of the Date in this Header.
|
||||
*
|
||||
* If a DateTime instance is provided, it is converted to DateTimeImmutable.
|
||||
*
|
||||
* @param DateTimeInterface $dateTime
|
||||
*/
|
||||
public function setDateTime(DateTimeInterface $dateTime)
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
use Egulias\EmailValidator\Validation\MessageIDValidation;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
|
||||
/**
|
||||
@@ -25,7 +26,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $ids = array();
|
||||
private $ids = [];
|
||||
|
||||
/**
|
||||
* The strict EmailValidator.
|
||||
@@ -34,16 +35,18 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
private $addressEncoder;
|
||||
|
||||
/**
|
||||
* Creates a new IdentificationHeader with the given $name and $id.
|
||||
*
|
||||
* @param string $name
|
||||
* @param EmailValidator $emailValidator
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name, EmailValidator $emailValidator)
|
||||
public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
$this->emailValidator = $emailValidator;
|
||||
$this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,7 +97,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->setIds(is_array($id) ? $id : array($id));
|
||||
$this->setIds(\is_array($id) ? $id : [$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +109,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
if (count($this->ids) > 0) {
|
||||
if (\count($this->ids) > 0) {
|
||||
return $this->ids[0];
|
||||
}
|
||||
}
|
||||
@@ -120,7 +123,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
public function setIds(array $ids)
|
||||
{
|
||||
$actualIds = array();
|
||||
$actualIds = [];
|
||||
|
||||
foreach ($ids as $id) {
|
||||
$this->assertValidId($id);
|
||||
@@ -156,10 +159,10 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
public function getFieldBody()
|
||||
{
|
||||
if (!$this->getCachedValue()) {
|
||||
$angleAddrs = array();
|
||||
$angleAddrs = [];
|
||||
|
||||
foreach ($this->ids as $id) {
|
||||
$angleAddrs[] = '<'.$id.'>';
|
||||
$angleAddrs[] = '<'.$this->addressEncoder->encodeString($id).'>';
|
||||
}
|
||||
|
||||
$this->setCachedValue(implode(' ', $angleAddrs));
|
||||
@@ -177,7 +180,9 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
|
||||
*/
|
||||
private function assertValidId($id)
|
||||
{
|
||||
if (!$this->emailValidator->isValid($id, new RFCValidation())) {
|
||||
$emailValidation = class_exists(MessageIDValidation::class) ? new MessageIDValidation() : new RFCValidation();
|
||||
|
||||
if (!$this->emailValidator->isValid($id, $emailValidation)) {
|
||||
throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $mailboxes = array();
|
||||
private $mailboxes = [];
|
||||
|
||||
/**
|
||||
* The strict EmailValidator.
|
||||
@@ -32,18 +32,19 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
private $addressEncoder;
|
||||
|
||||
/**
|
||||
* Creates a new MailboxHeader with $name.
|
||||
*
|
||||
* @param string $name of Header
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param EmailValidator $emailValidator
|
||||
* @param string $name of Header
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator)
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
$this->setEncoder($encoder);
|
||||
$this->emailValidator = $emailValidator;
|
||||
$this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,10 +258,10 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
protected function normalizeMailboxes(array $mailboxes)
|
||||
{
|
||||
$actualMailboxes = array();
|
||||
$actualMailboxes = [];
|
||||
|
||||
foreach ($mailboxes as $key => $value) {
|
||||
if (is_string($key)) {
|
||||
if (\is_string($key)) {
|
||||
//key is email addr
|
||||
$address = $key;
|
||||
$name = $value;
|
||||
@@ -327,10 +328,10 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
private function createNameAddressStrings(array $mailboxes)
|
||||
{
|
||||
$strings = array();
|
||||
$strings = [];
|
||||
|
||||
foreach ($mailboxes as $email => $name) {
|
||||
$mailboxStr = $email;
|
||||
$mailboxStr = $this->addressEncoder->encodeString($email);
|
||||
if (null !== $name) {
|
||||
$nameStr = $this->createDisplayNameString($name, empty($strings));
|
||||
$mailboxStr = $nameStr.' <'.$mailboxStr.'>';
|
||||
@@ -346,14 +347,12 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*
|
||||
* @param string $address
|
||||
*
|
||||
* @throws Swift_RfcComplianceException If invalid.
|
||||
* @throws Swift_RfcComplianceException if invalid
|
||||
*/
|
||||
private function assertValidAddress($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.'
|
||||
);
|
||||
throw new Swift_RfcComplianceException('Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
* An OpenDKIM Specific Header using only raw header datas without encoding.
|
||||
*
|
||||
* @author De Cock Xavier <xdecock@gmail.com>
|
||||
*
|
||||
* @deprecated since SwiftMailer 6.1.0; use Swift_Signers_DKIMSigner instead.
|
||||
*/
|
||||
class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
{
|
||||
@@ -111,7 +113,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return $this->fieldName.': '.$this->value;
|
||||
return $this->fieldName.': '.$this->value."\r\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,14 +34,12 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $params = array();
|
||||
private $params = [];
|
||||
|
||||
/**
|
||||
* Creates a new ParameterizedHeader with $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Encoder $paramEncoder, optional
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder = null)
|
||||
{
|
||||
@@ -83,7 +81,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
*/
|
||||
public function setParameter($parameter, $value)
|
||||
{
|
||||
$this->setParameters(array_merge($this->getParameters(), array($parameter => $value)));
|
||||
$this->setParameters(array_merge($this->getParameters(), [$parameter => $value]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +95,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
{
|
||||
$params = $this->getParameters();
|
||||
|
||||
return isset($params[$parameter]) ? $params[$parameter] : null;
|
||||
return $params[$parameter] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +155,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
foreach ($this->params as $name => $value) {
|
||||
if (null !== $value) {
|
||||
// Add the semi-colon separator
|
||||
$tokens[count($tokens) - 1] .= ';';
|
||||
$tokens[\count($tokens) - 1] .= ';';
|
||||
$tokens = array_merge($tokens, $this->generateTokenLines(
|
||||
' '.$this->createParameter($name, $value)
|
||||
));
|
||||
@@ -181,7 +179,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
|
||||
$encoded = false;
|
||||
// Allow room for parameter name, indices, "=" and DQUOTEs
|
||||
$maxValueLength = $this->getMaxLineLength() - strlen($name.'=*N"";') - 1;
|
||||
$maxValueLength = $this->getMaxLineLength() - \strlen($name.'=*N"";') - 1;
|
||||
$firstLineOffset = 0;
|
||||
|
||||
// If it's not already a valid parameter value...
|
||||
@@ -191,15 +189,15 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
|
||||
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;
|
||||
$firstLineOffset = strlen(
|
||||
$maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1;
|
||||
$firstLineOffset = \strlen(
|
||||
$this->getCharset()."'".$this->getLanguage()."'"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Encode if we need to
|
||||
if ($encoded || strlen($value) > $maxValueLength) {
|
||||
if ($encoded || \strlen($value) > $maxValueLength) {
|
||||
if (isset($this->paramEncoder)) {
|
||||
$value = $this->paramEncoder->encodeString(
|
||||
$origValue, $firstLineOffset, $maxValueLength, $this->getCharset()
|
||||
@@ -211,14 +209,14 @@ 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) : [$value];
|
||||
|
||||
// Need to add indices
|
||||
if (count($valueLines) > 1) {
|
||||
$paramLines = array();
|
||||
if (\count($valueLines) > 1) {
|
||||
$paramLines = [];
|
||||
foreach ($valueLines as $i => $line) {
|
||||
$paramLines[] = $name.'*'.$i.
|
||||
$this->getEndOfParameterValue($line, true, $i == 0);
|
||||
$this->getEndOfParameterValue($line, true, 0 == $i);
|
||||
}
|
||||
|
||||
return implode(";\r\n ", $paramLines);
|
||||
|
||||
@@ -32,16 +32,18 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
*/
|
||||
private $emailValidator;
|
||||
|
||||
private $addressEncoder;
|
||||
|
||||
/**
|
||||
* Creates a new PathHeader with the given $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param EmailValidator $emailValidator
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name, EmailValidator $emailValidator)
|
||||
public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null)
|
||||
{
|
||||
$this->setFieldName($name);
|
||||
$this->emailValidator = $emailValidator;
|
||||
$this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +129,8 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
{
|
||||
if (!$this->getCachedValue()) {
|
||||
if (isset($this->address)) {
|
||||
$this->setCachedValue('<'.$this->address.'>');
|
||||
$address = $this->addressEncoder->encodeString($this->address);
|
||||
$this->setCachedValue('<'.$address.'>');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,9 +147,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
|
||||
private function assertValidAddress($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.'
|
||||
);
|
||||
throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractH
|
||||
/**
|
||||
* Creates a new SimpleHeader with $name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name, Swift_Mime_HeaderEncoder $encoder)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
*/
|
||||
class Swift_Mime_IdGenerator implements Swift_IdGenerator
|
||||
{
|
||||
private $idRight;
|
||||
|
||||
/**
|
||||
* @param string $idRight
|
||||
*/
|
||||
@@ -46,8 +48,7 @@ class Swift_Mime_IdGenerator implements Swift_IdGenerator
|
||||
*/
|
||||
public function generateId()
|
||||
{
|
||||
$idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
|
||||
|
||||
return $idLeft.'@'.$this->idRight;
|
||||
// 32 hex values for the left part
|
||||
return bin2hex(random_bytes(16)).'@'.$this->idRight;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,11 +30,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
/**
|
||||
* Create a new MimePart with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param string $charset
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null)
|
||||
{
|
||||
@@ -173,7 +169,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
protected function fixHeaders()
|
||||
{
|
||||
parent::fixHeaders();
|
||||
if (count($this->getChildren())) {
|
||||
if (\count($this->getChildren())) {
|
||||
$this->setHeaderParameter('Content-Type', 'charset', null);
|
||||
$this->setHeaderParameter('Content-Type', 'format', null);
|
||||
$this->setHeaderParameter('Content-Type', 'delsp', null);
|
||||
@@ -193,18 +189,9 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
|
||||
/** Encode charset when charset is not utf-8 */
|
||||
protected function convertString($string)
|
||||
{
|
||||
$charset = strtolower($this->getCharset());
|
||||
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');
|
||||
} elseif (function_exists('iconv')) {
|
||||
$string = iconv('utf-8//TRANSLIT//IGNORE', $charset, $string);
|
||||
} else {
|
||||
throw new Swift_SwiftException('No suitable convert encoding function (use UTF-8 as your charset or install the mbstring or iconv extension).');
|
||||
}
|
||||
|
||||
return $string;
|
||||
$charset = strtolower($this->getCharset() ?? '');
|
||||
if (!\in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) {
|
||||
return mb_convert_encoding($string, $charset, 'utf-8');
|
||||
}
|
||||
|
||||
return $string;
|
||||
|
||||
@@ -23,29 +23,27 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
|
||||
/** The Encoder used by parameters */
|
||||
private $paramEncoder;
|
||||
|
||||
/** The Grammar */
|
||||
private $grammar;
|
||||
|
||||
/** Strict EmailValidator */
|
||||
private $emailValidator;
|
||||
|
||||
/** The charset of created Headers */
|
||||
private $charset;
|
||||
|
||||
/** Swift_AddressEncoder */
|
||||
private $addressEncoder;
|
||||
|
||||
/**
|
||||
* Creates a new SimpleHeaderFactory using $encoder and $paramEncoder.
|
||||
*
|
||||
* @param Swift_Mime_HeaderEncoder $encoder
|
||||
* @param Swift_Encoder $paramEncoder
|
||||
* @param EmailValidator $emailValidator
|
||||
* @param string|null $charset
|
||||
* @param string|null $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, EmailValidator $emailValidator, $charset = null)
|
||||
public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, EmailValidator $emailValidator, $charset = null, Swift_AddressEncoder $addressEncoder = null)
|
||||
{
|
||||
$this->encoder = $encoder;
|
||||
$this->paramEncoder = $paramEncoder;
|
||||
$this->emailValidator = $emailValidator;
|
||||
$this->charset = $charset;
|
||||
$this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +56,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
|
||||
*/
|
||||
public function createMailboxHeader($name, $addresses = null)
|
||||
{
|
||||
$header = new Swift_Mime_Headers_MailboxHeader($name, $this->encoder, $this->emailValidator);
|
||||
$header = new Swift_Mime_Headers_MailboxHeader($name, $this->encoder, $this->emailValidator, $this->addressEncoder);
|
||||
if (isset($addresses)) {
|
||||
$header->setFieldBodyModel($addresses);
|
||||
}
|
||||
@@ -70,8 +68,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
|
||||
/**
|
||||
* Create a new Date header using $dateTime.
|
||||
*
|
||||
* @param string $name
|
||||
* @param DateTimeInterface|null $dateTime
|
||||
* @param string $name
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
*/
|
||||
@@ -114,9 +111,9 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
|
||||
*
|
||||
* @return Swift_Mime_Headers_ParameterizedHeader
|
||||
*/
|
||||
public function createParameterizedHeader($name, $value = null, $params = array())
|
||||
public function createParameterizedHeader($name, $value = null, $params = [])
|
||||
{
|
||||
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, (strtolower($name) == 'content-disposition') ? $this->paramEncoder : null);
|
||||
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, ('content-disposition' == strtolower($name ?? '')) ? $this->paramEncoder : null);
|
||||
if (isset($value)) {
|
||||
$header->setFieldBodyModel($value);
|
||||
}
|
||||
@@ -185,6 +182,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
|
||||
{
|
||||
$this->encoder = clone $this->encoder;
|
||||
$this->paramEncoder = clone $this->paramEncoder;
|
||||
$this->addressEncoder = clone $this->addressEncoder;
|
||||
}
|
||||
|
||||
/** Apply the charset to the Header */
|
||||
|
||||
@@ -19,13 +19,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
private $factory;
|
||||
|
||||
/** Collection of set Headers */
|
||||
private $headers = array();
|
||||
private $headers = [];
|
||||
|
||||
/** Field ordering details */
|
||||
private $order = array();
|
||||
private $order = [];
|
||||
|
||||
/** List of fields which are required to be displayed */
|
||||
private $required = array();
|
||||
private $required = [];
|
||||
|
||||
/** The charset used by Headers */
|
||||
private $charset;
|
||||
@@ -33,8 +33,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
/**
|
||||
* Create a new SimpleHeaderSet with the given $factory.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderFactory $factory
|
||||
* @param string $charset
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderFactory $factory, $charset = null)
|
||||
{
|
||||
@@ -69,20 +68,17 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
*/
|
||||
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 $dateTime.
|
||||
*
|
||||
* @param string $name
|
||||
* @param DateTimeInterface $dateTime
|
||||
* @param string $name
|
||||
*/
|
||||
public function addDateHeader($name, DateTimeInterface $dateTime = null)
|
||||
{
|
||||
$this->storeHeader($name,
|
||||
$this->factory->createDateHeader($name, $dateTime));
|
||||
$this->storeHeader($name, $this->factory->createDateHeader($name, $dateTime));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,8 +89,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
*/
|
||||
public function addTextHeader($name, $value = null)
|
||||
{
|
||||
$this->storeHeader($name,
|
||||
$this->factory->createTextHeader($name, $value));
|
||||
$this->storeHeader($name, $this->factory->createTextHeader($name, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +99,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
* @param string $value
|
||||
* @param array $params
|
||||
*/
|
||||
public function addParameterizedHeader($name, $value = null, $params = array())
|
||||
public function addParameterizedHeader($name, $value = null, $params = [])
|
||||
{
|
||||
$this->storeHeader($name, $this->factory->createParameterizedHeader($name, $value, $params));
|
||||
}
|
||||
@@ -143,18 +138,18 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
*/
|
||||
public function has($name, $index = 0)
|
||||
{
|
||||
$lowerName = strtolower($name);
|
||||
$lowerName = strtolower($name ?? '');
|
||||
|
||||
if (!array_key_exists($lowerName, $this->headers)) {
|
||||
if (!\array_key_exists($lowerName, $this->headers)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (func_num_args() < 2) {
|
||||
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 (bool) \count($this->headers[$lowerName]);
|
||||
}
|
||||
|
||||
return array_key_exists($index, $this->headers[$lowerName]);
|
||||
return \array_key_exists($index, $this->headers[$lowerName]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,8 +161,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
* If $index is specified, the header will be inserted into the set at this
|
||||
* offset.
|
||||
*
|
||||
* @param Swift_Mime_Header $header
|
||||
* @param int $index
|
||||
* @param int $index
|
||||
*/
|
||||
public function set(Swift_Mime_Header $header, $index = 0)
|
||||
{
|
||||
@@ -183,13 +177,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
* @param string $name
|
||||
* @param int $index
|
||||
*
|
||||
* @return Swift_Mime_Header
|
||||
* @return Swift_Mime_Header|null
|
||||
*/
|
||||
public function get($name, $index = 0)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
$name = strtolower($name ?? '');
|
||||
|
||||
if (func_num_args() < 2) {
|
||||
if (\func_num_args() < 2) {
|
||||
if ($this->has($name)) {
|
||||
$values = array_values($this->headers[$name]);
|
||||
|
||||
@@ -212,7 +206,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
public function getAll($name = null)
|
||||
{
|
||||
if (!isset($name)) {
|
||||
$headers = array();
|
||||
$headers = [];
|
||||
foreach ($this->headers as $collection) {
|
||||
$headers = array_merge($headers, $collection);
|
||||
}
|
||||
@@ -220,9 +214,9 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
return $headers;
|
||||
}
|
||||
|
||||
$lowerName = strtolower($name);
|
||||
if (!array_key_exists($lowerName, $this->headers)) {
|
||||
return array();
|
||||
$lowerName = strtolower($name ?? '');
|
||||
if (!\array_key_exists($lowerName, $this->headers)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->headers[$lowerName];
|
||||
@@ -237,7 +231,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
{
|
||||
$headers = $this->headers;
|
||||
if ($this->canSort()) {
|
||||
uksort($headers, array($this, 'sortHeaders'));
|
||||
uksort($headers, [$this, 'sortHeaders']);
|
||||
}
|
||||
|
||||
return array_keys($headers);
|
||||
@@ -253,7 +247,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
*/
|
||||
public function remove($name, $index = 0)
|
||||
{
|
||||
$lowerName = strtolower($name);
|
||||
$lowerName = strtolower($name ?? '');
|
||||
unset($this->headers[$lowerName][$index]);
|
||||
}
|
||||
|
||||
@@ -264,7 +258,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
*/
|
||||
public function removeAll($name)
|
||||
{
|
||||
$lowerName = strtolower($name);
|
||||
$lowerName = strtolower($name ?? '');
|
||||
unset($this->headers[$lowerName]);
|
||||
}
|
||||
|
||||
@@ -272,8 +266,6 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
* 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)
|
||||
{
|
||||
@@ -284,8 +276,6 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
* 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)
|
||||
{
|
||||
@@ -312,11 +302,11 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
$string = '';
|
||||
$headers = $this->headers;
|
||||
if ($this->canSort()) {
|
||||
uksort($headers, array($this, 'sortHeaders'));
|
||||
uksort($headers, [$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();
|
||||
}
|
||||
}
|
||||
@@ -340,38 +330,38 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
/** Save a Header to the internal collection */
|
||||
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 ?? '')] = [];
|
||||
}
|
||||
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()
|
||||
{
|
||||
return count($this->order) > 0;
|
||||
return \count($this->order) > 0;
|
||||
}
|
||||
|
||||
/** uksort() algorithm for Header ordering */
|
||||
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;
|
||||
$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;
|
||||
|
||||
if (-1 === $aPos && -1 === $bPos) {
|
||||
// just be sure to be determinist here
|
||||
return $a > $b ? -1 : 1;
|
||||
}
|
||||
|
||||
if ($aPos == -1) {
|
||||
if (-1 == $aPos) {
|
||||
return 1;
|
||||
} elseif ($bPos == -1) {
|
||||
} elseif (-1 == $bPos) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -381,7 +371,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
|
||||
/** Test if the given Header is always displayed */
|
||||
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 */
|
||||
|
||||
@@ -24,16 +24,12 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
/**
|
||||
* Create a new SimpleMessage with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
* @param string $charset
|
||||
* @param string $charset
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null)
|
||||
{
|
||||
parent::__construct($headers, $encoder, $cache, $idGenerator, $charset);
|
||||
$this->getHeaders()->defineOrdering(array(
|
||||
$this->getHeaders()->defineOrdering([
|
||||
'Return-Path',
|
||||
'Received',
|
||||
'DKIM-Signature',
|
||||
@@ -50,8 +46,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
'MIME-Version',
|
||||
'Content-Type',
|
||||
'Content-Transfer-Encoding',
|
||||
));
|
||||
$this->getHeaders()->setAlwaysDisplayed(array('Date', 'Message-ID', 'From'));
|
||||
]);
|
||||
$this->getHeaders()->setAlwaysDisplayed(['Date', 'Message-ID', 'From']);
|
||||
$this->getHeaders()->addTextHeader('MIME-Version', '1.0');
|
||||
$this->setDate(new DateTimeImmutable());
|
||||
$this->setId($this->getId());
|
||||
@@ -97,8 +93,6 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
/**
|
||||
* Set the date at which this message was created.
|
||||
*
|
||||
* @param DateTimeInterface $dateTime
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDate(DateTimeInterface $dateTime)
|
||||
@@ -158,8 +152,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setSender($address, $name = null)
|
||||
{
|
||||
if (!is_array($address) && isset($name)) {
|
||||
$address = array($address => $name);
|
||||
if (!\is_array($address) && isset($name)) {
|
||||
$address = [$address => $name];
|
||||
}
|
||||
|
||||
if (!$this->setHeaderFieldModel('Sender', (array) $address)) {
|
||||
@@ -212,8 +206,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setFrom($addresses, $name = null)
|
||||
{
|
||||
if (!is_array($addresses) && isset($name)) {
|
||||
$addresses = array($addresses => $name);
|
||||
if (!\is_array($addresses) && isset($name)) {
|
||||
$addresses = [$addresses => $name];
|
||||
}
|
||||
|
||||
if (!$this->setHeaderFieldModel('From', (array) $addresses)) {
|
||||
@@ -266,8 +260,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setReplyTo($addresses, $name = null)
|
||||
{
|
||||
if (!is_array($addresses) && isset($name)) {
|
||||
$addresses = array($addresses => $name);
|
||||
if (!\is_array($addresses) && isset($name)) {
|
||||
$addresses = [$addresses => $name];
|
||||
}
|
||||
|
||||
if (!$this->setHeaderFieldModel('Reply-To', (array) $addresses)) {
|
||||
@@ -321,8 +315,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setTo($addresses, $name = null)
|
||||
{
|
||||
if (!is_array($addresses) && isset($name)) {
|
||||
$addresses = array($addresses => $name);
|
||||
if (!\is_array($addresses) && isset($name)) {
|
||||
$addresses = [$addresses => $name];
|
||||
}
|
||||
|
||||
if (!$this->setHeaderFieldModel('To', (array) $addresses)) {
|
||||
@@ -373,8 +367,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setCc($addresses, $name = null)
|
||||
{
|
||||
if (!is_array($addresses) && isset($name)) {
|
||||
$addresses = array($addresses => $name);
|
||||
if (!\is_array($addresses) && isset($name)) {
|
||||
$addresses = [$addresses => $name];
|
||||
}
|
||||
|
||||
if (!$this->setHeaderFieldModel('Cc', (array) $addresses)) {
|
||||
@@ -425,8 +419,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setBcc($addresses, $name = null)
|
||||
{
|
||||
if (!is_array($addresses) && isset($name)) {
|
||||
$addresses = array($addresses => $name);
|
||||
if (!\is_array($addresses) && isset($name)) {
|
||||
$addresses = [$addresses => $name];
|
||||
}
|
||||
|
||||
if (!$this->setHeaderFieldModel('Bcc', (array) $addresses)) {
|
||||
@@ -457,13 +451,13 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function setPriority($priority)
|
||||
{
|
||||
$priorityMap = array(
|
||||
$priorityMap = [
|
||||
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)) {
|
||||
$priority = max($pMapKeys);
|
||||
@@ -493,7 +487,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
'%[1-5]'
|
||||
);
|
||||
|
||||
return isset($priority) ? $priority : 3;
|
||||
return $priority ?? 3;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -526,13 +520,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
/**
|
||||
* Attach a {@link Swift_Mime_SimpleMimeEntity} such as an Attachment or MimePart.
|
||||
*
|
||||
* @param Swift_Mime_SimpleMimeEntity $entity
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function attach(Swift_Mime_SimpleMimeEntity $entity)
|
||||
{
|
||||
$this->setChildren(array_merge($this->getChildren(), array($entity)));
|
||||
$this->setChildren(array_merge($this->getChildren(), [$entity]));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -540,13 +532,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
/**
|
||||
* Remove an already attached entity.
|
||||
*
|
||||
* @param Swift_Mime_SimpleMimeEntity $entity
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function detach(Swift_Mime_SimpleMimeEntity $entity)
|
||||
{
|
||||
$newChildren = array();
|
||||
$newChildren = [];
|
||||
foreach ($this->getChildren() as $child) {
|
||||
if ($entity !== $child) {
|
||||
$newChildren[] = $child;
|
||||
@@ -559,9 +549,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
|
||||
/**
|
||||
* 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_SimpleMimeEntity $entity
|
||||
* This method should be used when embedding images or other data in a message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -579,8 +568,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') {
|
||||
$this->setChildren(array_merge(array($this->becomeMimePart()), $children));
|
||||
if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) {
|
||||
$this->setChildren(array_merge([$this->becomeMimePart()], $children));
|
||||
$string = parent::toString();
|
||||
$this->setChildren($children);
|
||||
} else {
|
||||
@@ -604,13 +593,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
|
||||
|
||||
/**
|
||||
* Write this message to a {@link Swift_InputByteStream}.
|
||||
*
|
||||
* @param Swift_InputByteStream $is
|
||||
*/
|
||||
public function toByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') {
|
||||
$this->setChildren(array_merge(array($this->becomeMimePart()), $children));
|
||||
if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) {
|
||||
$this->setChildren(array_merge([$this->becomeMimePart()], $children));
|
||||
parent::toByteStream($is);
|
||||
$this->setChildren($children);
|
||||
} else {
|
||||
|
||||
@@ -43,14 +43,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
private $boundary;
|
||||
|
||||
/** Mime types to be used based on the nesting level */
|
||||
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),
|
||||
);
|
||||
private $compositeRanges = [
|
||||
'multipart/mixed' => [self::LEVEL_TOP, self::LEVEL_MIXED],
|
||||
'multipart/alternative' => [self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE],
|
||||
'multipart/related' => [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 = [];
|
||||
|
||||
/** The nesting level of this entity */
|
||||
private $nestingLevel = self::LEVEL_ALTERNATIVE;
|
||||
@@ -59,20 +59,20 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
private $cache;
|
||||
|
||||
/** Direct descendants of this entity */
|
||||
private $immediateChildren = array();
|
||||
private $immediateChildren = [];
|
||||
|
||||
/** All descendants of this entity */
|
||||
private $children = array();
|
||||
private $children = [];
|
||||
|
||||
/** The maximum line length of the body of this entity */
|
||||
private $maxLineLength = 78;
|
||||
|
||||
/** The order in which alternative mime types should appear */
|
||||
private $alternativePartOrder = array(
|
||||
private $alternativePartOrder = [
|
||||
'text/plain' => 1,
|
||||
'text/html' => 2,
|
||||
'multipart/related' => 3,
|
||||
);
|
||||
];
|
||||
|
||||
/** The CID of this entity */
|
||||
private $id;
|
||||
@@ -84,20 +84,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
/**
|
||||
* Create a new SimpleMimeEntity with $headers, $encoder and $cache.
|
||||
*
|
||||
* @param Swift_Mime_SimpleHeaderSet $headers
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
* @param Swift_KeyCache $cache
|
||||
* @param Swift_IdGenerator $idGenerator
|
||||
*/
|
||||
public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator)
|
||||
{
|
||||
$this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
|
||||
$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(['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
|
||||
@@ -112,14 +107,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
// )
|
||||
// )
|
||||
|
||||
$this->compoundLevelFilters = array(
|
||||
(self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => array(
|
||||
self::LEVEL_ALTERNATIVE => array(
|
||||
$this->compoundLevelFilters = [
|
||||
(self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => [
|
||||
self::LEVEL_ALTERNATIVE => [
|
||||
'text/plain' => self::LEVEL_ALTERNATIVE,
|
||||
'text/html' => self::LEVEL_RELATED,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->id = $this->idGenerator->generateId();
|
||||
}
|
||||
@@ -168,6 +163,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
return $this->getHeaderFieldModel('Content-Type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Body Content-type of this entity.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBodyContentType()
|
||||
{
|
||||
return $this->userContentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Content-type of this entity.
|
||||
*
|
||||
@@ -293,16 +298,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
public function setChildren(array $children, $compoundLevel = null)
|
||||
{
|
||||
// TODO: Try to refactor this logic
|
||||
$compoundLevel = isset($compoundLevel) ? $compoundLevel : $this->getCompoundLevel($children);
|
||||
$immediateChildren = array();
|
||||
$grandchildren = array();
|
||||
$compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children);
|
||||
$immediateChildren = [];
|
||||
$grandchildren = [];
|
||||
$newContentType = $this->userContentType;
|
||||
|
||||
foreach ($children as $child) {
|
||||
$level = $this->getNeededChildLevel($child, $compoundLevel);
|
||||
if (empty($immediateChildren)) {
|
||||
//first iteration
|
||||
$immediateChildren = array($child);
|
||||
$immediateChildren = [$child];
|
||||
} else {
|
||||
$nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel);
|
||||
if ($nextLevel == $level) {
|
||||
@@ -311,7 +316,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
// Re-assign immediateChildren to grandchildren
|
||||
$grandchildren = array_merge($grandchildren, $immediateChildren);
|
||||
// Set new children
|
||||
$immediateChildren = array($child);
|
||||
$immediateChildren = [$child];
|
||||
} else {
|
||||
$grandchildren[] = $child;
|
||||
}
|
||||
@@ -375,7 +380,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
}
|
||||
|
||||
$this->body = $body;
|
||||
if (isset($contentType)) {
|
||||
if (null !== $contentType) {
|
||||
$this->setContentType($contentType);
|
||||
}
|
||||
|
||||
@@ -395,8 +400,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
/**
|
||||
* Set the encoder used for the body of this entity.
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setEncoder(Swift_Mime_ContentEncoder $encoder)
|
||||
@@ -420,7 +423,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
public function getBoundary()
|
||||
{
|
||||
if (!isset($this->boundary)) {
|
||||
$this->boundary = '_=_swift_'.time().'_'.md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)).'_=_';
|
||||
$this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_';
|
||||
}
|
||||
|
||||
return $this->boundary;
|
||||
@@ -457,8 +460,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
/**
|
||||
* Receive notification that the encoder of this entity or a parent entity
|
||||
* has changed.
|
||||
*
|
||||
* @param Swift_Mime_ContentEncoder $encoder
|
||||
*/
|
||||
public function encoderChanged(Swift_Mime_ContentEncoder $encoder)
|
||||
{
|
||||
@@ -522,8 +523,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
/**
|
||||
* Write this entire entity to a {@see Swift_InputByteStream}.
|
||||
*
|
||||
* @param Swift_InputByteStream
|
||||
*/
|
||||
public function toByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
@@ -535,8 +534,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
/**
|
||||
* Write this entire entity to a {@link Swift_InputByteStream}.
|
||||
*
|
||||
* @param Swift_InputByteStream
|
||||
*/
|
||||
protected function bodyToByteStream(Swift_InputByteStream $is)
|
||||
{
|
||||
@@ -637,7 +634,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
*/
|
||||
protected function fixHeaders()
|
||||
{
|
||||
if (count($this->immediateChildren)) {
|
||||
if (\count($this->immediateChildren)) {
|
||||
$this->setHeaderParameter('Content-Type', 'boundary',
|
||||
$this->getBoundary()
|
||||
);
|
||||
@@ -726,7 +723,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
private function getNeededChildLevel($child, $compoundLevel)
|
||||
{
|
||||
$filter = array();
|
||||
$filter = [];
|
||||
foreach ($this->compoundLevelFilters as $bitmask => $rules) {
|
||||
if (($compoundLevel & $bitmask) === $bitmask) {
|
||||
$filter = $rules + $filter;
|
||||
@@ -734,7 +731,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
}
|
||||
|
||||
$realLevel = $child->getNestingLevel();
|
||||
$lowercaseType = strtolower($child->getContentType());
|
||||
$lowercaseType = strtolower($child->getContentType() ?? '');
|
||||
|
||||
if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) {
|
||||
return $filter[$realLevel][$lowercaseType];
|
||||
@@ -769,7 +766,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
$shouldSort = false;
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
// NOTE: This include alternative parts moved into a related part
|
||||
if ($child->getNestingLevel() == self::LEVEL_ALTERNATIVE) {
|
||||
if (self::LEVEL_ALTERNATIVE == $child->getNestingLevel()) {
|
||||
$shouldSort = true;
|
||||
break;
|
||||
}
|
||||
@@ -778,13 +775,13 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
// Sort in order of preference, if there is one
|
||||
if ($shouldSort) {
|
||||
// Group the messages by order of preference
|
||||
$sorted = array();
|
||||
$sorted = [];
|
||||
foreach ($this->immediateChildren as $child) {
|
||||
$type = $child->getContentType();
|
||||
$level = array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
|
||||
$level = \array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
|
||||
|
||||
if (empty($sorted[$level])) {
|
||||
$sorted[$level] = array();
|
||||
$sorted[$level] = [];
|
||||
}
|
||||
|
||||
$sorted[$level][] = $child;
|
||||
@@ -792,7 +789,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
|
||||
ksort($sorted);
|
||||
|
||||
$this->immediateChildren = array_reduce($sorted, 'array_merge', array());
|
||||
$this->immediateChildren = array_reduce($sorted, 'array_merge', []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -813,11 +810,17 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
|
||||
{
|
||||
$this->headers = clone $this->headers;
|
||||
$this->encoder = clone $this->encoder;
|
||||
$this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true));
|
||||
$children = array();
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$children = [];
|
||||
foreach ($this->children as $pos => $child) {
|
||||
$children[$pos] = clone $child;
|
||||
}
|
||||
$this->setChildren($children);
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
|
||||
$this->cache = new Swift_KeyCache_ArrayKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user