diff --git a/tools/swift/CHANGES b/tools/swift/CHANGES new file mode 100644 index 000000000..3532ec2dc --- /dev/null +++ b/tools/swift/CHANGES @@ -0,0 +1,287 @@ +Changelog +========= + +5.4.12 (2018-07-31) +------------------- + + * fixed typo + +5.4.11 (2018-07-31) +------------------- + + * fixed startTLS support for PHP 5.6- + +5.4.10 (2018-07-27) +------------------- + + * fixed startTLS only allowed tls1.0, now allowed: tls1.0, tls1.1, tls1.2 + +5.4.9 (2018-01-23) +------------------ + + * no changes, last version of the 5.x series + +5.4.8 (2017-05-01) +------------------ + + * fixed encoding inheritance in addPart() + * fixed sorting MIME children when their types are equal + +5.4.7 (2017-04-20) +------------------ + + * fixed NTLMAuthenticator clobbering bcmath scale + +5.4.6 (2017-02-13) +------------------ + + * removed exceptions thrown in destructors as they lead to fatal errors + * switched to use sha256 by default in DKIM as per the RFC + * fixed an 'Undefined variable: pipes' PHP notice + * fixed long To headers when using the mail transport + * fixed NTLMAuthenticator when no domain is passed with the username + * prevented fatal error during unserialization of a message + * fixed a PHP warning when sending a message that has a length of a multiple of 8192 + +5.4.5 (2016-12-29) +------------------ + + * SECURITY FIX: fixed CVE-2016-10074 by disallowing potentially unsafe shell characters + + Prior to 5.4.5, the mail transport (Swift_Transport_MailTransport) was vulnerable to passing + arbitrary shell arguments if the "From", "ReturnPath" or "Sender" header came + from a non-trusted source, potentially allowing Remote Code Execution + * deprecated the mail transport + +5.4.4 (2016-11-23) +------------------ + + * reverted escaping command-line args to mail (PHP mail() function already does it) + +5.4.3 (2016-07-08) +------------------ + + * fixed SimpleHeaderSet::has()/get() when the 0 index is removed + * removed the need to have mcrypt installed + * fixed broken MIME header encoding with quotes/colons and non-ascii chars + * allowed mail transport send for messages without To header + * fixed PHP 7 support + +5.4.2 (2016-05-01) +------------------ + + * fixed support for IPv6 sockets + * added auto-retry when sending messages from the memory spool + * fixed consecutive read calls in Swift_ByteStream_FileByteStream + * added support for iso-8859-15 encoding + * fixed PHP mail extra params on missing reversePath + * added methods to set custom stream context options + * fixed charset changes in QpContentEncoderProxy + * added return-path header to the ignoredHeaders list of DKIMSigner + * fixed crlf for subject using mail + * fixed add soft line break only when necessary + * fixed escaping command-line args to mail + +5.4.1 (2015-06-06) +------------------ + + * made Swiftmailer exceptions confirm to PHP base exception constructor signature + * fixed MAIL FROM & RCPT TO headers to be RFC compliant + +5.4.0 (2015-03-14) +------------------ + + * added the possibility to add extra certs to PKCS#7 signature + * fix base64 encoding with streams + * added a new RESULT_SPOOLED status for SpoolTransport + * fixed getBody() on attachments when called more than once + * removed dots from generated filenames in filespool + +5.3.1 (2014-12-05) +------------------ + + * fixed cloning of messages with attachments + +5.3.0 (2014-10-04) +------------------ + + * fixed cloning when using signers + * reverted removal of Swift_Encoding + * drop support for PHP 5.2.x + +5.2.2 (2014-09-20) +------------------ + + * fixed Japanese support + * fixed the memory spool when the message changes when in the pool + * added support for cloning messages + * fixed PHP warning in the redirect plugin + * changed the way to and cc-ed email are sent to only use one transaction + +5.2.1 (2014-06-13) +------------------ + + * SECURITY FIX: fixed CLI escaping when using sendmail as a transport + + Prior to 5.2.1, the sendmail transport (Swift_Transport_SendmailTransport) + was vulnerable to an arbitrary shell execution if the "From" header came + from a non-trusted source and no "Return-Path" is configured. + + * fixed parameter in DKIMSigner + * fixed compatibility with PHP < 5.4 + +5.2.0 (2014-05-08) +------------------ + + * fixed Swift_ByteStream_FileByteStream::read() to match to the specification + * fixed from-charset and to-charset arguments in mbstring_convert_encoding() usages + * fixed infinite loop in StreamBuffer + * fixed NullTransport to return the number of ignored emails instead of 0 + * Use phpunit and mockery for unit testing (realityking) + +5.1.0 (2014-03-18) +------------------ + + * fixed data writing to stream when sending large messages + * added support for libopendkim (https://github.com/xdecock/php-opendkim) + * merged SignedMessage and Message + * added Gmail XOAuth2 authentication + * updated the list of known mime types + * added NTLM authentication + +5.0.3 (2013-12-03) +------------------ + + * fixed double-dot bug + * fixed DKIM signer + +5.0.2 (2013-08-30) +------------------ + + * handled correct exception type while reading IoBuffer output + +5.0.1 (2013-06-17) +------------------ + + * changed the spool to only start the transport when a mail has to be sent + * fixed compatibility with PHP 5.2 + * fixed LICENSE file + +5.0.0 (2013-04-30) +------------------ + + * changed the license from LGPL to MIT + +4.3.1 (2013-04-11) +------------------ + + * removed usage of the native QP encoder when the charset is not UTF-8 + * fixed usage of uniqid to avoid collisions + * made a performance improvement when tokenizing large headers + * fixed usage of the PHP native QP encoder on PHP 5.4.7+ + +4.3.0 (2013-01-08) +------------------ + + * made the temporary directory configurable via the TMPDIR env variable + * added S/MIME signer and encryption support + +4.2.2 (2012-10-25) +------------------ + + * added the possibility to throttle messages per second in ThrottlerPlugin (mostly for Amazon SES) + * switched mime.qpcontentencoder to automatically use the PHP native encoder on PHP 5.4.7+ + * allowed specifying a whitelist with regular expressions in RedirectingPlugin + +4.2.1 (2012-07-13) +------------------ + + * changed the coding standards to PSR-1/2 + * fixed issue with autoloading + * added NativeQpContentEncoder to enhance performance (for PHP 5.3+) + +4.2.0 (2012-06-29) +------------------ + + * added documentation about how to use the Japanese support introduced in 4.1.8 + * added a way to override the default configuration in a lazy way + * changed the PEAR init script to lazy-load the initialization + * fixed a bug when calling Swift_Preferences before anything else (regression introduced in 4.1.8) + +4.1.8 (2012-06-17) +------------------ + + * added Japanese iso-2022-jp support + * changed the init script to lazy-load the initialization + * fixed docblocks (@id) which caused some problems with libraries parsing the dobclocks + * fixed Swift_Mime_Headers_IdentificationHeader::setId() when passed an array of ids + * fixed encoding of email addresses in headers + * added replacements setter to the Decorator plugin + +4.1.7 (2012-04-26) +------------------ + + * fixed QpEncoder safeMapShareId property + +4.1.6 (2012-03-23) +------------------ + + * reduced the size of serialized Messages + +4.1.5 (2012-01-04) +------------------ + + * enforced Swift_Spool::queueMessage() to return a Boolean + * made an optimization to the memory spool: start the transport only when required + * prevented stream_socket_client() from generating an error and throw a Swift_TransportException instead + * fixed a PHP warning when calling to mail() when safe_mode is off + * many doc tweaks + +4.1.4 (2011-12-16) +------------------ + + * added a memory spool (Swift_MemorySpool) + * fixed too many opened files when sending emails with attachments + +4.1.3 (2011-10-27) +------------------ + + * added STARTTLS support + * added missing @return tags on fluent methods + * added a MessageLogger plugin that logs all sent messages + * added composer.json + +4.1.2 (2011-09-13) +------------------ + + * fixed wrong detection of magic_quotes_runtime + * fixed fatal errors when no To or Subject header has been set + * fixed charset on parameter header continuations + * added documentation about how to install Swiftmailer from the PEAR channel + * fixed various typos and markup problem in the documentation + * fixed warning when cache directory does not exist + * fixed "slashes are escaped" bug + * changed require_once() to require() in autoload + +4.1.1 (2011-07-04) +------------------ + + * added missing file in PEAR package + +4.1.0 (2011-06-30) +------------------ + + * documentation has been converted to ReST + +4.1.0 RC1 (2011-06-17) +---------------------- + +New features: + + * changed the Decorator Plugin to allow replacements in all headers + * added Swift_Mime_Grammar and Swift_Validate to validate an email address + * modified the autoloader to lazy-initialize Swiftmailer + * removed Swift_Mailer::batchSend() + * added NullTransport + * added new plugins: RedirectingPlugin and ImpersonatePlugin + * added a way to send messages asynchronously (Spool) diff --git a/tools/swift/README b/tools/swift/README new file mode 100644 index 000000000..52c075758 --- /dev/null +++ b/tools/swift/README @@ -0,0 +1,15 @@ +Swift Mailer +------------ + +Swift Mailer is a component based mailing solution for PHP 5. +It is released under the MIT license. + +Homepage: https://swiftmailer.symfony.com/ +Documentation: https://swiftmailer.symfony.com/docs/introduction.html +Bugs: https://github.com/swiftmailer/swiftmailer/issues +Repository: https://github.com/swiftmailer/swiftmailer + +Swift Mailer is highly object-oriented by design and lends itself +to use in complex web application with a great deal of flexibility. + +For full details on usage, see the documentation. diff --git a/tools/swift/VERSION b/tools/swift/VERSION new file mode 100644 index 000000000..82a2d1d04 --- /dev/null +++ b/tools/swift/VERSION @@ -0,0 +1 @@ +Swift-5.4.12 diff --git a/tools/swift/classes/Swift.php b/tools/swift/classes/Swift.php index 77145fdcb..82c381b73 100644 --- a/tools/swift/classes/Swift.php +++ b/tools/swift/classes/Swift.php @@ -16,12 +16,12 @@ */ abstract class Swift { - public static $initialized = false; - public static $inits = array(); - /** Swift Mailer Version number generated during dist release process */ const VERSION = '@SWIFT_VERSION_NUMBER@'; + public static $initialized = false; + public static $inits = array(); + /** * Registers an initializer callable that will be called the first time * a SwiftMailer class is autoloaded. @@ -47,7 +47,7 @@ abstract class Swift return; } - $path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php'; + $path = __DIR__.'/'.str_replace('_', '/', $class).'.php'; if (!file_exists($path)) { return; diff --git a/tools/swift/classes/Swift/Attachment.php b/tools/swift/classes/Swift/Attachment.php index 32759e0d8..a95bccfdf 100644 --- a/tools/swift/classes/Swift/Attachment.php +++ b/tools/swift/classes/Swift/Attachment.php @@ -11,7 +11,7 @@ /** * Attachment class for attaching files to a {@link Swift_Mime_Message}. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Attachment extends Swift_Mime_Attachment { diff --git a/tools/swift/classes/Swift/ByteStream/AbstractFilterableInputStream.php b/tools/swift/classes/Swift/ByteStream/AbstractFilterableInputStream.php index 3e597d17c..a7b0e3a62 100644 --- a/tools/swift/classes/Swift/ByteStream/AbstractFilterableInputStream.php +++ b/tools/swift/classes/Swift/ByteStream/AbstractFilterableInputStream.php @@ -11,7 +11,7 @@ /** * Provides the base functionality for an InputStream supporting filters. * - * @author Chris Corbyn + * @author Chris Corbyn */ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_InputByteStream, Swift_Filterable { @@ -22,6 +22,8 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I /** * StreamFilters. + * + * @var Swift_StreamFilter[] */ private $_filters = array(); @@ -75,9 +77,9 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I * * @param string $bytes * - * @return int - * * @throws Swift_IoException + * + * @return int */ public function write($bytes) { diff --git a/tools/swift/classes/Swift/ByteStream/ArrayByteStream.php b/tools/swift/classes/Swift/ByteStream/ArrayByteStream.php index 186a7c287..ef05a6d5e 100644 --- a/tools/swift/classes/Swift/ByteStream/ArrayByteStream.php +++ b/tools/swift/classes/Swift/ByteStream/ArrayByteStream.php @@ -11,7 +11,7 @@ /** * Allows reading and writing of bytes to and from an array. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_OutputByteStream { @@ -23,7 +23,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O private $_array = array(); /** - * The size of the stack + * The size of the stack. * * @var int */ @@ -70,7 +70,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O * remaining bytes are given instead. If no bytes are remaining at all, boolean * false is returned. * - * @param int $length + * @param int $length * * @return string */ @@ -82,9 +82,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O // Don't use array slice $end = $length + $this->_offset; - $end = $this->_arraySize<$end - ? $this->_arraySize - : $end; + $end = $this->_arraySize < $end ? $this->_arraySize : $end; $ret = ''; for (; $this->_offset < $end; ++$this->_offset) { $ret .= $this->_array[$this->_offset]; @@ -152,7 +150,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O /** * Move the internal read pointer to $byteOffset in the stream. * - * @param int $byteOffset + * @param int $byteOffset * * @return bool */ diff --git a/tools/swift/classes/Swift/ByteStream/FileByteStream.php b/tools/swift/classes/Swift/ByteStream/FileByteStream.php index 6c1446232..9ed852310 100644 --- a/tools/swift/classes/Swift/ByteStream/FileByteStream.php +++ b/tools/swift/classes/Swift/ByteStream/FileByteStream.php @@ -11,7 +11,7 @@ /** * Allows reading and writing of bytes to and from a file. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_FileStream { @@ -39,8 +39,8 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl /** * Create a new FileByteStream for $path. * - * @param string $path - * @param bool $writable if true + * @param string $path + * @param bool $writable if true */ public function __construct($path, $writable = false) { @@ -73,11 +73,11 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl * remaining bytes are given instead. If no bytes are remaining at all, boolean * false is returned. * - * @param int $length - * - * @return string|bool + * @param int $length * * @throws Swift_IoException + * + * @return string|bool */ public function read($length) { @@ -111,7 +111,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl /** * Move the internal read pointer to $byteOffset in the stream. * - * @param int $byteOffset + * @param int $byteOffset * * @return bool */ @@ -139,11 +139,13 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl private function _getReadHandle() { if (!isset($this->_reader)) { - if (!$this->_reader = fopen($this->_path, 'rb')) { + $pointer = @fopen($this->_path, 'rb'); + if (!$pointer) { throw new Swift_IoException( 'Unable to open file for reading ['.$this->_path.']' ); } + $this->_reader = $pointer; if ($this->_offset != 0) { $this->_getReadStreamSeekableStatus(); $this->_seekReadStreamToPosition($this->_offset); @@ -191,8 +193,8 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl } if ($this->_seekable === false) { $currentPos = ftell($this->_reader); - if ($currentPos<$offset) { - $toDiscard = $offset-$currentPos; + if ($currentPos < $offset) { + $toDiscard = $offset - $currentPos; fread($this->_reader, $toDiscard); return; diff --git a/tools/swift/classes/Swift/ByteStream/TemporaryFileByteStream.php b/tools/swift/classes/Swift/ByteStream/TemporaryFileByteStream.php index eb33151bb..1c9a80c03 100644 --- a/tools/swift/classes/Swift/ByteStream/TemporaryFileByteStream.php +++ b/tools/swift/classes/Swift/ByteStream/TemporaryFileByteStream.php @@ -9,7 +9,7 @@ */ /** - * @author Romain-Geissler + * @author Romain-Geissler */ class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByteStream { diff --git a/tools/swift/classes/Swift/ByteStream/index.php b/tools/swift/classes/Swift/ByteStream/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/ByteStream/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/CharacterReader.php b/tools/swift/classes/Swift/CharacterReader.php index febd77eb5..4267adbc5 100644 --- a/tools/swift/classes/Swift/CharacterReader.php +++ b/tools/swift/classes/Swift/CharacterReader.php @@ -11,8 +11,8 @@ /** * Analyzes characters for a specific character set. * - * @author Chris Corbyn - * @author Xavier De Cock + * @author Chris Corbyn + * @author Xavier De Cock */ interface Swift_CharacterReader { @@ -21,12 +21,12 @@ interface Swift_CharacterReader const MAP_TYPE_POSITIONS = 0x03; /** - * Returns the complete character map + * Returns the complete character map. * - * @param string $string - * @param int $startOffset - * @param array $currentMap - * @param mixed $ignoredChars + * @param string $string + * @param int $startOffset + * @param array $currentMap + * @param mixed $ignoredChars * * @return int */ @@ -48,8 +48,8 @@ interface Swift_CharacterReader * A value of zero means this is already a valid character. * A value of -1 means this cannot possibly be a valid character. * - * @param integer[] $bytes - * @param int $size + * @param int[] $bytes + * @param int $size * * @return int */ diff --git a/tools/swift/classes/Swift/CharacterReader/GenericFixedWidthReader.php b/tools/swift/classes/Swift/CharacterReader/GenericFixedWidthReader.php index d0c8698df..6a18e1dd1 100644 --- a/tools/swift/classes/Swift/CharacterReader/GenericFixedWidthReader.php +++ b/tools/swift/classes/Swift/CharacterReader/GenericFixedWidthReader.php @@ -11,8 +11,8 @@ /** * Provides fixed-width byte sizes for reading fixed-width character sets. * - * @author Chris Corbyn - * @author Xavier De Cock + * @author Chris Corbyn + * @author Xavier De Cock */ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterReader { @@ -26,7 +26,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe /** * Creates a new GenericFixedWidthReader using $width bytes per character. * - * @param int $width + * @param int $width */ public function __construct($width) { @@ -36,10 +36,10 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe /** * Returns the complete character map. * - * @param string $string - * @param int $startOffset - * @param array $currentMap - * @param mixed $ignoredChars + * @param string $string + * @param int $startOffset + * @param array $currentMap + * @param mixed $ignoredChars * * @return int */ @@ -48,7 +48,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe $strlen = strlen($string); // % and / are CPU intensive, so, maybe find a better way $ignored = $strlen % $this->_width; - $ignoredChars = substr($string, - $ignored); + $ignoredChars = $ignored ? substr($string, -$ignored) : ''; $currentMap = $this->_width; return ($strlen - $ignored) / $this->_width; @@ -73,8 +73,8 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe * A value of zero means this is already a valid character. * A value of -1 means this cannot possibly be a valid character. * - * @param string $bytes - * @param int $size + * @param string $bytes + * @param int $size * * @return int */ @@ -82,7 +82,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe { $needed = $this->_width - $size; - return ($needed > -1) ? $needed : -1; + return $needed > -1 ? $needed : -1; } /** diff --git a/tools/swift/classes/Swift/CharacterReader/UsAsciiReader.php b/tools/swift/classes/Swift/CharacterReader/UsAsciiReader.php index 229c567f6..67da48f6c 100644 --- a/tools/swift/classes/Swift/CharacterReader/UsAsciiReader.php +++ b/tools/swift/classes/Swift/CharacterReader/UsAsciiReader.php @@ -11,17 +11,17 @@ /** * Analyzes US-ASCII characters. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader { /** * Returns the complete character map. * - * @param string $string - * @param int $startOffset - * @param array $currentMap - * @param string $ignoredChars + * @param string $string + * @param int $startOffset + * @param array $currentMap + * @param string $ignoredChars * * @return int */ @@ -30,9 +30,9 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader $strlen = strlen($string); $ignoredChars = ''; for ($i = 0; $i < $strlen; ++$i) { - if ($string[$i]>"\x07F") { + if ($string[$i] > "\x07F") { // Invalid char - $currentMap[$i+$startOffset] = $string[$i]; + $currentMap[$i + $startOffset] = $string[$i]; } } @@ -40,9 +40,9 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader } /** - * Returns mapType + * Returns mapType. * - * @return int mapType + * @return int mapType */ public function getMapType() { @@ -57,8 +57,8 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader * A value of zero means this is already a valid character. * A value of -1 means this cannot possibly be a valid character. * - * @param string $bytes - * @param int $size + * @param string $bytes + * @param int $size * * @return int */ @@ -67,9 +67,9 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader $byte = reset($bytes); if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) { return 0; - } else { - return -1; } + + return -1; } /** diff --git a/tools/swift/classes/Swift/CharacterReader/Utf8Reader.php b/tools/swift/classes/Swift/CharacterReader/Utf8Reader.php index aebbecf66..22746bd85 100644 --- a/tools/swift/classes/Swift/CharacterReader/Utf8Reader.php +++ b/tools/swift/classes/Swift/CharacterReader/Utf8Reader.php @@ -11,30 +11,30 @@ /** * Analyzes UTF-8 characters. * - * @author Chris Corbyn - * @author Xavier De Cock + * @author Chris Corbyn + * @author Xavier De Cock */ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader { /** Pre-computed for optimization */ private static $length_map = array( // N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x0N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x2N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x3N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x4N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x5N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x6N - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x7N - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x8N - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0x9N - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xAN - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0xBN - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xCN - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // 0xDN - 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, // 0xEN - 4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0, // 0xFN + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x0N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x1N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x2N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x3N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x4N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x5N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x6N + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x7N + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x8N + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x9N + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xAN + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0xBN + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xCN + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xDN + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xEN + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN ); private static $s_length_map = array( @@ -75,16 +75,16 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader /** * Returns the complete character map. * - * @param string $string - * @param int $startOffset - * @param array $currentMap - * @param mixed $ignoredChars + * @param string $string + * @param int $startOffset + * @param array $currentMap + * @param mixed $ignoredChars * * @return int */ public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) { - if (!isset($currentMap['i']) || ! isset($currentMap['p'])) { + if (!isset($currentMap['i']) || !isset($currentMap['p'])) { $currentMap['p'] = $currentMap['i'] = array(); } @@ -134,7 +134,7 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader /** * Returns mapType. * - * @return int mapType + * @return int mapType */ public function getMapType() { @@ -149,22 +149,19 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader * A value of zero means this is already a valid character. * A value of -1 means this cannot possibly be a valid character. * - * @param string $bytes - * @param int $size + * @param string $bytes + * @param int $size * * @return int */ public function validateByteSequence($bytes, $size) { - if ($size<1) { + if ($size < 1) { return -1; } $needed = self::$length_map[$bytes[0]] - $size; - return ($needed > -1) - ? $needed - : -1 - ; + return $needed > -1 ? $needed : -1; } /** diff --git a/tools/swift/classes/Swift/CharacterReader/index.php b/tools/swift/classes/Swift/CharacterReader/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/CharacterReader/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/CharacterReaderFactory.php b/tools/swift/classes/Swift/CharacterReaderFactory.php index 5bf38b8bf..15b6c6920 100644 --- a/tools/swift/classes/Swift/CharacterReaderFactory.php +++ b/tools/swift/classes/Swift/CharacterReaderFactory.php @@ -11,7 +11,7 @@ /** * A factory for creating CharacterReaders. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_CharacterReaderFactory { diff --git a/tools/swift/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php b/tools/swift/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php index e08445eae..9171a0bac 100644 --- a/tools/swift/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php +++ b/tools/swift/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php @@ -11,7 +11,7 @@ /** * Standard factory for creating CharacterReaders. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift_CharacterReaderFactory { diff --git a/tools/swift/classes/Swift/CharacterReaderFactory/index.php b/tools/swift/classes/Swift/CharacterReaderFactory/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/CharacterReaderFactory/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/CharacterStream.php b/tools/swift/classes/Swift/CharacterStream.php index aa46779e7..717924f5d 100644 --- a/tools/swift/classes/Swift/CharacterStream.php +++ b/tools/swift/classes/Swift/CharacterStream.php @@ -15,7 +15,7 @@ * Classes implementing this interface may use a subsystem which requires less * memory than working with large strings of data. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_CharacterStream { @@ -52,7 +52,7 @@ interface Swift_CharacterStream * Read $length characters from the stream and move the internal pointer * $length further into the stream. * - * @param int $length + * @param int $length * * @return string */ @@ -62,7 +62,7 @@ interface Swift_CharacterStream * Read $length characters from the stream and return a 1-dimensional array * containing there octet values. * - * @param int $length + * @param int $length * * @return int[] */ @@ -78,7 +78,7 @@ interface Swift_CharacterStream /** * Move the internal pointer to $charOffset in the stream. * - * @param int $charOffset + * @param int $charOffset */ public function setPointer($charOffset); diff --git a/tools/swift/classes/Swift/CharacterStream/ArrayCharacterStream.php b/tools/swift/classes/Swift/CharacterStream/ArrayCharacterStream.php index 0cfadd49a..7213a40d7 100644 --- a/tools/swift/classes/Swift/CharacterStream/ArrayCharacterStream.php +++ b/tools/swift/classes/Swift/CharacterStream/ArrayCharacterStream.php @@ -11,7 +11,7 @@ /** * A CharacterStream implementation which stores characters in an internal array. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStream { @@ -121,7 +121,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea * Read $length characters from the stream and move the internal pointer * $length further into the stream. * - * @param int $length + * @param int $length * * @return string */ @@ -153,9 +153,9 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea * Read $length characters from the stream and return a 1-dimensional array * containing there octet values. * - * @param int $length + * @param int $length * - * @return integer[] + * @return int[] */ public function readBytes($length) { @@ -244,7 +244,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea /** * Move the internal pointer to $charOffset in the stream. * - * @param int $charOffset + * @param int $charOffset */ public function setPointer($charOffset) { diff --git a/tools/swift/classes/Swift/CharacterStream/NgCharacterStream.php b/tools/swift/classes/Swift/CharacterStream/NgCharacterStream.php index b962e403c..58bd140fd 100644 --- a/tools/swift/classes/Swift/CharacterStream/NgCharacterStream.php +++ b/tools/swift/classes/Swift/CharacterStream/NgCharacterStream.php @@ -11,9 +11,8 @@ /** * A CharacterStream implementation which stores characters in an internal array. * - * @author Xavier De Cock + * @author Xavier De Cock */ - class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream { /** @@ -45,7 +44,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream private $_datas = ''; /** - * Number of bytes in the stream + * Number of bytes in the stream. * * @var int */ @@ -156,7 +155,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream /** * @see Swift_CharacterStream::read() * - * @param int $length + * @param int $length * * @return string */ @@ -166,12 +165,10 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream return false; } $ret = false; - $length = ($this->_currentPos+$length > $this->_charCount) - ? $this->_charCount - $this->_currentPos - : $length; + $length = $this->_currentPos + $length > $this->_charCount ? $this->_charCount - $this->_currentPos : $length; switch ($this->_mapType) { case Swift_CharacterReader::MAP_TYPE_FIXED_LEN: - $len = $length*$this->_map; + $len = $length * $this->_map; $ret = substr($this->_datas, $this->_currentPos * $this->_map, $len); @@ -179,13 +176,9 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream break; case Swift_CharacterReader::MAP_TYPE_INVALID: - $end = $this->_currentPos + $length; - $end = $end > $this->_charCount - ? $this->_charCount - : $end; $ret = ''; for (; $this->_currentPos < $length; ++$this->_currentPos) { - if (isset ($this->_map[$this->_currentPos])) { + if (isset($this->_map[$this->_currentPos])) { $ret .= '?'; } else { $ret .= $this->_datas[$this->_currentPos]; @@ -195,13 +188,11 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream case Swift_CharacterReader::MAP_TYPE_POSITIONS: $end = $this->_currentPos + $length; - $end = $end > $this->_charCount - ? $this->_charCount - : $end; + $end = $end > $this->_charCount ? $this->_charCount : $end; $ret = ''; $start = 0; - if ($this->_currentPos>0) { - $start = $this->_map['p'][$this->_currentPos-1]; + if ($this->_currentPos > 0) { + $start = $this->_map['p'][$this->_currentPos - 1]; } $to = $start; for (; $this->_currentPos < $end; ++$this->_currentPos) { @@ -222,9 +213,9 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream /** * @see Swift_CharacterStream::readBytes() * - * @param int $length + * @param int $length * - * @return integer[] + * @return int[] */ public function readBytes($length) { @@ -241,11 +232,11 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream /** * @see Swift_CharacterStream::setPointer() * - * @param int $charOffset + * @param int $charOffset */ public function setPointer($charOffset) { - if ($this->_charCount<$charOffset) { + if ($this->_charCount < $charOffset) { $charOffset = $this->_charCount; } $this->_currentPos = $charOffset; @@ -268,7 +259,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream $this->_datas .= $chars; $this->_charCount += $this->_charReader->getCharPositions(substr($this->_datas, $this->_datasSize), $this->_datasSize, $this->_map, $ignored); if ($ignored !== false) { - $this->_datasSize = strlen($this->_datas)-strlen($ignored); + $this->_datasSize = strlen($this->_datas) - strlen($ignored); } else { $this->_datasSize = strlen($this->_datas); } diff --git a/tools/swift/classes/Swift/CharacterStream/index.php b/tools/swift/classes/Swift/CharacterStream/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/CharacterStream/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/ConfigurableSpool.php b/tools/swift/classes/Swift/ConfigurableSpool.php index df87527f6..4ae5bacfc 100644 --- a/tools/swift/classes/Swift/ConfigurableSpool.php +++ b/tools/swift/classes/Swift/ConfigurableSpool.php @@ -11,7 +11,7 @@ /** * Base class for Spools (implements time and message limits). * - * @author Fabien Potencier + * @author Fabien Potencier */ abstract class Swift_ConfigurableSpool implements Swift_Spool { @@ -24,7 +24,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool /** * Sets the maximum number of messages to send per flush. * - * @param int $limit + * @param int $limit */ public function setMessageLimit($limit) { @@ -34,7 +34,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool /** * Gets the maximum number of messages to send per flush. * - * @return int The limit + * @return int The limit */ public function getMessageLimit() { @@ -44,7 +44,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool /** * Sets the time limit (in seconds) per flush. * - * @param int $limit The limit + * @param int $limit The limit */ public function setTimeLimit($limit) { @@ -54,7 +54,7 @@ abstract class Swift_ConfigurableSpool implements Swift_Spool /** * Gets the time limit (in seconds) per flush. * - * @return int The limit + * @return int The limit */ public function getTimeLimit() { diff --git a/tools/swift/classes/Swift/DependencyContainer.php b/tools/swift/classes/Swift/DependencyContainer.php index 1d8cb3a39..befec9ac0 100644 --- a/tools/swift/classes/Swift/DependencyContainer.php +++ b/tools/swift/classes/Swift/DependencyContainer.php @@ -11,7 +11,7 @@ /** * Dependency Injection container. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_DependencyContainer { @@ -48,7 +48,7 @@ class Swift_DependencyContainer /** * Returns a singleton of the DependencyContainer. * - * @return Swift_DependencyContainer + * @return self */ public static function getInstance() { @@ -91,9 +91,9 @@ class Swift_DependencyContainer * * @param string $itemName * - * @return mixed - * * @throws Swift_DependencyException If the dependency is not found + * + * @return mixed */ public function lookup($itemName) { @@ -138,16 +138,17 @@ class Swift_DependencyContainer * This method returns the current DependencyContainer instance because it * requires the use of the fluid interface to set the specific details for the * dependency. + * * @see asNewInstanceOf(), asSharedInstanceOf(), asValue() * * @param string $itemName * - * @return Swift_DependencyContainer + * @return $this */ public function register($itemName) { $this->_store[$itemName] = array(); - $this->_endPoint = & $this->_store[$itemName]; + $this->_endPoint = &$this->_store[$itemName]; return $this; } @@ -159,11 +160,11 @@ class Swift_DependencyContainer * * @param mixed $value * - * @return Swift_DependencyContainer + * @return $this */ public function asValue($value) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); $endPoint['lookupType'] = self::TYPE_VALUE; $endPoint['value'] = $value; @@ -175,11 +176,11 @@ class Swift_DependencyContainer * * @param string $lookup * - * @return Swift_DependencyContainer + * @return $this */ public function asAliasOf($lookup) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); $endPoint['lookupType'] = self::TYPE_ALIAS; $endPoint['ref'] = $lookup; @@ -197,11 +198,11 @@ class Swift_DependencyContainer * * @param string $className * - * @return Swift_DependencyContainer + * @return $this */ public function asNewInstanceOf($className) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); $endPoint['lookupType'] = self::TYPE_INSTANCE; $endPoint['className'] = $className; @@ -215,11 +216,11 @@ class Swift_DependencyContainer * * @param string $className * - * @return Swift_DependencyContainer + * @return $this */ public function asSharedInstanceOf($className) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); $endPoint['lookupType'] = self::TYPE_SHARED; $endPoint['className'] = $className; @@ -235,11 +236,11 @@ class Swift_DependencyContainer * * @param array $lookups * - * @return Swift_DependencyContainer + * @return $this */ public function withDependencies(array $lookups) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); $endPoint['args'] = array(); foreach ($lookups as $lookup) { $this->addConstructorLookup($lookup); @@ -256,11 +257,11 @@ class Swift_DependencyContainer * * @param mixed $value * - * @return Swift_DependencyContainer + * @return $this */ public function addConstructorValue($value) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); if (!isset($endPoint['args'])) { $endPoint['args'] = array(); } @@ -277,11 +278,11 @@ class Swift_DependencyContainer * * @param string $lookup * - * @return Swift_DependencyContainer + * @return $this */ public function addConstructorLookup($lookup) { - $endPoint = & $this->_getEndPoint(); + $endPoint = &$this->_getEndPoint(); if (!isset($this->_endPoint['args'])) { $endPoint['args'] = array(); } @@ -310,9 +311,9 @@ class Swift_DependencyContainer return $reflector->newInstanceArgs( $this->createDependenciesFor($itemName) ); - } else { - return $reflector->newInstance(); } + + return $reflector->newInstance(); } /** Create and register a shared instance of $itemName */ @@ -365,8 +366,8 @@ class Swift_DependencyContainer } return $collection; - } else { - return $this->lookup($item); } + + return $this->lookup($item); } } diff --git a/tools/swift/classes/Swift/DependencyException.php b/tools/swift/classes/Swift/DependencyException.php index 0a96232e9..799d38d83 100644 --- a/tools/swift/classes/Swift/DependencyException.php +++ b/tools/swift/classes/Swift/DependencyException.php @@ -11,7 +11,7 @@ /** * DependencyException gets thrown when a requested dependency is missing. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_DependencyException extends Swift_SwiftException { diff --git a/tools/swift/classes/Swift/EmbeddedFile.php b/tools/swift/classes/Swift/EmbeddedFile.php index 486ad6083..d8c72ad4d 100644 --- a/tools/swift/classes/Swift/EmbeddedFile.php +++ b/tools/swift/classes/Swift/EmbeddedFile.php @@ -11,7 +11,7 @@ /** * An embedded file, in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile { diff --git a/tools/swift/classes/Swift/Encoder.php b/tools/swift/classes/Swift/Encoder.php index 7c6564245..2073abca1 100644 --- a/tools/swift/classes/Swift/Encoder.php +++ b/tools/swift/classes/Swift/Encoder.php @@ -10,6 +10,7 @@ /** * Interface for all Encoder schemes. + * * @author Chris Corbyn */ interface Swift_Encoder extends Swift_Mime_CharsetObserver @@ -17,9 +18,9 @@ interface Swift_Encoder extends Swift_Mime_CharsetObserver /** * Encode a given string to produce an encoded string. * - * @param string $string - * @param int $firstLineOffset if first line needs to be shorter - * @param int $maxLineLength - 0 indicates the default length for this encoding + * @param string $string + * @param int $firstLineOffset if first line needs to be shorter + * @param int $maxLineLength - 0 indicates the default length for this encoding * * @return string */ diff --git a/tools/swift/classes/Swift/Encoder/Base64Encoder.php b/tools/swift/classes/Swift/Encoder/Base64Encoder.php index 99cfb0252..0e7b2a1b0 100644 --- a/tools/swift/classes/Swift/Encoder/Base64Encoder.php +++ b/tools/swift/classes/Swift/Encoder/Base64Encoder.php @@ -11,7 +11,7 @@ /** * Handles Base 64 Encoding in Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Encoder_Base64Encoder implements Swift_Encoder { @@ -22,9 +22,9 @@ class Swift_Encoder_Base64Encoder implements Swift_Encoder * If the first line needs to be shorter, indicate the difference with * $firstLineOffset. * - * @param string $string to encode - * @param int $firstLineOffset - * @param int $maxLineLength optional, 0 indicates the default of 76 bytes + * @param string $string to encode + * @param int $firstLineOffset + * @param int $maxLineLength optional, 0 indicates the default of 76 bytes * * @return string */ diff --git a/tools/swift/classes/Swift/Encoder/QpEncoder.php b/tools/swift/classes/Swift/Encoder/QpEncoder.php index 81836f77b..edec10c51 100644 --- a/tools/swift/classes/Swift/Encoder/QpEncoder.php +++ b/tools/swift/classes/Swift/Encoder/QpEncoder.php @@ -13,7 +13,7 @@ * * Possibly the most accurate RFC 2045 QP implementation found in PHP. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Encoder_QpEncoder implements Swift_Encoder { @@ -37,26 +37,26 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder * @var string[] */ protected static $_qpMap = array( - 0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04', - 5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09', - 10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E', - 15 => '=0F', 16 => '=10', 17 => '=11', 18 => '=12', 19 => '=13', - 20 => '=14', 21 => '=15', 22 => '=16', 23 => '=17', 24 => '=18', - 25 => '=19', 26 => '=1A', 27 => '=1B', 28 => '=1C', 29 => '=1D', - 30 => '=1E', 31 => '=1F', 32 => '=20', 33 => '=21', 34 => '=22', - 35 => '=23', 36 => '=24', 37 => '=25', 38 => '=26', 39 => '=27', - 40 => '=28', 41 => '=29', 42 => '=2A', 43 => '=2B', 44 => '=2C', - 45 => '=2D', 46 => '=2E', 47 => '=2F', 48 => '=30', 49 => '=31', - 50 => '=32', 51 => '=33', 52 => '=34', 53 => '=35', 54 => '=36', - 55 => '=37', 56 => '=38', 57 => '=39', 58 => '=3A', 59 => '=3B', - 60 => '=3C', 61 => '=3D', 62 => '=3E', 63 => '=3F', 64 => '=40', - 65 => '=41', 66 => '=42', 67 => '=43', 68 => '=44', 69 => '=45', - 70 => '=46', 71 => '=47', 72 => '=48', 73 => '=49', 74 => '=4A', - 75 => '=4B', 76 => '=4C', 77 => '=4D', 78 => '=4E', 79 => '=4F', - 80 => '=50', 81 => '=51', 82 => '=52', 83 => '=53', 84 => '=54', - 85 => '=55', 86 => '=56', 87 => '=57', 88 => '=58', 89 => '=59', - 90 => '=5A', 91 => '=5B', 92 => '=5C', 93 => '=5D', 94 => '=5E', - 95 => '=5F', 96 => '=60', 97 => '=61', 98 => '=62', 99 => '=63', + 0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04', + 5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09', + 10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E', + 15 => '=0F', 16 => '=10', 17 => '=11', 18 => '=12', 19 => '=13', + 20 => '=14', 21 => '=15', 22 => '=16', 23 => '=17', 24 => '=18', + 25 => '=19', 26 => '=1A', 27 => '=1B', 28 => '=1C', 29 => '=1D', + 30 => '=1E', 31 => '=1F', 32 => '=20', 33 => '=21', 34 => '=22', + 35 => '=23', 36 => '=24', 37 => '=25', 38 => '=26', 39 => '=27', + 40 => '=28', 41 => '=29', 42 => '=2A', 43 => '=2B', 44 => '=2C', + 45 => '=2D', 46 => '=2E', 47 => '=2F', 48 => '=30', 49 => '=31', + 50 => '=32', 51 => '=33', 52 => '=34', 53 => '=35', 54 => '=36', + 55 => '=37', 56 => '=38', 57 => '=39', 58 => '=3A', 59 => '=3B', + 60 => '=3C', 61 => '=3D', 62 => '=3E', 63 => '=3F', 64 => '=40', + 65 => '=41', 66 => '=42', 67 => '=43', 68 => '=44', 69 => '=45', + 70 => '=46', 71 => '=47', 72 => '=48', 73 => '=49', 74 => '=4A', + 75 => '=4B', 76 => '=4C', 77 => '=4D', 78 => '=4E', 79 => '=4F', + 80 => '=50', 81 => '=51', 82 => '=52', 83 => '=53', 84 => '=54', + 85 => '=55', 86 => '=56', 87 => '=57', 88 => '=58', 89 => '=59', + 90 => '=5A', 91 => '=5B', 92 => '=5C', 93 => '=5D', 94 => '=5E', + 95 => '=5F', 96 => '=60', 97 => '=61', 98 => '=62', 99 => '=63', 100 => '=64', 101 => '=65', 102 => '=66', 103 => '=67', 104 => '=68', 105 => '=69', 106 => '=6A', 107 => '=6B', 108 => '=6C', 109 => '=6D', 110 => '=6E', 111 => '=6F', 112 => '=70', 113 => '=71', 114 => '=72', @@ -153,9 +153,9 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder * If the first line needs to be shorter, indicate the difference with * $firstLineOffset. * - * @param string $string to encode - * @param int $firstLineOffset, optional - * @param int $maxLineLength, optional 0 indicates the default of 76 chars + * @param string $string to encode + * @param int $firstLineOffset, optional + * @param int $maxLineLength, optional 0 indicates the default of 76 chars * * @return string */ @@ -170,7 +170,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder $lines = array(); $lNo = 0; $lines[$lNo] = ''; - $currentLine = & $lines[$lNo++]; + $currentLine = &$lines[$lNo++]; $size = $lineLen = 0; $this->_charStream->flushContents(); @@ -198,14 +198,25 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder } $enc = $this->_encodeByteSequence($bytes, $size); - if ($currentLine && $lineLen+$size >= $thisLineLength) { + + $i = strpos($enc, '=0D=0A'); + $newLineLength = $lineLen + ($i === false ? $size : $i); + + if ($currentLine && $newLineLength >= $thisLineLength) { $lines[$lNo] = ''; - $currentLine = & $lines[$lNo++]; + $currentLine = &$lines[$lNo++]; $thisLineLength = $maxLineLength; $lineLen = 0; } - $lineLen += $size; + $currentLine .= $enc; + + if ($i === false) { + $lineLen += $size; + } else { + // 6 is the length of '=0D=0A'. + $lineLen = $size - strrpos($enc, '=0D=0A') - 6; + } } return $this->_standardize(implode("=\r\n", $lines)); @@ -224,8 +235,8 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder /** * Encode the given byte array into a verbatim QP form. * - * @param integer[] $bytes - * @param int $size + * @param int[] $bytes + * @param int $size * * @return string */ @@ -249,9 +260,9 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder /** * Get the next sequence of bytes to read from the char stream. * - * @param int $size number of bytes to read + * @param int $size number of bytes to read * - * @return integer[] + * @return int[] */ protected function _nextSequence($size = 4) { @@ -267,7 +278,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder */ protected function _standardize($string) { - $string = str_replace(array("\t=0D=0A", " =0D=0A", "=0D=0A"), + $string = str_replace(array("\t=0D=0A", ' =0D=0A', '=0D=0A'), array("=09\r\n", "=20\r\n", "\r\n"), $string ); switch ($end = ord(substr($string, -1))) { @@ -280,8 +291,8 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder } /** - * Make a deep copy of object - */ + * Make a deep copy of object. + */ public function __clone() { $this->_charStream = clone $this->_charStream; diff --git a/tools/swift/classes/Swift/Encoder/Rfc2231Encoder.php b/tools/swift/classes/Swift/Encoder/Rfc2231Encoder.php index 1a7e21eb1..b0215e883 100644 --- a/tools/swift/classes/Swift/Encoder/Rfc2231Encoder.php +++ b/tools/swift/classes/Swift/Encoder/Rfc2231Encoder.php @@ -11,7 +11,7 @@ /** * Handles RFC 2231 specified Encoding in Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder { @@ -36,9 +36,9 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder * Takes an unencoded string and produces a string encoded according to * RFC 2231 from it. * - * @param string $string - * @param int $firstLineOffset - * @param int $maxLineLength optional, 0 indicates the default of 75 bytes + * @param string $string + * @param int $firstLineOffset + * @param int $maxLineLength optional, 0 indicates the default of 75 bytes * * @return string */ @@ -47,7 +47,7 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder $lines = array(); $lineCount = 0; $lines[] = ''; - $currentLine = & $lines[$lineCount++]; + $currentLine = &$lines[$lineCount++]; if (0 >= $maxLineLength) { $maxLineLength = 75; @@ -63,7 +63,7 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder if (0 != strlen($currentLine) && strlen($currentLine.$encodedChar) > $thisLineLength) { $lines[] = ''; - $currentLine = & $lines[$lineCount++]; + $currentLine = &$lines[$lineCount++]; $thisLineLength = $maxLineLength; } $currentLine .= $encodedChar; @@ -83,8 +83,8 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder } /** - * Make a deep copy of object - */ + * Make a deep copy of object. + */ public function __clone() { $this->_charStream = clone $this->_charStream; diff --git a/tools/swift/classes/Swift/Encoder/index.php b/tools/swift/classes/Swift/Encoder/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Encoder/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Encoding.php b/tools/swift/classes/Swift/Encoding.php new file mode 100644 index 000000000..245878706 --- /dev/null +++ b/tools/swift/classes/Swift/Encoding.php @@ -0,0 +1,62 @@ +lookup($key); + } +} diff --git a/tools/swift/classes/Swift/Events/CommandEvent.php b/tools/swift/classes/Swift/Events/CommandEvent.php index 670f4d3d8..674e6b5e4 100644 --- a/tools/swift/classes/Swift/Events/CommandEvent.php +++ b/tools/swift/classes/Swift/Events/CommandEvent.php @@ -11,7 +11,7 @@ /** * Generated when a command is sent over an SMTP connection. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_CommandEvent extends Swift_Events_EventObject { @@ -25,7 +25,7 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject /** * An array of codes which a successful response will contain. * - * @var integer[] + * @var int[] */ private $_successCodes = array(); @@ -56,7 +56,7 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject /** * Get the numeric response codes which indicate success for this command. * - * @return integer[] + * @return int[] */ public function getSuccessCodes() { diff --git a/tools/swift/classes/Swift/Events/CommandListener.php b/tools/swift/classes/Swift/Events/CommandListener.php index 3465c8d68..7545404e7 100644 --- a/tools/swift/classes/Swift/Events/CommandListener.php +++ b/tools/swift/classes/Swift/Events/CommandListener.php @@ -11,7 +11,7 @@ /** * Listens for Transports to send commands to the server. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_CommandListener extends Swift_Events_EventListener { diff --git a/tools/swift/classes/Swift/Events/Event.php b/tools/swift/classes/Swift/Events/Event.php index ffd9bed1b..720b15637 100644 --- a/tools/swift/classes/Swift/Events/Event.php +++ b/tools/swift/classes/Swift/Events/Event.php @@ -11,7 +11,7 @@ /** * The minimum interface for an Event. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_Event { @@ -25,7 +25,7 @@ interface Swift_Events_Event /** * Prevent this Event from bubbling any further up the stack. * - * @param bool $cancel, optional + * @param bool $cancel, optional */ public function cancelBubble($cancel = true); diff --git a/tools/swift/classes/Swift/Events/EventDispatcher.php b/tools/swift/classes/Swift/Events/EventDispatcher.php index c62c5e429..aac36aaa7 100644 --- a/tools/swift/classes/Swift/Events/EventDispatcher.php +++ b/tools/swift/classes/Swift/Events/EventDispatcher.php @@ -11,7 +11,7 @@ /** * Interface for the EventDispatcher which handles the event dispatching layer. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_EventDispatcher { diff --git a/tools/swift/classes/Swift/Events/EventListener.php b/tools/swift/classes/Swift/Events/EventListener.php index 751ec678c..512909541 100644 --- a/tools/swift/classes/Swift/Events/EventListener.php +++ b/tools/swift/classes/Swift/Events/EventListener.php @@ -11,7 +11,7 @@ /** * An identity interface which all EventListeners must extend. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_EventListener { diff --git a/tools/swift/classes/Swift/Events/EventObject.php b/tools/swift/classes/Swift/Events/EventObject.php index 50b6be6a8..90694a9a6 100644 --- a/tools/swift/classes/Swift/Events/EventObject.php +++ b/tools/swift/classes/Swift/Events/EventObject.php @@ -11,7 +11,7 @@ /** * A base Event which all Event classes inherit from. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_EventObject implements Swift_Events_Event { @@ -44,7 +44,7 @@ class Swift_Events_EventObject implements Swift_Events_Event /** * Prevent this Event from bubbling any further up the stack. * - * @param bool $cancel, optional + * @param bool $cancel, optional */ public function cancelBubble($cancel = true) { diff --git a/tools/swift/classes/Swift/Events/ResponseEvent.php b/tools/swift/classes/Swift/Events/ResponseEvent.php index b0ac1a8f5..2e92ba940 100644 --- a/tools/swift/classes/Swift/Events/ResponseEvent.php +++ b/tools/swift/classes/Swift/Events/ResponseEvent.php @@ -11,7 +11,7 @@ /** * Generated when a response is received on a SMTP connection. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_ResponseEvent extends Swift_Events_EventObject { diff --git a/tools/swift/classes/Swift/Events/ResponseListener.php b/tools/swift/classes/Swift/Events/ResponseListener.php index 9629f1e5b..c40919d21 100644 --- a/tools/swift/classes/Swift/Events/ResponseListener.php +++ b/tools/swift/classes/Swift/Events/ResponseListener.php @@ -11,7 +11,7 @@ /** * Listens for responses from a remote SMTP server. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_ResponseListener extends Swift_Events_EventListener { diff --git a/tools/swift/classes/Swift/Events/SendEvent.php b/tools/swift/classes/Swift/Events/SendEvent.php index 0d3b4141b..10da8080f 100644 --- a/tools/swift/classes/Swift/Events/SendEvent.php +++ b/tools/swift/classes/Swift/Events/SendEvent.php @@ -11,13 +11,16 @@ /** * Generated when a message is being sent. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_SendEvent extends Swift_Events_EventObject { /** Sending has yet to occur */ const RESULT_PENDING = 0x0001; + /** Email is spooled, ready to be sent */ + const RESULT_SPOOLED = 0x0011; + /** Sending was successful */ const RESULT_SUCCESS = 0x0010; @@ -104,7 +107,7 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject /** * Set the result of sending. * - * @param int $result + * @param int $result */ public function setResult($result) { diff --git a/tools/swift/classes/Swift/Events/SendListener.php b/tools/swift/classes/Swift/Events/SendListener.php index 7d35f18e0..d922e1bfa 100644 --- a/tools/swift/classes/Swift/Events/SendListener.php +++ b/tools/swift/classes/Swift/Events/SendListener.php @@ -11,7 +11,7 @@ /** * Listens for Messages being sent from within the Transport system. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_SendListener extends Swift_Events_EventListener { diff --git a/tools/swift/classes/Swift/Events/SimpleEventDispatcher.php b/tools/swift/classes/Swift/Events/SimpleEventDispatcher.php index a38f7aae8..e8aca752f 100644 --- a/tools/swift/classes/Swift/Events/SimpleEventDispatcher.php +++ b/tools/swift/classes/Swift/Events/SimpleEventDispatcher.php @@ -11,7 +11,7 @@ /** * The EventDispatcher which handles the event dispatching layer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher { diff --git a/tools/swift/classes/Swift/Events/TransportChangeEvent.php b/tools/swift/classes/Swift/Events/TransportChangeEvent.php index 23c829702..a8972fda9 100644 --- a/tools/swift/classes/Swift/Events/TransportChangeEvent.php +++ b/tools/swift/classes/Swift/Events/TransportChangeEvent.php @@ -11,7 +11,7 @@ /** * Generated when the state of a Transport is changed (i.e. stopped/started). * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_TransportChangeEvent extends Swift_Events_EventObject { diff --git a/tools/swift/classes/Swift/Events/TransportChangeListener.php b/tools/swift/classes/Swift/Events/TransportChangeListener.php index 0edfe377b..253165de8 100644 --- a/tools/swift/classes/Swift/Events/TransportChangeListener.php +++ b/tools/swift/classes/Swift/Events/TransportChangeListener.php @@ -11,7 +11,7 @@ /** * Listens for changes within the Transport system. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_TransportChangeListener extends Swift_Events_EventListener { diff --git a/tools/swift/classes/Swift/Events/TransportExceptionEvent.php b/tools/swift/classes/Swift/Events/TransportExceptionEvent.php index b2c72ca18..f87154fb9 100644 --- a/tools/swift/classes/Swift/Events/TransportExceptionEvent.php +++ b/tools/swift/classes/Swift/Events/TransportExceptionEvent.php @@ -11,7 +11,7 @@ /** * Generated when a TransportException is thrown from the Transport system. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject { diff --git a/tools/swift/classes/Swift/Events/TransportExceptionListener.php b/tools/swift/classes/Swift/Events/TransportExceptionListener.php index f153742cf..cc3c09937 100644 --- a/tools/swift/classes/Swift/Events/TransportExceptionListener.php +++ b/tools/swift/classes/Swift/Events/TransportExceptionListener.php @@ -11,7 +11,7 @@ /** * Listens for Exceptions thrown from within the Transport system. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Events_TransportExceptionListener extends Swift_Events_EventListener { diff --git a/tools/swift/classes/Swift/Events/index.php b/tools/swift/classes/Swift/Events/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Events/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/FailoverTransport.php b/tools/swift/classes/Swift/FailoverTransport.php index 6fa5fc70f..9951c5977 100644 --- a/tools/swift/classes/Swift/FailoverTransport.php +++ b/tools/swift/classes/Swift/FailoverTransport.php @@ -11,7 +11,7 @@ /** * Contains a list of redundant Transports so when one fails, the next is used. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_FailoverTransport extends Swift_Transport_FailoverTransport { @@ -36,7 +36,7 @@ class Swift_FailoverTransport extends Swift_Transport_FailoverTransport * * @param Swift_Transport[] $transports * - * @return Swift_FailoverTransport + * @return self */ public static function newInstance($transports = array()) { diff --git a/tools/swift/classes/Swift/FileSpool.php b/tools/swift/classes/Swift/FileSpool.php index b30f9f85a..c82c5dbf1 100644 --- a/tools/swift/classes/Swift/FileSpool.php +++ b/tools/swift/classes/Swift/FileSpool.php @@ -11,8 +11,8 @@ /** * Stores Messages on the filesystem. * - * @author Fabien Potencier - * @author Xavier De Cock + * @author Fabien Potencier + * @author Xavier De Cock */ class Swift_FileSpool extends Swift_ConfigurableSpool { @@ -20,7 +20,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool private $_path; /** - * File WriteRetry Limit + * File WriteRetry Limit. * * @var int */ @@ -39,7 +39,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool if (!file_exists($this->_path)) { if (!mkdir($this->_path, 0777, true)) { - throw new Swift_IoException('Unable to create Path ['.$this->_path.']'); + throw new Swift_IoException(sprintf('Unable to create path "%s".', $this->_path)); } } } @@ -73,7 +73,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool * * Default, is ten and allows over 64^20 different fileNames * - * @param int $limit + * @param int $limit */ public function setRetryLimit($limit) { @@ -85,9 +85,9 @@ class Swift_FileSpool extends Swift_ConfigurableSpool * * @param Swift_Mime_Message $message The message to store * - * @return bool - * * @throws Swift_IoException + * + * @return bool */ public function queueMessage(Swift_Mime_Message $message) { @@ -108,23 +108,23 @@ class Swift_FileSpool extends Swift_ConfigurableSpool } } - throw new Swift_IoException('Unable to create a file for enqueuing Message'); + throw new Swift_IoException(sprintf('Unable to create a file for enqueuing Message in "%s".', $this->_path)); } /** * Execute a recovery if for any reason a process is sending for too long. * - * @param int $timeout in second Defaults is for very slow smtp responses + * @param int $timeout in second Defaults is for very slow smtp responses */ public function recover($timeout = 900) { foreach (new DirectoryIterator($this->_path) as $file) { $file = $file->getRealPath(); - if (substr($file, - 16) == '.message.sending') { + if (substr($file, -16) == '.message.sending') { $lockedtime = filectime($file); if ((time() - $lockedtime) > $timeout) { - rename($file, substr($file, 0, - 8)); + rename($file, substr($file, 0, -8)); } } } @@ -136,7 +136,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool * @param Swift_Transport $transport A transport instance * @param string[] $failedRecipients An array of failures by-reference * - * @return int The number of sent e-mail's + * @return int The number of sent e-mail's */ public function flushQueue(Swift_Transport $transport, &$failedRecipients = null) { @@ -189,14 +189,14 @@ class Swift_FileSpool extends Swift_ConfigurableSpool /** * Returns a random string needed to generate a fileName for the queue. * - * @param int $count + * @param int $count * * @return string */ protected function getRandomString($count) { // This string MUST stay FS safe, avoid special chars - $base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-."; + $base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; $ret = ''; $strlen = strlen($base); for ($i = 0; $i < $count; ++$i) { diff --git a/tools/swift/classes/Swift/FileStream.php b/tools/swift/classes/Swift/FileStream.php index 802cb4305..0b24db1ce 100644 --- a/tools/swift/classes/Swift/FileStream.php +++ b/tools/swift/classes/Swift/FileStream.php @@ -11,7 +11,7 @@ /** * An OutputByteStream which specifically reads from a file. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_FileStream extends Swift_OutputByteStream { diff --git a/tools/swift/classes/Swift/Filterable.php b/tools/swift/classes/Swift/Filterable.php index 1f664de8f..6b75b5274 100644 --- a/tools/swift/classes/Swift/Filterable.php +++ b/tools/swift/classes/Swift/Filterable.php @@ -11,7 +11,7 @@ /** * Allows StreamFilters to operate on a stream. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Filterable { diff --git a/tools/swift/classes/Swift/Image.php b/tools/swift/classes/Swift/Image.php index 966bee72f..4213ee27e 100644 --- a/tools/swift/classes/Swift/Image.php +++ b/tools/swift/classes/Swift/Image.php @@ -11,7 +11,7 @@ /** * An image, embedded in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Image extends Swift_EmbeddedFile { @@ -36,7 +36,7 @@ class Swift_Image extends Swift_EmbeddedFile * @param string $filename * @param string $contentType * - * @return Swift_Image + * @return self */ public static function newInstance($data = null, $filename = null, $contentType = null) { @@ -48,14 +48,10 @@ class Swift_Image extends Swift_EmbeddedFile * * @param string $path * - * @return Swift_Image + * @return self */ public static function fromPath($path) { - $image = self::newInstance()->setFile( - new Swift_ByteStream_FileByteStream($path) - ); - - return $image; + return self::newInstance()->setFile(new Swift_ByteStream_FileByteStream($path)); } } diff --git a/tools/swift/classes/Swift/InputByteStream.php b/tools/swift/classes/Swift/InputByteStream.php index fd45ab93b..56efc7593 100644 --- a/tools/swift/classes/Swift/InputByteStream.php +++ b/tools/swift/classes/Swift/InputByteStream.php @@ -14,7 +14,7 @@ * Classes implementing this interface may use a subsystem which requires less * memory than working with large strings of data. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_InputByteStream { @@ -30,9 +30,9 @@ interface Swift_InputByteStream * * @param string $bytes * - * @return int - * * @throws Swift_IoException + * + * @return int */ public function write($bytes); diff --git a/tools/swift/classes/Swift/IoException.php b/tools/swift/classes/Swift/IoException.php index 75698f9a2..c405f352b 100644 --- a/tools/swift/classes/Swift/IoException.php +++ b/tools/swift/classes/Swift/IoException.php @@ -11,17 +11,19 @@ /** * I/O Exception class. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_IoException extends Swift_SwiftException { /** * Create a new IoException with $message. * - * @param string $message + * @param string $message + * @param int $code + * @param Exception $previous */ - public function __construct($message) + public function __construct($message, $code = 0, Exception $previous = null) { - parent::__construct($message); + parent::__construct($message, $code, $previous); } } diff --git a/tools/swift/classes/Swift/KeyCache.php b/tools/swift/classes/Swift/KeyCache.php index a16a90bd6..cd6f786df 100644 --- a/tools/swift/classes/Swift/KeyCache.php +++ b/tools/swift/classes/Swift/KeyCache.php @@ -11,7 +11,7 @@ /** * Provides a mechanism for storing data using two keys. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_KeyCache { @@ -26,10 +26,10 @@ interface Swift_KeyCache * * @see MODE_WRITE, MODE_APPEND * - * @param string $nsKey - * @param string $itemKey - * @param string $string - * @param int $mode + * @param string $nsKey + * @param string $itemKey + * @param string $string + * @param int $mode */ public function setString($nsKey, $itemKey, $string, $mode); diff --git a/tools/swift/classes/Swift/KeyCache/ArrayKeyCache.php b/tools/swift/classes/Swift/KeyCache/ArrayKeyCache.php index 71a32819b..b37f07f74 100644 --- a/tools/swift/classes/Swift/KeyCache/ArrayKeyCache.php +++ b/tools/swift/classes/Swift/KeyCache/ArrayKeyCache.php @@ -11,7 +11,7 @@ /** * A basic KeyCache backed by an array. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache { @@ -45,10 +45,10 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache * * @see MODE_WRITE, MODE_APPEND * - * @param string $nsKey - * @param string $itemKey - * @param string $string - * @param int $mode + * @param string $nsKey + * @param string $itemKey + * @param string $string + * @param int $mode */ public function setString($nsKey, $itemKey, $string, $mode) { diff --git a/tools/swift/classes/Swift/KeyCache/DiskKeyCache.php b/tools/swift/classes/Swift/KeyCache/DiskKeyCache.php index 5a7096255..453f50a15 100644 --- a/tools/swift/classes/Swift/KeyCache/DiskKeyCache.php +++ b/tools/swift/classes/Swift/KeyCache/DiskKeyCache.php @@ -11,7 +11,7 @@ /** * A KeyCache which streams to and from disk. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache { @@ -74,10 +74,10 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache * * @see MODE_WRITE, MODE_APPEND * - * @param string $nsKey - * @param string $itemKey - * @param string $string - * @param int $mode + * @param string $nsKey + * @param string $itemKey + * @param string $string + * @param int $mode * * @throws Swift_IoException */ @@ -167,9 +167,9 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache * @param string $nsKey * @param string $itemKey * - * @return string - * * @throws Swift_IoException + * + * @return string */ public function getString($nsKey, $itemKey) { @@ -280,19 +280,16 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache /** * Get a file handle on the cache item. * - * @param string $nsKey - * @param string $itemKey - * @param int $position + * @param string $nsKey + * @param string $itemKey + * @param int $position * * @return resource */ private function _getHandle($nsKey, $itemKey, $position) { if (!isset($this->_keys[$nsKey][$itemKey])) { - $openMode = $this->hasKey($nsKey, $itemKey) - ? 'r+b' - : 'w+b' - ; + $openMode = $this->hasKey($nsKey, $itemKey) ? 'r+b' : 'w+b'; $fp = fopen($this->_path.'/'.$nsKey.'/'.$itemKey, $openMode); $this->_keys[$nsKey][$itemKey] = $fp; } diff --git a/tools/swift/classes/Swift/KeyCache/KeyCacheInputStream.php b/tools/swift/classes/Swift/KeyCache/KeyCacheInputStream.php index 76039d8a1..af80bdca6 100644 --- a/tools/swift/classes/Swift/KeyCache/KeyCacheInputStream.php +++ b/tools/swift/classes/Swift/KeyCache/KeyCacheInputStream.php @@ -11,7 +11,7 @@ /** * Writes data to a KeyCache using a stream. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_KeyCache_KeyCacheInputStream extends Swift_InputByteStream { diff --git a/tools/swift/classes/Swift/KeyCache/NullKeyCache.php b/tools/swift/classes/Swift/KeyCache/NullKeyCache.php index 79ab89fc6..4efe78564 100644 --- a/tools/swift/classes/Swift/KeyCache/NullKeyCache.php +++ b/tools/swift/classes/Swift/KeyCache/NullKeyCache.php @@ -11,7 +11,7 @@ /** * A null KeyCache that does not cache at all. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_KeyCache_NullKeyCache implements Swift_KeyCache { @@ -20,10 +20,10 @@ class Swift_KeyCache_NullKeyCache implements Swift_KeyCache * * @see MODE_WRITE, MODE_APPEND * - * @param string $nsKey - * @param string $itemKey - * @param string $string - * @param int $mode + * @param string $nsKey + * @param string $itemKey + * @param string $string + * @param int $mode */ public function setString($nsKey, $itemKey, $string, $mode) { diff --git a/tools/swift/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php b/tools/swift/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php index e829c8fdb..b00d458a6 100644 --- a/tools/swift/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php +++ b/tools/swift/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php @@ -11,7 +11,7 @@ /** * Writes data to a KeyCache using a stream. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCacheInputStream { diff --git a/tools/swift/classes/Swift/KeyCache/index.php b/tools/swift/classes/Swift/KeyCache/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/KeyCache/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/LoadBalancedTransport.php b/tools/swift/classes/Swift/LoadBalancedTransport.php index 6e1080b9f..e151b8a9c 100644 --- a/tools/swift/classes/Swift/LoadBalancedTransport.php +++ b/tools/swift/classes/Swift/LoadBalancedTransport.php @@ -11,7 +11,7 @@ /** * Redundantly and rotationally uses several Transport implementations when sending. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport { @@ -36,7 +36,7 @@ class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport * * @param array $transports * - * @return Swift_LoadBalancedTransport + * @return self */ public static function newInstance($transports = array()) { diff --git a/tools/swift/classes/Swift/MailTransport.php b/tools/swift/classes/Swift/MailTransport.php index a6d3340d8..18556989a 100644 --- a/tools/swift/classes/Swift/MailTransport.php +++ b/tools/swift/classes/Swift/MailTransport.php @@ -11,7 +11,9 @@ /** * Sends Messages using the mail() function. * - * @author Chris Corbyn + * @author Chris Corbyn + * + * @deprecated since 5.4.5 (to be removed in 6.0) */ class Swift_MailTransport extends Swift_Transport_MailTransport { @@ -36,7 +38,7 @@ class Swift_MailTransport extends Swift_Transport_MailTransport * * @param string $extraParams To be passed to mail() * - * @return Swift_MailTransport + * @return self */ public static function newInstance($extraParams = '-f%s') { diff --git a/tools/swift/classes/Swift/Mailer.php b/tools/swift/classes/Swift/Mailer.php index 5677fcb4f..8314fe8fc 100644 --- a/tools/swift/classes/Swift/Mailer.php +++ b/tools/swift/classes/Swift/Mailer.php @@ -11,7 +11,7 @@ /** * Swift Mailer class. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mailer { @@ -33,7 +33,7 @@ class Swift_Mailer * * @param Swift_Transport $transport * - * @return Swift_Mailer + * @return self */ public static function newInstance(Swift_Transport $transport) { @@ -69,7 +69,7 @@ class Swift_Mailer * @param Swift_Mime_Message $message * @param array $failedRecipients An array of failures by-reference * - * @return int + * @return int The number of successful recipients. Can be 0 which indicates failure */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { diff --git a/tools/swift/classes/Swift/Mailer/ArrayRecipientIterator.php b/tools/swift/classes/Swift/Mailer/ArrayRecipientIterator.php index d02e1846b..e3e6cad05 100644 --- a/tools/swift/classes/Swift/Mailer/ArrayRecipientIterator.php +++ b/tools/swift/classes/Swift/Mailer/ArrayRecipientIterator.php @@ -11,7 +11,7 @@ /** * Wraps a standard PHP array in an iterator. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientIterator { @@ -44,7 +44,7 @@ class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientItera /** * Returns an array where the keys are the addresses of recipients and the - * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL) + * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL). * * @return array */ diff --git a/tools/swift/classes/Swift/Mailer/RecipientIterator.php b/tools/swift/classes/Swift/Mailer/RecipientIterator.php index a935c563f..650f3ec3d 100644 --- a/tools/swift/classes/Swift/Mailer/RecipientIterator.php +++ b/tools/swift/classes/Swift/Mailer/RecipientIterator.php @@ -11,7 +11,7 @@ /** * Provides an abstract way of specifying recipients for batch sending. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mailer_RecipientIterator { @@ -24,7 +24,7 @@ interface Swift_Mailer_RecipientIterator /** * Returns an array where the keys are the addresses of recipients and the - * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL) + * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL). * * @return array */ diff --git a/tools/swift/classes/Swift/Mailer/index.php b/tools/swift/classes/Swift/Mailer/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Mailer/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/MemorySpool.php b/tools/swift/classes/Swift/MemorySpool.php index 590fc4881..2cafb6751 100644 --- a/tools/swift/classes/Swift/MemorySpool.php +++ b/tools/swift/classes/Swift/MemorySpool.php @@ -11,11 +11,12 @@ /** * Stores Messages in memory. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_MemorySpool implements Swift_Spool { protected $messages = array(); + private $flushRetries = 3; /** * Tests if this Transport mechanism has started. @@ -41,12 +42,20 @@ class Swift_MemorySpool implements Swift_Spool { } + /** + * @param int $retries + */ + public function setFlushRetries($retries) + { + $this->flushRetries = $retries; + } + /** * Stores a message in the queue. * * @param Swift_Mime_Message $message The message to store * - * @return bool Whether the operation has succeeded + * @return bool Whether the operation has succeeded */ public function queueMessage(Swift_Mime_Message $message) { @@ -62,7 +71,7 @@ class Swift_MemorySpool implements Swift_Spool * @param Swift_Transport $transport A transport instance * @param string[] $failedRecipients An array of failures by-reference * - * @return int The number of sent emails + * @return int The number of sent emails */ public function flushQueue(Swift_Transport $transport, &$failedRecipients = null) { @@ -75,8 +84,25 @@ class Swift_MemorySpool implements Swift_Spool } $count = 0; - while ($message = array_pop($this->messages)) { - $count += $transport->send($message, $failedRecipients); + $retries = $this->flushRetries; + while ($retries--) { + try { + while ($message = array_pop($this->messages)) { + $count += $transport->send($message, $failedRecipients); + } + } catch (Swift_TransportException $exception) { + if ($retries) { + // re-queue the message at the end of the queue to give a chance + // to the other messages to be sent, in case the failure was due to + // this message and not just the transport failing + array_unshift($this->messages, $message); + + // wait half a second before we try again + usleep(500000); + } else { + throw $exception; + } + } } return $count; diff --git a/tools/swift/classes/Swift/Message.php b/tools/swift/classes/Swift/Message.php index 8112d96ef..242cbf314 100644 --- a/tools/swift/classes/Swift/Message.php +++ b/tools/swift/classes/Swift/Message.php @@ -11,7 +11,7 @@ /** * The Message class for building emails. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Message extends Swift_Mime_SimpleMessage { @@ -68,7 +68,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage * @param string $contentType * @param string $charset * - * @return Swift_Message + * @return $this */ public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null) { @@ -82,20 +82,19 @@ class Swift_Message extends Swift_Mime_SimpleMessage * @param string $contentType * @param string $charset * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function addPart($body, $contentType = null, $charset = null) { - return $this->attach(Swift_MimePart::newInstance( - $body, $contentType, $charset - )); + return $this->attach(Swift_MimePart::newInstance($body, $contentType, $charset)->setEncoder($this->getEncoder())); } /** - * Attach a new signature handler to the message. + * Detach a signature handler from a message. * * @param Swift_Signer $signer - * @return Swift_Message + * + * @return $this */ public function attachSigner(Swift_Signer $signer) { @@ -112,7 +111,8 @@ class Swift_Message extends Swift_Mime_SimpleMessage * Attach a new signature handler to the message. * * @param Swift_Signer $signer - * @return Swift_Message + * + * @return $this */ public function detachSigner(Swift_Signer $signer) { @@ -187,7 +187,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * loops through signers and apply the signatures + * loops through signers and apply the signatures. */ protected function doSign() { @@ -213,7 +213,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * save the message before any signature is applied + * save the message before any signature is applied. */ protected function saveMessage() { @@ -227,7 +227,8 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * save the original headers + * save the original headers. + * * @param array $altered */ protected function saveHeaders(array $altered) @@ -242,7 +243,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * Remove or restore altered headers + * Remove or restore altered headers. */ protected function restoreHeaders() { @@ -258,7 +259,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * Restore message body + * Restore message body. */ protected function restoreMessage() { @@ -268,4 +269,21 @@ class Swift_Message extends Swift_Mime_SimpleMessage $this->restoreHeaders(); $this->savedMessage = array(); } + + /** + * Clone Message Signers. + * + * @see Swift_Mime_SimpleMimeEntity::__clone() + */ + public function __clone() + { + parent::__clone(); + foreach ($this->bodySigners as $key => $bodySigner) { + $this->bodySigners[$key] = clone $bodySigner; + } + + foreach ($this->headerSigners as $key => $headerSigner) { + $this->headerSigners[$key] = clone $headerSigner; + } + } } diff --git a/tools/swift/classes/Swift/Mime/Attachment.php b/tools/swift/classes/Swift/Mime/Attachment.php index d9d965297..d5ba14b91 100644 --- a/tools/swift/classes/Swift/Mime/Attachment.php +++ b/tools/swift/classes/Swift/Mime/Attachment.php @@ -11,7 +11,7 @@ /** * An attachment, in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity { @@ -64,14 +64,12 @@ 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)) { - $this->getHeaders()->addParameterizedHeader( - 'Content-Disposition', $disposition - ); + $this->getHeaders()->addParameterizedHeader('Content-Disposition', $disposition); } return $this; @@ -92,7 +90,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity * * @param string $filename * - * @return Swift_Mime_Attachment + * @return $this */ public function setFilename($filename) { @@ -115,9 +113,9 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity /** * Set the file size of this attachment. * - * @param int $size + * @param int $size * - * @return Swift_Mime_Attachment + * @return $this */ public function setSize($size) { @@ -132,16 +130,14 @@ 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) { $this->setFilename(basename($file->getPath())); $this->setBody($file, $contentType); if (!isset($contentType)) { - $extension = strtolower(substr( - $file->getPath(), strrpos($file->getPath(), '.') + 1 - )); + $extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1)); if (array_key_exists($extension, $this->_mimeTypes)) { $this->setContentType($this->_mimeTypes[$extension]); diff --git a/tools/swift/classes/Swift/Mime/CharsetObserver.php b/tools/swift/classes/Swift/Mime/CharsetObserver.php index 57d8bc465..b49c3a873 100644 --- a/tools/swift/classes/Swift/Mime/CharsetObserver.php +++ b/tools/swift/classes/Swift/Mime/CharsetObserver.php @@ -11,7 +11,7 @@ /** * Observes changes in an Mime entity's character set. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_CharsetObserver { diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder.php b/tools/swift/classes/Swift/Mime/ContentEncoder.php index 3338b629f..d43ea9f40 100644 --- a/tools/swift/classes/Swift/Mime/ContentEncoder.php +++ b/tools/swift/classes/Swift/Mime/ContentEncoder.php @@ -11,7 +11,7 @@ /** * Interface for all Transfer Encoding schemes. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_ContentEncoder extends Swift_Encoder { diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php b/tools/swift/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php index fffbf0487..8f76d70f3 100644 --- a/tools/swift/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php +++ b/tools/swift/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php @@ -11,7 +11,7 @@ /** * Handles Base 64 Transfer Encoding in Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_ContentEncoder { @@ -30,9 +30,42 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 } $remainder = 0; + $base64ReadBufferRemainderBytes = null; - while (false !== $bytes = $os->read(8190)) { - $encoded = base64_encode($bytes); + // To reduce memory usage, the output buffer is streamed to the input buffer like so: + // Output Stream => base64encode => wrap line length => Input Stream + // HOWEVER it's important to note that base64_encode() should only be passed whole triplets of data (except for the final chunk of data) + // otherwise it will assume the input data has *ended* and it will incorrectly pad/terminate the base64 data mid-stream. + // We use $base64ReadBufferRemainderBytes to carry over 1-2 "remainder" bytes from the each chunk from OutputStream and pre-pend those onto the + // chunk of bytes read in the next iteration. + // When the OutputStream is empty, we must flush any remainder bytes. + while (true) { + $readBytes = $os->read(8192); + $atEOF = ($readBytes === false); + + if ($atEOF) { + $streamTheseBytes = $base64ReadBufferRemainderBytes; + } else { + $streamTheseBytes = $base64ReadBufferRemainderBytes.$readBytes; + } + $base64ReadBufferRemainderBytes = null; + $bytesLength = strlen($streamTheseBytes); + + if ($bytesLength === 0) { // no data left to encode + break; + } + + // if we're not on the last block of the ouput stream, make sure $streamTheseBytes ends with a complete triplet of data + // and carry over remainder 1-2 bytes to the next loop iteration + if (!$atEOF) { + $excessBytes = $bytesLength % 3; + if ($excessBytes !== 0) { + $base64ReadBufferRemainderBytes = substr($streamTheseBytes, -$excessBytes); + $streamTheseBytes = substr($streamTheseBytes, 0, $bytesLength - $excessBytes); + } + } + + $encoded = base64_encode($streamTheseBytes); $encodedTransformed = ''; $thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset; @@ -51,6 +84,10 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 } $is->write($encodedTransformed); + + if ($atEOF) { + break; + } } } diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php b/tools/swift/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php index e97195a58..710b5ac9e 100644 --- a/tools/swift/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php +++ b/tools/swift/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php @@ -11,7 +11,7 @@ /** * Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer using the PHP core function. * - * @author Lars Strojny + * @author Lars Strojny */ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder { @@ -77,13 +77,13 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con /** * Encode a given string to produce an encoded string. * - * @param string $string - * @param int $firstLineOffset if first line needs to be shorter - * @param int $maxLineLength 0 indicates the default length for this encoding - * - * @return string + * @param string $string + * @param int $firstLineOffset if first line needs to be shorter + * @param int $maxLineLength 0 indicates the default length for this encoding * * @throws RuntimeException + * + * @return string */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) { @@ -107,7 +107,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con // transform CR or LF to CRLF $string = preg_replace('~=0D(?!=0A)|(? $length) { $lines[] = ''; - $currentLine = & $lines[$lineCount++]; + $currentLine = &$lines[$lineCount++]; } $currentLine .= $chunk; } diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php b/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php index 58f05a10d..5cc907b8e 100644 --- a/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php +++ b/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php @@ -11,7 +11,7 @@ /** * 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 { @@ -95,15 +95,26 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder } $enc = $this->_encodeByteSequence($bytes, $size); - if ($currentLine && $lineLen+$size >= $thisLineLength) { + + $i = strpos($enc, '=0D=0A'); + $newLineLength = $lineLen + ($i === false ? $size : $i); + + if ($currentLine && $newLineLength >= $thisLineLength) { $is->write($prepend.$this->_standardize($currentLine)); $currentLine = ''; $prepend = "=\r\n"; $thisLineLength = $maxLineLength; $lineLen = 0; } - $lineLen += $size; + $currentLine .= $enc; + + if ($i === false) { + $lineLen += $size; + } else { + // 6 is the length of '=0D=0A'. + $lineLen = $size - strrpos($enc, '=0D=0A') - 6; + } } if (strlen($currentLine)) { $is->write($prepend.$this->_standardize($currentLine)); diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php b/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php index d6e8d7c32..3214e1cf3 100644 --- a/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php +++ b/tools/swift/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php @@ -13,7 +13,7 @@ * * Switches on the best QP encoder implementation for current charset. * - * @author Jean-François Simon + * @author Jean-François Simon */ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_ContentEncoder { @@ -47,7 +47,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont } /** - * Make a deep copy of object + * Make a deep copy of object. */ public function __clone() { @@ -61,6 +61,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont public function charsetChanged($charset) { $this->charset = $charset; + $this->safeEncoder->charsetChanged($charset); } /** diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php b/tools/swift/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php index f717dc789..0b8526e38 100644 --- a/tools/swift/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php +++ b/tools/swift/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php @@ -12,16 +12,17 @@ * Handles raw Transfer Encoding in Swift Mailer. * * - * @author Sebastiaan Stok + * @author Sebastiaan Stok */ class Swift_Mime_ContentEncoder_RawContentEncoder implements Swift_Mime_ContentEncoder { /** * Encode a given string to produce an encoded string. * - * @param string $string - * @param int $firstLineOffset ignored - * @param int $maxLineLength ignored + * @param string $string + * @param int $firstLineOffset ignored + * @param int $maxLineLength ignored + * * @return string */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) diff --git a/tools/swift/classes/Swift/Mime/ContentEncoder/index.php b/tools/swift/classes/Swift/Mime/ContentEncoder/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Mime/ContentEncoder/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Mime/EmbeddedFile.php b/tools/swift/classes/Swift/Mime/EmbeddedFile.php index ec1ef535f..6af757124 100644 --- a/tools/swift/classes/Swift/Mime/EmbeddedFile.php +++ b/tools/swift/classes/Swift/Mime/EmbeddedFile.php @@ -11,7 +11,7 @@ /** * An embedded file, in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment { diff --git a/tools/swift/classes/Swift/Mime/EncodingObserver.php b/tools/swift/classes/Swift/Mime/EncodingObserver.php index e262974bb..cc44a6efb 100644 --- a/tools/swift/classes/Swift/Mime/EncodingObserver.php +++ b/tools/swift/classes/Swift/Mime/EncodingObserver.php @@ -11,7 +11,7 @@ /** * Observes changes for a Mime entity's ContentEncoder. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_EncodingObserver { diff --git a/tools/swift/classes/Swift/Mime/Grammar.php b/tools/swift/classes/Swift/Mime/Grammar.php index 6bd280160..a09f33831 100644 --- a/tools/swift/classes/Swift/Mime/Grammar.php +++ b/tools/swift/classes/Swift/Mime/Grammar.php @@ -129,11 +129,11 @@ class Swift_Mime_Grammar { if (array_key_exists($name, self::$_grammar)) { return self::$_grammar[$name]; - } else { - throw new Swift_RfcComplianceException( - "No such grammar '".$name."' defined." - ); } + + throw new Swift_RfcComplianceException( + "No such grammar '".$name."' defined." + ); } /** diff --git a/tools/swift/classes/Swift/Mime/Header.php b/tools/swift/classes/Swift/Mime/Header.php index 7074c4f6a..a8ddd2721 100644 --- a/tools/swift/classes/Swift/Mime/Header.php +++ b/tools/swift/classes/Swift/Mime/Header.php @@ -11,7 +11,7 @@ /** * A MIME Header. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_Header { diff --git a/tools/swift/classes/Swift/Mime/HeaderEncoder.php b/tools/swift/classes/Swift/Mime/HeaderEncoder.php index 6e014a1d3..08fd453d6 100644 --- a/tools/swift/classes/Swift/Mime/HeaderEncoder.php +++ b/tools/swift/classes/Swift/Mime/HeaderEncoder.php @@ -11,7 +11,7 @@ /** * Interface for all Header Encoding schemes. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_HeaderEncoder extends Swift_Encoder { diff --git a/tools/swift/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php b/tools/swift/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php index 6dbc6edcd..83a4f2f3b 100644 --- a/tools/swift/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php +++ b/tools/swift/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php @@ -11,7 +11,7 @@ /** * Handles Base64 (B) Header Encoding in Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64Encoder implements Swift_Mime_HeaderEncoder { @@ -32,10 +32,10 @@ class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64E * If the charset is iso-2022-jp, it uses mb_encode_mimeheader instead of * default encodeString, otherwise pass to the parent method. * - * @param string $string string to encode - * @param int $firstLineOffset - * @param int $maxLineLength optional, 0 indicates the default of 76 bytes - * @param string $charset + * @param string $string string to encode + * @param int $firstLineOffset + * @param int $maxLineLength optional, 0 indicates the default of 76 bytes + * @param string $charset * * @return string */ diff --git a/tools/swift/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php b/tools/swift/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php index dd8ff382c..510dd6637 100644 --- a/tools/swift/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php +++ b/tools/swift/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php @@ -11,7 +11,7 @@ /** * Handles Quoted Printable (Q) Header Encoding in Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_HeaderEncoder { @@ -50,9 +50,9 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i /** * Takes an unencoded string and produces a QP encoded string from it. * - * @param string $string string to encode - * @param int $firstLineOffset optional - * @param int $maxLineLength optional, 0 indicates the default of 76 chars + * @param string $string string to encode + * @param int $firstLineOffset optional + * @param int $maxLineLength optional, 0 indicates the default of 76 chars * * @return string */ diff --git a/tools/swift/classes/Swift/Mime/HeaderEncoder/index.php b/tools/swift/classes/Swift/Mime/HeaderEncoder/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Mime/HeaderEncoder/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Mime/HeaderFactory.php b/tools/swift/classes/Swift/Mime/HeaderFactory.php index 423cebcf4..c65f26d72 100644 --- a/tools/swift/classes/Swift/Mime/HeaderFactory.php +++ b/tools/swift/classes/Swift/Mime/HeaderFactory.php @@ -11,7 +11,7 @@ /** * Creates MIME headers. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_HeaderFactory extends Swift_Mime_CharsetObserver { @@ -28,8 +28,8 @@ interface Swift_Mime_HeaderFactory extends Swift_Mime_CharsetObserver /** * Create a new Date header using $timestamp (UNIX time). * - * @param string $name - * @param int $timestamp + * @param string $name + * @param int $timestamp * * @return Swift_Mime_Header */ diff --git a/tools/swift/classes/Swift/Mime/HeaderSet.php b/tools/swift/classes/Swift/Mime/HeaderSet.php index b91406629..1768709e9 100644 --- a/tools/swift/classes/Swift/Mime/HeaderSet.php +++ b/tools/swift/classes/Swift/Mime/HeaderSet.php @@ -11,7 +11,7 @@ /** * A collection of MIME headers. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver { @@ -26,8 +26,8 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver /** * Add a new Date header using $timestamp (UNIX time). * - * @param string $name - * @param int $timestamp + * @param string $name + * @param int $timestamp */ public function addDateHeader($name, $timestamp = null); @@ -69,8 +69,8 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver * * If multiple headers match, the actual one may be specified by $index. * - * @param string $name - * @param int $index + * @param string $name + * @param int $index * * @return bool */ @@ -95,8 +95,8 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver * If multiple headers match, the actual one may be specified by $index. * Returns NULL if none present. * - * @param string $name - * @param int $index + * @param string $name + * @param int $index * * @return Swift_Mime_Header */ @@ -112,19 +112,19 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver public function getAll($name = null); /** - * Return the name of all Headers + * 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 + * @param string $name + * @param int $index */ public function remove($name, $index = 0); @@ -138,7 +138,7 @@ interface Swift_Mime_HeaderSet extends Swift_Mime_CharsetObserver /** * Create a new instance of this HeaderSet. * - * @return Swift_Mime_HeaderSet + * @return self */ public function newInstance(); diff --git a/tools/swift/classes/Swift/Mime/Headers/AbstractHeader.php b/tools/swift/classes/Swift/Mime/Headers/AbstractHeader.php index 0ccf27bb9..3a6d7b39e 100644 --- a/tools/swift/classes/Swift/Mime/Headers/AbstractHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/AbstractHeader.php @@ -11,7 +11,7 @@ /** * An abstract base MIME Header. * - * @author Chris Corbyn + * @author Chris Corbyn */ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header { @@ -177,7 +177,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Set the maximum length of lines in the header (excluding EOL). * - * @param int $lineLength + * @param int $lineLength */ public function setMaxLineLength($lineLength) { @@ -198,9 +198,9 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Get this Header rendered as a RFC 2822 compliant string. * - * @return string - * * @throws Swift_RfcComplianceException + * + * @return string */ public function toString() { @@ -219,8 +219,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header return $this->toString(); } - // -- Points of extension - /** * Set the name of this Header field. * @@ -357,8 +355,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Get a token as an encoded word for safe insertion into headers. * - * @param string $token token to encode - * @param int $firstLineOffset optional + * @param string $token token to encode + * @param int $firstLineOffset optional * * @return string */ @@ -431,7 +429,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Clear the cached value if $condition is met. * - * @param bool $condition + * @param bool $condition */ protected function clearCachedValueIf($condition) { @@ -449,7 +447,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(); } @@ -479,7 +477,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header $lineCount = 0; $headerLines = array(); $headerLines[] = $this->_name.': '; - $currentLine = & $headerLines[$lineCount++]; + $currentLine = &$headerLines[$lineCount++]; // Build all tokens back into compliant header foreach ($tokens as $i => $token) { @@ -488,7 +486,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header ($i > 0 && strlen($currentLine.$token) > $this->_lineLength) && 0 < strlen($currentLine)) { $headerLines[] = ''; - $currentLine = & $headerLines[$lineCount++]; + $currentLine = &$headerLines[$lineCount++]; } // Append token to the line diff --git a/tools/swift/classes/Swift/Mime/Headers/DateHeader.php b/tools/swift/classes/Swift/Mime/Headers/DateHeader.php index a1093fb08..4075cbfa1 100644 --- a/tools/swift/classes/Swift/Mime/Headers/DateHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/DateHeader.php @@ -11,7 +11,7 @@ /** * A Date MIME Header for Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader { @@ -59,7 +59,7 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader * * This method takes a UNIX timestamp. * - * @param int $model + * @param int $model */ public function setFieldBodyModel($model) { @@ -91,11 +91,11 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader /** * Set the UNIX timestamp of the Date in this Header. * - * @param int $timestamp + * @param int $timestamp */ public function setTimestamp($timestamp) { - if (!is_null($timestamp)) { + if (null !== $timestamp) { $timestamp = (int) $timestamp; } $this->clearCachedValueIf($this->_timestamp != $timestamp); diff --git a/tools/swift/classes/Swift/Mime/Headers/IdentificationHeader.php b/tools/swift/classes/Swift/Mime/Headers/IdentificationHeader.php index 1a5a3dd92..b114506b4 100644 --- a/tools/swift/classes/Swift/Mime/Headers/IdentificationHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/IdentificationHeader.php @@ -11,7 +11,7 @@ /** * An ID MIME Header for something like Message-ID or Content-ID. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_AbstractHeader { @@ -139,9 +139,9 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac * * @see toString() * - * @return string - * * @throws Swift_RfcComplianceException + * + * @return string */ public function getFieldBody() { diff --git a/tools/swift/classes/Swift/Mime/Headers/MailboxHeader.php b/tools/swift/classes/Swift/Mime/Headers/MailboxHeader.php index 165b86195..e4567fc80 100644 --- a/tools/swift/classes/Swift/Mime/Headers/MailboxHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/MailboxHeader.php @@ -11,7 +11,7 @@ /** * A Mailbox Address MIME Header for something like From or Sender. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader { @@ -68,9 +68,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader * * This method returns an associative array like {@link getNameAddresses()} * - * @return array - * * @throws Swift_RfcComplianceException + * + * @return array */ public function getFieldBodyModel() { @@ -128,9 +128,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader * @see getNameAddresses() * @see toString() * - * @return string[] - * * @throws Swift_RfcComplianceException + * + * @return string[] */ public function getNameAddressStrings() { @@ -224,22 +224,20 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader * * @see toString() * - * @return string - * * @throws Swift_RfcComplianceException + * + * @return string */ public function getFieldBody() { // Compute the string value of the header only if needed - if (is_null($this->getCachedValue())) { + 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. * @@ -270,16 +268,14 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader /** * Produces a compliant, formatted display-name based on the string given. * - * @param string $displayName as displayed - * @param bool $shorten the first line to make remove for header name + * @param string $displayName as displayed + * @param bool $shorten the first line to make remove for header name * * @return string */ 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); } /** @@ -287,9 +283,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader * * @param string[] $mailboxes * - * @return string - * * @throws Swift_RfcComplianceException + * + * @return string */ protected function createMailboxListString(array $mailboxes) { @@ -299,8 +295,9 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader /** * 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 +305,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); } /** @@ -324,7 +321,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader foreach ($mailboxes as $email => $name) { $mailboxStr = $email; - if (!is_null($name)) { + if (null !== $name) { $nameStr = $this->createDisplayNameString($name, empty($strings)); $mailboxStr = $nameStr.' <'.$mailboxStr.'>'; } diff --git a/tools/swift/classes/Swift/Mime/Headers/OpenDKIMHeader.php b/tools/swift/classes/Swift/Mime/Headers/OpenDKIMHeader.php index b55d46096..d74955007 100644 --- a/tools/swift/classes/Swift/Mime/Headers/OpenDKIMHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/OpenDKIMHeader.php @@ -9,9 +9,9 @@ */ /** - * An OpenDKIM Specific Header using only raw header datas without encoding + * An OpenDKIM Specific Header using only raw header datas without encoding. * - * @author De Cock Xavier + * @author De Cock Xavier */ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header { @@ -23,17 +23,14 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header private $_value; /** - * The name of this Header + * The name of this Header. + * * @var string */ 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) { @@ -118,16 +115,17 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header } /** - * Set the Header FieldName - * @see Swift_Mime_Header::getFieldName() - */ + * Set the Header FieldName. + * + * @see Swift_Mime_Header::getFieldName() + */ public function getFieldName() { return $this->_fieldName; } /** - * Ignored + * Ignored. */ public function setCharset($charset) { diff --git a/tools/swift/classes/Swift/Mime/Headers/ParameterizedHeader.php b/tools/swift/classes/Swift/Mime/Headers/ParameterizedHeader.php index 994fc940b..c1777d333 100644 --- a/tools/swift/classes/Swift/Mime/Headers/ParameterizedHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/ParameterizedHeader.php @@ -11,7 +11,7 @@ /** * An abstract base MIME Header. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_UnstructuredHeader implements Swift_Mime_ParameterizedHeader { @@ -98,9 +98,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct { $params = $this->getParameters(); - return array_key_exists($parameter, $params) - ? $params[$parameter] - : null; + return array_key_exists($parameter, $params) ? $params[$parameter] : null; } /** @@ -133,7 +131,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct { $body = parent::getFieldBody(); foreach ($this->_params as $name => $value) { - if (!is_null($value)) { + if (null !== $value) { // Add the parameter $body .= '; '.$this->_createParameter($name, $value); } @@ -158,9 +156,9 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct // Try creating any parameters foreach ($this->_params as $name => $value) { - if (!is_null($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) )); @@ -235,9 +233,9 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct /** * Returns the parameter value from the "=" and beyond. * - * @param string $value to append - * @param bool $encoded - * @param bool $firstLine + * @param string $value to append + * @param bool $encoded + * @param bool $firstLine * * @return string */ diff --git a/tools/swift/classes/Swift/Mime/Headers/PathHeader.php b/tools/swift/classes/Swift/Mime/Headers/PathHeader.php index eea9a9eed..4a814b122 100644 --- a/tools/swift/classes/Swift/Mime/Headers/PathHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/PathHeader.php @@ -11,7 +11,7 @@ /** * A Path Header in Swift Mailer, such a Return-Path. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader { @@ -80,7 +80,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader */ public function setAddress($address) { - if (is_null($address)) { + if (null === $address) { $this->_address = null; } elseif ('' == $address) { $this->_address = ''; diff --git a/tools/swift/classes/Swift/Mime/Headers/UnstructuredHeader.php b/tools/swift/classes/Swift/Mime/Headers/UnstructuredHeader.php index 41d4e63d7..86177f14a 100644 --- a/tools/swift/classes/Swift/Mime/Headers/UnstructuredHeader.php +++ b/tools/swift/classes/Swift/Mime/Headers/UnstructuredHeader.php @@ -11,7 +11,7 @@ /** * A Simple MIME Header. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractHeader { diff --git a/tools/swift/classes/Swift/Mime/Headers/index.php b/tools/swift/classes/Swift/Mime/Headers/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Mime/Headers/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Mime/Message.php b/tools/swift/classes/Swift/Mime/Message.php index 29bc4b337..9b36d2162 100644 --- a/tools/swift/classes/Swift/Mime/Message.php +++ b/tools/swift/classes/Swift/Mime/Message.php @@ -11,7 +11,7 @@ /** * A Message (RFC 2822) object. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_Message extends Swift_Mime_MimeEntity { @@ -39,7 +39,7 @@ interface Swift_Mime_Message extends Swift_Mime_MimeEntity /** * Set the origination date of the message as a UNIX timestamp. * - * @param int $date + * @param int $date */ public function setDate($date); diff --git a/tools/swift/classes/Swift/Mime/MimeEntity.php b/tools/swift/classes/Swift/Mime/MimeEntity.php index cd8b8a2b8..30f460cdc 100644 --- a/tools/swift/classes/Swift/Mime/MimeEntity.php +++ b/tools/swift/classes/Swift/Mime/MimeEntity.php @@ -11,7 +11,7 @@ /** * A MIME entity, such as an attachment. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_EncodingObserver { @@ -31,6 +31,7 @@ interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_E * 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 @@ -39,6 +40,7 @@ interface Swift_Mime_MimeEntity extends Swift_Mime_CharsetObserver, Swift_Mime_E /** * Get the qualified content-type of this mime entity. + * * @return string */ public function getContentType(); diff --git a/tools/swift/classes/Swift/Mime/MimePart.php b/tools/swift/classes/Swift/Mime/MimePart.php index b13e44823..4564fef6f 100644 --- a/tools/swift/classes/Swift/Mime/MimePart.php +++ b/tools/swift/classes/Swift/Mime/MimePart.php @@ -11,7 +11,7 @@ /** * A MIME part, in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity { @@ -40,7 +40,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity { parent::__construct($headers, $encoder, $cache, $grammar); $this->setContentType('text/plain'); - if (!is_null($charset)) { + if (null !== $charset) { $this->setCharset($charset); } } @@ -53,7 +53,7 @@ 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) { @@ -82,7 +82,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity * * @param string $charset * - * @return Swift_Mime_MimePart + * @return $this */ public function setCharset($charset) { @@ -111,7 +111,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity * * @param string $format * - * @return Swift_Mime_MimePart + * @return $this */ public function setFormat($format) { @@ -128,17 +128,15 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity */ public function getDelSp() { - return ($this->_getHeaderParameter('Content-Type', 'delsp') == 'yes') - ? true - : false; + return 'yes' == $this->_getHeaderParameter('Content-Type', 'delsp') ? true : false; } /** * Turn delsp on or off for this entity. * - * @param bool $delsp + * @param bool $delsp * - * @return Swift_Mime_MimePart + * @return $this */ public function setDelSp($delsp = true) { @@ -196,7 +194,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity 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'); diff --git a/tools/swift/classes/Swift/Mime/ParameterizedHeader.php b/tools/swift/classes/Swift/Mime/ParameterizedHeader.php index ea793201e..e15c6ef95 100644 --- a/tools/swift/classes/Swift/Mime/ParameterizedHeader.php +++ b/tools/swift/classes/Swift/Mime/ParameterizedHeader.php @@ -11,7 +11,7 @@ /** * A MIME Header with parameters. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Mime_ParameterizedHeader extends Swift_Mime_Header { diff --git a/tools/swift/classes/Swift/Mime/SimpleHeaderFactory.php b/tools/swift/classes/Swift/Mime/SimpleHeaderFactory.php index b50d4d54e..1ca504e75 100644 --- a/tools/swift/classes/Swift/Mime/SimpleHeaderFactory.php +++ b/tools/swift/classes/Swift/Mime/SimpleHeaderFactory.php @@ -11,7 +11,7 @@ /** * Creates MIME headers. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory { @@ -64,8 +64,9 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory /** * Create a new Date header using $timestamp (UNIX time). - * @param string $name - * @param int|null $timestamp + * + * @param string $name + * @param int|null $timestamp * * @return Swift_Mime_Header */ @@ -111,12 +112,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory 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, $this->_grammar); if (isset($value)) { $header->setFieldBodyModel($value); } @@ -179,8 +175,8 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory } /** - * Make a deep copy of object - */ + * Make a deep copy of object. + */ public function __clone() { $this->_encoder = clone $this->_encoder; diff --git a/tools/swift/classes/Swift/Mime/SimpleHeaderSet.php b/tools/swift/classes/Swift/Mime/SimpleHeaderSet.php index b44a02ca1..a06ce7247 100644 --- a/tools/swift/classes/Swift/Mime/SimpleHeaderSet.php +++ b/tools/swift/classes/Swift/Mime/SimpleHeaderSet.php @@ -11,7 +11,7 @@ /** * A collection of MIME headers. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet { @@ -71,8 +71,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet /** * Add a new Date header using $timestamp (UNIX time). * - * @param string $name - * @param int $timestamp + * @param string $name + * @param int $timestamp */ public function addDateHeader($name, $timestamp = null) { @@ -131,8 +131,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet * * If multiple headers match, the actual one may be specified by $index. * - * @param string $name - * @param int $index + * @param string $name + * @param int $index * * @return bool */ @@ -140,7 +140,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]); } /** @@ -166,17 +175,25 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet * If multiple headers match, the actual one may be specified by $index. * Returns NULL if none present. * - * @param string $name - * @param int $index + * @param string $name + * @param int $index * * @return Swift_Mime_Header */ 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]; + } } } @@ -207,7 +224,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet } /** - * Return the name of all Headers + * Return the name of all Headers. * * @return array */ @@ -221,13 +238,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet return array_keys($headers); } - /** + /** * 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 + * @param string $name + * @param int $index */ public function remove($name, $index = 0) { @@ -249,7 +266,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet /** * Create a new instance of this HeaderSet. * - * @return Swift_Mime_HeaderSet + * @return self */ public function newInstance() { @@ -349,12 +366,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet { $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 + return $a > $b ? -1 : 1; + } if ($aPos == -1) { return 1; @@ -362,7 +380,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet return -1; } - return ($aPos < $bPos) ? -1 : 1; + return $aPos < $bPos ? -1 : 1; } /** Test if the given Header is always displayed */ @@ -382,8 +400,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_HeaderSet } /** - * Make a deep copy of object - */ + * Make a deep copy of object. + */ public function __clone() { $this->_factory = clone $this->_factory; diff --git a/tools/swift/classes/Swift/Mime/SimpleMessage.php b/tools/swift/classes/Swift/Mime/SimpleMessage.php index 16d8d091c..72d40cee0 100644 --- a/tools/swift/classes/Swift/Mime/SimpleMessage.php +++ b/tools/swift/classes/Swift/Mime/SimpleMessage.php @@ -11,10 +11,16 @@ /** * The default email message class. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime_Message { + 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. * @@ -67,7 +73,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * * @param string $subject * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function setSubject($subject) { @@ -91,9 +97,9 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime /** * Set the date at which this message was created. * - * @param int $date + * @param int $date * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function setDate($date) { @@ -119,7 +125,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * * @param string $address * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function setReturnPath($address) { @@ -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) { @@ -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) { @@ -199,10 +205,10 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * If $name is passed and the first parameter is a string, this name will be * associated with the address. * - * @param string $addresses - * @param string $name optional + * @param string|array $addresses + * @param string $name optional * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function setFrom($addresses, $name = null) { @@ -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) { @@ -253,10 +259,10 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * If $name is passed and the first parameter is a string, this name will be * associated with the address. * - * @param string $addresses + * @param mixed $addresses * @param string $name optional * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function setReplyTo($addresses, $name = null) { @@ -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) { @@ -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) { @@ -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) { @@ -445,18 +451,18 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * * The value is an integer where 1 is the highest priority and 5 is the lowest. * - * @param int $priority + * @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)) { @@ -491,11 +497,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime } /** - * Ask for a delivery receipt from the recipient to be sent to $addresses + * Ask for a delivery receipt from the recipient to be sent to $addresses. * * @param array $addresses * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function setReadReceiptTo($addresses) { @@ -522,7 +528,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * * @param Swift_Mime_MimeEntity $entity * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function attach(Swift_Mime_MimeEntity $entity) { @@ -536,7 +542,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart implements Swift_Mime * * @param Swift_Mime_MimeEntity $entity * - * @return Swift_Mime_SimpleMessage + * @return $this */ public function detach(Swift_Mime_MimeEntity $entity) { diff --git a/tools/swift/classes/Swift/Mime/SimpleMimeEntity.php b/tools/swift/classes/Swift/Mime/SimpleMimeEntity.php index 60492920b..a13f1b23d 100644 --- a/tools/swift/classes/Swift/Mime/SimpleMimeEntity.php +++ b/tools/swift/classes/Swift/Mime/SimpleMimeEntity.php @@ -11,7 +11,7 @@ /** * A MIME entity, in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity { @@ -161,7 +161,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity * * @param string $type * - * @return Swift_Mime_SimpleMimeEntity + * @return $this */ public function setContentType($type) { @@ -192,7 +192,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity * * @param string $id * - * @return Swift_Mime_SimpleMimeEntity + * @return $this */ public function setId($id) { @@ -223,7 +223,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity * * @param string $description * - * @return Swift_Mime_SimpleMimeEntity + * @return $this */ public function setDescription($description) { @@ -249,9 +249,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity * * Though not enforced by the library, lines should not exceed 1000 chars. * - * @param int $length + * @param int $length * - * @return Swift_Mime_SimpleMimeEntity + * @return $this */ public function setMaxLineLength($length) { @@ -263,7 +263,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity /** * Get all children added to this entity. * - * @return array of Swift_Mime_Entity + * @return Swift_Mime_MimeEntity[] */ public function getChildren() { @@ -273,20 +273,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity /** * Set all children of this entity. * - * @param array $children Swift_Mime_Entity instances - * @param int $compoundLevel For internal use only + * @param Swift_Mime_MimeEntity[] $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 = isset($compoundLevel) ? $compoundLevel : $this->_getCompoundLevel($children); $immediateChildren = array(); $grandchildren = array(); $newContentType = $this->_userContentType; @@ -311,15 +307,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity } } - if (!empty($immediateChildren)) { + if ($immediateChildren) { $lowestLevel = $this->_getNeededChildLevel($immediateChildren[0], $compoundLevel); // Determine which composite media type is needed to accommodate the // immediate children foreach ($this->_compositeRanges as $mediaType => $range) { - if ($lowestLevel > $range[0] - && $lowestLevel <= $range[1]) { + if ($lowestLevel > $range[0] && $lowestLevel <= $range[1]) { $newContentType = $mediaType; + break; } } @@ -349,9 +345,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; } /** @@ -361,7 +355,7 @@ 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) { @@ -392,7 +386,7 @@ 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) { @@ -426,9 +420,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity * * @param string $boundary * - * @return Swift_Mime_SimpleMimeEntity - * * @throws Swift_RfcComplianceException + * + * @return $this */ public function setBoundary($boundary) { @@ -486,12 +480,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity 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; } @@ -576,7 +566,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity } /** - * Get the name of the header that provides the ID of this entity + * Get the name of the header that provides the ID of this entity. */ protected function _getIdField() { @@ -602,9 +592,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity $this->_headers->get($field)->setFieldBodyModel($model); return true; - } else { - return false; } + + return false; } /** @@ -626,9 +616,9 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity $this->_headers->get($field)->setParameter($parameter, $value); return true; - } else { - return false; } + + return false; } /** @@ -702,6 +692,8 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity $string .= $bytes; } + $os->setReadPointer(0); + return $string; } @@ -714,9 +706,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity private function _assertValidBoundary($boundary) { - if (!preg_match( - '/^[a-z0-9\'\(\)\+_\-,\.\/:=\?\ ]{0,69}[a-z0-9\'\(\)\+_\-,\.\/:=\?]$/Di', - $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.'); } } @@ -755,18 +745,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity $realLevel = $child->getNestingLevel(); $lowercaseType = strtolower($child->getContentType()); - if (isset($filter[$realLevel]) - && isset($filter[$realLevel][$lowercaseType])) { + if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) { return $filter[$realLevel][$lowercaseType]; - } else { - return $realLevel; } + + return $realLevel; } 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->_grammar); } private function _notifyEncoderChanged(Swift_Mime_ContentEncoder $encoder) @@ -798,34 +786,33 @@ 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); + if ($this->_cache instanceof Swift_KeyCache) { + $this->_cache->clearAll($this->_cacheKey); + } } /** @@ -837,26 +824,19 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_MimeEntity */ 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 (!preg_match('/^'.$this->_grammar->getDefinition('id-left').'@'.$this->_grammar->getDefinition('id-right').'$/D', $id)) { + throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>'); } } /** - * Make a deep copy of object + * Make a deep copy of object. */ public function __clone() { $this->_headers = clone $this->_headers; $this->_encoder = clone $this->_encoder; - $this->_cacheKey = uniqid(); - $this->generateId(); + $this->_cacheKey = md5(uniqid(getmypid().mt_rand(), true)); $children = array(); foreach ($this->_children as $pos => $child) { $children[$pos] = clone $child; diff --git a/tools/swift/classes/Swift/Mime/index.php b/tools/swift/classes/Swift/Mime/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Mime/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/MimePart.php b/tools/swift/classes/Swift/MimePart.php index 5702d1c14..525b7ec8e 100644 --- a/tools/swift/classes/Swift/MimePart.php +++ b/tools/swift/classes/Swift/MimePart.php @@ -11,7 +11,7 @@ /** * A MIME part, in a multipart message. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_MimePart extends Swift_Mime_MimePart { @@ -50,7 +50,7 @@ class Swift_MimePart extends Swift_Mime_MimePart * @param string $contentType * @param string $charset * - * @return Swift_Mime_MimePart + * @return self */ public static function newInstance($body = null, $contentType = null, $charset = null) { diff --git a/tools/swift/classes/Swift/NullTransport.php b/tools/swift/classes/Swift/NullTransport.php index 726d83ca1..ddde335c5 100644 --- a/tools/swift/classes/Swift/NullTransport.php +++ b/tools/swift/classes/Swift/NullTransport.php @@ -11,13 +11,10 @@ /** * Pretends messages have been sent, but just ignores them. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_NullTransport extends Swift_Transport_NullTransport { - /** - * Create a new NullTransport. - */ public function __construct() { call_user_func_array( @@ -30,7 +27,7 @@ class Swift_NullTransport extends Swift_Transport_NullTransport /** * Create a new NullTransport instance. * - * @return Swift_NullTransport + * @return self */ public static function newInstance() { diff --git a/tools/swift/classes/Swift/OutputByteStream.php b/tools/swift/classes/Swift/OutputByteStream.php index 0c2783f0f..1f26f9be5 100644 --- a/tools/swift/classes/Swift/OutputByteStream.php +++ b/tools/swift/classes/Swift/OutputByteStream.php @@ -14,7 +14,7 @@ * Classes implementing this interface may use a subsystem which requires less * memory than working with large strings of data. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_OutputByteStream { @@ -25,22 +25,22 @@ interface Swift_OutputByteStream * If less bytes exist than are requested the remaining bytes are given instead. * If no bytes are remaining at all, boolean false is returned. * - * @param int $length - * - * @return string|bool + * @param int $length * * @throws Swift_IoException + * + * @return string|bool */ public function read($length); /** * Move the internal read pointer to $byteOffset in the stream. * - * @param int $byteOffset - * - * @return bool + * @param int $byteOffset * * @throws Swift_IoException + * + * @return bool */ public function setReadPointer($byteOffset); } diff --git a/tools/swift/classes/Swift/Plugins/AntiFloodPlugin.php b/tools/swift/classes/Swift/Plugins/AntiFloodPlugin.php index 28f3a817b..a2ec2abcd 100644 --- a/tools/swift/classes/Swift/Plugins/AntiFloodPlugin.php +++ b/tools/swift/classes/Swift/Plugins/AntiFloodPlugin.php @@ -11,7 +11,7 @@ /** * Reduces network flooding when sending large amounts of mail. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_Plugins_Sleeper { @@ -60,7 +60,7 @@ class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_ /** * Set the number of emails to send before restarting. * - * @param int $threshold + * @param int $threshold */ public function setThreshold($threshold) { @@ -80,7 +80,7 @@ class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_ /** * Set the number of seconds to sleep for during a restart. * - * @param int $sleep time + * @param int $sleep time */ public function setSleepTime($sleep) { @@ -128,7 +128,7 @@ class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_ /** * Sleep for $seconds. * - * @param int $seconds + * @param int $seconds */ public function sleep($seconds) { diff --git a/tools/swift/classes/Swift/Plugins/BandwidthMonitorPlugin.php b/tools/swift/classes/Swift/Plugins/BandwidthMonitorPlugin.php index af1701a06..f7e18d0eb 100644 --- a/tools/swift/classes/Swift/Plugins/BandwidthMonitorPlugin.php +++ b/tools/swift/classes/Swift/Plugins/BandwidthMonitorPlugin.php @@ -11,7 +11,7 @@ /** * Reduces network flooding when sending large amounts of mail. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, Swift_Events_CommandListener, Swift_Events_ResponseListener, Swift_InputByteStream { diff --git a/tools/swift/classes/Swift/Plugins/Decorator/Replacements.php b/tools/swift/classes/Swift/Plugins/Decorator/Replacements.php index 861843398..9f9f08b56 100644 --- a/tools/swift/classes/Swift/Plugins/Decorator/Replacements.php +++ b/tools/swift/classes/Swift/Plugins/Decorator/Replacements.php @@ -11,7 +11,7 @@ /** * Allows customization of Messages on-the-fly. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Plugins_Decorator_Replacements { diff --git a/tools/swift/classes/Swift/Plugins/Decorator/index.php b/tools/swift/classes/Swift/Plugins/Decorator/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Plugins/Decorator/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Plugins/DecoratorPlugin.php b/tools/swift/classes/Swift/Plugins/DecoratorPlugin.php index e1aaebe9c..0762b36d2 100644 --- a/tools/swift/classes/Swift/Plugins/DecoratorPlugin.php +++ b/tools/swift/classes/Swift/Plugins/DecoratorPlugin.php @@ -11,8 +11,8 @@ /** * Allows customization of Messages on-the-fly. * - * @author Chris Corbyn - * @author Fabien Potencier + * @author Chris Corbyn + * @author Fabien Potencier */ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_Plugins_Decorator_Replacements { @@ -123,7 +123,7 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_ $children = (array) $message->getChildren(); foreach ($children as $child) { - list($type, ) = sscanf($child->getContentType(), '%[^/]/%s'); + list($type) = sscanf($child->getContentType(), '%[^/]/%s'); if ('text' == $type) { $body = $child->getBody(); $bodyReplaced = str_replace( @@ -157,12 +157,9 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_ { if ($this->_replacements instanceof Swift_Plugins_Decorator_Replacements) { return $this->_replacements->getReplacementsFor($address); - } else { - return isset($this->_replacements[$address]) - ? $this->_replacements[$address] - : null - ; } + + return isset($this->_replacements[$address]) ? $this->_replacements[$address] : null; } /** diff --git a/tools/swift/classes/Swift/Plugins/ImpersonatePlugin.php b/tools/swift/classes/Swift/Plugins/ImpersonatePlugin.php index 5bd0bbda5..583444053 100644 --- a/tools/swift/classes/Swift/Plugins/ImpersonatePlugin.php +++ b/tools/swift/classes/Swift/Plugins/ImpersonatePlugin.php @@ -1,4 +1,5 @@ getCommand(); - $this->_logger->add(sprintf(">> %s", $command)); + $this->_logger->add(sprintf('>> %s', $command)); } /** @@ -75,7 +75,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ public function responseReceived(Swift_Events_ResponseEvent $evt) { $response = $evt->getResponse(); - $this->_logger->add(sprintf("<< %s", $response)); + $this->_logger->add(sprintf('<< %s', $response)); } /** @@ -86,7 +86,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) { $transportName = get_class($evt->getSource()); - $this->_logger->add(sprintf("++ Starting %s", $transportName)); + $this->_logger->add(sprintf('++ Starting %s', $transportName)); } /** @@ -97,7 +97,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ public function transportStarted(Swift_Events_TransportChangeEvent $evt) { $transportName = get_class($evt->getSource()); - $this->_logger->add(sprintf("++ %s started", $transportName)); + $this->_logger->add(sprintf('++ %s started', $transportName)); } /** @@ -108,7 +108,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt) { $transportName = get_class($evt->getSource()); - $this->_logger->add(sprintf("++ Stopping %s", $transportName)); + $this->_logger->add(sprintf('++ Stopping %s', $transportName)); } /** @@ -119,7 +119,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ public function transportStopped(Swift_Events_TransportChangeEvent $evt) { $transportName = get_class($evt->getSource()); - $this->_logger->add(sprintf("++ %s stopped", $transportName)); + $this->_logger->add(sprintf('++ %s stopped', $transportName)); } /** @@ -131,11 +131,12 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ { $e = $evt->getException(); $message = $e->getMessage(); - $this->_logger->add(sprintf("!! %s", $message)); + $code = $e->getCode(); + $this->_logger->add(sprintf('!! %s (code: %s)', $message, $code)); $message .= PHP_EOL; $message .= 'Log data:'.PHP_EOL; $message .= $this->_logger->dump(); $evt->cancelBubble(); - throw new Swift_TransportException($message); + throw new Swift_TransportException($message, $code, $e->getPrevious()); } } diff --git a/tools/swift/classes/Swift/Plugins/Loggers/ArrayLogger.php b/tools/swift/classes/Swift/Plugins/Loggers/ArrayLogger.php index f1739e8e6..865bb0aa3 100644 --- a/tools/swift/classes/Swift/Plugins/Loggers/ArrayLogger.php +++ b/tools/swift/classes/Swift/Plugins/Loggers/ArrayLogger.php @@ -11,7 +11,7 @@ /** * Logs to an Array backend. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_Loggers_ArrayLogger implements Swift_Plugins_Logger { @@ -32,7 +32,7 @@ class Swift_Plugins_Loggers_ArrayLogger implements Swift_Plugins_Logger /** * Create a new ArrayLogger with a maximum of $size entries. * - * @var int $size + * @var int */ public function __construct($size = 50) { diff --git a/tools/swift/classes/Swift/Plugins/Loggers/EchoLogger.php b/tools/swift/classes/Swift/Plugins/Loggers/EchoLogger.php index e8b6c18a3..3583297ab 100644 --- a/tools/swift/classes/Swift/Plugins/Loggers/EchoLogger.php +++ b/tools/swift/classes/Swift/Plugins/Loggers/EchoLogger.php @@ -11,7 +11,7 @@ /** * Prints all log messages in real time. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_Loggers_EchoLogger implements Swift_Plugins_Logger { @@ -21,7 +21,7 @@ class Swift_Plugins_Loggers_EchoLogger implements Swift_Plugins_Logger /** * Create a new EchoLogger. * - * @param bool $isHtml + * @param bool $isHtml */ public function __construct($isHtml = true) { diff --git a/tools/swift/classes/Swift/Plugins/Loggers/index.php b/tools/swift/classes/Swift/Plugins/Loggers/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Plugins/Loggers/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Plugins/MessageLogger.php b/tools/swift/classes/Swift/Plugins/MessageLogger.php index a02ad98e8..5ff1d9321 100644 --- a/tools/swift/classes/Swift/Plugins/MessageLogger.php +++ b/tools/swift/classes/Swift/Plugins/MessageLogger.php @@ -11,12 +11,12 @@ /** * Stores all sent emails for further usage. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener { /** - * @var array + * @var Swift_Mime_Message[] */ private $messages; @@ -26,9 +26,9 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener } /** - * Get the message list + * Get the message list. * - * @return array + * @return Swift_Mime_Message[] */ public function getMessages() { @@ -36,9 +36,9 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener } /** - * Get the message count + * Get the message count. * - * @return int count + * @return int count */ public function countMessages() { @@ -46,8 +46,7 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener } /** - * Empty the message list - * + * Empty the message list. */ public function clear() { diff --git a/tools/swift/classes/Swift/Plugins/Pop/Pop3Connection.php b/tools/swift/classes/Swift/Plugins/Pop/Pop3Connection.php index 1e18016a9..fb99e4c94 100644 --- a/tools/swift/classes/Swift/Plugins/Pop/Pop3Connection.php +++ b/tools/swift/classes/Swift/Plugins/Pop/Pop3Connection.php @@ -11,7 +11,7 @@ /** * Pop3Connection interface for connecting and disconnecting to a POP3 host. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Plugins_Pop_Pop3Connection { diff --git a/tools/swift/classes/Swift/Plugins/Pop/Pop3Exception.php b/tools/swift/classes/Swift/Plugins/Pop/Pop3Exception.php index 870207269..dc7be0c4e 100644 --- a/tools/swift/classes/Swift/Plugins/Pop/Pop3Exception.php +++ b/tools/swift/classes/Swift/Plugins/Pop/Pop3Exception.php @@ -11,7 +11,7 @@ /** * Pop3Exception thrown when an error occurs connecting to a POP3 host. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_Pop_Pop3Exception extends Swift_IoException { diff --git a/tools/swift/classes/Swift/Plugins/Pop/index.php b/tools/swift/classes/Swift/Plugins/Pop/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Plugins/Pop/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Plugins/PopBeforeSmtpPlugin.php b/tools/swift/classes/Swift/Plugins/PopBeforeSmtpPlugin.php index 77b4d68ce..31461526c 100644 --- a/tools/swift/classes/Swift/Plugins/PopBeforeSmtpPlugin.php +++ b/tools/swift/classes/Swift/Plugins/PopBeforeSmtpPlugin.php @@ -11,7 +11,7 @@ /** * Makes sure a connection to a POP3 host has been established prior to connecting to SMTP. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeListener, Swift_Plugins_Pop_Pop3Connection { @@ -45,9 +45,9 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Create a new PopBeforeSmtpPlugin for $host and $port. * - * @param string $host - * @param int $port - * @param string $crypto as "tls" or "ssl" + * @param string $host + * @param int $port + * @param string $crypto as "tls" or "ssl" */ public function __construct($host, $port = 110, $crypto = null) { @@ -59,11 +59,11 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Create a new PopBeforeSmtpPlugin for $host and $port. * - * @param string $host - * @param int $port - * @param string $crypto as "tls" or "ssl" + * @param string $host + * @param int $port + * @param string $crypto as "tls" or "ssl" * - * @return Swift_Plugins_PopBeforeSmtpPlugin + * @return self */ public static function newInstance($host, $port = 110, $crypto = null) { @@ -75,7 +75,7 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL * * @param Swift_Plugins_Pop_Pop3Connection $connection * - * @return Swift_Plugins_PopBeforeSmtpPlugin + * @return $this */ public function setConnection(Swift_Plugins_Pop_Pop3Connection $connection) { @@ -97,9 +97,9 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Set the connection timeout in seconds (default 10). * - * @param int $timeout + * @param int $timeout * - * @return Swift_Plugins_PopBeforeSmtpPlugin + * @return $this */ public function setTimeout($timeout) { @@ -113,7 +113,7 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL * * @param string $username * - * @return Swift_Plugins_PopBeforeSmtpPlugin + * @return $this */ public function setUsername($username) { @@ -127,7 +127,7 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL * * @param string $password * - * @return Swift_Plugins_PopBeforeSmtpPlugin + * @return $this */ public function setPassword($password) { diff --git a/tools/swift/classes/Swift/Plugins/RedirectingPlugin.php b/tools/swift/classes/Swift/Plugins/RedirectingPlugin.php index cc86134c6..c3a1f8685 100644 --- a/tools/swift/classes/Swift/Plugins/RedirectingPlugin.php +++ b/tools/swift/classes/Swift/Plugins/RedirectingPlugin.php @@ -11,7 +11,7 @@ /** * Redirects all email to a single recipient. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener { @@ -23,7 +23,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener private $_recipient; /** - * List of regular expression for recipient whitelisting + * List of regular expression for recipient whitelisting. * * @var array */ @@ -33,7 +33,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener * Create a new RedirectingPlugin. * * @param mixed $recipient - * @param array $whitelist + * @param array $whitelist */ public function __construct($recipient, array $whitelist = array()) { @@ -62,7 +62,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener } /** - * Set a list of regular expressions to whitelist certain recipients + * Set a list of regular expressions to whitelist certain recipients. * * @param array $whitelist */ @@ -72,7 +72,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener } /** - * Get the whitelist + * Get the whitelist. * * @return array */ @@ -116,7 +116,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener $to = array(); } - foreach ( (array) $this->_recipient as $recipient) { + foreach ((array) $this->_recipient as $recipient) { if (!array_key_exists($recipient, $to)) { $message->addTo($recipient); } @@ -124,10 +124,10 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener } /** - * Filter header set against a whitelist of regular expressions + * Filter header set against a whitelist of regular expressions. * * @param Swift_Mime_HeaderSet $headerSet - * @param string $type + * @param string $type */ private function _filterHeaderSet(Swift_Mime_HeaderSet $headerSet, $type) { @@ -137,9 +137,10 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener } /** - * Filtered list of addresses => name pairs + * Filtered list of addresses => name pairs. * * @param array $recipients + * * @return array */ private function _filterNameAddresses(array $recipients) @@ -156,9 +157,10 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener } /** - * Matches address against whitelist of regular expressions + * Matches address against whitelist of regular expressions. * * @param $recipient + * * @return bool */ protected function _isWhitelisted($recipient) diff --git a/tools/swift/classes/Swift/Plugins/Reporter.php b/tools/swift/classes/Swift/Plugins/Reporter.php index 294b547d2..0f21b7d60 100644 --- a/tools/swift/classes/Swift/Plugins/Reporter.php +++ b/tools/swift/classes/Swift/Plugins/Reporter.php @@ -11,7 +11,7 @@ /** * The Reporter plugin sends pass/fail notification to a Reporter. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Plugins_Reporter { diff --git a/tools/swift/classes/Swift/Plugins/ReporterPlugin.php b/tools/swift/classes/Swift/Plugins/ReporterPlugin.php index 452945339..a37901ff0 100644 --- a/tools/swift/classes/Swift/Plugins/ReporterPlugin.php +++ b/tools/swift/classes/Swift/Plugins/ReporterPlugin.php @@ -11,7 +11,7 @@ /** * Does real time reporting of pass/fail for each recipient. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener { @@ -49,25 +49,13 @@ class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener $message = $evt->getMessage(); $failures = array_flip($evt->getFailedRecipients()); foreach ((array) $message->getTo() as $address => $null) { - $this->_reporter->notify( - $message, $address, (array_key_exists($address, $failures) - ? Swift_Plugins_Reporter::RESULT_FAIL - : Swift_Plugins_Reporter::RESULT_PASS) - ); + $this->_reporter->notify($message, $address, array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS); } foreach ((array) $message->getCc() as $address => $null) { - $this->_reporter->notify( - $message, $address, (array_key_exists($address, $failures) - ? Swift_Plugins_Reporter::RESULT_FAIL - : Swift_Plugins_Reporter::RESULT_PASS) - ); + $this->_reporter->notify($message, $address, array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS); } foreach ((array) $message->getBcc() as $address => $null) { - $this->_reporter->notify( - $message, $address, (array_key_exists($address, $failures) - ? Swift_Plugins_Reporter::RESULT_FAIL - : Swift_Plugins_Reporter::RESULT_PASS) - ); + $this->_reporter->notify($message, $address, array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS); } } } diff --git a/tools/swift/classes/Swift/Plugins/Reporters/HitReporter.php b/tools/swift/classes/Swift/Plugins/Reporters/HitReporter.php index ea60f51dc..cad9d168e 100644 --- a/tools/swift/classes/Swift/Plugins/Reporters/HitReporter.php +++ b/tools/swift/classes/Swift/Plugins/Reporters/HitReporter.php @@ -11,7 +11,7 @@ /** * A reporter which "collects" failures for the Reporter plugin. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_Reporters_HitReporter implements Swift_Plugins_Reporter { diff --git a/tools/swift/classes/Swift/Plugins/Reporters/HtmlReporter.php b/tools/swift/classes/Swift/Plugins/Reporters/HtmlReporter.php index 817e32f51..c62593557 100644 --- a/tools/swift/classes/Swift/Plugins/Reporters/HtmlReporter.php +++ b/tools/swift/classes/Swift/Plugins/Reporters/HtmlReporter.php @@ -11,7 +11,7 @@ /** * A HTML output reporter for the Reporter plugin. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_Reporters_HtmlReporter implements Swift_Plugins_Reporter { @@ -25,14 +25,14 @@ class Swift_Plugins_Reporters_HtmlReporter implements Swift_Plugins_Reporter public function notify(Swift_Mime_Message $message, $address, $result) { if (self::RESULT_PASS == $result) { - echo "
".PHP_EOL; - echo "PASS ".$address.PHP_EOL; - echo "
".PHP_EOL; + echo '
'.PHP_EOL; + echo 'PASS '.$address.PHP_EOL; + echo '
'.PHP_EOL; flush(); } else { - echo "
".PHP_EOL; - echo "FAIL ".$address.PHP_EOL; - echo "
".PHP_EOL; + echo '
'.PHP_EOL; + echo 'FAIL '.$address.PHP_EOL; + echo '
'.PHP_EOL; flush(); } } diff --git a/tools/swift/classes/Swift/Plugins/Reporters/index.php b/tools/swift/classes/Swift/Plugins/Reporters/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Plugins/Reporters/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Plugins/Sleeper.php b/tools/swift/classes/Swift/Plugins/Sleeper.php index 38727052b..595c0f603 100644 --- a/tools/swift/classes/Swift/Plugins/Sleeper.php +++ b/tools/swift/classes/Swift/Plugins/Sleeper.php @@ -11,14 +11,14 @@ /** * Sleeps for a duration of time. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Plugins_Sleeper { /** * Sleep for $seconds. * - * @param int $seconds + * @param int $seconds */ public function sleep($seconds); } diff --git a/tools/swift/classes/Swift/Plugins/ThrottlerPlugin.php b/tools/swift/classes/Swift/Plugins/ThrottlerPlugin.php index 0d2c135e4..2f4b9a75e 100644 --- a/tools/swift/classes/Swift/Plugins/ThrottlerPlugin.php +++ b/tools/swift/classes/Swift/Plugins/ThrottlerPlugin.php @@ -11,7 +11,7 @@ /** * Throttles the rate at which emails are sent. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin implements Swift_Plugins_Sleeper, Swift_Plugins_Timer { @@ -98,16 +98,16 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin $duration = $time - $this->_start; switch ($this->_mode) { - case self::BYTES_PER_MINUTE : + case self::BYTES_PER_MINUTE: $sleep = $this->_throttleBytesPerMinute($duration); break; - case self::MESSAGES_PER_SECOND : + case self::MESSAGES_PER_SECOND: $sleep = $this->_throttleMessagesPerSecond($duration); break; - case self::MESSAGES_PER_MINUTE : + case self::MESSAGES_PER_MINUTE: $sleep = $this->_throttleMessagesPerMinute($duration); break; - default : + default: $sleep = 0; break; } @@ -131,7 +131,7 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin /** * Sleep for $seconds. * - * @param int $seconds + * @param int $seconds */ public function sleep($seconds) { @@ -151,15 +151,15 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin { if (isset($this->_timer)) { return $this->_timer->getTimestamp(); - } else { - return time(); } + + return time(); } /** * Get a number of seconds to sleep for. * - * @param int $timePassed + * @param int $timePassed * * @return int */ @@ -187,7 +187,7 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin /** * Get a number of seconds to sleep for. * - * @param int $timePassed + * @param int $timePassed * * @return int */ diff --git a/tools/swift/classes/Swift/Plugins/Timer.php b/tools/swift/classes/Swift/Plugins/Timer.php index a05e3181e..9c8deb38a 100644 --- a/tools/swift/classes/Swift/Plugins/Timer.php +++ b/tools/swift/classes/Swift/Plugins/Timer.php @@ -11,7 +11,7 @@ /** * Provides timestamp data. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Plugins_Timer { diff --git a/tools/swift/classes/Swift/Plugins/index.php b/tools/swift/classes/Swift/Plugins/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Plugins/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Preferences.php b/tools/swift/classes/Swift/Preferences.php index 7cd61312d..83cbddcd2 100644 --- a/tools/swift/classes/Swift/Preferences.php +++ b/tools/swift/classes/Swift/Preferences.php @@ -11,7 +11,7 @@ /** * Changes some global preference settings in Swift Mailer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Preferences { @@ -26,7 +26,7 @@ class Swift_Preferences /** * Gets the instance of Preferences. * - * @return Swift_Preferences + * @return self */ public static function getInstance() { @@ -42,12 +42,11 @@ class Swift_Preferences * * @param string $charset * - * @return Swift_Preferences + * @return $this */ public function setCharset($charset) { - Swift_DependencyContainer::getInstance() - ->register('properties.charset')->asValue($charset); + Swift_DependencyContainer::getInstance()->register('properties.charset')->asValue($charset); return $this; } @@ -57,12 +56,11 @@ class Swift_Preferences * * @param string $dir * - * @return Swift_Preferences + * @return $this */ public function setTempDir($dir) { - Swift_DependencyContainer::getInstance() - ->register('tempdir')->asValue($dir); + Swift_DependencyContainer::getInstance()->register('tempdir')->asValue($dir); return $this; } @@ -72,12 +70,11 @@ class Swift_Preferences * * @param string $type * - * @return Swift_Preferences + * @return $this */ public function setCacheType($type) { - Swift_DependencyContainer::getInstance() - ->register('cache')->asAliasOf(sprintf('cache.%s', $type)); + Swift_DependencyContainer::getInstance()->register('cache')->asAliasOf(sprintf('cache.%s', $type)); return $this; } @@ -85,9 +82,9 @@ class Swift_Preferences /** * Set the QuotedPrintable dot escaper preference. * - * @param bool $dotEscape + * @param bool $dotEscape * - * @return Swift_Preferences + * @return $this */ public function setQPDotEscape($dotEscape) { diff --git a/tools/swift/classes/Swift/ReplacementFilterFactory.php b/tools/swift/classes/Swift/ReplacementFilterFactory.php index ca9e4f60d..2897474e7 100644 --- a/tools/swift/classes/Swift/ReplacementFilterFactory.php +++ b/tools/swift/classes/Swift/ReplacementFilterFactory.php @@ -11,7 +11,7 @@ /** * Creates StreamFilters. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_ReplacementFilterFactory { diff --git a/tools/swift/classes/Swift/RfcComplianceException.php b/tools/swift/classes/Swift/RfcComplianceException.php index cdb2bee23..81bc4031e 100644 --- a/tools/swift/classes/Swift/RfcComplianceException.php +++ b/tools/swift/classes/Swift/RfcComplianceException.php @@ -11,7 +11,7 @@ /** * RFC Compliance Exception class. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_RfcComplianceException extends Swift_SwiftException { diff --git a/tools/swift/classes/Swift/SendmailTransport.php b/tools/swift/classes/Swift/SendmailTransport.php index 1ef0e5e17..47ae7a591 100644 --- a/tools/swift/classes/Swift/SendmailTransport.php +++ b/tools/swift/classes/Swift/SendmailTransport.php @@ -11,7 +11,7 @@ /** * SendmailTransport for sending mail through a Sendmail/Postfix (etc..) binary. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_SendmailTransport extends Swift_Transport_SendmailTransport { @@ -36,7 +36,7 @@ class Swift_SendmailTransport extends Swift_Transport_SendmailTransport * * @param string $command * - * @return Swift_SendmailTransport + * @return self */ public static function newInstance($command = '/usr/sbin/sendmail -bs') { diff --git a/tools/swift/classes/Swift/SignedMessage.php b/tools/swift/classes/Swift/SignedMessage.php index 66e1c68cd..2e7a8726d 100644 --- a/tools/swift/classes/Swift/SignedMessage.php +++ b/tools/swift/classes/Swift/SignedMessage.php @@ -15,6 +15,7 @@ * * * @author Xavier De Cock + * * @deprecated */ class Swift_SignedMessage extends Swift_Message diff --git a/tools/swift/classes/Swift/Signer.php b/tools/swift/classes/Swift/Signer.php index 7448179fb..2d8176d90 100644 --- a/tools/swift/classes/Swift/Signer.php +++ b/tools/swift/classes/Swift/Signer.php @@ -12,7 +12,7 @@ * Base Class of Signer Infrastructure. * * - * @author Xavier De Cock + * @author Xavier De Cock */ interface Swift_Signer { diff --git a/tools/swift/classes/Swift/Signers/BodySigner.php b/tools/swift/classes/Swift/Signers/BodySigner.php index 93dc8ac7a..8e66e18f4 100644 --- a/tools/swift/classes/Swift/Signers/BodySigner.php +++ b/tools/swift/classes/Swift/Signers/BodySigner.php @@ -9,9 +9,9 @@ */ /** - * Body Signer Interface used to apply Body-Based Signature to a message + * Body Signer Interface used to apply Body-Based Signature to a message. * - * @author Xavier De Cock + * @author Xavier De Cock */ interface Swift_Signers_BodySigner extends Swift_Signer { @@ -20,12 +20,12 @@ interface Swift_Signers_BodySigner extends Swift_Signer * * @param Swift_Message $message * - * @return Swift_Signers_BodySigner + * @return self */ public function signMessage(Swift_Message $message); /** - * Return the list of header a signer might tamper + * Return the list of header a signer might tamper. * * @return array */ diff --git a/tools/swift/classes/Swift/Signers/DKIMSigner.php b/tools/swift/classes/Swift/Signers/DKIMSigner.php index 220c3ac98..454e84b47 100644 --- a/tools/swift/classes/Swift/Signers/DKIMSigner.php +++ b/tools/swift/classes/Swift/Signers/DKIMSigner.php @@ -9,91 +9,93 @@ */ /** - * DKIM Signer used to apply DKIM Signature to a message + * DKIM Signer used to apply DKIM Signature to a message. * - * @author Xavier De Cock + * @author Xavier De Cock */ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner { /** - * PrivateKey + * PrivateKey. * * @var string */ protected $_privateKey; /** - * DomainName + * DomainName. * * @var string */ protected $_domainName; /** - * Selector + * Selector. * * @var string */ protected $_selector; /** - * Hash algorithm used + * Hash algorithm used. + * + * @see RFC6376 3.3: Signers MUST implement and SHOULD sign using rsa-sha256. * * @var string */ - protected $_hashAlgorithm = 'rsa-sha1'; + protected $_hashAlgorithm = 'rsa-sha256'; /** - * Body canon method + * Body canon method. * * @var string */ protected $_bodyCanon = 'simple'; /** - * Header canon method + * Header canon method. * * @var string */ protected $_headerCanon = 'simple'; /** - * Headers not being signed + * Headers not being signed. * * @var array */ - protected $_ignoredHeaders = array(); + protected $_ignoredHeaders = array('return-path' => true); /** - * Signer identity + * Signer identity. * - * @var unknown_type + * @var string */ protected $_signerIdentity; /** - * BodyLength + * BodyLength. * * @var int */ protected $_bodyLen = 0; /** - * Maximum signedLen + * Maximum signedLen. * * @var int */ protected $_maxLen = PHP_INT_MAX; /** - * Embbed bodyLen in signature + * Embbed bodyLen in signature. * * @var bool */ protected $_showLen = false; /** - * When the signature has been applied (true means time()), false means not embedded + * When the signature has been applied (true means time()), false means not embedded. * * @var mixed */ @@ -101,7 +103,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * When will the signature expires false means not embedded, if sigTimestamp is auto - * Expiration is relative, otherwhise it's absolute + * Expiration is relative, otherwise it's absolute. * * @var int */ @@ -116,40 +118,33 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner // work variables /** - * Headers used to generate hash + * Headers used to generate hash. * * @var array */ protected $_signedHeaders = array(); /** - * If debugHeaders is set store debugDatas here + * If debugHeaders is set store debugData here. * * @var string */ private $_debugHeadersData = ''; /** - * Stores the bodyHash + * Stores the bodyHash. * * @var string */ private $_bodyHash = ''; /** - * Stores the signature header + * Stores the signature header. * * @var Swift_Mime_Headers_ParameterizedHeader */ protected $_dkimHeader; - /** - * Hash Handler - * - * @var hash_ressource - */ - private $_headerHashHandler; - private $_bodyHashHandler; private $_headerHash; @@ -169,7 +164,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner private $_bound = array(); /** - * Constructor + * Constructor. * * @param string $privateKey * @param string $domainName @@ -181,15 +176,21 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner $this->_domainName = $domainName; $this->_signerIdentity = '@'.$domainName; $this->_selector = $selector; + + // keep fallback hash algorithm sha1 if php version is lower than 5.4.8 + if (PHP_VERSION_ID < 50408) { + $this->_hashAlgorithm = 'rsa-sha1'; + } } /** - * Instanciate DKIMSigner + * Instanciate DKIMSigner. * * @param string $privateKey * @param string $domainName * @param string $selector - * @return Swift_Signers_DKIMSigner + * + * @return self */ public static function newInstance($privateKey, $domainName, $selector) { @@ -197,14 +198,14 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Reset the Signer + * Reset the Signer. + * * @see Swift_Signer::reset() */ public function reset() { $this->_headerHash = null; $this->_signedHeaders = array(); - $this->_headerHashHandler = null; $this->_bodyHash = null; $this->_bodyHashHandler = null; $this->_bodyCanonIgnoreStart = 2; @@ -224,9 +225,12 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner * second, etc etc). * * @param string $bytes - * @return int + * * @throws Swift_IoException + * + * @return int */ + // TODO fix return public function write($bytes) { $this->_canonicalizeBody($bytes); @@ -238,8 +242,6 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * For any bytes that are currently buffered inside the stream, force them * off the buffer. - * - * @throws Swift_IoException */ public function commit() { @@ -280,8 +282,6 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner return; } } - - return; } /** @@ -296,28 +296,39 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set hash_algorithm, must be one of rsa-sha256 | rsa-sha1 defaults to rsa-sha256 + * Set hash_algorithm, must be one of rsa-sha256 | rsa-sha1. * - * @param string $hash - * @return Swift_Signers_DKIMSigner + * @param string $hash 'rsa-sha1' or 'rsa-sha256' + * + * @throws Swift_SwiftException + * + * @return $this */ public function setHashAlgorithm($hash) { - // Unable to sign with rsa-sha256 - if ($hash == 'rsa-sha1') { - $this->_hashAlgorithm = 'rsa-sha1'; - } else { - $this->_hashAlgorithm = 'rsa-sha256'; + switch ($hash) { + case 'rsa-sha1': + $this->_hashAlgorithm = 'rsa-sha1'; + break; + case 'rsa-sha256': + $this->_hashAlgorithm = 'rsa-sha256'; + if (!defined('OPENSSL_ALGO_SHA256')) { + throw new Swift_SwiftException('Unable to set sha256 as it is not supported by OpenSSL.'); + } + break; + default: + throw new Swift_SwiftException('Unable to set the hash algorithm, must be one of rsa-sha1 or rsa-sha256 (%s given).', $hash); } return $this; } /** - * Set the body canonicalization algorithm + * Set the body canonicalization algorithm. * * @param string $canon - * @return Swift_Signers_DKIMSigner + * + * @return $this */ public function setBodyCanon($canon) { @@ -331,10 +342,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set the header canonicalization algorithm + * Set the header canonicalization algorithm. * * @param string $canon - * @return Swift_Signers_DKIMSigner + * + * @return $this */ public function setHeaderCanon($canon) { @@ -348,10 +360,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set the signer identity + * Set the signer identity. * * @param string $identity - * @return Swift_Signers_DKIMSigner + * + * @return $this */ public function setSignerIdentity($identity) { @@ -361,10 +374,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set the length of the body to sign + * Set the length of the body to sign. * * @param mixed $len (bool or int) - * @return Swift_Signers_DKIMSigner + * + * @return $this */ public function setBodySignedLen($len) { @@ -372,7 +386,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner $this->_showLen = true; $this->_maxLen = PHP_INT_MAX; } elseif ($len === false) { - $this->showLen = false; + $this->_showLen = false; $this->_maxLen = PHP_INT_MAX; } else { $this->_showLen = true; @@ -383,10 +397,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set the signature timestamp + * Set the signature timestamp. * - * @param timestamp $time - * @return Swift_Signers_DKIMSigner + * @param int $time A timestamp + * + * @return $this */ public function setSignatureTimestamp($time) { @@ -396,10 +411,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set the signature expiration timestamp + * Set the signature expiration timestamp. * - * @param timestamp $time - * @return Swift_Signers_DKIMSigner + * @param int $time A timestamp + * + * @return $this */ public function setSignatureExpiration($time) { @@ -409,9 +425,10 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Enable / disable the DebugHeaders + * Enable / disable the DebugHeaders. + * + * @param bool $debug * - * @param bool $debug * @return Swift_Signers_DKIMSigner */ public function setDebugHeaders($debug) @@ -422,17 +439,16 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Start Body - * + * Start Body. */ public function startBody() { // Init switch ($this->_hashAlgorithm) { - case 'rsa-sha256' : + case 'rsa-sha256': $this->_bodyHashHandler = hash_init('sha256'); break; - case 'rsa-sha1' : + case 'rsa-sha1': $this->_bodyHashHandler = hash_init('sha1'); break; } @@ -440,8 +456,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * End Body - * + * End Body. */ public function endBody() { @@ -449,7 +464,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Returns the list of Headers Tampered by this plugin + * Returns the list of Headers Tampered by this plugin. * * @return array */ @@ -463,9 +478,10 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Adds an ignored Header + * Adds an ignored Header. * * @param string $header_name + * * @return Swift_Signers_DKIMSigner */ public function ignoreHeader($header_name) @@ -476,9 +492,10 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Set the headers to sign + * Set the headers to sign. * * @param Swift_Mime_HeaderSet $headers + * * @return Swift_Signers_DKIMSigner */ public function setHeaders(Swift_Mime_HeaderSet $headers) @@ -488,7 +505,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner $listHeaders = $headers->listAll(); foreach ($listHeaders as $hName) { // Check if we need to ignore Header - if (! isset($this->_ignoredHeaders[strtolower($hName)])) { + if (!isset($this->_ignoredHeaders[strtolower($hName)])) { if ($headers->has($hName)) { $tmp = $headers->getAll($hName); foreach ($tmp as $header) { @@ -505,9 +522,10 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner } /** - * Add the signature to the given Headers + * Add the signature to the given Headers. * * @param Swift_Mime_HeaderSet $headers + * * @return Swift_Signers_DKIMSigner */ public function addSignature(Swift_Mime_HeaderSet $headers) @@ -552,7 +570,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner if ($this->_debugHeaders) { $headers->addTextHeader('X-DebugHash', base64_encode($this->_headerHash)); } - $this->_dkimHeader->setValue($string." b=".trim(chunk_split(base64_encode($this->_getEncryptedHash()), 73, " "))); + $this->_dkimHeader->setValue($string.' b='.trim(chunk_split(base64_encode($this->_getEncryptedHash()), 73, ' '))); return $this; } @@ -562,39 +580,43 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner protected function _addHeader($header, $is_sig = false) { switch ($this->_headerCanon) { - case 'relaxed' : + case 'relaxed': // Prepare Header and cascade $exploded = explode(':', $header, 2); $name = strtolower(trim($exploded[0])); - $value = str_replace("\r\n", "", $exploded[1]); - $value = preg_replace("/[ \t][ \t]+/", " ", $value); - $header = $name.":".trim($value).($is_sig ? '' : "\r\n"); - case 'simple' : + $value = str_replace("\r\n", '', $exploded[1]); + $value = preg_replace("/[ \t][ \t]+/", ' ', $value); + $header = $name.':'.trim($value).($is_sig ? '' : "\r\n"); + case 'simple': // Nothing to do } $this->_addToHeaderHash($header); } + /** + * @deprecated This method is currently useless in this class but it must be + * kept for BC reasons due to its "protected" scope. This method + * might be overridden by custom client code. + */ protected function _endOfHeaders() { - //$this->_headerHash=hash_final($this->_headerHashHandler, true); } protected function _canonicalizeBody($string) { $len = strlen($string); $canon = ''; - $method = ($this->_bodyCanon == "relaxed"); + $method = ($this->_bodyCanon == 'relaxed'); for ($i = 0; $i < $len; ++$i) { if ($this->_bodyCanonIgnoreStart > 0) { --$this->_bodyCanonIgnoreStart; continue; } switch ($string[$i]) { - case "\r" : + case "\r": $this->_bodyCanonLastChar = "\r"; break; - case "\n" : + case "\n": if ($this->_bodyCanonLastChar == "\r") { if ($method) { $this->_bodyCanonSpace = false; @@ -610,13 +632,13 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner // todo handle it but should never happen } break; - case " " : - case "\t" : + case ' ': + case "\t": if ($method) { $this->_bodyCanonSpace = true; break; } - default : + default: if ($this->_bodyCanonEmptyCounter > 0) { $canon .= str_repeat("\r\n", $this->_bodyCanonEmptyCounter); $this->_bodyCanonEmptyCounter = 0; @@ -663,11 +685,13 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * @throws Swift_SwiftException + * * @return string */ private function _getEncryptedHash() { $signature = ''; + switch ($this->_hashAlgorithm) { case 'rsa-sha1': $algorithm = OPENSSL_ALGO_SHA1; diff --git a/tools/swift/classes/Swift/Signers/DomainKeySigner.php b/tools/swift/classes/Swift/Signers/DomainKeySigner.php index b52ffdf4e..0365363c8 100644 --- a/tools/swift/classes/Swift/Signers/DomainKeySigner.php +++ b/tools/swift/classes/Swift/Signers/DomainKeySigner.php @@ -9,56 +9,56 @@ */ /** - * DomainKey Signer used to apply DomainKeys Signature to a message + * DomainKey Signer used to apply DomainKeys Signature to a message. * - * @author Xavier De Cock + * @author Xavier De Cock */ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner { /** - * PrivateKey + * PrivateKey. * * @var string */ protected $_privateKey; /** - * DomainName + * DomainName. * * @var string */ protected $_domainName; /** - * Selector + * Selector. * * @var string */ protected $_selector; /** - * Hash algorithm used + * Hash algorithm used. * * @var string */ protected $_hashAlgorithm = 'rsa-sha1'; /** - * Canonisation method + * Canonisation method. * * @var string */ protected $_canon = 'simple'; /** - * Headers not being signed + * Headers not being signed. * * @var array */ protected $_ignoredHeaders = array(); /** - * Signer identity + * Signer identity. * * @var string */ @@ -73,21 +73,21 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner // work variables /** - * Headers used to generate hash + * Headers used to generate hash. * * @var array */ private $_signedHeaders = array(); /** - * Stores the signature header + * Stores the signature header. * * @var Swift_Mime_Headers_ParameterizedHeader */ protected $_domainKeyHeader; /** - * Hash Handler + * Hash Handler. * * @var resource|null */ @@ -110,7 +110,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner private $_bound = array(); /** - * Constructor + * Constructor. * * @param string $privateKey * @param string $domainName @@ -125,12 +125,13 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Instanciate DomainKeySigner + * Instanciate DomainKeySigner. * * @param string $privateKey * @param string $domainName * @param string $selector - * @return Swift_Signers_DomainKeySigner + * + * @return self */ public static function newInstance($privateKey, $domainName, $selector) { @@ -138,9 +139,9 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Resets internal states + * Resets internal states. * - * @return Swift_Signers_DomainKeysSigner + * @return $this */ public function reset() { @@ -165,9 +166,10 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * second, etc etc). * * @param string $bytes - * @return int + * * @throws Swift_IoException - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function write($bytes) { @@ -184,7 +186,8 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * off the buffer. * * @throws Swift_IoException - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function commit() { @@ -198,7 +201,8 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * All {@link write()} and {@link flushBuffers()} operations will be mirrored. * * @param Swift_InputByteStream $is - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function bind(Swift_InputByteStream $is) { @@ -215,7 +219,8 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * before unbinding occurs. * * @param Swift_InputByteStream $is - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function unbind(Swift_InputByteStream $is) { @@ -224,7 +229,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner if ($stream === $is) { unset($this->_bound[$k]); - return; + break; } } @@ -236,7 +241,8 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * to the beginning. * * @throws Swift_IoException - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function flushBuffers() { @@ -246,10 +252,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Set hash_algorithm, must be one of rsa-sha256 | rsa-sha1 defaults to rsa-sha256 + * Set hash_algorithm, must be one of rsa-sha256 | rsa-sha1 defaults to rsa-sha256. * * @param string $hash - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function setHashAlgorithm($hash) { @@ -259,10 +266,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Set the canonicalization algorithm + * Set the canonicalization algorithm. * * @param string $canon simple | nofws defaults to simple - * @return Swift_Signers_DomainKeysSigner + * + * @return $this */ public function setCanon($canon) { @@ -276,10 +284,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Set the signer identity + * Set the signer identity. * * @param string $identity - * @return Swift_Signers_DomainKeySigner + * + * @return $this */ public function setSignerIdentity($identity) { @@ -289,10 +298,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Enable / disable the DebugHeaders + * Enable / disable the DebugHeaders. * - * @param bool $debug - * @return Swift_Signers_DomainKeySigner + * @param bool $debug + * + * @return $this */ public function setDebugHeaders($debug) { @@ -302,16 +312,14 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Start Body - * + * Start Body. */ public function startBody() { } /** - * End Body - * + * End Body. */ public function endBody() { @@ -319,7 +327,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Returns the list of Headers Tampered by this plugin + * Returns the list of Headers Tampered by this plugin. * * @return array */ @@ -327,16 +335,17 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner { if ($this->_debugHeaders) { return array('DomainKey-Signature', 'X-DebugHash'); - } else { - return array('DomainKey-Signature'); } + + return array('DomainKey-Signature'); } /** - * Adds an ignored Header + * Adds an ignored Header. * * @param string $header_name - * @return Swift_Signers_DomainKeySigner + * + * @return $this */ public function ignoreHeader($header_name) { @@ -346,10 +355,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Set the headers to sign + * Set the headers to sign. * * @param Swift_Mime_HeaderSet $headers - * @return Swift_Signers_DomainKeySigner + * + * @return $this */ public function setHeaders(Swift_Mime_HeaderSet $headers) { @@ -359,7 +369,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner $listHeaders = $headers->listAll(); foreach ($listHeaders as $hName) { // Check if we need to ignore Header - if (! isset($this->_ignoredHeaders[strtolower($hName)])) { + if (!isset($this->_ignoredHeaders[strtolower($hName)])) { if ($headers->has($hName)) { $tmp = $headers->getAll($hName); foreach ($tmp as $header) { @@ -377,15 +387,16 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner } /** - * Add the signature to the given Headers + * Add the signature to the given Headers. * * @param Swift_Mime_HeaderSet $headers - * @return Swift_Signers_DomainKeySigner + * + * @return $this */ public function addSignature(Swift_Mime_HeaderSet $headers) { // Prepare the DomainKey-Signature Header - $params = array('a' => $this->_hashAlgorithm, 'b' => chunk_split(base64_encode($this->_getEncryptedHash()), 73, " "), 'c' => $this->_canon, 'd' => $this->_domainName, 'h' => implode(': ', $this->_signedHeaders), 'q' => 'dns', 's' => $this->_selector); + $params = array('a' => $this->_hashAlgorithm, 'b' => chunk_split(base64_encode($this->_getEncryptedHash()), 73, ' '), 'c' => $this->_canon, 'd' => $this->_domainName, 'h' => implode(': ', $this->_signedHeaders), 'q' => 'dns', 's' => $this->_selector); $string = ''; foreach ($params as $k => $v) { $string .= $k.'='.$v.'; '; @@ -401,14 +412,14 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner protected function _addHeader($header) { switch ($this->_canon) { - case 'nofws' : + case 'nofws': // Prepare Header and cascade $exploded = explode(':', $header, 2); $name = strtolower(trim($exploded[0])); - $value = str_replace("\r\n", "", $exploded[1]); - $value = preg_replace("/[ \t][ \t]+/", " ", $value); - $header = $name.":".trim($value)."\r\n"; - case 'simple' : + $value = str_replace("\r\n", '', $exploded[1]); + $value = preg_replace("/[ \t][ \t]+/", ' ', $value); + $header = $name.':'.trim($value)."\r\n"; + case 'simple': // Nothing to do } $this->_addToHash($header); @@ -423,17 +434,17 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner { $len = strlen($string); $canon = ''; - $nofws = ($this->_canon == "nofws"); + $nofws = ($this->_canon == 'nofws'); for ($i = 0; $i < $len; ++$i) { if ($this->_bodyCanonIgnoreStart > 0) { --$this->_bodyCanonIgnoreStart; continue; } switch ($string[$i]) { - case "\r" : + case "\r": $this->_bodyCanonLastChar = "\r"; break; - case "\n" : + case "\n": if ($this->_bodyCanonLastChar == "\r") { if ($nofws) { $this->_bodyCanonSpace = false; @@ -449,14 +460,14 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner throw new Swift_SwiftException('Invalid new line sequence in mail found \n without preceding \r'); } break; - case " " : - case "\t" : + case ' ': + case "\t": case "\x09": //HTAB if ($nofws) { $this->_bodyCanonSpace = true; break; } - default : + default: if ($this->_bodyCanonEmptyCounter > 0) { $canon .= str_repeat("\r\n", $this->_bodyCanonEmptyCounter); $this->_bodyCanonEmptyCounter = 0; @@ -486,15 +497,16 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner { // Init switch ($this->_hashAlgorithm) { - case 'rsa-sha1' : + case 'rsa-sha1': $this->_hashHandler = hash_init('sha1'); break; } - $this->_canonLine = ''; + $this->_bodyCanonLine = ''; } /** * @throws Swift_SwiftException + * * @return string */ private function _getEncryptedHash() diff --git a/tools/swift/classes/Swift/Signers/HeaderSigner.php b/tools/swift/classes/Swift/Signers/HeaderSigner.php index 67c794130..ef8832fdf 100644 --- a/tools/swift/classes/Swift/Signers/HeaderSigner.php +++ b/tools/swift/classes/Swift/Signers/HeaderSigner.php @@ -9,55 +9,55 @@ */ /** - * Header Signer Interface used to apply Header-Based Signature to a message + * Header Signer Interface used to apply Header-Based Signature to a message. * - * @author Xavier De Cock + * @author Xavier De Cock */ interface Swift_Signers_HeaderSigner extends Swift_Signer, Swift_InputByteStream { /** - * Exclude an header from the signed headers + * Exclude an header from the signed headers. * * @param string $header_name * - * @return Swift_Signers_HeaderSigner + * @return self */ public function ignoreHeader($header_name); /** - * Prepare the Signer to get a new Body + * Prepare the Signer to get a new Body. * - * @return Swift_Signers_HeaderSigner + * @return self */ public function startBody(); /** - * Give the signal that the body has finished streaming + * Give the signal that the body has finished streaming. * - * @return Swift_Signers_HeaderSigner + * @return self */ public function endBody(); /** - * Give the headers already given + * Give the headers already given. * * @param Swift_Mime_SimpleHeaderSet $headers * - * @return Swift_Signers_HeaderSigner + * @return self */ public function setHeaders(Swift_Mime_HeaderSet $headers); /** - * Add the header(s) to the headerSet + * Add the header(s) to the headerSet. * * @param Swift_Mime_HeaderSet $headers * - * @return Swift_Signers_HeaderSigner + * @return self */ public function addSignature(Swift_Mime_HeaderSet $headers); /** - * Return the list of header a signer might tamper + * Return the list of header a signer might tamper. * * @return array */ diff --git a/tools/swift/classes/Swift/Signers/OpenDKIMSigner.php b/tools/swift/classes/Swift/Signers/OpenDKIMSigner.php index b9738f423..8fdbaa43b 100644 --- a/tools/swift/classes/Swift/Signers/OpenDKIMSigner.php +++ b/tools/swift/classes/Swift/Signers/OpenDKIMSigner.php @@ -10,9 +10,9 @@ /** * DKIM Signer used to apply DKIM Signature to a message - * Takes advantage of pecl extension + * Takes advantage of pecl extension. * - * @author Xavier De Cock + * @author Xavier De Cock */ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner { @@ -29,11 +29,12 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner public function __construct($privateKey, $domainName, $selector) { - if (extension_loaded('opendkim')) { - $this->_peclLoaded = true; - } else { + if (!extension_loaded('opendkim')) { throw new Swift_SwiftException('php-opendkim extension not found'); } + + $this->_peclLoaded = true; + parent::__construct($privateKey, $domainName, $selector); } @@ -59,11 +60,11 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner { $bodyLen = $this->_bodyLen; if (is_bool($bodyLen)) { - $bodyLen = - 1; + $bodyLen = -1; } - $hash = ($this->_hashAlgorithm == 'rsa-sha1') ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256; - $bodyCanon = ($this->_bodyCanon == 'simple') ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; - $headerCanon = ($this->_headerCanon == 'simple') ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; + $hash = $this->_hashAlgorithm == 'rsa-sha1' ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256; + $bodyCanon = $this->_bodyCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; + $headerCanon = $this->_headerCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; $this->_dkimHandler = new OpenDKIMSign($this->_privateKey, $this->_selector, $this->_domainName, $headerCanon, $bodyCanon, $hash, $bodyLen); // Hardcode signature Margin for now $this->_dkimHandler->setMargin(78); @@ -81,7 +82,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner $listHeaders = $headers->listAll(); foreach ($listHeaders as $hName) { // Check if we need to ignore Header - if (! isset($this->_ignoredHeaders[strtolower($hName)])) { + if (!isset($this->_ignoredHeaders[strtolower($hName)])) { $tmp = $headers->getAll($hName); if ($headers->has($hName)) { foreach ($tmp as $header) { @@ -100,7 +101,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner public function startBody() { - if (! $this->_peclLoaded) { + if (!$this->_peclLoaded) { return parent::startBody(); } $this->dropFirstLF = true; @@ -111,7 +112,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner public function endBody() { - if (! $this->_peclLoaded) { + if (!$this->_peclLoaded) { return parent::endBody(); } $this->_dkimHandler->eom(); @@ -128,10 +129,11 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner } /** - * Set the signature timestamp + * Set the signature timestamp. * - * @param timestamp $time - * @return Swift_Signers_DKIMSigner + * @param int $time + * + * @return $this */ public function setSignatureTimestamp($time) { @@ -141,10 +143,11 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner } /** - * Set the signature expiration timestamp + * Set the signature expiration timestamp. * - * @param timestamp $time - * @return Swift_Signers_DKIMSigner + * @param int $time + * + * @return $this */ public function setSignatureExpiration($time) { @@ -154,10 +157,11 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner } /** - * Enable / disable the DebugHeaders + * Enable / disable the DebugHeaders. * - * @param bool $debug - * @return Swift_Signers_DKIMSigner + * @param bool $debug + * + * @return $this */ public function setDebugHeaders($debug) { @@ -170,7 +174,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner protected function _canonicalizeBody($string) { - if (! $this->_peclLoaded) { + if (!$this->_peclLoaded) { return parent::_canonicalizeBody($string); } if (false && $this->dropFirstLF === true) { diff --git a/tools/swift/classes/Swift/Signers/SMimeSigner.php b/tools/swift/classes/Swift/Signers/SMimeSigner.php index 42e294c6d..d13c02e4c 100644 --- a/tools/swift/classes/Swift/Signers/SMimeSigner.php +++ b/tools/swift/classes/Swift/Signers/SMimeSigner.php @@ -12,8 +12,8 @@ * MIME Message Signer used to apply S/MIME Signature/Encryption to a message. * * - * @author Romain-Geissler - * @author Sebastiaan Stok + * @author Romain-Geissler + * @author Sebastiaan Stok */ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner { @@ -26,6 +26,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner protected $signOptions; protected $encryptOptions; protected $encryptCipher; + protected $extraCerts = null; /** * @var Swift_StreamFilters_StringReplacementFilterFactory @@ -40,9 +41,9 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * Constructor. * - * @param string $certificate - * @param string $privateKey - * @param string $encryptCertificate + * @param string|null $signCertificate + * @param string|null $signPrivateKey + * @param string|null $encryptCertificate */ public function __construct($signCertificate = null, $signPrivateKey = null, $encryptCertificate = null) { @@ -73,7 +74,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner * @param string $certificate * @param string $privateKey * - * @return Swift_Signers_SMimeSigner + * @return self */ public static function newInstance($certificate = null, $privateKey = null) { @@ -83,15 +84,16 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * Set the certificate location to use for signing. * - * @link http://www.php.net/manual/en/openssl.pkcs7.flags.php + * @see http://www.php.net/manual/en/openssl.pkcs7.flags.php * * @param string $certificate * @param string|array $privateKey If the key needs an passphrase use array('file-location', 'passphrase') instead * @param int $signOptions Bitwise operator options for openssl_pkcs7_sign() + * @param string $extraCerts A file containing intermediate certificates needed by the signing certificate * - * @return Swift_Signers_SMimeSigner + * @return $this */ - public function setSignCertificate($certificate, $privateKey = null, $signOptions = PKCS7_DETACHED) + public function setSignCertificate($certificate, $privateKey = null, $signOptions = PKCS7_DETACHED, $extraCerts = null) { $this->signCertificate = 'file://'.str_replace('\\', '/', realpath($certificate)); @@ -105,6 +107,9 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner } $this->signOptions = $signOptions; + if (null !== $extraCerts) { + $this->extraCerts = str_replace('\\', '/', realpath($extraCerts)); + } return $this; } @@ -112,13 +117,13 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * Set the certificate location to use for encryption. * - * @link http://www.php.net/manual/en/openssl.pkcs7.flags.php - * @link http://nl3.php.net/manual/en/openssl.ciphers.php + * @see http://www.php.net/manual/en/openssl.pkcs7.flags.php + * @see http://nl3.php.net/manual/en/openssl.ciphers.php * * @param string|array $recipientCerts Either an single X.509 certificate, or an assoc array of X.509 certificates. * @param int $cipher * - * @return Swift_Signers_SMimeSigner + * @return $this */ public function setEncryptCertificate($recipientCerts, $cipher = null) { @@ -162,9 +167,9 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner * But some older mail clients, namely Microsoft Outlook 2000 will work when the message first encrypted. * As this goes against the official specs, its recommended to only use 'encryption -> signing' when specifically targeting these 'broken' clients. * - * @param string $signThenEncrypt + * @param bool $signThenEncrypt * - * @return Swift_Signers_SMimeSigner + * @return $this */ public function setSignThenEncrypt($signThenEncrypt = true) { @@ -184,7 +189,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * Resets internal states. * - * @return Swift_Signers_SMimeSigner + * @return $this */ public function reset() { @@ -196,7 +201,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner * * @param Swift_Message $message * - * @return Swift_Signers_SMimeSigner + * @return $this */ public function signMessage(Swift_Message $message) { @@ -229,7 +234,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * @param Swift_InputByteStream $inputStream - * @param Swift_Message $mimeEntity + * @param Swift_Message $mimeEntity */ protected function toSMimeByteStream(Swift_InputByteStream $inputStream, Swift_Message $message) { @@ -287,7 +292,12 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner { $signedMessageStream = new Swift_ByteStream_TemporaryFileByteStream(); - if (!openssl_pkcs7_sign($outputStream->getPath(), $signedMessageStream->getPath(), $this->signCertificate, $this->signPrivateKey, array(), $this->signOptions)) { + $args = array($outputStream->getPath(), $signedMessageStream->getPath(), $this->signCertificate, $this->signPrivateKey, array(), $this->signOptions); + if (null !== $this->extraCerts) { + $args[] = $this->extraCerts; + } + + if (!call_user_func_array('openssl_pkcs7_sign', $args)) { throw new Swift_IoException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string())); } @@ -390,7 +400,6 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner } $boundary = trim($contentTypeData['1'], '"'); - $boundaryLen = strlen($boundary); // Skip the header and CRLF CRLF $fromStream->setReadPointer($headersPosEnd + 4); diff --git a/tools/swift/classes/Swift/Signers/index.php b/tools/swift/classes/Swift/Signers/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Signers/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/SmtpTransport.php b/tools/swift/classes/Swift/SmtpTransport.php index 5d4945e17..b97f01e7c 100644 --- a/tools/swift/classes/Swift/SmtpTransport.php +++ b/tools/swift/classes/Swift/SmtpTransport.php @@ -11,7 +11,8 @@ /** * Sends Messages over SMTP with ESMTP support. * - * @author Chris Corbyn + * @author Chris Corbyn + * * @method Swift_SmtpTransport setUsername(string $username) Set the username to authenticate with. * @method string getUsername() Get the username to authenticate with. * @method Swift_SmtpTransport setPassword(string $password) Set the password to authenticate with. @@ -24,9 +25,9 @@ class Swift_SmtpTransport extends Swift_Transport_EsmtpTransport /** * Create a new SmtpTransport, optionally with $host, $port and $security. * - * @param string $host - * @param int $port - * @param string $security + * @param string $host + * @param int $port + * @param string $security */ public function __construct($host = 'localhost', $port = 25, $security = null) { @@ -44,11 +45,11 @@ class Swift_SmtpTransport extends Swift_Transport_EsmtpTransport /** * Create a new SmtpTransport instance. * - * @param string $host - * @param int $port - * @param string $security + * @param string $host + * @param int $port + * @param string $security * - * @return Swift_SmtpTransport + * @return self */ public static function newInstance($host = 'localhost', $port = 25, $security = null) { diff --git a/tools/swift/classes/Swift/Spool.php b/tools/swift/classes/Swift/Spool.php index afae5fac3..c16ab4b38 100644 --- a/tools/swift/classes/Swift/Spool.php +++ b/tools/swift/classes/Swift/Spool.php @@ -11,7 +11,7 @@ /** * Interface for spools. * - * @author Fabien Potencier + * @author Fabien Potencier */ interface Swift_Spool { @@ -37,7 +37,7 @@ interface Swift_Spool * * @param Swift_Mime_Message $message The message to store * - * @return bool Whether the operation has succeeded + * @return bool Whether the operation has succeeded */ public function queueMessage(Swift_Mime_Message $message); @@ -47,7 +47,7 @@ interface Swift_Spool * @param Swift_Transport $transport A transport instance * @param string[] $failedRecipients An array of failures by-reference * - * @return int The number of sent emails + * @return int The number of sent emails */ public function flushQueue(Swift_Transport $transport, &$failedRecipients = null); } diff --git a/tools/swift/classes/Swift/SpoolTransport.php b/tools/swift/classes/Swift/SpoolTransport.php index 9351c40d3..79c9b1f03 100644 --- a/tools/swift/classes/Swift/SpoolTransport.php +++ b/tools/swift/classes/Swift/SpoolTransport.php @@ -11,7 +11,7 @@ /** * Stores Messages in a queue. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_SpoolTransport extends Swift_Transport_SpoolTransport { @@ -38,7 +38,7 @@ class Swift_SpoolTransport extends Swift_Transport_SpoolTransport * * @param Swift_Spool $spool * - * @return Swift_SpoolTransport + * @return self */ public static function newInstance(Swift_Spool $spool) { diff --git a/tools/swift/classes/Swift/StreamFilter.php b/tools/swift/classes/Swift/StreamFilter.php index 1c3fd3a57..362be2e8d 100644 --- a/tools/swift/classes/Swift/StreamFilter.php +++ b/tools/swift/classes/Swift/StreamFilter.php @@ -11,7 +11,7 @@ /** * Processes bytes as they pass through a stream and performs filtering. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_StreamFilter { diff --git a/tools/swift/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php b/tools/swift/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php index 886869929..9412b1dc7 100644 --- a/tools/swift/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php +++ b/tools/swift/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php @@ -13,7 +13,7 @@ * * This stream filter deals with Byte arrays rather than simple strings. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilter { @@ -53,11 +53,11 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt $last_size = $size = 0; foreach ($search as $i => $search_element) { if ($tree !== null) { - $tree[-1] = min (count($replace) - 1, $i - 1); + $tree[-1] = min(count($replace) - 1, $i - 1); $tree[-2] = $last_size; } $tree = &$this->_tree; - if (is_array ($search_element)) { + if (is_array($search_element)) { foreach ($search_element as $k => $char) { $this->_index[$char] = true; if (!isset($tree[$char])) { @@ -65,7 +65,7 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt } $tree = &$tree[$char]; } - $last_size = $k+1; + $last_size = $k + 1; $size = max($size, $last_size); } else { $last_size = 1; @@ -78,13 +78,13 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt } } if ($i !== null) { - $tree[-1] = min (count ($replace) - 1, $i); + $tree[-1] = min(count($replace) - 1, $i); $tree[-2] = $last_size; $this->_treeMaxLen = $size; } foreach ($replace as $rep) { if (!is_array($rep)) { - $rep = array ($rep); + $rep = array($rep); } $this->_replace[] = $rep; } @@ -105,14 +105,14 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt { $endOfBuffer = end($buffer); - return isset ($this->_index[$endOfBuffer]); + return isset($this->_index[$endOfBuffer]); } /** * Perform the actual replacements on $buffer and return the result. * - * @param array $buffer - * @param int $_minReplaces + * @param array $buffer + * @param int $_minReplaces * * @return array */ @@ -124,16 +124,17 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt $newBuffer = array(); $buf_size = count($buffer); + $last_size = 0; for ($i = 0; $i < $buf_size; ++$i) { $search_pos = $this->_tree; $last_found = PHP_INT_MAX; // We try to find if the next byte is part of a search pattern for ($j = 0; $j <= $this->_treeMaxLen; ++$j) { // We have a new byte for a search pattern - if (isset ($buffer [$p = $i + $j]) && isset($search_pos[$buffer[$p]])) { + if (isset($buffer[$p = $i + $j]) && isset($search_pos[$buffer[$p]])) { $search_pos = $search_pos[$buffer[$p]]; // We have a complete pattern, save, in case we don't find a better match later - if (isset($search_pos[- 1]) && $search_pos[-1] < $last_found + if (isset($search_pos[-1]) && $search_pos[-1] < $last_found && $search_pos[-1] > $_minReplaces) { $last_found = $search_pos[-1]; $last_size = $search_pos[-2]; diff --git a/tools/swift/classes/Swift/StreamFilters/StringReplacementFilter.php b/tools/swift/classes/Swift/StreamFilters/StringReplacementFilter.php index e6b9e7b8a..f64144af2 100644 --- a/tools/swift/classes/Swift/StreamFilters/StringReplacementFilter.php +++ b/tools/swift/classes/Swift/StreamFilters/StringReplacementFilter.php @@ -11,7 +11,7 @@ /** * Processes bytes as they pass through a buffer and replaces sequences in it. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_StreamFilters_StringReplacementFilter implements Swift_StreamFilter { @@ -42,6 +42,10 @@ class Swift_StreamFilters_StringReplacementFilter implements Swift_StreamFilter */ public function shouldBuffer($buffer) { + if ('' === $buffer) { + return false; + } + $endOfBuffer = substr($buffer, -1); foreach ((array) $this->_search as $needle) { if (false !== strpos($needle, $endOfBuffer)) { diff --git a/tools/swift/classes/Swift/StreamFilters/StringReplacementFilterFactory.php b/tools/swift/classes/Swift/StreamFilters/StringReplacementFilterFactory.php index 4b12cfffd..e98240b5b 100644 --- a/tools/swift/classes/Swift/StreamFilters/StringReplacementFilterFactory.php +++ b/tools/swift/classes/Swift/StreamFilters/StringReplacementFilterFactory.php @@ -11,7 +11,7 @@ /** * Creates filters for replacing needles in a string buffer. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_StreamFilters_StringReplacementFilterFactory implements Swift_ReplacementFilterFactory { diff --git a/tools/swift/classes/Swift/StreamFilters/index.php b/tools/swift/classes/Swift/StreamFilters/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/StreamFilters/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/SwiftException.php b/tools/swift/classes/Swift/SwiftException.php index 22ee3eb40..db3d31093 100644 --- a/tools/swift/classes/Swift/SwiftException.php +++ b/tools/swift/classes/Swift/SwiftException.php @@ -11,17 +11,19 @@ /** * Base Exception class. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_SwiftException extends Exception { /** * Create a new SwiftException with $message. * - * @param string $message + * @param string $message + * @param int $code + * @param Exception $previous */ - public function __construct($message) + public function __construct($message, $code = 0, Exception $previous = null) { - parent::__construct($message); + parent::__construct($message, $code, $previous); } } diff --git a/tools/swift/classes/Swift/Transport.php b/tools/swift/classes/Swift/Transport.php index ac97b409f..6535eadf2 100644 --- a/tools/swift/classes/Swift/Transport.php +++ b/tools/swift/classes/Swift/Transport.php @@ -11,7 +11,7 @@ /** * Sends Messages via an abstract Transport subsystem. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Transport { diff --git a/tools/swift/classes/Swift/Transport/AbstractSmtpTransport.php b/tools/swift/classes/Swift/Transport/AbstractSmtpTransport.php index 6fcc32125..60233f968 100644 --- a/tools/swift/classes/Swift/Transport/AbstractSmtpTransport.php +++ b/tools/swift/classes/Swift/Transport/AbstractSmtpTransport.php @@ -11,7 +11,7 @@ /** * Sends Messages over SMTP. * - * @author Chris Corbyn + * @author Chris Corbyn */ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport { @@ -57,7 +57,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport * * @param string $domain * - * @return Swift_Transport_AbstractSmtpTransport + * @return $this */ public function setLocalDomain($domain) { @@ -87,7 +87,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport } /** - * Returns the IP used to connect to the destination + * Returns the IP used to connect to the destination. * * @return string */ @@ -159,9 +159,10 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport } if (!$reversePath = $this->_getReversePath($message)) { - throw new Swift_TransportException( + $this->_throwException(new Swift_TransportException( 'Cannot send message without a sender address' - ); + ) + ); } $to = (array) $message->getTo(); @@ -300,7 +301,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport protected function _doMailFromCommand($address) { $this->executeCommand( - sprintf("MAIL FROM: <%s>\r\n", $address), array(250) + sprintf("MAIL FROM:<%s>\r\n", $address), array(250) ); } @@ -308,7 +309,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport protected function _doRcptToCommand($address) { $this->executeCommand( - sprintf("RCPT TO: <%s>\r\n", $address), array(250, 251, 252) + sprintf("RCPT TO:<%s>\r\n", $address), array(250, 251, 252) ); } @@ -395,7 +396,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport do { $line = $this->_buffer->readLine($seq); $response .= $line; - } while (null !== $line && false !== $line && ' ' != $line{3}); + } while (null !== $line && false !== $line && ' ' != $line[3]); } catch (Swift_TransportException $e) { $this->_throwException($e); } catch (Swift_IoException $e) { @@ -416,7 +417,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport foreach ($recipients as $forwardPath) { try { $this->_doRcptToCommand($forwardPath); - $sent++; + ++$sent; } catch (Swift_TransportException $e) { $failedRecipients[] = $forwardPath; } @@ -460,11 +461,17 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport /** Try to determine the hostname of the server this is run on */ private function _lookupHostname() { - if (!empty($_SERVER['SERVER_NAME']) - && $this->_isFqdn($_SERVER['SERVER_NAME'])) { + if (!empty($_SERVER['SERVER_NAME']) && $this->_isFqdn($_SERVER['SERVER_NAME'])) { $this->_domain = $_SERVER['SERVER_NAME']; } elseif (!empty($_SERVER['SERVER_ADDR'])) { - $this->_domain = sprintf('[%s]', $_SERVER['SERVER_ADDR']); + // Set the address literal tag (See RFC 5321, section: 4.1.3) + if (false === strpos($_SERVER['SERVER_ADDR'], ':')) { + $prefix = ''; // IPv4 addresses are not tagged. + } else { + $prefix = 'IPv6:'; // Adding prefix in case of IPv6. + } + + $this->_domain = sprintf('[%s%s]', $prefix, $_SERVER['SERVER_ADDR']); } } @@ -474,9 +481,9 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport // We could do a really thorough check, but there's really no point if (false !== $dotPos = strpos($hostname, '.')) { return ($dotPos > 0) && ($dotPos != strlen($hostname) - 1); - } else { - return false; } + + return false; } /** @@ -484,6 +491,9 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport */ public function __destruct() { - $this->stop(); + try { + $this->stop(); + } catch (Exception $e) { + } } } diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php b/tools/swift/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php index 4774e0324..53f721d03 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php @@ -11,7 +11,7 @@ /** * Handles CRAM-MD5 authentication. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_Esmtp_Auth_CramMd5Authenticator implements Swift_Transport_Esmtp_Authenticator { @@ -73,7 +73,7 @@ class Swift_Transport_Esmtp_Auth_CramMd5Authenticator implements Swift_Transport $k_ipad = substr($secret, 0, 64) ^ str_repeat(chr(0x36), 64); $k_opad = substr($secret, 0, 64) ^ str_repeat(chr(0x5C), 64); - $inner = pack('H32', md5($k_ipad.$challenge)); + $inner = pack('H32', md5($k_ipad.$challenge)); $digest = md5($k_opad.$inner); return $digest; diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php b/tools/swift/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php index ebb35520b..6ab6e3337 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php @@ -11,7 +11,7 @@ /** * Handles LOGIN authentication. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_Esmtp_Auth_LoginAuthenticator implements Swift_Transport_Esmtp_Authenticator { diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php b/tools/swift/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php index 2c02bd2c1..839265857 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php @@ -13,12 +13,12 @@ /** * Handles NTLM authentication. * - * @author Ward Peeters + * @author Ward Peeters */ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Esmtp_Authenticator { const NTLMSIG = "NTLMSSP\x00"; - const DESCONST = "KGS!@#$%"; + const DESCONST = 'KGS!@#$%'; /** * Get the name of the AUTH mechanism this Authenticator handles. @@ -34,23 +34,19 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es * Try to authenticate the user with $username and $password. * * @param Swift_Transport_SmtpAgent $agent - * @param string $username - * @param string $password + * @param string $username + * @param string $password * * @return bool */ public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password) { - if (!function_exists('mcrypt_module_open')) { - throw new LogicException('The mcrypt functions need to be enabled to use the NTLM authenticator.'); - } - - if (!function_exists('openssl_random_pseudo_bytes')) { + if (!function_exists('openssl_random_pseudo_bytes') || !function_exists('openssl_encrypt')) { throw new LogicException('The OpenSSL extension must be enabled to use the NTLM authenticator.'); } if (!function_exists('bcmul')) { - throw new LogicException('The BCMatch functions must be enabled to use the NTLM authenticator.'); + throw new LogicException('The BCMath functions must be enabled to use the NTLM authenticator.'); } try { @@ -59,7 +55,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $response = base64_decode(substr(trim($this->sendMessage1($agent)), 4)); // extra parameters for our unit cases - $timestamp = func_num_args() > 3 ? func_get_arg(3) : $this->getCorrectTimestamp(bcmul(microtime(true), "1000")); + $timestamp = func_num_args() > 3 ? func_get_arg(3) : $this->getCorrectTimestamp(bcmul(microtime(true), '1000')); $client = func_num_args() > 4 ? func_get_arg(4) : $this->getRandomBytes(8); // Message 3 response @@ -83,7 +79,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es // pad to $bits bit $bin_length = strlen($bin); if ($bin_length < $bits) { - $bin = str_repeat("0", $bits - $bin_length).$bin; + $bin = str_repeat('0', $bits - $bin_length).$bin; } } else { // negative @@ -91,7 +87,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $bin = base_convert($si, 10, 2); $bin_length = strlen($bin); if ($bin_length > $bits) { - $bin = str_repeat("1", $bits - $bin_length).$bin; + $bin = str_repeat('1', $bits - $bin_length).$bin; } } } @@ -100,9 +96,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Send our auth message and returns the response + * Send our auth message and returns the response. * * @param Swift_Transport_SmtpAgent $agent + * * @return string SMTP Response */ protected function sendMessage1(Swift_Transport_SmtpAgent $agent) @@ -113,9 +110,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Fetch all details of our response (message 2) + * Fetch all details of our response (message 2). * * @param string $response + * * @return array our response parsed */ protected function parseMessage2($response) @@ -146,9 +144,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Read the blob information in from message2 + * Read the blob information in from message2. * * @param $block + * * @return array */ protected function readSubBlock($block) @@ -177,15 +176,16 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Send our final message with all our data + * Send our final message with all our data. * - * @param string $response Message 1 response (message 2) - * @param string $username - * @param string $password - * @param string $timestamp - * @param string $client + * @param string $response Message 1 response (message 2) + * @param string $username + * @param string $password + * @param string $timestamp + * @param string $client * @param Swift_Transport_SmtpAgent $agent - * @param bool $v2 Use version2 of the protocol + * @param bool $v2 Use version2 of the protocol + * * @return string */ protected function sendMessage3($response, $username, $password, $timestamp, $client, Swift_Transport_SmtpAgent $agent, $v2 = true) @@ -212,7 +212,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Create our message 1 + * Create our message 1. * * @return string */ @@ -224,13 +224,14 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Create our message 3 + * Create our message 3. * * @param string $domain * @param string $username * @param string $workstation * @param string $lmResponse * @param string $ntlmResponse + * * @return string */ protected function createMessage3($domain, $username, $workstation, $lmResponse, $ntlmResponse) @@ -253,7 +254,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es .$domainSec // Domain header .$userSec // User header .$workSec // Workstation header -.$this->createByte("000000009a", 8) // session key header (empty) +.$this->createByte('000000009a', 8) // session key header (empty) .$this->createByte('01020000') // FLAGS .$this->convertTo16bit($domain) // domain name .$this->convertTo16bit($username) // username @@ -263,9 +264,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * @param string $timestamp Epoch timestamp in microseconds - * @param string $client Random bytes + * @param string $timestamp Epoch timestamp in microseconds + * @param string $client Random bytes * @param string $targetInfo + * * @return string */ protected function createBlob($timestamp, $client, $targetInfo) @@ -280,11 +282,12 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Get domain and username from our username + * Get domain and username from our username. * * @example DOMAIN\username * * @param string $name + * * @return array */ protected function getDomainAndUsername($name) @@ -293,16 +296,22 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es return explode('\\', $name); } - list($user, $domain) = explode('@', $name); + if (false !== strpos($name, '@')) { + list($user, $domain) = explode('@', $name); - return array($domain, $user); + return array($domain, $user); + } + + // no domain passed + return array('', $name); } /** - * Create LMv1 response + * Create LMv1 response. * * @param string $password * @param string $challenge + * * @return string */ protected function createLMPassword($password, $challenge) @@ -327,10 +336,11 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Create NTLMv1 response + * Create NTLMv1 response. * * @param string $password * @param string $challenge + * * @return string */ protected function createNTLMPassword($password, $challenge) @@ -347,23 +357,22 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Convert a normal timestamp to a tenth of a microtime epoch time + * Convert a normal timestamp to a tenth of a microtime epoch time. * * @param string $time + * * @return string */ protected function getCorrectTimestamp($time) { // Get our timestamp (tricky!) - bcscale(0); - $time = number_format($time, 0, '.', ''); // save microtime to string - $time = bcadd($time, "11644473600000"); // add epoch time - $time = bcmul($time, 10000); // tenths of a microsecond. + $time = bcadd($time, '11644473600000', 0); // add epoch time + $time = bcmul($time, 10000, 0); // tenths of a microsecond. $binary = $this->si2bin($time, 64); // create 64 bit binary string - $timestamp = ""; - for ($i = 0; $i < 8; $i++) { + $timestamp = ''; + for ($i = 0; $i < 8; ++$i) { $timestamp .= chr(bindec(substr($binary, -(($i + 1) * 8), 8))); } @@ -371,13 +380,14 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Create LMv2 response + * Create LMv2 response. * * @param string $password * @param string $username * @param string $domain * @param string $challenge NTLM Challenge - * @param string $client Random string + * @param string $client Random string + * * @return string */ protected function createLMv2Password($password, $username, $domain, $challenge, $client) @@ -395,16 +405,18 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Create NTLMv2 response + * Create NTLMv2 response. * * @param string $password * @param string $username * @param string $domain - * @param string $challenge Hex values + * @param string $challenge Hex values * @param string $targetInfo Hex values * @param string $timestamp - * @param string $client Random bytes + * @param string $client Random bytes + * * @return string + * * @see http://davenport.sourceforge.net/ntlm.html#theNtlmResponse */ protected function createNTLMv2Hash($password, $username, $domain, $challenge, $targetInfo, $timestamp, $client) @@ -424,7 +436,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es { $material = array(bin2hex($key[0])); $len = strlen($key); - for ($i = 1; $i < $len; $i++) { + for ($i = 1; $i < $len; ++$i) { list($high, $low) = str_split(bin2hex($key[$i])); $v = $this->castToByte(ord($key[$i - 1]) << (7 + 1 - $i) | $this->uRShift(hexdec(dechex(hexdec($high) & 0xf).dechex(hexdec($low) & 0xf)), $i)); $material[] = str_pad(substr(dechex($v), -2), 2, '0', STR_PAD_LEFT); // cast to byte @@ -450,12 +462,14 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** HELPER FUNCTIONS */ + /** - * Create our security buffer depending on length and offset + * Create our security buffer depending on length and offset. + * + * @param string $value Value we want to put in + * @param int $offset start of value + * @param bool $is16 Do we 16bit string or not? * - * @param string $value Value we want to put in - * @param int $offset start of value - * @param bool $is16 Do we 16bit string or not? * @return string */ protected function createSecurityBuffer($value, $offset, $is16 = false) @@ -468,9 +482,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Read our security buffer to fetch length and offset of our value + * Read our security buffer to fetch length and offset of our value. * * @param string $value Securitybuffer in hex + * * @return array array with length and offset */ protected function readSecurityBuffer($value) @@ -482,9 +497,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Cast to byte java equivalent to (byte) + * Cast to byte java equivalent to (byte). * * @param int $v + * * @return int */ protected function castToByte($v) @@ -494,10 +510,11 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es /** * Java unsigned right bitwise - * $a >>> $b + * $a >>> $b. * * @param int $a * @param int $b + * * @return int */ protected function uRShift($a, $b) @@ -510,11 +527,12 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Right padding with 0 to certain length + * Right padding with 0 to certain length. * * @param string $input - * @param int $bytes Length of bytes - * @param bool $isHex Did we provided hex value + * @param int $bytes Length of bytes + * @param bool $isHex Did we provided hex value + * * @return string */ protected function createByte($input, $bytes = 4, $isHex = true) @@ -529,9 +547,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Create random bytes + * Create random bytes. * * @param $length + * * @return string */ protected function getRandomBytes($length) @@ -546,26 +565,27 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** ENCRYPTION ALGORITHMS */ + /** - * DES Encryption + * DES Encryption. * - * @param string $value + * @param string $value An 8-byte string * @param string $key + * * @return string */ protected function desEncrypt($value, $key) { - $cipher = mcrypt_module_open(MCRYPT_DES, '', 'ecb', ''); - mcrypt_generic_init($cipher, $key, mcrypt_create_iv(mcrypt_enc_get_iv_size($cipher), MCRYPT_DEV_RANDOM)); - - return mcrypt_generic($cipher, $value); + // 1 == OPENSSL_RAW_DATA - but constant is only available as of PHP 5.4. + return substr(openssl_encrypt($value, 'DES-ECB', $key, 1), 0, 8); } /** - * MD5 Encryption + * MD5 Encryption. * * @param string $key Encryption key * @param string $msg Message to encrypt + * * @return string */ protected function md5Encrypt($key, $msg) @@ -583,10 +603,12 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * MD4 Encryption + * MD4 Encryption. * * @param string $input + * * @return string + * * @see http://php.net/manual/en/ref.hash.php */ protected function md4Encrypt($input) @@ -597,9 +619,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Convert UTF-8 to UTF-16 + * Convert UTF-8 to UTF-16. * * @param string $input + * * @return string */ protected function convertTo16bit($input) @@ -608,8 +631,10 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Hex2bin replacement for < PHP 5.4 + * Hex2bin replacement for < PHP 5.4. + * * @param string $hex + * * @return string Binary */ protected function hex2bin($hex) @@ -631,7 +656,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es echo substr($message, 0, 16)." NTLMSSP Signature
\n"; echo $messageId." Type Indicator
\n"; - if ($messageId == "02000000") { + if ($messageId == '02000000') { $map = array( 'Challenge', 'Context', @@ -650,7 +675,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es foreach ($map as $key => $value) { echo bin2hex($data[$key]).' - '.$data[$key].' ||| '.$value."
\n"; } - } elseif ($messageId == "03000000") { + } elseif ($messageId == '03000000') { $i = 0; $data[$i++] = substr($message, 24, 16); list($lmLength, $lmOffset) = $this->readSecurityBuffer($data[$i - 1]); @@ -695,6 +720,6 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } } - echo "

"; + echo '

'; } } diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php b/tools/swift/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php index 98f6d1816..43219f934 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php @@ -11,7 +11,7 @@ /** * Handles PLAIN authentication. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_Esmtp_Auth_PlainAuthenticator implements Swift_Transport_Esmtp_Authenticator { diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php b/tools/swift/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php index 80c00b987..ca35e7b83 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php @@ -19,7 +19,8 @@ * ->setPassword('YOUR_ACCESS_TOKEN'); * * - * @author xu.li + * @author xu.li + * * @see https://developers.google.com/google-apps/gmail/xoauth2_protocol */ class Swift_Transport_Esmtp_Auth_XOAuth2Authenticator implements Swift_Transport_Esmtp_Authenticator @@ -47,7 +48,7 @@ class Swift_Transport_Esmtp_Auth_XOAuth2Authenticator implements Swift_Transport { try { $param = $this->constructXOAuth2Params($email, $token); - $agent->executeCommand("AUTH XOAUTH2 ".$param."\r\n", array(235)); + $agent->executeCommand('AUTH XOAUTH2 '.$param."\r\n", array(235)); return true; } catch (Swift_TransportException $e) { @@ -58,7 +59,7 @@ class Swift_Transport_Esmtp_Auth_XOAuth2Authenticator implements Swift_Transport } /** - * Construct the auth parameter + * Construct the auth parameter. * * @see https://developers.google.com/google-apps/gmail/xoauth2_protocol#the_sasl_xoauth2_mechanism */ diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Auth/index.php b/tools/swift/classes/Swift/Transport/Esmtp/Auth/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Transport/Esmtp/Auth/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Transport/Esmtp/AuthHandler.php b/tools/swift/classes/Swift/Transport/Esmtp/AuthHandler.php index 6b83194c9..cb36133c9 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/AuthHandler.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/AuthHandler.php @@ -11,7 +11,7 @@ /** * An ESMTP handler for AUTH support. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler { @@ -172,7 +172,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler foreach ($this->_getAuthenticatorsForAgent() as $authenticator) { if (in_array(strtolower($authenticator->getAuthKeyword()), array_map('strtolower', $this->_esmtpParams))) { - $count++; + ++$count; if ($authenticator->authenticate($agent, $this->_username, $this->_password)) { return; } diff --git a/tools/swift/classes/Swift/Transport/Esmtp/Authenticator.php b/tools/swift/classes/Swift/Transport/Esmtp/Authenticator.php index 9078003a9..12a9abf81 100644 --- a/tools/swift/classes/Swift/Transport/Esmtp/Authenticator.php +++ b/tools/swift/classes/Swift/Transport/Esmtp/Authenticator.php @@ -11,7 +11,7 @@ /** * An Authentication mechanism. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Transport_Esmtp_Authenticator { diff --git a/tools/swift/classes/Swift/Transport/Esmtp/index.php b/tools/swift/classes/Swift/Transport/Esmtp/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Transport/Esmtp/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/Transport/EsmtpHandler.php b/tools/swift/classes/Swift/Transport/EsmtpHandler.php index cb76eddf8..c17ef8feb 100644 --- a/tools/swift/classes/Swift/Transport/EsmtpHandler.php +++ b/tools/swift/classes/Swift/Transport/EsmtpHandler.php @@ -11,7 +11,7 @@ /** * An ESMTP handler. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Transport_EsmtpHandler { diff --git a/tools/swift/classes/Swift/Transport/EsmtpTransport.php b/tools/swift/classes/Swift/Transport/EsmtpTransport.php index e860a8ef3..156e2cf5b 100644 --- a/tools/swift/classes/Swift/Transport/EsmtpTransport.php +++ b/tools/swift/classes/Swift/Transport/EsmtpTransport.php @@ -11,7 +11,7 @@ /** * Sends Messages over SMTP with ESMTP support. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTransport implements Swift_Transport_SmtpAgent { @@ -42,6 +42,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo 'blocking' => 1, 'tls' => false, 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET, + 'stream_context_options' => array(), ); /** @@ -62,7 +63,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo * * @param string $host * - * @return Swift_Transport_EsmtpTransport + * @return $this */ public function setHost($host) { @@ -84,9 +85,9 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo /** * Set the port to connect to. * - * @param int $port + * @param int $port * - * @return Swift_Transport_EsmtpTransport + * @return $this */ public function setPort($port) { @@ -108,9 +109,9 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo /** * Set the connection timeout. * - * @param int $timeout seconds + * @param int $timeout seconds * - * @return Swift_Transport_EsmtpTransport + * @return $this */ public function setTimeout($timeout) { @@ -131,14 +132,15 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo } /** - * Set the encryption type (tls or ssl) + * Set the encryption type (tls or ssl). * * @param string $encryption * - * @return Swift_Transport_EsmtpTransport + * @return $this */ public function setEncryption($encryption) { + $encryption = strtolower($encryption); if ('tls' == $encryption) { $this->_params['protocol'] = 'tcp'; $this->_params['tls'] = true; @@ -160,12 +162,36 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo return $this->_params['tls'] ? 'tls' : $this->_params['protocol']; } + /** + * Sets the stream context options. + * + * @param array $options + * + * @return $this + */ + public function setStreamOptions($options) + { + $this->_params['stream_context_options'] = $options; + + return $this; + } + + /** + * Returns the stream context options. + * + * @return array + */ + public function getStreamOptions() + { + return $this->_params['stream_context_options']; + } + /** * Sets the source IP. * * @param string $source * - * @return Swift_Transport_EsmtpTransport + * @return $this */ public function setSourceIp($source) { @@ -181,7 +207,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo */ public function getSourceIp() { - return $this->_params['sourceIp']; + return isset($this->_params['sourceIp']) ? $this->_params['sourceIp'] : null; } /** @@ -189,7 +215,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo * * @param Swift_Transport_EsmtpHandler[] $handlers * - * @return Swift_Transport_EsmtpTransport + * @return $this */ public function setExtensionHandlers(array $handlers) { @@ -197,7 +223,8 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo foreach ($handlers as $handler) { $assoc[$handler->getHandledKeyword()] = $handler; } - uasort($assoc, array($this, '_sortHandlers')); + + @uasort($assoc, array($this, '_sortHandlers')); $this->_handlers = $assoc; $this->_setHandlerParams(); @@ -243,8 +270,6 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo return parent::executeCommand($command, $codes, $failures); } - // -- Mixin invocation code - /** Mixin handling method for ESMTP handlers */ public function __call($method, $args) { @@ -254,7 +279,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo )) { $return = call_user_func_array(array($handler, $method), $args); // Allow fluid method calls - if (is_null($return) && substr($method, 0, 3) == 'set') { + if (null === $return && substr($method, 0, 3) == 'set') { return $this; } else { return $return; @@ -318,7 +343,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo } $paramStr = !empty($params) ? ' '.implode(' ', $params) : ''; $this->executeCommand( - sprintf("MAIL FROM: <%s>%s\r\n", $address, $paramStr), array(250) + sprintf("MAIL FROM:<%s>%s\r\n", $address, $paramStr), array(250) ); } @@ -332,7 +357,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo } $paramStr = !empty($params) ? ' '.implode(' ', $params) : ''; $this->executeCommand( - sprintf("RCPT TO: <%s>%s\r\n", $address, $paramStr), array(250, 251, 252) + sprintf("RCPT TO:<%s>%s\r\n", $address, $paramStr), array(250, 251, 252) ); } diff --git a/tools/swift/classes/Swift/Transport/FailoverTransport.php b/tools/swift/classes/Swift/Transport/FailoverTransport.php index eafde009b..311a0f2ad 100644 --- a/tools/swift/classes/Swift/Transport/FailoverTransport.php +++ b/tools/swift/classes/Swift/Transport/FailoverTransport.php @@ -11,7 +11,7 @@ /** * Contains a list of redundant Transports so when one fails, the next is used. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTransport { @@ -22,9 +22,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran */ private $_currentTransport; - /** - * Creates a new FailoverTransport. - */ + // needed as __construct is called from elsewhere explicitly public function __construct() { parent::__construct(); @@ -45,6 +43,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran { $maxTransports = count($this->_transports); $sent = 0; + $this->_lastUsedTransport = null; for ($i = 0; $i < $maxTransports && $transport = $this->_getNextTransport(); ++$i) { @@ -53,7 +52,11 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran $transport->start(); } - return $transport->send($message, $failedRecipients); + if ($sent = $transport->send($message, $failedRecipients)) { + $this->_lastUsedTransport = $transport; + + return $sent; + } } catch (Swift_TransportException $e) { $this->_killCurrentTransport(); } diff --git a/tools/swift/classes/Swift/Transport/IoBuffer.php b/tools/swift/classes/Swift/Transport/IoBuffer.php index 71b3f1e5d..af97adf1f 100644 --- a/tools/swift/classes/Swift/Transport/IoBuffer.php +++ b/tools/swift/classes/Swift/Transport/IoBuffer.php @@ -11,7 +11,7 @@ /** * Buffers input and output to a resource. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Transport_IoBuffer extends Swift_InputByteStream, Swift_OutputByteStream { @@ -59,7 +59,7 @@ interface Swift_Transport_IoBuffer extends Swift_InputByteStream, Swift_OutputBy * The $sequence number comes from any writes and may or may not be used * depending upon the implementation. * - * @param int $sequence of last write to scan from + * @param int $sequence of last write to scan from * * @return string */ diff --git a/tools/swift/classes/Swift/Transport/LoadBalancedTransport.php b/tools/swift/classes/Swift/Transport/LoadBalancedTransport.php index 440e8d4b3..e2adc567e 100644 --- a/tools/swift/classes/Swift/Transport/LoadBalancedTransport.php +++ b/tools/swift/classes/Swift/Transport/LoadBalancedTransport.php @@ -11,7 +11,7 @@ /** * Redundantly and rotationally uses several Transports when sending. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_LoadBalancedTransport implements Swift_Transport { @@ -30,8 +30,13 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport protected $_transports = array(); /** - * Creates a new LoadBalancedTransport. + * The Transport used in the last successful send operation. + * + * @var Swift_Transport */ + protected $_lastUsedTransport = null; + + // needed as __construct is called from elsewhere explicitly public function __construct() { } @@ -57,6 +62,16 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport return array_merge($this->_transports, $this->_deadTransports); } + /** + * Get the Transport used in the last successful send operation. + * + * @return Swift_Transport + */ + public function getLastUsedTransport() + { + return $this->_lastUsedTransport; + } + /** * Test if this Transport mechanism has started. * @@ -100,6 +115,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport { $maxTransports = count($this->_transports); $sent = 0; + $this->_lastUsedTransport = null; for ($i = 0; $i < $maxTransports && $transport = $this->_getNextTransport(); ++$i) { @@ -108,6 +124,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport $transport->start(); } if ($sent = $transport->send($message, $failedRecipients)) { + $this->_lastUsedTransport = $transport; break; } } catch (Swift_TransportException $e) { diff --git a/tools/swift/classes/Swift/Transport/MailTransport.php b/tools/swift/classes/Swift/Transport/MailTransport.php index ef3bc09d7..48ef4a702 100644 --- a/tools/swift/classes/Swift/Transport/MailTransport.php +++ b/tools/swift/classes/Swift/Transport/MailTransport.php @@ -19,7 +19,9 @@ * due to limitations of PHP's internal mail() function. You'll get an * all-or-nothing result from sending. * - * @author Chris Corbyn + * @author Chris Corbyn + * + * @deprecated since 5.4.5 (to be removed in 6.0) */ class Swift_Transport_MailTransport implements Swift_Transport { @@ -40,6 +42,8 @@ class Swift_Transport_MailTransport implements Swift_Transport */ public function __construct(Swift_Transport_MailInvoker $invoker, Swift_Events_EventDispatcher $eventDispatcher) { + @trigger_error(sprintf('The %s class is deprecated since version 5.4.5 and will be removed in 6.0. Use the Sendmail or SMTP transport instead.', __CLASS__), E_USER_DEPRECATED); + $this->_invoker = $invoker; $this->_eventDispatcher = $eventDispatcher; } @@ -73,7 +77,7 @@ class Swift_Transport_MailTransport implements Swift_Transport * * @param string $params * - * @return Swift_Transport_MailTransport + * @return $this */ public function setExtraParams($params) { @@ -125,12 +129,10 @@ class Swift_Transport_MailTransport implements Swift_Transport $toHeader = $message->getHeaders()->get('To'); $subjectHeader = $message->getHeaders()->get('Subject'); - if (!$toHeader) { - throw new Swift_TransportException( - 'Cannot send message without a recipient' - ); + if (0 === $count) { + $this->_throwException(new Swift_TransportException('Cannot send message without a recipient')); } - $to = $toHeader->getFieldBody(); + $to = $toHeader ? $toHeader->getFieldBody() : ''; $subject = $subjectHeader ? $subjectHeader->getFieldBody() : ''; $reversePath = $this->_getReversePath($message); @@ -141,7 +143,9 @@ class Swift_Transport_MailTransport implements Swift_Transport $messageStr = $message->toString(); - $message->getHeaders()->set($toHeader); + if ($toHeader) { + $message->getHeaders()->set($toHeader); + } $message->getHeaders()->set($subjectHeader); // Separate headers from body @@ -158,15 +162,18 @@ class Swift_Transport_MailTransport implements Swift_Transport if ("\r\n" != PHP_EOL) { // Non-windows (not using SMTP) $headers = str_replace("\r\n", PHP_EOL, $headers); + $subject = str_replace("\r\n", PHP_EOL, $subject); $body = str_replace("\r\n", PHP_EOL, $body); + $to = str_replace("\r\n", PHP_EOL, $to); } else { // Windows, using SMTP $headers = str_replace("\r\n.", "\r\n..", $headers); + $subject = str_replace("\r\n.", "\r\n..", $subject); $body = str_replace("\r\n.", "\r\n..", $body); + $to = str_replace("\r\n.", "\r\n..", $to); } - if ($this->_invoker->mail($to, $subject, $body, $headers, - sprintf($this->_extraParams, $reversePath))) { + if ($this->_invoker->mail($to, $subject, $body, $headers, $this->_formatExtraParams($this->_extraParams, $reversePath))) { if ($evt) { $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS); $evt->setFailedRecipients($failedRecipients); @@ -204,6 +211,19 @@ class Swift_Transport_MailTransport implements Swift_Transport $this->_eventDispatcher->bindEventListener($plugin); } + /** Throw a TransportException, first sending it to any listeners */ + protected function _throwException(Swift_TransportException $e) + { + if ($evt = $this->_eventDispatcher->createTransportExceptionEvent($this, $e)) { + $this->_eventDispatcher->dispatchEvent($evt, 'exceptionThrown'); + if (!$evt->bubbleCancelled()) { + throw $e; + } + } else { + throw $e; + } + } + /** Determine the best-use reverse path for this message */ private function _getReversePath(Swift_Mime_Message $message) { @@ -223,4 +243,55 @@ class Swift_Transport_MailTransport implements Swift_Transport return $path; } + + /** + * Fix CVE-2016-10074 by disallowing potentially unsafe shell characters. + * + * Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows. + * + * @param string $string The string to be validated + * + * @return bool + */ + private function _isShellSafe($string) + { + // Future-proof + if (escapeshellcmd($string) !== $string || !in_array(escapeshellarg($string), array("'$string'", "\"$string\""))) { + return false; + } + + $length = strlen($string); + for ($i = 0; $i < $length; ++$i) { + $c = $string[$i]; + // All other characters have a special meaning in at least one common shell, including = and +. + // Full stop (.) has a special meaning in cmd.exe, but its impact should be negligible here. + // Note that this does permit non-Latin alphanumeric characters based on the current locale. + if (!ctype_alnum($c) && strpos('@_-.', $c) === false) { + return false; + } + } + + return true; + } + + /** + * Return php mail extra params to use for invoker->mail. + * + * @param $extraParams + * @param $reversePath + * + * @return string|null + */ + private function _formatExtraParams($extraParams, $reversePath) + { + if (false !== strpos($extraParams, '-f%s')) { + if (empty($reversePath) || false === $this->_isShellSafe($reversePath)) { + $extraParams = str_replace('-f%s', '', $extraParams); + } else { + $extraParams = sprintf($extraParams, $reversePath); + } + } + + return !empty($extraParams) ? $extraParams : null; + } } diff --git a/tools/swift/classes/Swift/Transport/NullTransport.php b/tools/swift/classes/Swift/Transport/NullTransport.php index f87cfbf3e..ad20e0e53 100644 --- a/tools/swift/classes/Swift/Transport/NullTransport.php +++ b/tools/swift/classes/Swift/Transport/NullTransport.php @@ -11,7 +11,7 @@ /** * Pretends messages have been sent, but just ignores them. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_Transport_NullTransport implements Swift_Transport { @@ -56,7 +56,7 @@ class Swift_Transport_NullTransport implements Swift_Transport * @param Swift_Mime_Message $message * @param string[] $failedRecipients An array of failures by-reference * - * @return int The number of sent emails + * @return int The number of sent emails */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { diff --git a/tools/swift/classes/Swift/Transport/SendmailTransport.php b/tools/swift/classes/Swift/Transport/SendmailTransport.php index c508cb135..6430d5f6b 100644 --- a/tools/swift/classes/Swift/Transport/SendmailTransport.php +++ b/tools/swift/classes/Swift/Transport/SendmailTransport.php @@ -15,7 +15,7 @@ * It is advised to use -bs mode since error reporting with -t mode is not * possible. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTransport { @@ -64,7 +64,7 @@ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTran * * @param string $command * - * @return Swift_Transport_SendmailTransport + * @return $this */ public function setCommand($command) { @@ -102,6 +102,7 @@ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTran $failedRecipients = (array) $failedRecipients; $command = $this->getCommand(); $buffer = $this->getBuffer(); + $count = 0; if (false !== strpos($command, ' -t')) { if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) { diff --git a/tools/swift/classes/Swift/Transport/SimpleMailInvoker.php b/tools/swift/classes/Swift/Transport/SimpleMailInvoker.php index 21e629a64..4cab66bd6 100644 --- a/tools/swift/classes/Swift/Transport/SimpleMailInvoker.php +++ b/tools/swift/classes/Swift/Transport/SimpleMailInvoker.php @@ -32,8 +32,8 @@ class Swift_Transport_SimpleMailInvoker implements Swift_Transport_MailInvoker { if (!ini_get('safe_mode')) { return @mail($to, $subject, $body, $headers, $extraParams); - } else { - return @mail($to, $subject, $body, $headers); } + + return @mail($to, $subject, $body, $headers); } } diff --git a/tools/swift/classes/Swift/Transport/SmtpAgent.php b/tools/swift/classes/Swift/Transport/SmtpAgent.php index 4763b67ec..90e913f8e 100644 --- a/tools/swift/classes/Swift/Transport/SmtpAgent.php +++ b/tools/swift/classes/Swift/Transport/SmtpAgent.php @@ -11,7 +11,7 @@ /** * Wraps an IoBuffer to send/receive SMTP commands/responses. * - * @author Chris Corbyn + * @author Chris Corbyn */ interface Swift_Transport_SmtpAgent { diff --git a/tools/swift/classes/Swift/Transport/SpoolTransport.php b/tools/swift/classes/Swift/Transport/SpoolTransport.php index 6ee9ef5c7..e4b87f347 100644 --- a/tools/swift/classes/Swift/Transport/SpoolTransport.php +++ b/tools/swift/classes/Swift/Transport/SpoolTransport.php @@ -11,7 +11,7 @@ /** * Stores Messages in a queue. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Swift_Transport_SpoolTransport implements Swift_Transport { @@ -35,7 +35,7 @@ class Swift_Transport_SpoolTransport implements Swift_Transport * * @param Swift_Spool $spool * - * @return Swift_Transport_SpoolTransport + * @return $this */ public function setSpool(Swift_Spool $spool) { @@ -84,7 +84,7 @@ class Swift_Transport_SpoolTransport implements Swift_Transport * @param Swift_Mime_Message $message * @param string[] $failedRecipients An array of failures by-reference * - * @return int The number of sent e-mail's + * @return int The number of sent e-mail's */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { @@ -98,7 +98,7 @@ class Swift_Transport_SpoolTransport implements Swift_Transport $success = $this->_spool->queueMessage($message); if ($evt) { - $evt->setResult($success ? Swift_Events_SendEvent::RESULT_SUCCESS : Swift_Events_SendEvent::RESULT_FAILED); + $evt->setResult($success ? Swift_Events_SendEvent::RESULT_SPOOLED : Swift_Events_SendEvent::RESULT_FAILED); $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed'); } diff --git a/tools/swift/classes/Swift/Transport/StreamBuffer.php b/tools/swift/classes/Swift/Transport/StreamBuffer.php index 53e2ffa8d..3a9fe76b2 100644 --- a/tools/swift/classes/Swift/Transport/StreamBuffer.php +++ b/tools/swift/classes/Swift/Transport/StreamBuffer.php @@ -11,7 +11,7 @@ /** * A generic IoBuffer implementation supporting remote sockets and local processes. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableInputStream implements Swift_Transport_IoBuffer { @@ -84,7 +84,6 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn if ($this->_stream) { stream_set_blocking($this->_stream, 1); } - } } $this->_params[$param] = $value; @@ -92,7 +91,16 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn public function startTLS() { - return stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + // STREAM_CRYPTO_METHOD_TLS_CLIENT only allow tls1.0 connections (some php versions) + // To support modern tls we allow explicit tls1.0, tls1.1, tls1.2 + // Ssl3 and older are not allowed because they are vulnerable + // @TODO make tls arguments configurable + $cryptoType = STREAM_CRYPTO_METHOD_TLS_CLIENT; + if (PHP_VERSION_ID >= 50600) { + $cryptoType = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; + } + + return stream_socket_enable_crypto($this->_stream, true, $cryptoType); } /** @@ -151,11 +159,11 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn * The $sequence number comes from any writes and may or may not be used * depending upon the implementation. * - * @param int $sequence of last write to scan from - * - * @return string + * @param int $sequence of last write to scan from * * @throws Swift_IoException + * + * @return string */ public function readLine($sequence) { @@ -183,11 +191,11 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn * If less bytes exist than are requested the remaining bytes are given instead. * If no bytes are remaining at all, boolean false is returned. * - * @param int $length - * - * @return string|bool + * @param int $length * * @throws Swift_IoException + * + * @return string|bool */ public function read($length) { @@ -260,7 +268,11 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn if (!empty($this->_params['sourceIp'])) { $options['socket']['bindto'] = $this->_params['sourceIp'].':0'; } - $this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options)); + if (isset($this->_params['stream_context_options'])) { + $options = array_merge($options, $this->_params['stream_context_options']); + } + $streamContext = stream_context_create($options); + $this->_stream = @stream_socket_client($host.':'.$this->_params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext); if (false === $this->_stream) { throw new Swift_TransportException( 'Connection could not be established with host '.$this->_params['host']. @@ -273,8 +285,8 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn stream_set_blocking($this->_stream, 0); } stream_set_timeout($this->_stream, $timeout); - $this->_in = & $this->_stream; - $this->_out = & $this->_stream; + $this->_in = &$this->_stream; + $this->_out = &$this->_stream; } /** @@ -288,6 +300,7 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn 1 => array('pipe', 'w'), 2 => array('pipe', 'w'), ); + $pipes = array(); $this->_stream = proc_open($command, $descriptorSpec, $pipes); stream_set_blocking($pipes[2], 0); if ($err = stream_get_contents($pipes[2])) { @@ -295,8 +308,8 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn 'Process could not be started ['.$err.']' ); } - $this->_in = & $pipes[0]; - $this->_out = & $pipes[1]; + $this->_in = &$pipes[0]; + $this->_out = &$pipes[1]; } private function _getReadConnectionDescription() diff --git a/tools/swift/classes/Swift/Transport/index.php b/tools/swift/classes/Swift/Transport/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/Swift/Transport/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/Swift/TransportException.php b/tools/swift/classes/Swift/TransportException.php index bdcd23bb9..4ae2412e6 100644 --- a/tools/swift/classes/Swift/TransportException.php +++ b/tools/swift/classes/Swift/TransportException.php @@ -11,17 +11,19 @@ /** * TransportException thrown when an error occurs in the Transport subsystem. * - * @author Chris Corbyn + * @author Chris Corbyn */ class Swift_TransportException extends Swift_IoException { /** * Create a new TransportException with $message. * - * @param string $message + * @param string $message + * @param int $code + * @param Exception $previous */ - public function __construct($message) + public function __construct($message, $code = 0, Exception $previous = null) { - parent::__construct($message); + parent::__construct($message, $code, $previous); } } diff --git a/tools/swift/classes/Swift/Validate.php b/tools/swift/classes/Swift/Validate.php index 21e16c869..e16c212c4 100644 --- a/tools/swift/classes/Swift/Validate.php +++ b/tools/swift/classes/Swift/Validate.php @@ -1,4 +1,5 @@ -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/classes/index.php b/tools/swift/classes/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/classes/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/dependency_maps/index.php b/tools/swift/dependency_maps/index.php deleted file mode 100644 index 9a99a8662..000000000 --- a/tools/swift/dependency_maps/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2017 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); - -header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Cache-Control: post-check=0, pre-check=0", false); -header("Pragma: no-cache"); - -header("Location: ../"); -exit; diff --git a/tools/swift/dependency_maps/mime_deps.php b/tools/swift/dependency_maps/mime_deps.php index 04f394b32..d575e4f2d 100644 --- a/tools/swift/dependency_maps/mime_deps.php +++ b/tools/swift/dependency_maps/mime_deps.php @@ -1,6 +1,6 @@ register('properties.charset') @@ -117,7 +117,7 @@ Swift_DependencyContainer::getInstance() // As of PHP 5.4.7, the quoted_printable_encode() function behaves correctly. // see https://github.com/php/php-src/commit/18bb426587d62f93c54c40bf8535eb8416603629 ->register('mime.qpcontentencoder') - ->asAliasOf(version_compare(phpversion(), '5.4.7', '>=') ? 'mime.qpcontentencoderproxy' : 'mime.safeqpcontentencoder') + ->asAliasOf(PHP_VERSION_ID >= 50407 ? 'mime.qpcontentencoderproxy' : 'mime.safeqpcontentencoder') ; unset($swift_mime_types); diff --git a/tools/swift/mime_types.php b/tools/swift/mime_types.php index 2d7b98dc1..b42c1cc1a 100644 --- a/tools/swift/mime_types.php +++ b/tools/swift/mime_types.php @@ -7,7 +7,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * - * autogenerated using http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types + * autogenerated using https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types * and https://raw.github.com/minad/mimemagic/master/script/freedesktop.org.xml */ diff --git a/tools/swift/preferences.php b/tools/swift/preferences.php index e51950148..0b430e67d 100644 --- a/tools/swift/preferences.php +++ b/tools/swift/preferences.php @@ -20,6 +20,6 @@ if (@is_writable($tmpDir = sys_get_temp_dir())) { // this should only be done when Swiftmailer won't use the native QP content encoder // see mime_deps.php -if (version_compare(phpversion(), '5.4.7', '<')) { +if (PHP_VERSION_ID < 50407) { $preferences->setQPDotEscape(false); } diff --git a/tools/swift/swift_init.php b/tools/swift/swift_init.php index 5c4bae4f4..ff7196344 100644 --- a/tools/swift/swift_init.php +++ b/tools/swift/swift_init.php @@ -19,10 +19,10 @@ if (defined('SWIFT_INIT_LOADED')) { define('SWIFT_INIT_LOADED', true); // Load in dependency maps -require dirname(__FILE__).'/dependency_maps/cache_deps.php'; -require dirname(__FILE__).'/dependency_maps/mime_deps.php'; -require dirname(__FILE__).'/dependency_maps/message_deps.php'; -require dirname(__FILE__).'/dependency_maps/transport_deps.php'; +require __DIR__.'/dependency_maps/cache_deps.php'; +require __DIR__.'/dependency_maps/mime_deps.php'; +require __DIR__.'/dependency_maps/message_deps.php'; +require __DIR__.'/dependency_maps/transport_deps.php'; // Load in global library preferences -require dirname(__FILE__).'/preferences.php'; +require __DIR__.'/preferences.php'; diff --git a/tools/swift/swift_required.php b/tools/swift/swift_required.php index ca7d8a38c..03a72ceae 100644 --- a/tools/swift/swift_required.php +++ b/tools/swift/swift_required.php @@ -17,12 +17,12 @@ if (class_exists('Swift', false)) { } // Load Swift utility class -require dirname(__FILE__).'/classes/Swift.php'; +require __DIR__.'/classes/Swift.php'; if (!function_exists('_swiftmailer_init')) { function _swiftmailer_init() { - require dirname(__FILE__).'/swift_init.php'; + require __DIR__.'/swift_init.php'; } } diff --git a/tools/swift/swift_required_pear.php b/tools/swift/swift_required_pear.php index d826d0f97..2b5181a93 100644 --- a/tools/swift/swift_required_pear.php +++ b/tools/swift/swift_required_pear.php @@ -17,12 +17,12 @@ if (class_exists('Swift', false)) { } // Load Swift utility class -require dirname(__FILE__).'/Swift.php'; +require __DIR__.'/Swift.php'; if (!function_exists('_swiftmailer_init')) { function _swiftmailer_init() { - require dirname(__FILE__).'/swift_init.php'; + require __DIR__.'/swift_init.php'; } } diff --git a/tools/swift/swiftmailer_generate_mimes_config.php b/tools/swift/swiftmailer_generate_mimes_config.php old mode 100644 new mode 100755 index 31cee0d01..85f2d69f2 --- a/tools/swift/swiftmailer_generate_mimes_config.php +++ b/tools/swift/swiftmailer_generate_mimes_config.php @@ -1,8 +1,8 @@ #!/usr/bin/php 'application/x-php', + 'php' => 'application/x-php', 'php3' => 'application/x-php', 'php4' => 'application/x-php', 'php5' => 'application/x-php', - 'zip' => 'application/zip', - 'gif' => 'image/gif', - 'png' => 'image/png', - 'css' => 'text/css', - 'js' => 'text/javascript', - 'txt' => 'text/plain', - 'xml' => 'text/xml', - 'aif' => 'audio/x-aiff', + 'zip' => 'application/zip', + 'gif' => 'image/gif', + 'png' => 'image/png', + 'css' => 'text/css', + 'js' => 'text/javascript', + 'txt' => 'text/plain', + 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', - 'avi' => 'video/avi', - 'bmp' => 'image/bmp', - 'bz2' => 'application/x-bz2', - 'csv' => 'text/csv', - 'dmg' => 'application/x-apple-diskimage', - 'doc' => 'application/msword', + 'avi' => 'video/avi', + 'bmp' => 'image/bmp', + 'bz2' => 'application/x-bz2', + 'csv' => 'text/csv', + 'dmg' => 'application/x-apple-diskimage', + 'doc' => 'application/msword', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'eml' => 'message/rfc822', - 'aps' => 'application/postscript', - 'exe' => 'application/x-ms-dos-executable', - 'flv' => 'video/x-flv', - 'gz' => 'application/x-gzip', - 'hqx' => 'application/stuffit', - 'htm' => 'text/html', + 'eml' => 'message/rfc822', + 'aps' => 'application/postscript', + 'exe' => 'application/x-ms-dos-executable', + 'flv' => 'video/x-flv', + 'gz' => 'application/x-gzip', + 'hqx' => 'application/stuffit', + 'htm' => 'text/html', 'html' => 'text/html', - 'jar' => 'application/x-java-archive', + 'jar' => 'application/x-java-archive', 'jpeg' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'm3u' => 'audio/x-mpegurl', - 'm4a' => 'audio/mp4', - 'mdb' => 'application/x-msaccess', - 'mid' => 'audio/midi', + 'jpg' => 'image/jpeg', + 'm3u' => 'audio/x-mpegurl', + 'm4a' => 'audio/mp4', + 'mdb' => 'application/x-msaccess', + 'mid' => 'audio/midi', 'midi' => 'audio/midi', - 'mov' => 'video/quicktime', - 'mp3' => 'audio/mpeg', - 'mp4' => 'video/mp4', + 'mov' => 'video/quicktime', + 'mp3' => 'audio/mpeg', + 'mp4' => 'video/mp4', 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'odg' => 'vnd.oasis.opendocument.graphics', - 'odp' => 'vnd.oasis.opendocument.presentation', - 'odt' => 'vnd.oasis.opendocument.text', - 'ods' => 'vnd.oasis.opendocument.spreadsheet', - 'ogg' => 'audio/ogg', - 'pdf' => 'application/pdf', - 'ppt' => 'application/vnd.ms-powerpoint', + 'mpg' => 'video/mpeg', + 'odg' => 'vnd.oasis.opendocument.graphics', + 'odp' => 'vnd.oasis.opendocument.presentation', + 'odt' => 'vnd.oasis.opendocument.text', + 'ods' => 'vnd.oasis.opendocument.spreadsheet', + 'ogg' => 'audio/ogg', + 'pdf' => 'application/pdf', + 'ppt' => 'application/vnd.ms-powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'ps' => 'application/postscript', - 'rar' => 'application/x-rar-compressed', - 'rtf' => 'application/rtf', - 'tar' => 'application/x-tar', - 'sit' => 'application/x-stuffit', - 'svg' => 'image/svg+xml', - 'tif' => 'image/tiff', + 'ps' => 'application/postscript', + 'rar' => 'application/x-rar-compressed', + 'rtf' => 'application/rtf', + 'tar' => 'application/x-tar', + 'sit' => 'application/x-stuffit', + 'svg' => 'image/svg+xml', + 'tif' => 'image/tiff', 'tiff' => 'image/tiff', - 'ttf' => 'application/x-font-truetype', - 'vcf' => 'text/x-vcard', - 'wav' => 'audio/wav', - 'wma' => 'audio/x-ms-wma', - 'wmv' => 'audio/x-ms-wmv', - 'xls' => 'application/excel', + 'ttf' => 'application/x-font-truetype', + 'vcf' => 'text/x-vcard', + 'wav' => 'audio/wav', + 'wma' => 'audio/x-ms-wma', + 'wmv' => 'audio/x-ms-wmv', + 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'xml' => 'application/xml', + 'xml' => 'application/xml', ); // wrap array for generating file @@ -110,7 +109,7 @@ function generateUpToDateMimeArray() // all extensions from second match foreach ($matches[2] as $i => $extensions) { // explode multiple extensions from string - $extensions = explode(" ", strtolower($extensions)); + $extensions = explode(' ', strtolower($extensions)); // force array for foreach if (!is_array($extensions)) { @@ -139,14 +138,14 @@ function generateUpToDateMimeArray() foreach ($xml as $node) { // check if there is no pattern - if (!isset($node->glob["pattern"])) { + if (!isset($node->glob['pattern'])) { continue; } // get all matching extensions from match - foreach ((array) $node->glob["pattern"] as $extension) { + foreach ((array) $node->glob['pattern'] as $extension) { // skip none glob extensions - if (strpos($extension, '.') === FALSE) { + if (strpos($extension, '.') === false) { continue; } @@ -160,15 +159,15 @@ function generateUpToDateMimeArray() } } - if (isset($node->glob["pattern"][0])) { + if (isset($node->glob['pattern'][0])) { // mime type - $mime_type = strtolower((string) $node["type"]); + $mime_type = strtolower((string) $node['type']); // get first extension - $extension = strtolower(trim($node->glob["ddpattern"][0], '*.')); + $extension = strtolower(trim($node->glob['ddpattern'][0], '*.')); // skip none glob extensions and check if string length between 1 and 10 - if (strpos($extension, '.') !== FALSE || strlen($extension) < 1 || strlen($extension) > 9) { + if (strpos($extension, '.') !== false || strlen($extension) < 1 || strlen($extension) > 9) { continue; }