updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -5,5 +5,7 @@
*.priv -crlf
*.txt -crlf
# ignore /notes in the git-generated distributed .zip archive
# ignore directories in the git-generated distributed .zip archive
/doc/notes export-ignore
/tests export-ignore
/phpunit.xml.dist export-ignore

View File

@@ -0,0 +1,55 @@
name: tests
on:
push:
pull_request:
jobs:
linux_tests:
runs-on: ubuntu-20.04
services:
mailcatcher:
image: dockage/mailcatcher:0.7.1
ports:
- 4456:1025
strategy:
fail-fast: true
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
name: PHP ${{ matrix.php }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, intl
tools: composer:v2
coverage: none
- name: Prepare test config files
run: |
cp tests/acceptance.conf.php.default tests/acceptance.conf.php
cp tests/smoke.conf.php.default tests/smoke.conf.php
- name: Require Symfony PHPUnit Bridge 5.4 for PHP 8.1
if: ${{ matrix.php >= 8.1 }}
run: composer require symfony/phpunit-bridge:^5.4 --dev --prefer-dist --no-interaction --no-progress
- name: Install dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
- name: Execute tests
run: vendor/bin/simple-phpunit --verbose
env:
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT: 1

View File

@@ -1,5 +1,6 @@
/.php_cs.cache
/.phpunit
/.phpunit.result.cache
/build/*
/composer.lock
/phpunit.xml

View File

@@ -4,12 +4,17 @@ return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'php_unit_dedicate_assert' => ['target' => '5.6'],
'array_syntax' => ['syntax' => 'short'],
'php_unit_fqcn_annotation' => true,
'no_unreachable_default_argument_value' => false,
'braces' => ['allow_single_line_closure' => true],
'heredoc_to_nowdoc' => false,
'phpdoc_annotation_without_dot' => false,
'ternary_to_null_coalescing' => true,
'ordered_imports' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'],
'fopen_flags' => false,
])
->setRiskyAllowed(true)
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__))

View File

@@ -1,25 +0,0 @@
language: php
sudo: false
before_script:
- cp tests/acceptance.conf.php.default tests/acceptance.conf.php
- cp tests/smoke.conf.php.default tests/smoke.conf.php
- composer self-update
- composer update --no-interaction --prefer-source
- gem install mime-types -v 2.99.1
- gem install mailcatcher
- mailcatcher --smtp-port 4456
script: SYMFONY_PHPUNIT_VERSION=6.1 ./vendor/bin/simple-phpunit
matrix:
include:
- php: 7.0
- php: 7.1
- php: 7.2
fast_finish: true
cache:
directories:
- .phpunit

View File

@@ -1,7 +1,66 @@
Changelog
=========
6.1.3 (2018-XX-XX)
**Swiftmailer will stop being maintained at the end of November 2021.**
Please, move to Symfony Mailer at your earliest convenience.
Symfony Mailer is the next evolution of Swiftmailer.
It provides the same features with support for modern PHP code and support for third-party providers.
See https://symfony.com/doc/current/mailer.html for more information.
6.3.0 (2021-10-18)
------------------
* Fix support for PHP 8.1
6.2.7 (2021-03-09)
------------------
* Allow egulias/email-validator 3.1+
6.2.6 (2021-03-05)
------------------
* Fix Bcc support
6.2.5 (2021-01-12)
------------------
* Don't trust properties at destruct time
* Remove invalid PHPDocs param in EventDispatcher interface
* Bump license year
* Removes PHP version from README
6.2.4 (2020-12-08)
------------------
* Prevent flushing of the bubble queue when event handler raises another event
* Add support for PHP 8
* Code cleanups
6.2.3 (2019-11-12)
------------------
* no changes
6.2.2 (2019-11-12)
------------------
* fixed compat with PHP 7.4
* fixed error message when connecting to a stream raises an error before connect()
6.2.1 (2019-04-21)
------------------
* reverted "deprecated Swift_CharacterStream_ArrayCharacterStream and Swift_CharacterStream_NgCharacterStream in favor of Swift_CharacterStream_CharacterStream"
6.2.0 (2019-03-10)
------------------
* added support for symfony/polyfill-intl-dn
* deprecated Swift_CharacterStream_ArrayCharacterStream and Swift_CharacterStream_NgCharacterStream in favor of Swift_CharacterStream_CharacterStream
6.1.3 (2018-09-11)
------------------
* added auto-start to the SMTP transport when sending a message

View File

@@ -1,4 +1,4 @@
Copyright (c) 2013-2018 Fabien Potencier
Copyright (c) 2013-2021 Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,15 +0,0 @@
Swift Mailer
------------
Swift Mailer is a component based mailing solution for PHP 7.
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.

View File

@@ -0,0 +1,25 @@
Swift Mailer
------------
**Swiftmailer will stop being maintained at the end of November 2021.**
Please, move to [Symfony Mailer](https://symfony.com/doc/current/mailer.html) at your earliest convenience.
[Symfony Mailer](https://symfony.com/doc/current/mailer.html) is the next evolution of Swiftmailer.
It provides the same features with support for modern PHP code and support for third-party providers.
Swift Mailer is a component based mailing solution for PHP.
It is released under the MIT license.
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, read the [documentation](https://swiftmailer.symfony.com/docs/introduction.html).
Sponsors
--------
<div>
<a href="https://blackfire.io/docs/introduction?utm_source=swiftmailer&utm_medium=github_readme&utm_campaign=logo">
<img src="https://static.blackfire.io/assets/intemporals/logo/png/blackfire-io_secondary_horizontal_transparent.png?1" width="255px" alt="Blackfire.io">
</a>
</div>

View File

@@ -16,15 +16,17 @@
],
"require": {
"php": ">=7.0.0",
"egulias/email-validator": "~2.0"
"egulias/email-validator": "^2.0|^3.1",
"symfony/polyfill-iconv": "^1.0",
"symfony/polyfill-mbstring": "^1.0",
"symfony/polyfill-intl-idn": "^1.10"
},
"require-dev": {
"mockery/mockery": "~0.9.1",
"symfony/phpunit-bridge": "~3.3@dev"
"mockery/mockery": "^1.0",
"symfony/phpunit-bridge": "^4.4|^5.4"
},
"suggest": {
"ext-intl": "Needed to support internationalized email addresses",
"true/punycode": "Needed to support internationalized email addresses, if ext-intl is not installed"
"ext-intl": "Needed to support internationalized email addresses"
},
"autoload": {
"files": ["lib/swift_required.php"]
@@ -34,7 +36,9 @@
},
"extra": {
"branch-alias": {
"dev-master": "6.1-dev"
"dev-master": "6.2-dev"
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@@ -1,7 +1,13 @@
Introduction
============
Swiftmailer: A feature-rich PHP Mailer
======================================
Swift Mailer is a for sending e-mails from PHP applications.
Swift Mailer is a component based library for sending e-mails from PHP applications.
**Swiftmailer will stop being maintained at the end of November 2021.**
Please, move to `Symfony Mailer <https://symfony.com/doc/current/mailer.html>`_ at your earliest convenience.
`Symfony Mailer <https://symfony.com/doc/current/mailer.html>`_ is the next evolution of Swiftmailer.
It provides the same features with support for modern PHP code and support for third-party providers.
System Requirements
-------------------

View File

@@ -100,7 +100,7 @@ with a strict format, you only need to pass a DateTimeInterface instance to
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Date`` | Specifies the date at which the message was sent | ``getDate()`` / ``setDate()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Content-Type`` | Specifies the format of the message (usually text/plain or text/html) | ``getContentType()`` / ``setContentType()`` |
| ``Content-Type`` | Specifies the format of the message (usually ``text/plain`` or ``text/html``) | ``getContentType()`` / ``setContentType()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
| ``Content-Transfer-Encoding`` | Specifies the encoding scheme in the message | ``getEncoder()`` / ``setEncoder()`` |
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------+---------------------------------------------+
@@ -479,11 +479,13 @@ Mailer will throw a ``Swift_RfcComplianceException``.
If you add recipients automatically based on a data source that may contain
invalid email addresses, you can prevent possible exceptions by validating the
addresses using::
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
$validator = new EmailValidator();
$validator->isValid("example@example.com", new RFCValidation()); //true
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\RFCValidation;
$validator = new EmailValidator();
$validator->isValid("example@example.com", new RFCValidation()); //true
and only adding addresses that validate. Another way would be to wrap your ``setTo()``, ``setCc()`` and
``setBcc()`` calls in a try-catch block and handle the
``Swift_RfcComplianceException`` in the catch block.
@@ -520,9 +522,8 @@ Setting ``To:`` Recipients
or ``addTo()`` methods of the message.
To set ``To:`` recipients, create the message object using either ``new
Swift_Message( ... )`` or ``new Swift_Message( ... )``, then call the
``setTo()`` method with a complete array of addresses, or use the ``addTo()``
method to iteratively add recipients.
Swift_Message( ... )``, then call the ``setTo()`` method with a complete array
of addresses, or use the ``addTo()`` method to iteratively add recipients.
The ``setTo()`` method accepts input in various formats as described earlier in
this chapter. The ``addTo()`` method takes either one or two parameters. The
@@ -558,9 +559,8 @@ Setting ``Cc:`` Recipients
message.
To set ``Cc:`` recipients, create the message object using either ``new
Swift_Message( ... )`` or ``new Swift_Message( ... )``, then call the
``setCc()`` method with a complete array of addresses, or use the ``addCc()``
method to iteratively add recipients.
Swift_Message( ... )``, then call the ``setCc()`` method with a complete array
of addresses, or use the ``addCc()`` method to iteratively add recipients.
The ``setCc()`` method accepts input in various formats as described earlier in
this chapter. The ``addCc()`` method takes either one or two parameters. The
@@ -596,9 +596,8 @@ Setting ``Bcc:`` Recipients
it, and are set with the ``setBcc()`` or ``addBcc()`` methods of the message.
To set ``Bcc:`` recipients, create the message object using either ``new
Swift_Message( ... )`` or ``new Swift_Message( ... )``, then call the
``setBcc()`` method with a complete array of addresses, or use the ``addBcc()``
method to iteratively add recipients.
Swift_Message( ... )``, then call the ``setBcc()`` method with a complete array
of addresses, or use the ``addBcc()`` method to iteratively add recipients.
The ``setBcc()`` method accepts input in various formats as described earlier
in this chapter. The ``addBcc()`` method takes either one or two parameters.
@@ -823,7 +822,7 @@ Requesting a Read Receipt
It is possible to request a read-receipt to be sent to an address when the
email is opened. To request a read receipt set the address with
``setReadReceiptTo()``:
``setReadReceiptTo()``::
$message->setReadReceiptTo('your@address.tld');

View File

@@ -265,7 +265,7 @@ this to one user:
Subject: Important notice for smilingsunshine2009
Hello smilingsunshine2009,you requested to reset your password.
Hello smilingsunshine2009, you requested to reset your password.
Please visit https://example.com/pwreset and use the reset code 183457 to set a new password.
While another use may receive the message as:

View File

@@ -95,7 +95,8 @@ within your application and adjust the settings accordingly if the code is
moved or if the SMTP server is changed.
Some SMTP servers -- Google for example -- use encryption for security reasons.
Swift Mailer supports using both SSL and TLS encryption settings.
Swift Mailer supports using both ``ssl`` (SMTPS = SMTP over TLS) and ``tls``
(SMTP with STARTTLS) encryption settings.
Using the SMTP Transport
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -129,11 +130,14 @@ A connection to the SMTP server will be established upon the first call to
Encrypted SMTP
^^^^^^^^^^^^^^
You can use SSL or TLS encryption with the SMTP Transport by specifying it as a
parameter or with a method call::
You can use ``ssl`` (SMTPS) or ``tls`` (STARTTLS) encryption with the SMTP Transport
by specifying it as a parameter or with a method call::
// Create the Transport
// Option #1: SMTPS = SMTP over TLS (always encrypted):
$transport = new Swift_SmtpTransport('smtp.example.org', 587, 'ssl');
// Option #2: SMTP with STARTTLS (best effort encryption):
$transport = new Swift_SmtpTransport('smtp.example.org', 587, 'tls');
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
@@ -143,8 +147,7 @@ A connection to the SMTP server will be established upon the first call to
settings.
.. note::
For SSL or TLS encryption to work your PHP installation must have
For SMTPS or STARTTLS encryption to work your PHP installation must have
appropriate OpenSSL transports wrappers. You can check if "tls" and/or
"ssl" are present in your PHP installation by using the PHP function
``stream_get_transports()``.
@@ -153,6 +156,14 @@ settings.
If you are using Mailcatcher_, make sure you do not set the encryption
for the ``Swift_SmtpTransport``, since Mailcatcher does not support encryption.
.. note::
When in doubt, try ``ssl`` first for higher security, since the communication
is always encrypted.
.. note::
Usually, port 587 or 465 is used for encrypted SMTP. Check the documentation
of your mail provider.
SMTP with a Username and Password
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@@ -15,7 +15,7 @@
*/
abstract class Swift
{
const VERSION = '6.1.3';
const VERSION = '6.3.0';
public static $initialized = false;
public static $inits = [];
@@ -56,7 +56,7 @@ abstract class Swift
if (self::$inits && !self::$initialized) {
self::$initialized = true;
foreach (self::$inits as $init) {
call_user_func($init);
\call_user_func($init);
}
}
}

View File

@@ -18,8 +18,8 @@ interface Swift_AddressEncoder
/**
* Encodes an email address.
*
* @throws Swift_AddressEncoderException If the email cannot be represented in
* the encoding implemented by this class.
* @throws Swift_AddressEncoderException if the email cannot be represented in
* the encoding implemented by this class
*/
public function encodeString(string $address): string;
}

View File

@@ -27,8 +27,7 @@ class Swift_AddressEncoder_IdnAddressEncoder implements Swift_AddressEncoder
/**
* Encodes the domain part of an address using IDN.
*
* @throws Swift_AddressEncoderException If local-part contains non-ASCII characters,
* or if no suitable IDN encoder is installed.
* @throws Swift_AddressEncoderException If local-part contains non-ASCII characters
*/
public function encodeString(string $address): string
{
@@ -42,28 +41,10 @@ class Swift_AddressEncoder_IdnAddressEncoder implements Swift_AddressEncoder
}
if (preg_match('/[^\x00-\x7F]/', $domain)) {
$address = sprintf('%s@%s', $local, $this->idnToAscii($domain));
$address = sprintf('%s@%s', $local, idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46));
}
}
return $address;
}
/**
* IDN-encodes a UTF-8 string to ASCII.
*/
protected function idnToAscii(string $string): string
{
if (function_exists('idn_to_ascii')) {
return idn_to_ascii($string, 0, INTL_IDNA_VARIANT_UTS46);
}
if (class_exists('TrueBV\Punycode')) {
$punycode = new \TrueBV\Punycode();
return $punycode->encode($string);
}
throw new Swift_AddressEncoderException('Non-ASCII characters in address, but no IDN encoder found (install the intl extension or the true/punycode package)', $string);
}
}

View File

@@ -26,7 +26,7 @@ class Swift_Attachment extends Swift_Mime_Attachment
*/
public function __construct($data = null, $filename = null, $contentType = null)
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Mime_Attachment::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.attachment')
@@ -42,7 +42,7 @@ class Swift_Attachment extends Swift_Mime_Attachment
* @param string $path
* @param string $contentType optional
*
* @return Swift_Mime_Attachment
* @return self
*/
public static function fromPath($path, $contentType = null)
{

View File

@@ -52,10 +52,10 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
*/
public function __construct($stack = null)
{
if (is_array($stack)) {
if (\is_array($stack)) {
$this->array = $stack;
$this->arraySize = count($stack);
} elseif (is_string($stack)) {
$this->arraySize = \count($stack);
} elseif (\is_string($stack)) {
$this->write($stack);
} else {
$this->array = [];
@@ -102,7 +102,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O
foreach ($to_add as $value) {
$this->array[] = $value;
}
$this->arraySize = count($this->array);
$this->arraySize = \count($this->array);
foreach ($this->mirrors as $stream) {
$stream->write($bytes);

View File

@@ -81,7 +81,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
// If we read one byte after reaching the end of the file
// feof() will return false and an empty string is returned
if ('' === $bytes && feof($fp)) {
if ((false === $bytes || '' === $bytes) && feof($fp)) {
$this->resetReadHandle();
return false;
@@ -145,9 +145,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
{
if (!isset($this->writer)) {
if (!$this->writer = fopen($this->path, $this->mode)) {
throw new Swift_IoException(
'Unable to open file for writing ['.$this->path.']'
);
throw new Swift_IoException('Unable to open file for writing ['.$this->path.']');
}
}
@@ -194,7 +192,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl
{
if ($tmpFile = fopen('php://temp/maxmemory:4096', 'w+b')) {
/* We have opened a php:// Stream Should work without problem */
} elseif (function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()) && ($tmpFile = tmpfile())) {
} elseif (\function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()) && ($tmpFile = tmpfile())) {
/* We have opened a tmpfile */
} else {
throw new Swift_IoException('Unable to copy the file to make it seekable, sys_temp_dir is not writable, php://memory not available');

View File

@@ -39,4 +39,14 @@ class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByte
@unlink($this->getPath());
}
}
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
}

View File

@@ -45,7 +45,7 @@ class Swift_CharacterReader_GenericFixedWidthReader implements Swift_CharacterRe
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$strlen = strlen($string);
$strlen = \strlen($string);
// % and / are CPU intensive, so, maybe find a better way
$ignored = $strlen % $this->width;
$ignoredChars = $ignored ? substr($string, -$ignored) : '';

View File

@@ -27,7 +27,7 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
*/
public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars)
{
$strlen = strlen($string);
$strlen = \strlen($string);
$ignoredChars = '';
for ($i = 0; $i < $strlen; ++$i) {
if ($string[$i] > "\x07F") {
@@ -65,7 +65,7 @@ class Swift_CharacterReader_UsAsciiReader implements Swift_CharacterReader
public function validateByteSequence($bytes, $size)
{
$byte = reset($bytes);
if (1 == count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
if (1 == \count($bytes) && $byte >= 0x00 && $byte <= 0x7F) {
return 0;
}

View File

@@ -18,7 +18,7 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
{
/** Pre-computed for optimization */
private static $length_map = [
// N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,
// 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
@@ -34,7 +34,7 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
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
4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 0, 0, // 0xFN
];
private static $s_length_map = [
@@ -88,8 +88,8 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader
$currentMap['p'] = $currentMap['i'] = [];
}
$strlen = strlen($string);
$charPos = count($currentMap['p']);
$strlen = \strlen($string);
$charPos = \count($currentMap['p']);
$foundChars = 0;
$invalid = false;
for ($i = 0; $i < $strlen; ++$i) {

View File

@@ -44,7 +44,7 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
public function init()
{
if (count(self::$map) > 0) {
if (\count(self::$map) > 0) {
return;
}
@@ -103,11 +103,11 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift
*/
public function getReaderFor($charset)
{
$charset = strtolower(trim($charset));
$charset = strtolower(trim($charset ?? ''));
foreach (self::$map as $pattern => $spec) {
$re = '/^'.$pattern.'$/D';
if (preg_match($re, $charset)) {
if (!array_key_exists($pattern, self::$loaded)) {
if (!\array_key_exists($pattern, self::$loaded)) {
$reflector = new ReflectionClass($spec['class']);
if ($reflector->getConstructor()) {
$reader = $reflector->newInstanceArgs($spec['constructor']);

View File

@@ -28,8 +28,6 @@ interface Swift_CharacterStream
/**
* Set the CharacterReaderFactory for multi charset support.
*
* @param Swift_CharacterReaderFactory $factory
*/
public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory);

View File

@@ -86,15 +86,15 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
$startLength = $this->charReader->getInitialByteSize();
while (false !== $bytes = $os->read($startLength)) {
$c = [];
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
for ($i = 0, $len = \strlen($bytes); $i < $len; ++$i) {
$c[] = self::$byteMap[$bytes[$i]];
}
$size = count($c);
$size = \count($c);
$need = $this->charReader
->validateByteSequence($c, $size);
if ($need > 0 &&
false !== $bytes = $os->read($need)) {
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
for ($i = 0, $len = \strlen($bytes); $i < $len; ++$i) {
$c[] = self::$byteMap[$bytes[$i]];
}
}
@@ -204,7 +204,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
$new = $this->reloadBuffer($fp, 100);
if ($new) {
$buffer = array_merge($buf, $new);
$buf_len = count($buffer);
$buf_len = \count($buffer);
$buf_pos = 0;
} else {
$has_datas = false;
@@ -224,7 +224,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
if ($new) {
$buffer = array_merge($buffer, $new);
$buf_len = count($buffer);
$buf_len = \count($buffer);
}
}
for ($i = 0; $i < $need && isset($buffer[$buf_pos]); ++$i) {
@@ -268,7 +268,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
{
if (!feof($fp) && false !== ($bytes = fread($fp, $len))) {
$buf = [];
for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) {
for ($i = 0, $len = \strlen($bytes); $i < $len; ++$i) {
$buf[] = self::$byteMap[$bytes[$i]];
}
@@ -283,7 +283,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea
if (!isset(self::$charMap)) {
self::$charMap = [];
for ($byte = 0; $byte < 256; ++$byte) {
self::$charMap[$byte] = chr($byte);
self::$charMap[$byte] = \chr($byte);
}
self::$byteMap = array_flip(self::$charMap);
}

View File

@@ -254,9 +254,9 @@ 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 (false !== $ignored) {
$this->datasSize = strlen($this->datas) - strlen($ignored);
$this->datasSize = \strlen($this->datas) - \strlen($ignored);
} else {
$this->datasSize = strlen($this->datas);
$this->datasSize = \strlen($this->datas);
}
}
}

View File

@@ -83,7 +83,7 @@ class Swift_DependencyContainer
*/
public function has($itemName)
{
return array_key_exists($itemName, $this->store)
return \array_key_exists($itemName, $this->store)
&& isset($this->store[$itemName]['lookupType']);
}
@@ -101,9 +101,7 @@ class Swift_DependencyContainer
public function lookup($itemName)
{
if (!$this->has($itemName)) {
throw new Swift_DependencyException(
'Cannot lookup dependency "'.$itemName.'" since it is not registered.'
);
throw new Swift_DependencyException('Cannot lookup dependency "'.$itemName.'" since it is not registered.');
}
switch ($this->store[$itemName]['lookupType']) {
@@ -348,9 +346,7 @@ class Swift_DependencyContainer
private function &getEndPoint()
{
if (!isset($this->endPoint)) {
throw new BadMethodCallException(
'Component must first be registered by calling register()'
);
throw new BadMethodCallException('Component must first be registered by calling register()');
}
return $this->endPoint;
@@ -377,7 +373,7 @@ class Swift_DependencyContainer
/** Resolve a single dependency with an collections */
private function lookupRecursive($item)
{
if (is_array($item)) {
if (\is_array($item)) {
$collection = [];
foreach ($item as $k => $v) {
$collection[$k] = $this->lookupRecursive($v);

View File

@@ -26,7 +26,7 @@ class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile
*/
public function __construct($data = null, $filename = null, $contentType = null)
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Mime_EmbeddedFile::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.embeddedfile')

View File

@@ -34,7 +34,7 @@ class Swift_Encoder_Base64Encoder implements Swift_Encoder
$maxLineLength = 76;
}
$encodedString = base64_encode($string);
$encodedString = base64_encode($string ?? '');
$firstLine = '';
if (0 != $firstLineOffset) {

View File

@@ -135,14 +135,14 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
protected function getSafeMapShareId()
{
return get_class($this);
return static::class;
}
protected function initSafeMap()
{
foreach (array_merge(
[0x09, 0x20], range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte) {
$this->safeMap[$byte] = chr($byte);
$this->safeMap[$byte] = \chr($byte);
}
}
@@ -281,7 +281,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder
$string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A'],
["=09\r\n", "=20\r\n", "\r\n"], $string
);
switch ($end = ord(substr($string, -1))) {
switch ($end = \ord(substr($string, -1))) {
case 0x09:
case 0x20:
$string = substr_replace($string, self::$qpMap[$end], -1);

View File

@@ -58,8 +58,8 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
while (false !== $char = $this->charStream->read(4)) {
$encodedChar = rawurlencode($char);
if (0 != strlen($currentLine)
&& strlen($currentLine.$encodedChar) > $thisLineLength) {
if (0 != \strlen($currentLine)
&& \strlen($currentLine.$encodedChar) > $thisLineLength) {
$lines[] = '';
$currentLine = &$lines[$lineCount++];
$thisLineLength = $maxLineLength;

View File

@@ -17,8 +17,6 @@ interface Swift_Events_CommandListener extends Swift_Events_EventListener
{
/**
* Invoked immediately following a command being sent.
*
* @param Swift_Events_CommandEvent $evt
*/
public function commandSent(Swift_Events_CommandEvent $evt);
}

View File

@@ -18,9 +18,6 @@ interface Swift_Events_EventDispatcher
/**
* Create a new SendEvent for $source and $message.
*
* @param Swift_Transport $source
* @param Swift_Mime_SimpleMessage
*
* @return Swift_Events_SendEvent
*/
public function createSendEvent(Swift_Transport $source, Swift_Mime_SimpleMessage $message);
@@ -28,9 +25,8 @@ interface Swift_Events_EventDispatcher
/**
* Create a new CommandEvent for $source and $command.
*
* @param Swift_Transport $source
* @param string $command That will be executed
* @param array $successCodes That are needed
* @param string $command That will be executed
* @param array $successCodes That are needed
*
* @return Swift_Events_CommandEvent
*/
@@ -39,9 +35,8 @@ interface Swift_Events_EventDispatcher
/**
* Create a new ResponseEvent for $source and $response.
*
* @param Swift_Transport $source
* @param string $response
* @param bool $valid If the response is valid
* @param string $response
* @param bool $valid If the response is valid
*
* @return Swift_Events_ResponseEvent
*/
@@ -50,8 +45,6 @@ interface Swift_Events_EventDispatcher
/**
* Create a new TransportChangeEvent for $source.
*
* @param Swift_Transport $source
*
* @return Swift_Events_TransportChangeEvent
*/
public function createTransportChangeEvent(Swift_Transport $source);
@@ -59,25 +52,19 @@ interface Swift_Events_EventDispatcher
/**
* Create a new TransportExceptionEvent for $source.
*
* @param Swift_Transport $source
* @param Swift_TransportException $ex
*
* @return Swift_Events_TransportExceptionEvent
*/
public function createTransportExceptionEvent(Swift_Transport $source, Swift_TransportException $ex);
/**
* Bind an event listener to this dispatcher.
*
* @param Swift_Events_EventListener $listener
*/
public function bindEventListener(Swift_Events_EventListener $listener);
/**
* Dispatch the given Event to all suitable listeners.
*
* @param Swift_Events_EventObject $evt
* @param string $target method
* @param string $target method
*/
public function dispatchEvent(Swift_Events_EventObject $evt, $target);
}

View File

@@ -17,8 +17,6 @@ interface Swift_Events_ResponseListener extends Swift_Events_EventListener
{
/**
* Invoked immediately following a response coming back.
*
* @param Swift_Events_ResponseEvent $evt
*/
public function responseReceived(Swift_Events_ResponseEvent $evt);
}

View File

@@ -17,15 +17,11 @@ interface Swift_Events_SendListener extends Swift_Events_EventListener
{
/**
* Invoked immediately before the Message is sent.
*
* @param Swift_Events_SendEvent $evt
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt);
/**
* Invoked immediately after the Message is sent.
*
* @param Swift_Events_SendEvent $evt
*/
public function sendPerformed(Swift_Events_SendEvent $evt);
}

View File

@@ -21,9 +21,6 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
/** Event listeners bound to this dispatcher */
private $listeners = [];
/** Listeners queued to have an Event bubbled up the stack to them */
private $bubbleQueue = [];
/**
* Create a new EventDispatcher.
*/
@@ -115,29 +112,31 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher
*/
public function dispatchEvent(Swift_Events_EventObject $evt, $target)
{
$this->prepareBubbleQueue($evt);
$this->bubble($evt, $target);
$bubbleQueue = $this->prepareBubbleQueue($evt);
$this->bubble($bubbleQueue, $evt, $target);
}
/** Queue listeners on a stack ready for $evt to be bubbled up it */
private function prepareBubbleQueue(Swift_Events_EventObject $evt)
{
$this->bubbleQueue = [];
$evtClass = get_class($evt);
$bubbleQueue = [];
$evtClass = \get_class($evt);
foreach ($this->listeners as $listener) {
if (array_key_exists($evtClass, $this->eventMap)
if (\array_key_exists($evtClass, $this->eventMap)
&& ($listener instanceof $this->eventMap[$evtClass])) {
$this->bubbleQueue[] = $listener;
$bubbleQueue[] = $listener;
}
}
return $bubbleQueue;
}
/** Bubble $evt up the stack calling $target() on each listener */
private function bubble(Swift_Events_EventObject $evt, $target)
private function bubble(array &$bubbleQueue, Swift_Events_EventObject $evt, $target)
{
if (!$evt->bubbleCancelled() && $listener = array_shift($this->bubbleQueue)) {
if (!$evt->bubbleCancelled() && $listener = array_shift($bubbleQueue)) {
$listener->$target($evt);
$this->bubble($evt, $target);
$this->bubble($bubbleQueue, $evt, $target);
}
}
}

View File

@@ -17,29 +17,21 @@ interface Swift_Events_TransportChangeListener extends Swift_Events_EventListene
{
/**
* Invoked just before a Transport is started.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked immediately after the Transport is started.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function transportStarted(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked just before a Transport is stopped.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt);
/**
* Invoked immediately after the Transport is stopped.
*
* @param Swift_Events_TransportChangeEvent $evt
*/
public function transportStopped(Swift_Events_TransportChangeEvent $evt);
}

View File

@@ -17,8 +17,6 @@ interface Swift_Events_TransportExceptionListener extends Swift_Events_EventList
{
/**
* Invoked as a TransportException is thrown in the Transport system.
*
* @param Swift_Events_TransportExceptionEvent $evt
*/
public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt);
}

View File

@@ -22,7 +22,7 @@ class Swift_FailoverTransport extends Swift_Transport_FailoverTransport
*/
public function __construct($transports = [])
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Transport_FailoverTransport::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.failover')

View File

@@ -198,7 +198,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool
// This string MUST stay FS safe, avoid special chars
$base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
$ret = '';
$strlen = strlen($base);
$strlen = \strlen($base);
for ($i = 0; $i < $count; ++$i) {
$ret .= $base[random_int(0, $strlen - 1)];
}

View File

@@ -18,8 +18,7 @@ interface Swift_Filterable
/**
* Add a new StreamFilter, referenced by $key.
*
* @param Swift_StreamFilter $filter
* @param string $key
* @param string $key
*/
public function addFilter(Swift_StreamFilter $filter, $key);

View File

@@ -38,10 +38,9 @@ interface Swift_KeyCache
*
* @see MODE_WRITE, MODE_APPEND
*
* @param string $nsKey
* @param string $itemKey
* @param Swift_OutputByteStream $os
* @param int $mode
* @param string $nsKey
* @param string $itemKey
* @param int $mode
*/
public function importFromByteStream($nsKey, $itemKey, Swift_OutputByteStream $os, $mode);

View File

@@ -62,10 +62,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
$this->contents[$nsKey][$itemKey] .= $string;
break;
default:
throw new Swift_SwiftException(
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey);
}
}
@@ -94,10 +91,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
}
break;
default:
throw new Swift_SwiftException(
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey);
}
}
@@ -165,7 +159,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
{
$this->prepareCache($nsKey);
return array_key_exists($itemKey, $this->contents[$nsKey]);
return \array_key_exists($itemKey, $this->contents[$nsKey]);
}
/**
@@ -196,7 +190,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache
*/
private function prepareCache($nsKey)
{
if (!array_key_exists($nsKey, $this->contents)) {
if (!\array_key_exists($nsKey, $this->contents)) {
$this->contents[$nsKey] = [];
}
}

View File

@@ -80,10 +80,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
$fp = $this->getHandle($nsKey, $itemKey, self::POSITION_END);
break;
default:
throw new Swift_SwiftException(
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey);
break;
}
fwrite($fp, $string);
@@ -112,10 +109,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
$fp = $this->getHandle($nsKey, $itemKey, self::POSITION_END);
break;
default:
throw new Swift_SwiftException(
'Invalid mode ['.$mode.'] used to set nsKey='.
$nsKey.', itemKey='.$itemKey
);
throw new Swift_SwiftException('Invalid mode ['.$mode.'] used to set nsKey='.$nsKey.', itemKey='.$itemKey);
break;
}
while (false !== $bytes = $os->read(8192)) {
@@ -224,7 +218,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
*/
public function clearAll($nsKey)
{
if (array_key_exists($nsKey, $this->keys)) {
if (\array_key_exists($nsKey, $this->keys)) {
foreach ($this->keys[$nsKey] as $itemKey => $null) {
$this->clearKey($nsKey, $itemKey);
}
@@ -292,4 +286,9 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache
$this->clearAll($nsKey);
}
}
public function __wakeup()
{
$this->keys = [];
}
}

View File

@@ -17,8 +17,6 @@ interface Swift_KeyCache_KeyCacheInputStream extends Swift_InputByteStream
{
/**
* Set the KeyCache to wrap.
*
* @param Swift_KeyCache $keyCache
*/
public function setKeyCache(Swift_KeyCache $keyCache);
@@ -38,8 +36,6 @@ interface Swift_KeyCache_KeyCacheInputStream extends Swift_InputByteStream
/**
* Specify a stream to write through for each write().
*
* @param Swift_InputByteStream $is
*/
public function setWriteThroughStream(Swift_InputByteStream $is);

View File

@@ -22,7 +22,7 @@ class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport
*/
public function __construct($transports = [])
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Transport_LoadBalancedTransport::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.loadbalanced')

View File

@@ -42,7 +42,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
*/
public function __construct($subject = null, $body = null, $contentType = null, $charset = null)
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Mime_SimpleMessage::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.message')
@@ -212,7 +212,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
$this->savedMessage = ['headers' => []];
$this->savedMessage['body'] = $this->getBody();
$this->savedMessage['children'] = $this->getChildren();
if (count($this->savedMessage['children']) > 0 && '' != $this->getBody()) {
if (\count($this->savedMessage['children']) > 0 && '' != $this->getBody()) {
$this->setChildren(array_merge([$this->becomeMimePart()], $this->savedMessage['children']));
$this->setBody('');
}
@@ -224,7 +224,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage
protected function saveHeaders(array $altered)
{
foreach ($altered as $head) {
$lc = strtolower($head);
$lc = strtolower($head ?? '');
if (!isset($this->savedMessage['headers'][$lc])) {
$this->savedMessage['headers'][$lc] = $this->getHeaders()->getAll($head);

View File

@@ -134,7 +134,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity
if (!isset($contentType)) {
$extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1));
if (array_key_exists($extension, $this->mimeTypes)) {
if (\array_key_exists($extension, $this->mimeTypes)) {
$this->setContentType($this->mimeTypes[$extension]);
}
}

View File

@@ -27,7 +27,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
}
$remainder = 0;
$base64ReadBufferRemainderBytes = null;
$base64ReadBufferRemainderBytes = '';
// To reduce memory usage, the output buffer is streamed to the input buffer like so:
// Output Stream => base64encode => wrap line length => Input Stream
@@ -45,8 +45,8 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
} else {
$streamTheseBytes = $base64ReadBufferRemainderBytes.$readBytes;
}
$base64ReadBufferRemainderBytes = null;
$bytesLength = strlen($streamTheseBytes);
$base64ReadBufferRemainderBytes = '';
$bytesLength = \strlen($streamTheseBytes);
if (0 === $bytesLength) { // no data left to encode
break;
@@ -66,7 +66,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
$encodedTransformed = '';
$thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset;
while ($thisMaxLineLength < strlen($encoded)) {
while ($thisMaxLineLength < \strlen($encoded)) {
$encodedTransformed .= substr($encoded, 0, $thisMaxLineLength)."\r\n";
$firstLineOffset = 0;
$encoded = substr($encoded, $thisMaxLineLength);
@@ -74,7 +74,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6
$remainder = 0;
}
if (0 < $remainingLength = strlen($encoded)) {
if (0 < $remainingLength = \strlen($encoded)) {
$remainder += $remainingLength;
$encodedTransformed .= $encoded;
$encoded = null;

View File

@@ -16,16 +16,16 @@
class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder
{
/**
* @var null|string
* @var string|null
*/
private $charset;
/**
* @param null|string $charset
* @param string|null $charset
*/
public function __construct($charset = null)
{
$this->charset = $charset ? $charset : 'utf-8';
$this->charset = $charset ?: 'utf-8';
}
/**
@@ -51,8 +51,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
{
if ('utf-8' !== $this->charset) {
throw new RuntimeException(
sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
}
$string = '';
@@ -88,8 +87,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
{
if ('utf-8' !== $this->charset) {
throw new RuntimeException(
sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset));
}
return $this->standardize(quoted_printable_encode($string));
@@ -109,7 +107,7 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con
// transform =0D=0A to CRLF
$string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A'], ["=09\r\n", "=20\r\n", "\r\n"], $string);
switch (ord(substr($string, -1))) {
switch (\ord(substr($string, -1))) {
case 0x09:
$string = substr_replace($string, '=09', -1);
break;

View File

@@ -21,7 +21,7 @@ class Swift_Mime_ContentEncoder_NullContentEncoder implements Swift_Mime_Content
*
* @var string
*/
private $_name;
private $name;
/**
* Creates a new NullContentEncoder with $name (probably 7bit or 8bit).
@@ -30,7 +30,7 @@ class Swift_Mime_ContentEncoder_NullContentEncoder implements Swift_Mime_Content
*/
public function __construct($name)
{
$this->_name = $name;
$this->name = $name;
}
/**
@@ -67,7 +67,7 @@ class Swift_Mime_ContentEncoder_NullContentEncoder implements Swift_Mime_Content
*/
public function getName()
{
return $this->_name;
return $this->name;
}
/**

View File

@@ -37,7 +37,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
* Creates a new PlainContentEncoder with $name (probably 7bit or 8bit).
*
* @param string $name
* @param bool $canonical If canonicalization transformation should be done.
* @param bool $canonical if canonicalization transformation should be done
*/
public function __construct($name, $canonical = false)
{
@@ -84,7 +84,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
$is->write($wrapped);
}
if (strlen($leftOver)) {
if (\strlen($leftOver)) {
$is->write($leftOver);
}
}
@@ -134,8 +134,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten
$chunks = preg_split('/(?<=\s)/', $originalLine);
foreach ($chunks as $chunk) {
if (0 != strlen($currentLine)
&& strlen($currentLine.$chunk) > $length) {
if (0 != \strlen($currentLine)
&& \strlen($currentLine.$chunk) > $length) {
$lines[] = '';
$currentLine = &$lines[$lineCount++];
}

View File

@@ -37,7 +37,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
protected function getSafeMapShareId()
{
return get_class($this).($this->dotEscape ? '.dotEscape' : '');
return static::class.($this->dotEscape ? '.dotEscape' : '');
}
protected function initSafeMap()
@@ -116,7 +116,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
$lineLen = $size - strrpos($enc, '=0D=0A') - 6;
}
}
if (strlen($currentLine)) {
if (\strlen($currentLine)) {
$is->write($prepend.$this->standardize($currentLine));
}
}

View File

@@ -28,7 +28,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont
private $nativeEncoder;
/**
* @var null|string
* @var string|null
*/
private $charset;

View File

@@ -17,8 +17,6 @@ interface Swift_Mime_EncodingObserver
{
/**
* Notify this observer that the observed entity's ContentEncoder has changed.
*
* @param Swift_Mime_ContentEncoder $encoder
*/
public function encoderChanged(Swift_Mime_ContentEncoder $encoder);
}

View File

@@ -41,7 +41,7 @@ class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64E
*/
public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8')
{
if ('iso-2022-jp' === strtolower($charset)) {
if ('iso-2022-jp' === strtolower($charset ?? '')) {
$old = mb_internal_encoding();
mb_internal_encoding('utf-8');
$newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n");

View File

@@ -31,7 +31,7 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i
range(0x61, 0x7A), range(0x41, 0x5A),
range(0x30, 0x39), [0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F]
) as $byte) {
$this->safeMap[$byte] = chr($byte);
$this->safeMap[$byte] = \chr($byte);
}
}

View File

@@ -216,7 +216,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
// ... otherwise it needs encoding
// Determine space remaining on line if first line
if ($shorten) {
$usedLength = strlen($header->getFieldName().': ');
$usedLength = \strlen($header->getFieldName().': ');
} else {
$usedLength = 0;
}
@@ -271,7 +271,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
}
if (-1 == $usedLength) {
$usedLength = strlen($header->getFieldName().': ') + strlen($value);
$usedLength = \strlen($header->getFieldName().': ') + \strlen($value);
}
$value .= $this->getTokenAsEncodedWord($token, $usedLength);
@@ -309,18 +309,18 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
$encodedToken = '';
// Split at all whitespace boundaries
foreach (preg_split('~(?=[\t ])~', $string) as $token) {
foreach (preg_split('~(?=[\t ])~', $string ?? '') as $token) {
if ($this->tokenNeedsEncoding($token)) {
$encodedToken .= $token;
} else {
if (strlen($encodedToken) > 0) {
if (\strlen($encodedToken) > 0) {
$tokens[] = $encodedToken;
$encodedToken = '';
}
$tokens[] = $token;
}
}
if (strlen($encodedToken)) {
if (\strlen($encodedToken)) {
$tokens[] = $encodedToken;
}
@@ -342,7 +342,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
if (isset($this->lang)) {
$charsetDecl .= '*'.$this->lang;
}
$encodingWrapperLength = strlen(
$encodingWrapperLength = \strlen(
'=?'.$charsetDecl.'?'.$this->encoder->getName().'??='
);
@@ -354,10 +354,10 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
$encodedTextLines = explode("\r\n",
$this->encoder->encodeString(
$token, $firstLineOffset, 75 - $encodingWrapperLength, $this->charset
)
) ?? ''
);
if ('iso-2022-jp' !== strtolower($this->charset)) {
if ('iso-2022-jp' !== strtolower($this->charset ?? '')) {
// special encoding for iso-2022-jp using mb_encode_mimeheader
foreach ($encodedTextLines as $lineNum => $line) {
$encodedTextLines[$lineNum] = '=?'.$charsetDecl.
@@ -378,7 +378,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
*/
protected function generateTokenLines($token)
{
return preg_split('~(\r\n)~', $token, -1, PREG_SPLIT_DELIM_CAPTURE);
return preg_split('~(\r\n)~', $token ?? '', -1, PREG_SPLIT_DELIM_CAPTURE);
}
/**
@@ -429,7 +429,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
$tokens = [];
// Generate atoms; split at all invisible boundaries followed by WSP
foreach (preg_split('~(?=[ \t])~', $string) as $token) {
foreach (preg_split('~(?=[ \t])~', $string ?? '') as $token) {
$newTokens = $this->generateTokenLines($token);
foreach ($newTokens as $newToken) {
$tokens[] = $newToken;
@@ -458,8 +458,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
foreach ($tokens as $i => $token) {
// Line longer than specified maximum or token was just a new line
if (("\r\n" == $token) ||
($i > 0 && strlen($currentLine.$token) > $this->lineLength)
&& 0 < strlen($currentLine)) {
($i > 0 && \strlen($currentLine.$token) > $this->lineLength)
&& 0 < \strlen($currentLine)) {
$headerLines[] = '';
$currentLine = &$headerLines[$lineCount++];
}
@@ -473,4 +473,14 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header
// Implode with FWS (RFC 2822, 2.2.3)
return implode("\r\n", $headerLines)."\r\n";
}
/**
* Make a deep copy of object.
*/
public function __clone()
{
if ($this->encoder) {
$this->encoder = clone $this->encoder;
}
}
}

View File

@@ -9,6 +9,7 @@
*/
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\MessageIDValidation;
use Egulias\EmailValidator\Validation\RFCValidation;
/**
@@ -96,7 +97,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
*/
public function setId($id)
{
$this->setIds(is_array($id) ? $id : [$id]);
$this->setIds(\is_array($id) ? $id : [$id]);
}
/**
@@ -108,7 +109,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
*/
public function getId()
{
if (count($this->ids) > 0) {
if (\count($this->ids) > 0) {
return $this->ids[0];
}
}
@@ -179,7 +180,9 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac
*/
private function assertValidId($id)
{
if (!$this->emailValidator->isValid($id, new RFCValidation())) {
$emailValidation = class_exists(MessageIDValidation::class) ? new MessageIDValidation() : new RFCValidation();
if (!$this->emailValidator->isValid($id, $emailValidation)) {
throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>');
}
}

View File

@@ -261,7 +261,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
$actualMailboxes = [];
foreach ($mailboxes as $key => $value) {
if (is_string($key)) {
if (\is_string($key)) {
//key is email addr
$address = $key;
$name = $value;
@@ -347,14 +347,12 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader
*
* @param string $address
*
* @throws Swift_RfcComplianceException If invalid.
* @throws Swift_RfcComplianceException if invalid
*/
private function assertValidAddress($address)
{
if (!$this->emailValidator->isValid($address, new RFCValidation())) {
throw new Swift_RfcComplianceException(
'Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.'
);
throw new Swift_RfcComplianceException('Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.');
}
}
}

View File

@@ -155,7 +155,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
foreach ($this->params as $name => $value) {
if (null !== $value) {
// Add the semi-colon separator
$tokens[count($tokens) - 1] .= ';';
$tokens[\count($tokens) - 1] .= ';';
$tokens = array_merge($tokens, $this->generateTokenLines(
' '.$this->createParameter($name, $value)
));
@@ -179,7 +179,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
$encoded = false;
// Allow room for parameter name, indices, "=" and DQUOTEs
$maxValueLength = $this->getMaxLineLength() - strlen($name.'=*N"";') - 1;
$maxValueLength = $this->getMaxLineLength() - \strlen($name.'=*N"";') - 1;
$firstLineOffset = 0;
// If it's not already a valid parameter value...
@@ -189,15 +189,15 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
if (!preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $value)) {
$encoded = true;
// Allow space for the indices, charset and language
$maxValueLength = $this->getMaxLineLength() - strlen($name.'*N*="";') - 1;
$firstLineOffset = strlen(
$maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1;
$firstLineOffset = \strlen(
$this->getCharset()."'".$this->getLanguage()."'"
);
}
}
// Encode if we need to
if ($encoded || strlen($value) > $maxValueLength) {
if ($encoded || \strlen($value) > $maxValueLength) {
if (isset($this->paramEncoder)) {
$value = $this->paramEncoder->encodeString(
$origValue, $firstLineOffset, $maxValueLength, $this->getCharset()
@@ -212,7 +212,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct
$valueLines = isset($this->paramEncoder) ? explode("\r\n", $value) : [$value];
// Need to add indices
if (count($valueLines) > 1) {
if (\count($valueLines) > 1) {
$paramLines = [];
foreach ($valueLines as $i => $line) {
$paramLines[] = $name.'*'.$i.

View File

@@ -147,9 +147,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader
private function assertValidAddress($address)
{
if (!$this->emailValidator->isValid($address, new RFCValidation())) {
throw new Swift_RfcComplianceException(
'Address set in PathHeader does not comply with addr-spec of RFC 2822.'
);
throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.');
}
}
}

View File

@@ -169,7 +169,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
protected function fixHeaders()
{
parent::fixHeaders();
if (count($this->getChildren())) {
if (\count($this->getChildren())) {
$this->setHeaderParameter('Content-Type', 'charset', null);
$this->setHeaderParameter('Content-Type', 'format', null);
$this->setHeaderParameter('Content-Type', 'delsp', null);
@@ -189,18 +189,9 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity
/** Encode charset when charset is not utf-8 */
protected function convertString($string)
{
$charset = strtolower($this->getCharset());
if (!in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) {
// mb_convert_encoding must be the first one to check, since iconv cannot convert some words.
if (function_exists('mb_convert_encoding')) {
$string = mb_convert_encoding($string, $charset, 'utf-8');
} elseif (function_exists('iconv')) {
$string = iconv('utf-8//TRANSLIT//IGNORE', $charset, $string);
} else {
throw new Swift_SwiftException('No suitable convert encoding function (use UTF-8 as your charset or install the mbstring or iconv extension).');
}
return $string;
$charset = strtolower($this->getCharset() ?? '');
if (!\in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) {
return mb_convert_encoding($string, $charset, 'utf-8');
}
return $string;

View File

@@ -68,8 +68,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
/**
* Create a new Date header using $dateTime.
*
* @param string $name
* @param DateTimeInterface|null $dateTime
* @param string $name
*
* @return Swift_Mime_Header
*/
@@ -114,7 +113,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
*/
public function createParameterizedHeader($name, $value = null, $params = [])
{
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, ('content-disposition' == strtolower($name)) ? $this->paramEncoder : null);
$header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, ('content-disposition' == strtolower($name ?? '')) ? $this->paramEncoder : null);
if (isset($value)) {
$header->setFieldBodyModel($value);
}
@@ -183,6 +182,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver
{
$this->encoder = clone $this->encoder;
$this->paramEncoder = clone $this->paramEncoder;
$this->addressEncoder = clone $this->addressEncoder;
}
/** Apply the charset to the Header */

View File

@@ -138,18 +138,18 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
*/
public function has($name, $index = 0)
{
$lowerName = strtolower($name);
$lowerName = strtolower($name ?? '');
if (!array_key_exists($lowerName, $this->headers)) {
if (!\array_key_exists($lowerName, $this->headers)) {
return false;
}
if (func_num_args() < 2) {
if (\func_num_args() < 2) {
// index was not specified, so we only need to check that there is at least one header value set
return (bool) count($this->headers[$lowerName]);
return (bool) \count($this->headers[$lowerName]);
}
return array_key_exists($index, $this->headers[$lowerName]);
return \array_key_exists($index, $this->headers[$lowerName]);
}
/**
@@ -177,13 +177,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
* @param string $name
* @param int $index
*
* @return Swift_Mime_Header
* @return Swift_Mime_Header|null
*/
public function get($name, $index = 0)
{
$name = strtolower($name);
$name = strtolower($name ?? '');
if (func_num_args() < 2) {
if (\func_num_args() < 2) {
if ($this->has($name)) {
$values = array_values($this->headers[$name]);
@@ -214,8 +214,8 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
return $headers;
}
$lowerName = strtolower($name);
if (!array_key_exists($lowerName, $this->headers)) {
$lowerName = strtolower($name ?? '');
if (!\array_key_exists($lowerName, $this->headers)) {
return [];
}
@@ -247,7 +247,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
*/
public function remove($name, $index = 0)
{
$lowerName = strtolower($name);
$lowerName = strtolower($name ?? '');
unset($this->headers[$lowerName][$index]);
}
@@ -258,7 +258,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
*/
public function removeAll($name)
{
$lowerName = strtolower($name);
$lowerName = strtolower($name ?? '');
unset($this->headers[$lowerName]);
}
@@ -330,29 +330,29 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
/** Save a Header to the internal collection */
private function storeHeader($name, Swift_Mime_Header $header, $offset = null)
{
if (!isset($this->headers[strtolower($name)])) {
$this->headers[strtolower($name)] = [];
if (!isset($this->headers[strtolower($name ?? '')])) {
$this->headers[strtolower($name ?? '')] = [];
}
if (!isset($offset)) {
$this->headers[strtolower($name)][] = $header;
$this->headers[strtolower($name ?? '')][] = $header;
} else {
$this->headers[strtolower($name)][$offset] = $header;
$this->headers[strtolower($name ?? '')][$offset] = $header;
}
}
/** Test if the headers can be sorted */
private function canSort()
{
return count($this->order) > 0;
return \count($this->order) > 0;
}
/** uksort() algorithm for Header ordering */
private function sortHeaders($a, $b)
{
$lowerA = strtolower($a);
$lowerB = strtolower($b);
$aPos = array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1;
$bPos = array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1;
$lowerA = strtolower($a ?? '');
$lowerB = strtolower($b ?? '');
$aPos = \array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1;
$bPos = \array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1;
if (-1 === $aPos && -1 === $bPos) {
// just be sure to be determinist here
@@ -371,7 +371,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver
/** Test if the given Header is always displayed */
private function isDisplayed(Swift_Mime_Header $header)
{
return array_key_exists(strtolower($header->getFieldName()), $this->required);
return \array_key_exists(strtolower($header->getFieldName() ?? ''), $this->required);
}
/** Notify all Headers of the new charset */

View File

@@ -152,7 +152,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function setSender($address, $name = null)
{
if (!is_array($address) && isset($name)) {
if (!\is_array($address) && isset($name)) {
$address = [$address => $name];
}
@@ -206,7 +206,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function setFrom($addresses, $name = null)
{
if (!is_array($addresses) && isset($name)) {
if (!\is_array($addresses) && isset($name)) {
$addresses = [$addresses => $name];
}
@@ -260,7 +260,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function setReplyTo($addresses, $name = null)
{
if (!is_array($addresses) && isset($name)) {
if (!\is_array($addresses) && isset($name)) {
$addresses = [$addresses => $name];
}
@@ -315,7 +315,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function setTo($addresses, $name = null)
{
if (!is_array($addresses) && isset($name)) {
if (!\is_array($addresses) && isset($name)) {
$addresses = [$addresses => $name];
}
@@ -367,7 +367,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function setCc($addresses, $name = null)
{
if (!is_array($addresses) && isset($name)) {
if (!\is_array($addresses) && isset($name)) {
$addresses = [$addresses => $name];
}
@@ -419,7 +419,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function setBcc($addresses, $name = null)
{
if (!is_array($addresses) && isset($name)) {
if (!\is_array($addresses) && isset($name)) {
$addresses = [$addresses => $name];
}
@@ -568,7 +568,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function toString()
{
if (count($children = $this->getChildren()) > 0 && '' != $this->getBody()) {
if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) {
$this->setChildren(array_merge([$this->becomeMimePart()], $children));
$string = parent::toString();
$this->setChildren($children);
@@ -596,7 +596,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart
*/
public function toByteStream(Swift_InputByteStream $is)
{
if (count($children = $this->getChildren()) > 0 && '' != $this->getBody()) {
if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) {
$this->setChildren(array_merge([$this->becomeMimePart()], $children));
parent::toByteStream($is);
$this->setChildren($children);

View File

@@ -634,7 +634,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
*/
protected function fixHeaders()
{
if (count($this->immediateChildren)) {
if (\count($this->immediateChildren)) {
$this->setHeaderParameter('Content-Type', 'boundary',
$this->getBoundary()
);
@@ -731,7 +731,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
}
$realLevel = $child->getNestingLevel();
$lowercaseType = strtolower($child->getContentType());
$lowercaseType = strtolower($child->getContentType() ?? '');
if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) {
return $filter[$realLevel][$lowercaseType];
@@ -778,7 +778,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
$sorted = [];
foreach ($this->immediateChildren as $child) {
$type = $child->getContentType();
$level = array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
$level = \array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1;
if (empty($sorted[$level])) {
$sorted[$level] = [];
@@ -817,4 +817,10 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M
}
$this->setChildren($children);
}
public function __wakeup()
{
$this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values
$this->cache = new Swift_KeyCache_ArrayKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream());
}
}

View File

@@ -26,7 +26,7 @@ class Swift_MimePart extends Swift_Mime_MimePart
*/
public function __construct($body = null, $contentType = null, $charset = null)
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Mime_MimePart::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.part')

View File

@@ -17,7 +17,7 @@ class Swift_NullTransport extends Swift_Transport_NullTransport
{
public function __construct()
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Transport_NullTransport::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.null')

View File

@@ -54,7 +54,7 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener,
public function commandSent(Swift_Events_CommandEvent $evt)
{
$command = $evt->getCommand();
$this->out += strlen($command);
$this->out += \strlen($command);
}
/**
@@ -63,7 +63,7 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener,
public function responseReceived(Swift_Events_ResponseEvent $evt)
{
$response = $evt->getResponse();
$this->in += strlen($response);
$this->in += \strlen($response);
}
/**
@@ -73,7 +73,7 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener,
*/
public function write($bytes)
{
$this->out += strlen($bytes);
$this->out += \strlen($bytes);
foreach ($this->mirrors as $stream) {
$stream->write($bytes);
}

View File

@@ -96,20 +96,20 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_
foreach ($message->getHeaders()->getAll() as $header) {
$body = $header->getFieldBodyModel();
$count = 0;
if (is_array($body)) {
if (\is_array($body)) {
$bodyReplaced = [];
foreach ($body as $key => $value) {
$count1 = 0;
$count2 = 0;
$key = is_string($key) ? str_replace($search, $replace, $key, $count1) : $key;
$value = is_string($value) ? str_replace($search, $replace, $value, $count2) : $value;
$key = \is_string($key) ? str_replace($search, $replace, $key, $count1) : $key;
$value = \is_string($value) ? str_replace($search, $replace, $value, $count2) : $value;
$bodyReplaced[$key] = $value;
if (!$count && ($count1 || $count2)) {
$count = 1;
}
}
} elseif (is_string($body)) {
} elseif (\is_string($body)) {
$bodyReplaced = str_replace($search, $replace, $body, $count);
}
@@ -178,7 +178,7 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_
}
if (!empty($this->originalHeaders)) {
foreach ($message->getHeaders()->getAll() as $header) {
if (array_key_exists($header->getFieldName(), $this->originalHeaders)) {
if (\array_key_exists($header->getFieldName(), $this->originalHeaders)) {
$header->setFieldBodyModel($this->originalHeaders[$header->getFieldName()]);
}
}
@@ -188,7 +188,7 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_
$children = (array) $message->getChildren();
foreach ($children as $child) {
$id = $child->getId();
if (array_key_exists($id, $this->originalChildBodies)) {
if (\array_key_exists($id, $this->originalChildBodies)) {
$child->setBody($this->originalChildBodies[$id]);
}
}

View File

@@ -77,7 +77,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_
*/
public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt)
{
$transportName = get_class($evt->getSource());
$transportName = \get_class($evt->getSource());
$this->logger->add(sprintf('++ Starting %s', $transportName));
}
@@ -86,7 +86,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_
*/
public function transportStarted(Swift_Events_TransportChangeEvent $evt)
{
$transportName = get_class($evt->getSource());
$transportName = \get_class($evt->getSource());
$this->logger->add(sprintf('++ %s started', $transportName));
}
@@ -95,7 +95,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_
*/
public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt)
{
$transportName = get_class($evt->getSource());
$transportName = \get_class($evt->getSource());
$this->logger->add(sprintf('++ Stopping %s', $transportName));
}
@@ -104,7 +104,7 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_
*/
public function transportStopped(Swift_Events_TransportChangeEvent $evt)
{
$transportName = get_class($evt->getSource());
$transportName = \get_class($evt->getSource());
$this->logger->add(sprintf('++ %s stopped', $transportName));
}

View File

@@ -47,7 +47,7 @@ class Swift_Plugins_Loggers_ArrayLogger implements Swift_Plugins_Logger
public function add($entry)
{
$this->log[] = $entry;
while (count($this->log) > $this->size) {
while (\count($this->log) > $this->size) {
array_shift($this->log);
}
}

View File

@@ -42,7 +42,7 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener
*/
public function countMessages()
{
return count($this->messages);
return \count($this->messages);
}
/**

View File

@@ -132,16 +132,12 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL
if (!isset($this->socket)) {
if (!$socket = fsockopen(
$this->getHostString(), $this->port, $errno, $errstr, $this->timeout)) {
throw new Swift_Plugins_Pop_Pop3Exception(
sprintf('Failed to connect to POP3 host [%s]: %s', $this->host, $errstr)
);
throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to connect to POP3 host [%s]: %s', $this->host, $errstr));
}
$this->socket = $socket;
if (false === $greeting = fgets($this->socket)) {
throw new Swift_Plugins_Pop_Pop3Exception(
sprintf('Failed to connect to POP3 host [%s]', trim($greeting))
);
throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to connect to POP3 host [%s]', trim($greeting ?? '')));
}
$this->assertOk($greeting);
@@ -164,9 +160,7 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL
} else {
$this->command("QUIT\r\n");
if (!fclose($this->socket)) {
throw new Swift_Plugins_Pop_Pop3Exception(
sprintf('POP3 host [%s] connection could not be stopped', $this->host)
);
throw new Swift_Plugins_Pop_Pop3Exception(sprintf('POP3 host [%s] connection could not be stopped', $this->host));
}
$this->socket = null;
}
@@ -211,15 +205,11 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL
private function command($command)
{
if (!fwrite($this->socket, $command)) {
throw new Swift_Plugins_Pop_Pop3Exception(
sprintf('Failed to write command [%s] to POP3 host', trim($command))
);
throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to write command [%s] to POP3 host', trim($command ?? '')));
}
if (false === $response = fgets($this->socket)) {
throw new Swift_Plugins_Pop_Pop3Exception(
sprintf('Failed to read from POP3 host after command [%s]', trim($command))
);
throw new Swift_Plugins_Pop_Pop3Exception(sprintf('Failed to read from POP3 host after command [%s]', trim($command ?? '')));
}
$this->assertOk($response);
@@ -230,16 +220,14 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL
private function assertOk($response)
{
if ('+OK' != substr($response, 0, 3)) {
throw new Swift_Plugins_Pop_Pop3Exception(
sprintf('POP3 command failed [%s]', trim($response))
);
throw new Swift_Plugins_Pop_Pop3Exception(sprintf('POP3 command failed [%s]', trim($response ?? '')));
}
}
private function getHostString()
{
$host = $this->host;
switch (strtolower($this->crypto)) {
switch (strtolower($this->crypto ?? '')) {
case 'ssl':
$host = 'ssl://'.$host;
break;

View File

@@ -112,7 +112,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener
}
foreach ((array) $this->recipient as $recipient) {
if (!array_key_exists($recipient, $to)) {
if (!\array_key_exists($recipient, $to)) {
$message->addTo($recipient);
}
}
@@ -155,7 +155,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener
*/
protected function isWhitelisted($recipient)
{
if (in_array($recipient, (array) $this->recipient)) {
if (\in_array($recipient, (array) $this->recipient)) {
return true;
}

View File

@@ -24,9 +24,8 @@ interface Swift_Plugins_Reporter
/**
* Notifies this ReportNotifier that $address failed or succeeded.
*
* @param Swift_Mime_SimpleMessage $message
* @param string $address
* @param int $result from {@link RESULT_PASS, RESULT_FAIL}
* @param string $address
* @param int $result from {@link RESULT_PASS, RESULT_FAIL}
*/
public function notify(Swift_Mime_SimpleMessage $message, $address, $result);
}

View File

@@ -45,13 +45,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));
}
}
}

View File

@@ -22,7 +22,7 @@ class Swift_SendmailTransport extends Swift_Transport_SendmailTransport
*/
public function __construct($command = '/usr/sbin/sendmail -bs')
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Transport_SendmailTransport::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.sendmail')

View File

@@ -18,8 +18,6 @@ interface Swift_Signers_BodySigner extends Swift_Signer
/**
* Change the Swift_Signed_Message to apply the singing.
*
* @param Swift_Message $message
*
* @return self
*/
public function signMessage(Swift_Message $message);

View File

@@ -129,9 +129,9 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
/**
* If debugHeaders is set store debugData here.
*
* @var string
* @var string[]
*/
private $debugHeadersData = '';
private $debugHeadersData = [];
/**
* Stores the bodyHash.
@@ -295,7 +295,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
break;
case 'rsa-sha256':
$this->hashAlgorithm = 'rsa-sha256';
if (!defined('OPENSSL_ALGO_SHA256')) {
if (!\defined('OPENSSL_ALGO_SHA256')) {
throw new Swift_SwiftException('Unable to set sha256 as it is not supported by OpenSSL.');
}
break;
@@ -469,7 +469,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
*/
public function ignoreHeader($header_name)
{
$this->ignoredHeaders[strtolower($header_name)] = true;
$this->ignoredHeaders[strtolower($header_name ?? '')] = true;
return $this;
}
@@ -486,7 +486,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) {
@@ -510,7 +510,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
public function addSignature(Swift_Mime_SimpleHeaderSet $headers)
{
// Prepare the DKIM-Signature
$params = ['v' => '1', 'a' => $this->hashAlgorithm, 'bh' => base64_encode($this->bodyHash), 'd' => $this->domainName, 'h' => implode(': ', $this->signedHeaders), 'i' => $this->signerIdentity, 's' => $this->selector];
$params = ['v' => '1', 'a' => $this->hashAlgorithm, 'bh' => base64_encode($this->bodyHash ?? ''), 'd' => $this->domainName, 'h' => implode(': ', $this->signedHeaders), 'i' => $this->signerIdentity, 's' => $this->selector];
if ('simple' != $this->bodyCanon) {
$params['c'] = $this->headerCanon.'/'.$this->bodyCanon;
} elseif ('simple' != $this->headerCanon) {
@@ -544,11 +544,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
// Add the last DKIM-Signature
$tmp = $headers->getAll('DKIM-Signature');
$this->dkimHeader = end($tmp);
$this->addHeader(trim($this->dkimHeader->toString())."\r\n b=", true);
$this->addHeader(trim($this->dkimHeader->toString() ?? '')."\r\n b=", true);
if ($this->debugHeaders) {
$headers->addTextHeader('X-DebugHash', base64_encode($this->headerHash));
$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;
}
@@ -574,7 +574,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
protected function canonicalizeBody($string)
{
$len = strlen($string);
$len = \strlen($string);
$canon = '';
$method = ('relaxed' == $this->bodyCanon);
for ($i = 0; $i < $len; ++$i) {
@@ -629,7 +629,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
protected function endOfBody()
{
// Add trailing Line return if last line is non empty
if (strlen($this->bodyCanonLine) > 0) {
if (\strlen($this->bodyCanonLine) > 0) {
$this->addToBodyHash("\r\n");
}
$this->bodyHash = hash_final($this->bodyHashHandler, true);
@@ -637,7 +637,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
private function addToBodyHash($string)
{
$len = strlen($string);
$len = \strlen($string);
if ($len > ($new_len = ($this->maxLen - $this->bodyLen))) {
$string = substr($string, 0, $new_len);
$len = $new_len;
@@ -649,7 +649,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner
private function addToHeaderHash($header)
{
if ($this->debugHeaders) {
$this->debugHeadersData[] = trim($header);
$this->debugHeadersData[] = trim($header ?? '');
}
$this->headerCanonData .= $header;
}

View File

@@ -332,7 +332,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
*/
public function ignoreHeader($header_name)
{
$this->ignoredHeaders[strtolower($header_name)] = true;
$this->ignoredHeaders[strtolower($header_name ?? '')] = true;
return $this;
}
@@ -350,7 +350,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) {
@@ -375,7 +375,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
public function addSignature(Swift_Mime_SimpleHeaderSet $headers)
{
// Prepare the DomainKey-Signature Header
$params = ['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 = ['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.'; ';
@@ -412,7 +412,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
protected function canonicalizeBody($string)
{
$len = strlen($string);
$len = \strlen($string);
$canon = '';
$nofws = ('nofws' == $this->canon);
for ($i = 0; $i < $len; ++$i) {
@@ -462,7 +462,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner
protected function endOfBody()
{
if (strlen($this->bodyCanonLine) > 0) {
if (\strlen($this->bodyCanonLine) > 0) {
$this->addToHash("\r\n");
}
}

View File

@@ -41,8 +41,6 @@ interface Swift_Signers_HeaderSigner extends Swift_Signer, Swift_InputByteStream
/**
* Give the headers already given.
*
* @param Swift_Mime_SimpleHeaderSet $headers
*
* @return self
*/
public function setHeaders(Swift_Mime_SimpleHeaderSet $headers);
@@ -50,8 +48,6 @@ interface Swift_Signers_HeaderSigner extends Swift_Signer, Swift_InputByteStream
/**
* Add the header(s) to the headerSet.
*
* @param Swift_Mime_SimpleHeaderSet $headers
*
* @return self
*/
public function addSignature(Swift_Mime_SimpleHeaderSet $headers);

View File

@@ -31,7 +31,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
public function __construct($privateKey, $domainName, $selector)
{
if (!extension_loaded('opendkim')) {
if (!\extension_loaded('opendkim')) {
throw new Swift_SwiftException('php-opendkim extension not found');
}
@@ -44,7 +44,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
{
$header = new Swift_Mime_Headers_OpenDKIMHeader('DKIM-Signature');
$headerVal = $this->dkimHandler->getSignatureHeader();
if (false === $headerVal || is_int($headerVal)) {
if (false === $headerVal || \is_int($headerVal)) {
throw new Swift_SwiftException('OpenDKIM Error: '.$this->dkimHandler->getError());
}
$header->setValue($headerVal);
@@ -75,7 +75,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) {
@@ -176,7 +176,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner
}
}
$this->dropFirstLF = false;
if (strlen($string)) {
if (\strlen($string)) {
$this->dkimHandler->body($string);
}
}

View File

@@ -80,7 +80,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner
$this->signCertificate = 'file://'.str_replace('\\', '/', realpath($certificate));
if (null !== $privateKey) {
if (is_array($privateKey)) {
if (\is_array($privateKey)) {
$this->signPrivateKey = $privateKey;
$this->signPrivateKey[0] = 'file://'.str_replace('\\', '/', realpath($privateKey[0]));
} else {
@@ -107,7 +107,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner
*/
public function setEncryptCertificate($recipientCerts, $cipher = null)
{
if (is_array($recipientCerts)) {
if (\is_array($recipientCerts)) {
$this->encryptCert = [];
foreach ($recipientCerts as $cert) {
@@ -496,20 +496,20 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner
foreach ($headerLines as $headerLine) {
// Handle headers that span multiple lines
if (false === strpos($headerLine, ':')) {
$headers[$currentHeaderName] .= ' '.trim($headerLine);
$headers[$currentHeaderName] .= ' '.trim($headerLine ?? '');
continue;
}
$header = explode(':', $headerLine, 2);
$currentHeaderName = strtolower($header[0]);
$headers[$currentHeaderName] = trim($header[1]);
$currentHeaderName = strtolower($header[0] ?? '');
$headers[$currentHeaderName] = trim($header[1] ?? '');
}
// Read the entire email body into a byte stream
$bodyStream = new Swift_ByteStream_TemporaryFileByteStream();
// Skip the header and separator and point to the body
$emailStream->setReadPointer($headersPosEnd + strlen($headerBodySeparator));
$emailStream->setReadPointer($headersPosEnd + \strlen($headerBodySeparator));
while (false !== ($buffer = $emailStream->read($bufferLength))) {
$bodyStream->write($buffer);

View File

@@ -25,15 +25,18 @@ class Swift_SmtpTransport extends Swift_Transport_EsmtpTransport
/**
* @param string $host
* @param int $port
* @param string $encryption
* @param string|null $encryption SMTP encryption mode:
* - null for plain SMTP (no encryption),
* - 'tls' for SMTP with STARTTLS (best effort encryption),
* - 'ssl' for SMTPS = SMTP over TLS (always encrypted).
*/
public function __construct($host = 'localhost', $port = 25, $encryption = null)
{
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Transport_EsmtpTransport::__construct'],
Swift_DependencyContainer::getInstance()
->createDependenciesFor('transport.smtp')
);
);
$this->setHost($host);
$this->setPort($port);

View File

@@ -25,7 +25,7 @@ class Swift_SpoolTransport extends Swift_Transport_SpoolTransport
$arguments[] = $spool;
call_user_func_array(
\call_user_func_array(
[$this, 'Swift_Transport_SpoolTransport::__construct'],
$arguments
);

View File

@@ -49,11 +49,11 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt
$last_size = $size = 0;
foreach ($search as $i => $search_element) {
if (null !== $tree) {
$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])) {
@@ -74,19 +74,19 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt
}
}
if (null !== $i) {
$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)) {
if (!\is_array($rep)) {
$rep = [$rep];
}
$this->replace[] = $rep;
}
for ($i = count($this->replace) - 1; $i >= 0; --$i) {
for ($i = \count($this->replace) - 1; $i >= 0; --$i) {
$this->replace[$i] = $rep = $this->filter($this->replace[$i], $i);
$this->repSize[$i] = count($rep);
$this->repSize[$i] = \count($rep);
}
}
@@ -119,7 +119,7 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt
}
$newBuffer = [];
$buf_size = count($buffer);
$buf_size = \count($buffer);
$last_size = 0;
for ($i = 0; $i < $buf_size; ++$i) {
$search_pos = $this->tree;

View File

@@ -63,8 +63,7 @@ interface Swift_Transport
*
* This is the responsibility of the send method to start the transport if needed.
*
* @param Swift_Mime_SimpleMessage $message
* @param string[] $failedRecipients An array of failures by-reference
* @param string[] $failedRecipients An array of failures by-reference
*
* @return int
*/
@@ -72,8 +71,6 @@ interface Swift_Transport
/**
* Register a plugin in the Transport.
*
* @param Swift_Events_EventListener $plugin
*/
public function registerPlugin(Swift_Events_EventListener $plugin);
}

View File

@@ -197,20 +197,19 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
$to = (array) $message->getTo();
$cc = (array) $message->getCc();
$tos = array_merge($to, $cc);
$bcc = (array) $message->getBcc();
$tos = array_merge($to, $cc, $bcc);
$message->setBcc([]);
try {
$sent += $this->sendTo($message, $reversePath, $tos, $failedRecipients);
$sent += $this->sendBcc($message, $reversePath, $bcc, $failedRecipients);
} finally {
$message->setBcc($bcc);
}
if ($evt) {
if ($sent == count($to) + count($cc) + count($bcc)) {
if ($sent == \count($to) + \count($cc) + \count($bcc)) {
$evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
} elseif ($sent > 0) {
$evt->setResult(Swift_Events_SendEvent::RESULT_TENTATIVE);
@@ -318,7 +317,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
* @param int[] $codes
* @param string[] $failures An array of failures by-reference
* @param bool $pipeline Do not wait for response
* @param string $address The address, if command is RCPT TO.
* @param string $address the address, if command is RCPT TO
*
* @return string|null The server response, or null if pipelining is enabled
*/
@@ -331,20 +330,23 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
}
$this->pipeline[] = [$command, $seq, $codes, $address];
if ($pipeline && $this->pipelining) {
$response = null;
} else {
while ($this->pipeline) {
list($command, $seq, $codes, $address) = array_shift($this->pipeline);
$response = $this->getFullResponse($seq);
try {
$this->assertResponseCode($response, $codes);
} catch (Swift_TransportException $e) {
if ($this->pipeline && $address) {
$failures[] = $address;
} else {
$this->throwException($e);
}
return null;
}
$response = null;
while ($this->pipeline) {
list($command, $seq, $codes, $address) = array_shift($this->pipeline);
$response = $this->getFullResponse($seq);
try {
$this->assertResponseCode($response, $codes);
} catch (Swift_TransportException $e) {
if ($this->pipeline && $address) {
$failures[] = $address;
} else {
$this->throwException($e);
}
}
}
@@ -446,7 +448,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
}
list($code) = sscanf($response, '%3d');
$valid = (empty($wanted) || in_array($code, $wanted));
$valid = (empty($wanted) || \in_array($code, $wanted));
if ($evt = $this->eventDispatcher->createResponseEvent($this, $response,
$valid)) {
@@ -493,9 +495,9 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
}
if (0 != $sent) {
$sent += count($failedRecipients);
$sent += \count($failedRecipients);
$this->doDataCommand($failedRecipients);
$sent -= count($failedRecipients);
$sent -= \count($failedRecipients);
$this->streamMessage($message);
} else {
@@ -516,20 +518,6 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
$failedRecipients);
}
/** Send a message to all Bcc: recipients */
private function sendBcc(Swift_Mime_SimpleMessage $message, $reversePath, array $bcc, array &$failedRecipients)
{
$sent = 0;
foreach ($bcc as $forwardPath => $name) {
$message->setBcc([$forwardPath => $name]);
$sent += $this->doMailTransaction(
$message, $reversePath, [$forwardPath], $failedRecipients
);
}
return $sent;
}
/**
* Destructor.
*/
@@ -540,4 +528,14 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport
} catch (Exception $e) {
}
}
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
}
}

View File

@@ -35,7 +35,7 @@ class Swift_Transport_Esmtp_Auth_CramMd5Authenticator implements Swift_Transport
$challenge = base64_decode(substr($challenge, 4));
$message = base64_encode(
$username.' '.$this->getResponse($password, $challenge)
);
);
$agent->executeCommand(sprintf("%s\r\n", $message), [235]);
return true;
@@ -56,16 +56,16 @@ class Swift_Transport_Esmtp_Auth_CramMd5Authenticator implements Swift_Transport
*/
private function getResponse($secret, $challenge)
{
if (strlen($secret) > 64) {
if (\strlen($secret) > 64) {
$secret = pack('H32', md5($secret));
}
if (strlen($secret) < 64) {
$secret = str_pad($secret, 64, chr(0));
if (\strlen($secret) < 64) {
$secret = str_pad($secret, 64, \chr(0));
}
$k_ipad = substr($secret, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($secret, 0, 64) ^ str_repeat(chr(0x5C), 64);
$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));
$digest = md5($k_opad.$inner);

View File

@@ -32,8 +32,8 @@ class Swift_Transport_Esmtp_Auth_LoginAuthenticator implements Swift_Transport_E
{
try {
$agent->executeCommand("AUTH LOGIN\r\n", [334]);
$agent->executeCommand(sprintf("%s\r\n", base64_encode($username)), [334]);
$agent->executeCommand(sprintf("%s\r\n", base64_encode($password)), [235]);
$agent->executeCommand(sprintf("%s\r\n", base64_encode($username ?? '')), [334]);
$agent->executeCommand(sprintf("%s\r\n", base64_encode($password ?? '')), [235]);
return true;
} catch (Swift_TransportException $e) {

View File

@@ -37,22 +37,22 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
*/
public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password)
{
if (!function_exists('openssl_encrypt')) {
if (!\function_exists('openssl_encrypt')) {
throw new LogicException('The OpenSSL extension must be enabled to use the NTLM authenticator.');
}
if (!function_exists('bcmul')) {
if (!\function_exists('bcmul')) {
throw new LogicException('The BCMath functions must be enabled to use the NTLM authenticator.');
}
try {
// execute AUTH command and filter out the code at the beginning
// AUTH NTLM xxxx
$response = base64_decode(substr(trim($this->sendMessage1($agent)), 4));
$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'));
$client = func_num_args() > 4 ? func_get_arg(4) : random_bytes(8);
$timestamp = \func_num_args() > 3 ? func_get_arg(3) : $this->getCorrectTimestamp(bcmul(microtime(true), '1000'));
$client = \func_num_args() > 4 ? func_get_arg(4) : random_bytes(8);
// Message 3 response
$this->sendMessage3($response, $username, $password, $timestamp, $client, $agent);
@@ -68,20 +68,20 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
protected function si2bin($si, $bits = 32)
{
$bin = null;
if ($si >= -pow(2, $bits - 1) && ($si <= pow(2, $bits - 1))) {
if ($si >= -2 ** ($bits - 1) && ($si <= 2 ** ($bits - 1))) {
// positive or zero
if ($si >= 0) {
$bin = base_convert($si, 10, 2);
// pad to $bits bit
$bin_length = strlen($bin);
$bin_length = \strlen($bin);
if ($bin_length < $bits) {
$bin = str_repeat('0', $bits - $bin_length).$bin;
}
} else {
// negative
$si = -$si - pow(2, $bits);
$si = -$si - 2 ** $bits;
$bin = base_convert($si, 10, 2);
$bin_length = strlen($bin);
$bin_length = \strlen($bin);
if ($bin_length > $bits) {
$bin = str_repeat('1', $bits - $bin_length).$bin;
}
@@ -147,7 +147,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
// remove terminatorByte cause it's always the same
$block = substr($block, 0, -8);
$length = strlen($block);
$length = \strlen($block);
$offset = 0;
$data = [];
while ($offset < $length) {
@@ -157,7 +157,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
$offset += $blockLength * 2;
}
if (3 == count($data)) {
if (3 == \count($data)) {
$data[] = $data[2];
$data[2] = '';
}
@@ -364,7 +364,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
$binary = $this->si2bin($time, 64); // create 64 bit binary string
$timestamp = '';
for ($i = 0; $i < 8; ++$i) {
$timestamp .= chr(bindec(substr($binary, -(($i + 1) * 8), 8)));
$timestamp .= \chr(bindec(substr($binary, -(($i + 1) * 8), 8)));
}
return $timestamp;
@@ -385,7 +385,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
{
$lmPass = '00'; // by default 00
// if $password > 15 than we can't use this method
if (strlen($password) <= 15) {
if (\strlen($password) <= 15) {
$ntlmHash = $this->md4Encrypt($password);
$ntml2Hash = $this->md5Encrypt($ntlmHash, $this->convertTo16bit(strtoupper($username).$domain));
@@ -426,13 +426,13 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
protected function createDesKey($key)
{
$material = [bin2hex($key[0])];
$len = strlen($key);
$len = \strlen($key);
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));
$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
}
$material[] = str_pad(substr(dechex($this->castToByte(ord($key[6]) << 1)), -2), 2, '0');
$material[] = str_pad(substr(dechex($this->castToByte(\ord($key[6]) << 1)), -2), 2, '0');
// odd parity
foreach ($material as $k => $v) {
@@ -465,7 +465,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
*/
protected function createSecurityBuffer($value, $offset, $is16 = false)
{
$length = strlen(bin2hex($value));
$length = \strlen(bin2hex($value));
$length = $is16 ? $length / 2 : $length;
$length = $this->createByte(str_pad(dechex($length), 2, '0', STR_PAD_LEFT), 2);
@@ -563,7 +563,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
protected function md5Encrypt($key, $msg)
{
$blocksize = 64;
if (strlen($key) > $blocksize) {
if (\strlen($key) > $blocksize) {
$key = pack('H*', md5($key));
}
@@ -587,7 +587,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es
{
$input = $this->convertTo16bit($input);
return function_exists('hash') ? hex2bin(hash('md4', $input)) : mhash(MHASH_MD4, $input);
return \function_exists('hash') ? hex2bin(hash('md4', $input)) : mhash(MHASH_MD4, $input);
}
/**

View File

@@ -31,7 +31,7 @@ class Swift_Transport_Esmtp_Auth_PlainAuthenticator implements Swift_Transport_E
public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password)
{
try {
$message = base64_encode($username.chr(0).$username.chr(0).$password);
$message = base64_encode($username.\chr(0).$username.\chr(0).$password);
$agent->executeCommand(sprintf("AUTH PLAIN %s\r\n", $message), [235]);
return true;

View File

@@ -171,7 +171,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler
$count = 0;
$errors = [];
foreach ($this->getAuthenticatorsForAgent() as $authenticator) {
if (in_array(strtolower($authenticator->getAuthKeyword()), array_map('strtolower', $this->esmtpParams))) {
if (\in_array(strtolower($authenticator->getAuthKeyword() ?? ''), array_map('strtolower', $this->esmtpParams))) {
++$count;
try {
if ($authenticator->authenticate($agent, $this->username, $this->password)) {
@@ -179,7 +179,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler
}
} catch (Swift_TransportException $e) {
// keep the error message, but tries the other authenticators
$errors[] = [$authenticator->getAuthKeyword(), $e];
$errors[] = [$authenticator->getAuthKeyword(), $e->getMessage()];
}
}
}
@@ -253,12 +253,12 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler
*/
protected function getAuthenticatorsForAgent()
{
if (!$mode = strtolower($this->auth_mode)) {
if (!$mode = strtolower($this->auth_mode ?? '')) {
return $this->authenticators;
}
foreach ($this->authenticators as $authenticator) {
if (strtolower($authenticator->getAuthKeyword()) == $mode) {
if (strtolower($authenticator->getAuthKeyword() ?? '') == $mode) {
return [$authenticator];
}
}

View File

@@ -25,9 +25,8 @@ interface Swift_Transport_Esmtp_Authenticator
/**
* 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 true if authentication worked (returning false is deprecated, throw a Swift_TransportException instead)
*

View File

@@ -141,7 +141,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
*/
public function setEncryption($encryption)
{
$encryption = strtolower($encryption);
$encryption = strtolower($encryption ?? '');
if ('tls' == $encryption) {
$this->params['protocol'] = 'tcp';
$this->params['tls'] = true;
@@ -235,7 +235,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
* Returns whether SMTP pipelining is enabled.
*
* @return bool|null a boolean if pipelining is explicitly enabled or disabled,
* or null if support is auto-detected.
* or null if support is auto-detected
*/
public function getPipelining()
{
@@ -284,7 +284,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
* @param int[] $codes
* @param string[] $failures An array of failures by-reference
* @param bool $pipeline Do not wait for response
* @param string $address The address, if command is RCPT TO.
* @param string $address the address, if command is RCPT TO
*
* @return string|null The server response, or null if pipelining is enabled
*/
@@ -309,10 +309,10 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
public function __call($method, $args)
{
foreach ($this->handlers as $handler) {
if (in_array(strtolower($method),
if (\in_array(strtolower($method),
array_map('strtolower', (array) $handler->exposeMixinMethods())
)) {
$return = call_user_func_array([$handler, $method], $args);
$return = \call_user_func_array([$handler, $method], $args);
// Allow fluid method calls
if (null === $return && 'set' == substr($method, 0, 3)) {
return $this;
@@ -406,7 +406,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
private function getCapabilities($ehloResponse)
{
$capabilities = [];
$ehloResponse = trim($ehloResponse);
$ehloResponse = trim($ehloResponse ?? '');
$lines = explode("\r\n", $ehloResponse);
array_shift($lines);
foreach ($lines as $line) {
@@ -425,7 +425,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
private function setHandlerParams()
{
foreach ($this->handlers as $keyword => $handler) {
if (array_key_exists($keyword, $this->capabilities)) {
if (\array_key_exists($keyword, $this->capabilities)) {
$handler->setKeywordParams($this->capabilities[$keyword]);
}
}
@@ -436,7 +436,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo
{
$handlers = [];
foreach ($this->handlers as $keyword => $handler) {
if (array_key_exists($keyword, $this->capabilities)) {
if (\array_key_exists($keyword, $this->capabilities)) {
$handlers[] = $handler;
}
}

View File

@@ -33,7 +33,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
*/
public function ping()
{
$maxTransports = count($this->transports);
$maxTransports = \count($this->transports);
for ($i = 0; $i < $maxTransports
&& $transport = $this->getNextTransport(); ++$i) {
if ($transport->ping()) {
@@ -43,7 +43,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
}
}
return count($this->transports) > 0;
return \count($this->transports) > 0;
}
/**
@@ -58,7 +58,7 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
*/
public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$maxTransports = count($this->transports);
$maxTransports = \count($this->transports);
$sent = 0;
$this->lastUsedTransport = null;
@@ -79,10 +79,8 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran
}
}
if (0 == count($this->transports)) {
throw new Swift_TransportException(
'All Transports in FailoverTransport failed, or no Transports available'
);
if (0 == \count($this->transports)) {
throw new Swift_TransportException('All Transports in FailoverTransport failed, or no Transports available');
}
return $sent;

Some files were not shown because too many files have changed in this diff Show More