From 1ca199d7962505f92be5af52a11d409385bda992 Mon Sep 17 00:00:00 2001 From: kamel Date: Tue, 7 Dec 2021 17:11:34 +0100 Subject: [PATCH 1/3] FIX: Update swiftmailer librairies --- .../EmailValidator/EmailLexer.php | 74 ++- .../EmailValidator/EmailParser.php | 39 +- .../EmailValidator/EmailValidator.php | 10 +- .../Exception/DomainAcceptsNoMail.php | 9 + .../Exception/ExpectingQPair.php | 2 +- .../Exception/LocalOrReservedDomain.php | 9 + .../EmailValidator/Exception/NoDNSRecord.php | 2 - .../Exception/UnclosedComment.php | 2 +- .../EmailValidator/Parser/DomainPart.php | 125 ++++- .../EmailValidator/Parser/LocalPart.php | 25 +- .../EmailValidator/Parser/Parser.php | 40 +- .../Validation/DNSCheckValidation.php | 129 ++++- .../Exception/EmptyValidationList.php | 3 + .../Validation/MultipleErrors.php | 8 +- .../Validation/MultipleValidationWithAnd.php | 22 +- .../Validation/NoRFCWarningsValidation.php | 5 +- .../Validation/RFCValidation.php | 4 +- .../Validation/SpoofCheckValidation.php | 8 +- .../EmailValidator/Warning/QuotedPart.php | 4 + .../EmailValidator/Warning/QuotedString.php | 4 + .../EmailValidator/Warning/Warning.php | 23 +- .../Doctrine/Common/Lexer/AbstractLexer.php | 5 + .../swiftmailer/lib/classes/Swift.php | 9 +- .../lib/classes/Swift/AddressEncoder.php | 25 + .../AddressEncoder/IdnAddressEncoder.php | 50 ++ .../AddressEncoder/Utf8AddressEncoder.php | 36 ++ .../classes/Swift/AddressEncoderException.php | 32 ++ .../lib/classes/Swift/Attachment.php | 11 +- .../AbstractFilterableInputStream.php | 15 +- .../Swift/ByteStream/ArrayByteStream.php | 20 +- .../Swift/ByteStream/FileByteStream.php | 14 +- .../ByteStream/TemporaryFileByteStream.php | 14 +- .../GenericFixedWidthReader.php | 2 +- .../Swift/CharacterReader/UsAsciiReader.php | 4 +- .../Swift/CharacterReader/Utf8Reader.php | 22 +- .../SimpleCharacterReaderFactory.php | 34 +- .../lib/classes/Swift/CharacterStream.php | 2 - .../CharacterStream/ArrayCharacterStream.php | 40 +- .../CharacterStream/NgCharacterStream.php | 17 +- .../lib/classes/Swift/DependencyContainer.php | 62 ++- .../lib/classes/Swift/EmbeddedFile.php | 4 +- .../classes/Swift/Encoder/Base64Encoder.php | 2 +- .../lib/classes/Swift/Encoder/QpEncoder.php | 34 +- .../classes/Swift/Encoder/Rfc2231Encoder.php | 8 +- .../lib/classes/Swift/Events/CommandEvent.php | 9 +- .../classes/Swift/Events/CommandListener.php | 2 - .../classes/Swift/Events/EventDispatcher.php | 25 +- .../lib/classes/Swift/Events/EventObject.php | 2 - .../classes/Swift/Events/ResponseEvent.php | 5 +- .../classes/Swift/Events/ResponseListener.php | 2 - .../lib/classes/Swift/Events/SendEvent.php | 5 +- .../lib/classes/Swift/Events/SendListener.php | 4 - .../Swift/Events/SimpleEventDispatcher.php | 56 +- .../Swift/Events/TransportChangeListener.php | 8 - .../Swift/Events/TransportExceptionEvent.php | 3 - .../Events/TransportExceptionListener.php | 2 - .../lib/classes/Swift/FailoverTransport.php | 6 +- .../lib/classes/Swift/FileSpool.php | 8 +- .../lib/classes/Swift/Filterable.php | 3 +- .../lib/classes/Swift/InputByteStream.php | 4 +- .../lib/classes/Swift/IoException.php | 5 +- .../lib/classes/Swift/KeyCache.php | 7 +- .../classes/Swift/KeyCache/ArrayKeyCache.php | 33 +- .../classes/Swift/KeyCache/DiskKeyCache.php | 36 +- .../Swift/KeyCache/KeyCacheInputStream.php | 4 - .../classes/Swift/KeyCache/NullKeyCache.php | 12 +- .../KeyCache/SimpleKeyCacheInputStream.php | 4 - .../classes/Swift/LoadBalancedTransport.php | 6 +- .../swiftmailer/lib/classes/Swift/Mailer.php | 8 +- .../Swift/Mailer/ArrayRecipientIterator.php | 4 +- .../lib/classes/Swift/MemorySpool.php | 2 +- .../swiftmailer/lib/classes/Swift/Message.php | 45 +- .../lib/classes/Swift/Mime/Attachment.php | 15 +- .../ContentEncoder/Base64ContentEncoder.php | 21 +- .../ContentEncoder/NativeQpContentEncoder.php | 20 +- .../ContentEncoder/NullContentEncoder.php | 79 +++ .../ContentEncoder/PlainContentEncoder.php | 24 +- .../Mime/ContentEncoder/QpContentEncoder.php | 10 +- .../ContentEncoder/QpContentEncoderProxy.php | 6 +- .../Mime/ContentEncoder/RawContentEncoder.php | 9 +- .../lib/classes/Swift/Mime/EmbeddedFile.php | 8 +- .../classes/Swift/Mime/EncodingObserver.php | 2 - .../lib/classes/Swift/Mime/Header.php | 2 +- .../HeaderEncoder/Base64HeaderEncoder.php | 2 +- .../Mime/HeaderEncoder/QpHeaderEncoder.php | 6 +- .../Swift/Mime/Headers/AbstractHeader.php | 61 ++- .../classes/Swift/Mime/Headers/DateHeader.php | 2 - .../Mime/Headers/IdentificationHeader.php | 25 +- .../Swift/Mime/Headers/MailboxHeader.php | 25 +- .../Swift/Mime/Headers/OpenDKIMHeader.php | 4 +- .../Mime/Headers/ParameterizedHeader.php | 28 +- .../classes/Swift/Mime/Headers/PathHeader.php | 15 +- .../Swift/Mime/Headers/UnstructuredHeader.php | 3 +- .../lib/classes/Swift/Mime/IdGenerator.php | 7 +- .../lib/classes/Swift/Mime/MimePart.php | 23 +- .../Swift/Mime/SimpleHeaderFactory.php | 24 +- .../classes/Swift/Mime/SimpleHeaderSet.php | 88 ++-- .../lib/classes/Swift/Mime/SimpleMessage.php | 65 +-- .../classes/Swift/Mime/SimpleMimeEntity.php | 99 ++-- .../lib/classes/Swift/MimePart.php | 4 +- .../lib/classes/Swift/NullTransport.php | 4 +- .../classes/Swift/Plugins/AntiFloodPlugin.php | 4 - .../Swift/Plugins/BandwidthMonitorPlugin.php | 18 +- .../classes/Swift/Plugins/DecoratorPlugin.php | 28 +- .../Swift/Plugins/ImpersonatePlugin.php | 4 - .../classes/Swift/Plugins/LoggerPlugin.php | 24 +- .../Swift/Plugins/Loggers/ArrayLogger.php | 6 +- .../classes/Swift/Plugins/MessageLogger.php | 14 +- .../Swift/Plugins/PopBeforeSmtpPlugin.php | 37 +- .../Swift/Plugins/RedirectingPlugin.php | 26 +- .../lib/classes/Swift/Plugins/Reporter.php | 5 +- .../classes/Swift/Plugins/ReporterPlugin.php | 10 +- .../Swift/Plugins/Reporters/HitReporter.php | 11 +- .../Swift/Plugins/Reporters/HtmlReporter.php | 5 +- .../classes/Swift/Plugins/ThrottlerPlugin.php | 6 +- .../lib/classes/Swift/Preferences.php | 2 +- .../lib/classes/Swift/SendmailTransport.php | 4 +- .../swiftmailer/lib/classes/Swift/Signer.php | 1 - .../lib/classes/Swift/Signers/BodySigner.php | 2 - .../lib/classes/Swift/Signers/DKIMSigner.php | 78 ++- .../classes/Swift/Signers/DomainKeySigner.php | 46 +- .../classes/Swift/Signers/HeaderSigner.php | 4 - .../classes/Swift/Signers/OpenDKIMSigner.php | 28 +- .../lib/classes/Swift/Signers/SMimeSigner.php | 485 +++++++++++------- .../lib/classes/Swift/SmtpTransport.php | 17 +- .../lib/classes/Swift/SpoolTransport.php | 6 +- .../ByteArrayReplacementFilter.php | 44 +- .../StringReplacementFilterFactory.php | 6 +- .../lib/classes/Swift/SwiftException.php | 5 +- .../lib/classes/Swift/Transport.php | 7 +- .../Swift/Transport/AbstractSmtpTransport.php | 164 +++--- .../Esmtp/Auth/CramMd5Authenticator.php | 28 +- .../Esmtp/Auth/LoginAuthenticator.php | 18 +- .../Esmtp/Auth/NTLMAuthenticator.php | 123 ++--- .../Esmtp/Auth/PlainAuthenticator.php | 16 +- .../Esmtp/Auth/XOAuth2Authenticator.php | 14 +- .../Swift/Transport/Esmtp/AuthHandler.php | 47 +- .../Swift/Transport/Esmtp/Authenticator.php | 9 +- .../Transport/Esmtp/EightBitMimeHandler.php | 113 ++++ .../Swift/Transport/Esmtp/SmtpUtf8Handler.php | 107 ++++ .../classes/Swift/Transport/EsmtpHandler.php | 4 +- .../Swift/Transport/EsmtpTransport.php | 101 ++-- .../Swift/Transport/FailoverTransport.php | 15 +- .../lib/classes/Swift/Transport/IoBuffer.php | 2 - .../Swift/Transport/LoadBalancedTransport.php | 23 +- .../classes/Swift/Transport/NullTransport.php | 11 +- .../Swift/Transport/SendmailTransport.php | 31 +- .../lib/classes/Swift/Transport/SmtpAgent.php | 2 +- .../Swift/Transport/SpoolTransport.php | 7 +- .../classes/Swift/Transport/StreamBuffer.php | 65 ++- .../lib/classes/Swift/TransportException.php | 5 +- .../lib/dependency_maps/cache_deps.php | 4 +- .../lib/dependency_maps/mime_deps.php | 62 +-- .../lib/dependency_maps/transport_deps.php | 56 +- .../includes/swiftmailer/lib/mime_types.php | 4 +- .../lib/swiftmailer_generate_mimes_config.php | 43 +- 156 files changed, 2370 insertions(+), 1637 deletions(-) create mode 100644 htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/DomainAcceptsNoMail.php create mode 100644 htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/LocalOrReservedDomain.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoder.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoder/IdnAddressEncoder.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoder/Utf8AddressEncoder.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoderException.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/NullContentEncoder.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/EightBitMimeHandler.php create mode 100644 htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/SmtpUtf8Handler.php diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php index 882c968154d..59dcd5876fd 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php @@ -13,6 +13,8 @@ class EmailLexer extends AbstractLexer const S_BACKSLASH = 92; const S_DOT = 46; const S_DQUOTE = 34; + const S_SQUOTE = 39; + const S_BACKTICK = 96; const S_OPENPARENTHESIS = 49; const S_CLOSEPARENTHESIS = 261; const S_OPENBRACKET = 262; @@ -58,6 +60,8 @@ class EmailLexer extends AbstractLexer '/' => self::S_SLASH, ',' => self::S_COMMA, '.' => self::S_DOT, + "'" => self::S_SQUOTE, + "`" => self::S_BACKTICK, '"' => self::S_DQUOTE, '-' => self::S_HYPHEN, '::' => self::S_DOUBLECOLON, @@ -73,25 +77,73 @@ class EmailLexer extends AbstractLexer '\0' => self::C_NUL, ); + /** + * @var bool + */ protected $hasInvalidTokens = false; - protected $previous; + /** + * @var array + * + * @psalm-var array{value:string, type:null|int, position:int}|array + */ + protected $previous = []; + /** + * The last matched/seen token. + * + * @var array + * + * @psalm-var array{value:string, type:null|int, position:int} + */ + public $token; + + /** + * The next token in the input. + * + * @var array|null + */ + public $lookahead; + + /** + * @psalm-var array{value:'', type:null, position:0} + */ + private static $nullToken = [ + 'value' => '', + 'type' => null, + 'position' => 0, + ]; + + public function __construct() + { + $this->previous = $this->token = self::$nullToken; + $this->lookahead = null; + } + + /** + * @return void + */ public function reset() { $this->hasInvalidTokens = false; parent::reset(); + $this->previous = $this->token = self::$nullToken; } + /** + * @return bool + */ public function hasInvalidTokens() { return $this->hasInvalidTokens; } /** - * @param $type + * @param int $type * @throws \UnexpectedValueException * @return boolean + * + * @psalm-suppress InvalidScalarArgument */ public function find($type) { @@ -107,7 +159,7 @@ class EmailLexer extends AbstractLexer /** * getPrevious * - * @return array token + * @return array */ public function getPrevious() { @@ -122,8 +174,10 @@ class EmailLexer extends AbstractLexer public function moveNext() { $this->previous = $this->token; + $hasNext = parent::moveNext(); + $this->token = $this->token ?: self::$nullToken; - return parent::moveNext(); + return $hasNext; } /** @@ -179,6 +233,11 @@ class EmailLexer extends AbstractLexer return self::GENERIC; } + /** + * @param string $value + * + * @return bool + */ protected function isValid($value) { if (isset($this->charValue[$value])) { @@ -189,7 +248,7 @@ class EmailLexer extends AbstractLexer } /** - * @param $value + * @param string $value * @return bool */ protected function isNullType($value) @@ -202,7 +261,7 @@ class EmailLexer extends AbstractLexer } /** - * @param $value + * @param string $value * @return bool */ protected function isUTF8Invalid($value) @@ -214,6 +273,9 @@ class EmailLexer extends AbstractLexer return false; } + /** + * @return string + */ protected function getModifiers() { return 'iu'; diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php index d0627d82410..6b7bad66927 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php @@ -17,11 +17,33 @@ class EmailParser { const EMAIL_MAX_LENGTH = 254; - protected $warnings; + /** + * @var array + */ + protected $warnings = []; + + /** + * @var string + */ protected $domainPart = ''; + + /** + * @var string + */ protected $localPart = ''; + /** + * @var EmailLexer + */ protected $lexer; + + /** + * @var LocalPart + */ protected $localPartParser; + + /** + * @var DomainPart + */ protected $domainPartParser; public function __construct(EmailLexer $lexer) @@ -29,11 +51,10 @@ class EmailParser $this->lexer = $lexer; $this->localPartParser = new LocalPart($this->lexer); $this->domainPartParser = new DomainPart($this->lexer); - $this->warnings = new \SplObjectStorage(); } /** - * @param $str + * @param string $str * @return array */ public function parse($str) @@ -57,6 +78,9 @@ class EmailParser return array('local' => $this->localPart, 'domain' => $this->domainPart); } + /** + * @return Warning\Warning[] + */ public function getWarnings() { $localPartWarnings = $this->localPartParser->getWarnings(); @@ -68,11 +92,17 @@ class EmailParser return $this->warnings; } + /** + * @return string + */ public function getParsedDomainPart() { return $this->domainPart; } + /** + * @param string $email + */ protected function setParts($email) { $parts = explode('@', $email); @@ -80,6 +110,9 @@ class EmailParser $this->localPart = $parts[0]; } + /** + * @return bool + */ protected function hasAtToken() { $this->lexer->moveNext(); diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php index 44b4b93c6bb..a30f21dcd30 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php @@ -13,12 +13,12 @@ class EmailValidator private $lexer; /** - * @var array + * @var Warning\Warning[] */ - protected $warnings; + protected $warnings = []; /** - * @var InvalidEmail + * @var InvalidEmail|null */ protected $error; @@ -28,7 +28,7 @@ class EmailValidator } /** - * @param $email + * @param string $email * @param EmailValidation $emailValidation * @return bool */ @@ -58,7 +58,7 @@ class EmailValidator } /** - * @return InvalidEmail + * @return InvalidEmail|null */ public function getError() { diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/DomainAcceptsNoMail.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/DomainAcceptsNoMail.php new file mode 100644 index 00000000000..40a99705ce9 --- /dev/null +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/DomainAcceptsNoMail.php @@ -0,0 +1,9 @@ +lexer->moveNext(); - if ($this->lexer->token['type'] === EmailLexer::S_DOT) { - throw new DotAtStart(); - } - - if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) { - throw new NoDomainPart(); - } - if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) { - throw new DomainHyphened(); - } - - if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { - $this->warnings[DeprecatedComment::CODE] = new DeprecatedComment(); - $this->parseDomainComments(); - } + $this->performDomainStartChecks(); $domain = $this->doParseDomainPart(); @@ -77,11 +68,50 @@ class DomainPart extends Parser $this->domainPart = $domain; } + private function performDomainStartChecks() + { + $this->checkInvalidTokensAfterAT(); + $this->checkEmptyDomain(); + + if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { + $this->warnings[DeprecatedComment::CODE] = new DeprecatedComment(); + $this->parseDomainComments(); + } + } + + private function checkEmptyDomain() + { + $thereIsNoDomain = $this->lexer->token['type'] === EmailLexer::S_EMPTY || + ($this->lexer->token['type'] === EmailLexer::S_SP && + !$this->lexer->isNextToken(EmailLexer::GENERIC)); + + if ($thereIsNoDomain) { + throw new NoDomainPart(); + } + } + + private function checkInvalidTokensAfterAT() + { + if ($this->lexer->token['type'] === EmailLexer::S_DOT) { + throw new DotAtStart(); + } + if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) { + throw new DomainHyphened(); + } + } + + /** + * @return string + */ public function getDomainPart() { return $this->domainPart; } + /** + * @param string $addressLiteral + * @param int $maxGroups + */ public function checkIPV6Tag($addressLiteral, $maxGroups = 8) { $prev = $this->lexer->getPrevious(); @@ -125,9 +155,13 @@ class DomainPart extends Parser } } + /** + * @return string + */ protected function doParseDomainPart() { $domain = ''; + $label = ''; $openedParenthesis = 0; do { $prev = $this->lexer->getPrevious(); @@ -158,7 +192,12 @@ class DomainPart extends Parser $this->parseDomainLiteral(); } - $this->checkLabelLength($prev); + if ($this->lexer->token['type'] === EmailLexer::S_DOT) { + $this->checkLabelLength($label); + $label = ''; + } else { + $label .= $this->lexer->token['value']; + } if ($this->isFWS()) { $this->parseFWS(); @@ -166,12 +205,17 @@ class DomainPart extends Parser $domain .= $this->lexer->token['value']; $this->lexer->moveNext(); - } while ($this->lexer->token); + if ($this->lexer->token['type'] === EmailLexer::S_SP) { + throw new CharNotAllowed(); + } + } while (null !== $this->lexer->token['type']); + + $this->checkLabelLength($label); return $domain; } - private function checkNotAllowedChars($token) + private function checkNotAllowedChars(array $token) { $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; if (isset($notAllowed[$token['type']])) { @@ -179,6 +223,9 @@ class DomainPart extends Parser } } + /** + * @return string|false + */ protected function parseDomainLiteral() { if ($this->lexer->isNextToken(EmailLexer::S_COLON)) { @@ -195,6 +242,9 @@ class DomainPart extends Parser return $this->doParseDomainLiteral(); } + /** + * @return string|false + */ protected function doParseDomainLiteral() { $IPv6TAG = false; @@ -262,6 +312,11 @@ class DomainPart extends Parser return $addressLiteral; } + /** + * @param string $addressLiteral + * + * @return string|false + */ protected function checkIPV4Tag($addressLiteral) { $matchesIP = array(); @@ -279,16 +334,18 @@ class DomainPart extends Parser return false; } // Convert IPv4 part to IPv6 format for further testing - $addressLiteral = substr($addressLiteral, 0, $index) . '0:0'; + $addressLiteral = substr($addressLiteral, 0, (int) $index) . '0:0'; } return $addressLiteral; } - protected function checkDomainPartExceptions($prev) + protected function checkDomainPartExceptions(array $prev) { $invalidDomainTokens = array( EmailLexer::S_DQUOTE => true, + EmailLexer::S_SQUOTE => true, + EmailLexer::S_BACKTICK => true, EmailLexer::S_SEMICOLON => true, EmailLexer::S_GREATERTHAN => true, EmailLexer::S_LOWERTHAN => true, @@ -320,6 +377,9 @@ class DomainPart extends Parser } } + /** + * @return bool + */ protected function hasBrackets() { if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) { @@ -335,16 +395,31 @@ class DomainPart extends Parser return true; } - protected function checkLabelLength($prev) + /** + * @param string $label + */ + protected function checkLabelLength($label) { - if ($this->lexer->token['type'] === EmailLexer::S_DOT && - $prev['type'] === EmailLexer::GENERIC && - strlen($prev['value']) > 63 - ) { + if ($this->isLabelTooLong($label)) { $this->warnings[LabelTooLong::CODE] = new LabelTooLong(); } } + /** + * @param string $label + * @return bool + */ + private function isLabelTooLong($label) + { + if (preg_match('/[^\x00-\x7F]/', $label)) { + idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo); + + return (bool) ($idnaInfo['errors'] & IDNA_ERROR_LABEL_TOO_LONG); + } + + return strlen($label) > self::LABEL_MAX_LENGTH; + } + protected function parseDomainComments() { $this->isUnclosedComment(); diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php index 8ab16ab4a1f..3c21f34ac07 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php @@ -5,7 +5,6 @@ namespace Egulias\EmailValidator\Parser; use Egulias\EmailValidator\Exception\DotAtEnd; use Egulias\EmailValidator\Exception\DotAtStart; use Egulias\EmailValidator\EmailLexer; -use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Exception\ExpectingAT; use Egulias\EmailValidator\Exception\ExpectingATEXT; use Egulias\EmailValidator\Exception\UnclosedQuotedString; @@ -20,9 +19,10 @@ class LocalPart extends Parser $parseDQuote = true; $closingQuote = false; $openedParenthesis = 0; + $totalLength = 0; - while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) { - if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) { + while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) { + if ($this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type']) { throw new DotAtStart(); } @@ -35,12 +35,13 @@ class LocalPart extends Parser $this->parseComments(); $openedParenthesis += $this->getOpenedParenthesis(); } + if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) { if ($openedParenthesis === 0) { throw new UnopenedComment(); - } else { - $openedParenthesis--; } + + $openedParenthesis--; } $this->checkConsecutiveDots(); @@ -58,15 +59,18 @@ class LocalPart extends Parser $this->parseFWS(); } + $totalLength += strlen($this->lexer->token['value']); $this->lexer->moveNext(); } - $prev = $this->lexer->getPrevious(); - if (strlen($prev['value']) > LocalTooLong::LOCAL_PART_LENGTH) { + if ($totalLength > LocalTooLong::LOCAL_PART_LENGTH) { $this->warnings[LocalTooLong::CODE] = new LocalTooLong(); } } + /** + * @return bool + */ protected function parseDoubleQuote() { $parseAgain = true; @@ -86,7 +90,7 @@ class LocalPart extends Parser $this->lexer->moveNext(); - while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) { + while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) { $parseAgain = false; if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) { $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS(); @@ -118,7 +122,10 @@ class LocalPart extends Parser return $parseAgain; } - protected function isInvalidToken($token, $closingQuote) + /** + * @param bool $closingQuote + */ + protected function isInvalidToken(array $token, $closingQuote) { $forbidden = array( EmailLexer::S_COMMA, diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php index e5042e1a859..ccdc93889a2 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php @@ -8,7 +8,7 @@ use Egulias\EmailValidator\Exception\ConsecutiveDot; use Egulias\EmailValidator\Exception\CRLFAtTheEnd; use Egulias\EmailValidator\Exception\CRLFX2; use Egulias\EmailValidator\Exception\CRNoLF; -use Egulias\EmailValidator\Exception\ExpectedQPair; +use Egulias\EmailValidator\Exception\ExpectingQPair; use Egulias\EmailValidator\Exception\ExpectingATEXT; use Egulias\EmailValidator\Exception\ExpectingCTEXT; use Egulias\EmailValidator\Exception\UnclosedComment; @@ -21,8 +21,19 @@ use Egulias\EmailValidator\Warning\QuotedString; abstract class Parser { + /** + * @var array + */ protected $warnings = []; + + /** + * @var EmailLexer + */ protected $lexer; + + /** + * @var int + */ protected $openedParenthesis = 0; public function __construct(EmailLexer $lexer) @@ -30,11 +41,17 @@ abstract class Parser $this->lexer = $lexer; } + /** + * @return \Egulias\EmailValidator\Warning\Warning[] + */ public function getWarnings() { return $this->warnings; } + /** + * @param string $str + */ abstract public function parse($str); /** @return int */ @@ -50,7 +67,7 @@ abstract class Parser { if (!($this->lexer->token['type'] === EmailLexer::INVALID || $this->lexer->token['type'] === EmailLexer::C_DEL)) { - throw new ExpectedQPair(); + throw new ExpectingQPair(); } $this->warnings[QuotedPart::CODE] = @@ -80,6 +97,9 @@ abstract class Parser } } + /** + * @return bool + */ protected function isUnclosedComment() { try { @@ -122,6 +142,9 @@ abstract class Parser } } + /** + * @return bool + */ protected function isFWS() { if ($this->escaped()) { @@ -140,11 +163,14 @@ abstract class Parser return false; } + /** + * @return bool + */ protected function escaped() { $previous = $this->lexer->getPrevious(); - if ($previous['type'] === EmailLexer::S_BACKSLASH + if ($previous && $previous['type'] === EmailLexer::S_BACKSLASH && $this->lexer->token['type'] !== EmailLexer::GENERIC ) { @@ -154,6 +180,9 @@ abstract class Parser return false; } + /** + * @return bool + */ protected function warnEscaping() { if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { @@ -174,6 +203,11 @@ abstract class Parser } + /** + * @param bool $hasClosingQuote + * + * @return bool + */ protected function checkDQUOTE($hasClosingQuote) { if ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE) { diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/DNSCheckValidation.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/DNSCheckValidation.php index ecca1dd976a..491082a590f 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/DNSCheckValidation.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/DNSCheckValidation.php @@ -4,6 +4,8 @@ namespace Egulias\EmailValidator\Validation; use Egulias\EmailValidator\EmailLexer; use Egulias\EmailValidator\Exception\InvalidEmail; +use Egulias\EmailValidator\Exception\LocalOrReservedDomain; +use Egulias\EmailValidator\Exception\DomainAcceptsNoMail; use Egulias\EmailValidator\Warning\NoDNSMXRecord; use Egulias\EmailValidator\Exception\NoDNSRecord; @@ -15,10 +17,23 @@ class DNSCheckValidation implements EmailValidation private $warnings = []; /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; + /** + * @var array + */ + private $mxRecords = []; + + + public function __construct() + { + if (!function_exists('idn_to_ascii')) { + throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); + } + } + public function isValid($email, EmailLexer $emailLexer) { // use the input to check DNS if we cannot extract something similar to a domain @@ -29,7 +44,40 @@ class DNSCheckValidation implements EmailValidation $host = substr($email, $lastAtPos + 1); } - return $this->checkDNS($host); + // Get the domain parts + $hostParts = explode('.', $host); + + // Reserved Top Level DNS Names (https://tools.ietf.org/html/rfc2606#section-2), + // mDNS and private DNS Namespaces (https://tools.ietf.org/html/rfc6762#appendix-G) + $reservedTopLevelDnsNames = [ + // Reserved Top Level DNS Names + 'test', + 'example', + 'invalid', + 'localhost', + + // mDNS + 'local', + + // Private DNS Namespaces + 'intranet', + 'internal', + 'private', + 'corp', + 'home', + 'lan', + ]; + + $isLocalDomain = count($hostParts) <= 1; + $isReservedTopLevel = in_array($hostParts[(count($hostParts) - 1)], $reservedTopLevelDnsNames, true); + + // Exclude reserved top level DNS names + if ($isLocalDomain || $isReservedTopLevel) { + $this->error = new LocalOrReservedDomain(); + return false; + } + + return $this->checkDns($host); } public function getError() @@ -42,20 +90,77 @@ class DNSCheckValidation implements EmailValidation return $this->warnings; } - protected function checkDNS($host) + /** + * @param string $host + * + * @return bool + */ + protected function checkDns($host) { - $host = rtrim($host, '.') . '.'; + $variant = INTL_IDNA_VARIANT_UTS46; - $Aresult = true; - $MXresult = checkdnsrr($host, 'MX'); + $host = rtrim(idn_to_ascii($host, IDNA_DEFAULT, $variant), '.') . '.'; - if (!$MXresult) { - $this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord(); - $Aresult = checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'); - if (!$Aresult) { - $this->error = new NoDNSRecord(); + return $this->validateDnsRecords($host); + } + + + /** + * Validate the DNS records for given host. + * + * @param string $host A set of DNS records in the format returned by dns_get_record. + * + * @return bool True on success. + */ + private function validateDnsRecords($host) + { + // Get all MX, A and AAAA DNS records for host + // Using @ as workaround to fix https://bugs.php.net/bug.php?id=73149 + $dnsRecords = @dns_get_record($host, DNS_MX + DNS_A + DNS_AAAA); + + + // No MX, A or AAAA DNS records + if (empty($dnsRecords)) { + $this->error = new NoDNSRecord(); + return false; + } + + // For each DNS record + foreach ($dnsRecords as $dnsRecord) { + if (!$this->validateMXRecord($dnsRecord)) { + return false; } } - return $MXresult || $Aresult; + + // No MX records (fallback to A or AAAA records) + if (empty($this->mxRecords)) { + $this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord(); + } + + return true; + } + + /** + * Validate an MX record + * + * @param array $dnsRecord Given DNS record. + * + * @return bool True if valid. + */ + private function validateMxRecord($dnsRecord) + { + if ($dnsRecord['type'] !== 'MX') { + return true; + } + + // "Null MX" record indicates the domain accepts no mail (https://tools.ietf.org/html/rfc7505) + if (empty($dnsRecord['target']) || $dnsRecord['target'] === '.') { + $this->error = new DomainAcceptsNoMail(); + return false; + } + + $this->mxRecords[] = $dnsRecord; + + return true; } } diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/Exception/EmptyValidationList.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/Exception/EmptyValidationList.php index 775ad16fb51..ee7c41aa033 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/Exception/EmptyValidationList.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/Exception/EmptyValidationList.php @@ -6,6 +6,9 @@ use Exception; class EmptyValidationList extends \InvalidArgumentException { + /** + * @param int $code + */ public function __construct($code = 0, Exception $previous = null) { parent::__construct("Empty validation list is not allowed", $code, $previous); diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleErrors.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleErrors.php index d5e87d8ce06..3be59732664 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleErrors.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleErrors.php @@ -9,16 +9,22 @@ class MultipleErrors extends InvalidEmail const CODE = 999; const REASON = "Accumulated errors for multiple validations"; /** - * @var array + * @var InvalidEmail[] */ private $errors = []; + /** + * @param InvalidEmail[] $errors + */ public function __construct(array $errors) { $this->errors = $errors; parent::__construct(); } + /** + * @return InvalidEmail[] + */ public function getErrors() { return $this->errors; diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleValidationWithAnd.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleValidationWithAnd.php index 43fa42a64b7..feb224023da 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleValidationWithAnd.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/MultipleValidationWithAnd.php @@ -30,12 +30,12 @@ class MultipleValidationWithAnd implements EmailValidation private $warnings = []; /** - * @var MultipleErrors + * @var MultipleErrors|null */ private $error; /** - * @var bool + * @var int */ private $mode; @@ -62,7 +62,8 @@ class MultipleValidationWithAnd implements EmailValidation $errors = []; foreach ($this->validations as $validation) { $emailLexer->reset(); - $result = $result && $validation->isValid($email, $emailLexer); + $validationResult = $validation->isValid($email, $emailLexer); + $result = $result && $validationResult; $this->warnings = array_merge($this->warnings, $validation->getWarnings()); $errors = $this->addNewError($validation->getError(), $errors); @@ -78,6 +79,12 @@ class MultipleValidationWithAnd implements EmailValidation return $result; } + /** + * @param \Egulias\EmailValidator\Exception\InvalidEmail|null $possibleError + * @param \Egulias\EmailValidator\Exception\InvalidEmail[] $errors + * + * @return \Egulias\EmailValidator\Exception\InvalidEmail[] + */ private function addNewError($possibleError, array $errors) { if (null !== $possibleError) { @@ -87,13 +94,20 @@ class MultipleValidationWithAnd implements EmailValidation return $errors; } + /** + * @param bool $result + * + * @return bool + */ private function shouldStop($result) { return !$result && $this->mode === self::STOP_ON_ERROR; } /** - * {@inheritdoc} + * Returns the validation errors. + * + * @return MultipleErrors|null */ public function getError() { diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/NoRFCWarningsValidation.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/NoRFCWarningsValidation.php index f3656b35a52..6b31e5440ec 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/NoRFCWarningsValidation.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/NoRFCWarningsValidation.php @@ -9,7 +9,7 @@ use Egulias\EmailValidator\Validation\Error\RFCWarnings; class NoRFCWarningsValidation extends RFCValidation { /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; @@ -22,8 +22,7 @@ class NoRFCWarningsValidation extends RFCValidation return false; } - $ret = $this->getWarnings(); - if (empty($ret)) { + if (empty($this->getWarnings())) { return true; } diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php index c4ffe35034b..8781e0b62d1 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php @@ -9,7 +9,7 @@ use Egulias\EmailValidator\Exception\InvalidEmail; class RFCValidation implements EmailValidation { /** - * @var EmailParser + * @var EmailParser|null */ private $parser; @@ -19,7 +19,7 @@ class RFCValidation implements EmailValidation private $warnings = []; /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/SpoofCheckValidation.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/SpoofCheckValidation.php index 4721f0d8c98..e10bfabd92f 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/SpoofCheckValidation.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/SpoofCheckValidation.php @@ -10,7 +10,7 @@ use \Spoofchecker; class SpoofCheckValidation implements EmailValidation { /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; @@ -21,6 +21,9 @@ class SpoofCheckValidation implements EmailValidation } } + /** + * @psalm-suppress InvalidArgument + */ public function isValid($email, EmailLexer $emailLexer) { $checker = new Spoofchecker(); @@ -33,6 +36,9 @@ class SpoofCheckValidation implements EmailValidation return $this->error === null; } + /** + * @return InvalidEmail|null + */ public function getError() { return $this->error; diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedPart.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedPart.php index 7be9e6a3f25..36a4265a515 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedPart.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedPart.php @@ -6,6 +6,10 @@ class QuotedPart extends Warning { const CODE = 36; + /** + * @param scalar $prevToken + * @param scalar $postToken + */ public function __construct($prevToken, $postToken) { $this->message = "Deprecated Quoted String found between $prevToken and $postToken"; diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedString.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedString.php index e9d56e1e032..817e4e84b07 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedString.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/QuotedString.php @@ -6,6 +6,10 @@ class QuotedString extends Warning { const CODE = 11; + /** + * @param scalar $prevToken + * @param scalar $postToken + */ public function __construct($prevToken, $postToken) { $this->message = "Quoted String found between $prevToken and $postToken"; diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php index ec6a365ffb7..a2ee7b0de1e 100644 --- a/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php +++ b/htdocs/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php @@ -5,19 +5,36 @@ namespace Egulias\EmailValidator\Warning; abstract class Warning { const CODE = 0; - protected $message; - protected $rfcNumber; + /** + * @var string + */ + protected $message = ''; + + /** + * @var int + */ + protected $rfcNumber = 0; + + /** + * @return string + */ public function message() { return $this->message; } + /** + * @return int + */ public function code() { - return self::CODE; + return static::CODE; } + /** + * @return int + */ public function RFCNumber() { return $this->rfcNumber; diff --git a/htdocs/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php b/htdocs/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php index 399a55230b0..dd3ea768e3b 100644 --- a/htdocs/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php +++ b/htdocs/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php @@ -258,6 +258,11 @@ abstract class AbstractLexer $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE; $matches = preg_split($regex, $input, -1, $flags); + if (false === $matches) { + // Work around https://bugs.php.net/78122 + $matches = array(array($input, 0)); + } + foreach ($matches as $match) { // Must remain before 'value' assignment since it can change content $type = $this->getType($match[0]); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift.php b/htdocs/includes/swiftmailer/lib/classes/Swift.php index e89703eaebb..51b19c9cb4e 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift.php @@ -11,15 +11,14 @@ /** * General utility class in Swift Mailer, not to be instantiated. * - * * @author Chris Corbyn */ abstract class Swift { - const VERSION = '6.0.2'; + const VERSION = '6.3.0'; public static $initialized = false; - public static $inits = array(); + public static $inits = []; /** * Registers an initializer callable that will be called the first time @@ -57,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); } } } @@ -74,6 +73,6 @@ abstract class Swift if (null !== $callable) { self::$inits[] = $callable; } - spl_autoload_register(array('Swift', 'autoload')); + spl_autoload_register(['Swift', 'autoload']); } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoder.php new file mode 100644 index 00000000000..a1704ffb40a --- /dev/null +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/AddressEncoder.php @@ -0,0 +1,25 @@ +address = $address; + } + + public function getAddress(): string + { + return $this->address; + } +} diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Attachment.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Attachment.php index 1fb232c9fe6..7a1420f7986 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Attachment.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Attachment.php @@ -26,17 +26,14 @@ class Swift_Attachment extends Swift_Mime_Attachment */ public function __construct($data = null, $filename = null, $contentType = null) { - call_user_func_array( - array($this, 'Swift_Mime_Attachment::__construct'), + \call_user_func_array( + [$this, 'Swift_Mime_Attachment::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('mime.attachment') ); - $this->setBody($data); + $this->setBody($data, $contentType); $this->setFilename($filename); - if ($contentType) { - $this->setContentType($contentType); - } } /** @@ -45,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) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php index bfd2c79bcbd..3a69c15f1c4 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/AbstractFilterableInputStream.php @@ -25,7 +25,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I * * @var Swift_StreamFilter[] */ - private $filters = array(); + private $filters = []; /** * A buffer for writing. @@ -37,7 +37,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I * * @var Swift_InputByteStream[] */ - private $mirrors = array(); + private $mirrors = []; /** * Commit the given bytes to the storage medium immediately. @@ -54,8 +54,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I /** * Add a StreamFilter to this InputByteStream. * - * @param Swift_StreamFilter $filter - * @param string $key + * @param string $key */ public function addFilter(Swift_StreamFilter $filter, $key) { @@ -110,8 +109,6 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I * * The stream acts as an observer, receiving all data that is written. * All {@link write()} and {@link flushBuffers()} operations will be mirrored. - * - * @param Swift_InputByteStream $is */ public function bind(Swift_InputByteStream $is) { @@ -124,14 +121,12 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I * If $is is not bound, no errors will be raised. * If the stream currently has any buffered data it will be written to $is * before unbinding occurs. - * - * @param Swift_InputByteStream $is */ public function unbind(Swift_InputByteStream $is) { foreach ($this->mirrors as $k => $stream) { if ($is === $stream) { - if ($this->writeBuffer !== '') { + if ('' !== $this->writeBuffer) { $stream->write($this->writeBuffer); } unset($this->mirrors[$k]); @@ -147,7 +142,7 @@ abstract class Swift_ByteStream_AbstractFilterableInputStream implements Swift_I */ public function flushBuffers() { - if ($this->writeBuffer !== '') { + if ('' !== $this->writeBuffer) { $this->doWrite($this->writeBuffer); } $this->flush(); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/ArrayByteStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/ArrayByteStream.php index 31b85e0e02a..4f3dcc37745 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/ArrayByteStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/ArrayByteStream.php @@ -20,7 +20,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O * * @var string[] */ - private $array = array(); + private $array = []; /** * The size of the stack. @@ -41,7 +41,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O * * @var Swift_InputByteStream[] */ - private $mirrors = array(); + private $mirrors = []; /** * Create a new ArrayByteStream. @@ -52,13 +52,13 @@ 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 = array(); + $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); @@ -121,8 +121,6 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O * * The stream acts as an observer, receiving all data that is written. * All {@link write()} and {@link flushBuffers()} operations will be mirrored. - * - * @param Swift_InputByteStream $is */ public function bind(Swift_InputByteStream $is) { @@ -135,8 +133,6 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O * If $is is not bound, no errors will be raised. * If the stream currently has any buffered data it will be written to $is * before unbinding occurs. - * - * @param Swift_InputByteStream $is */ public function unbind(Swift_InputByteStream $is) { @@ -172,7 +168,7 @@ class Swift_ByteStream_ArrayByteStream implements Swift_InputByteStream, Swift_O public function flushBuffers() { $this->offset = 0; - $this->array = array(); + $this->array = []; $this->arraySize = 0; foreach ($this->mirrors as $stream) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php index 61f820e5a14..f6391219e71 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php @@ -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; @@ -131,7 +131,7 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl throw new Swift_IoException('Unable to open file for reading ['.$this->path.']'); } $this->reader = $pointer; - if ($this->offset != 0) { + if (0 != $this->offset) { $this->getReadStreamSeekableStatus(); $this->seekReadStreamToPosition($this->offset); } @@ -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.']'); } } @@ -173,10 +171,10 @@ class Swift_ByteStream_FileByteStream extends Swift_ByteStream_AbstractFilterabl /** Streams in a readOnly stream ensuring copy if needed */ private function seekReadStreamToPosition($offset) { - if ($this->seekable === null) { + if (null === $this->seekable) { $this->getReadStreamSeekableStatus(); } - if ($this->seekable === false) { + if (false === $this->seekable) { $currentPos = ftell($this->reader); if ($currentPos < $offset) { $toDiscard = $offset - $currentPos; @@ -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'); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/TemporaryFileByteStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/TemporaryFileByteStream.php index 1c9a80c0376..0dc61909d31 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/TemporaryFileByteStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/ByteStream/TemporaryFileByteStream.php @@ -17,7 +17,7 @@ class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByte { $filePath = tempnam(sys_get_temp_dir(), 'FileByteStream'); - if ($filePath === false) { + if (false === $filePath) { throw new Swift_IoException('Failed to retrieve temporary file name.'); } @@ -26,7 +26,7 @@ class Swift_ByteStream_TemporaryFileByteStream extends Swift_ByteStream_FileByte public function getContent() { - if (($content = file_get_contents($this->getPath())) === false) { + if (false === ($content = file_get_contents($this->getPath()))) { throw new Swift_IoException('Failed to get temporary file content.'); } @@ -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__); + } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/GenericFixedWidthReader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/GenericFixedWidthReader.php index b09bb5b6c38..3e055afd9dc 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/GenericFixedWidthReader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/GenericFixedWidthReader.php @@ -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) : ''; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/UsAsciiReader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/UsAsciiReader.php index 67da48f6cb0..ffc05f7166a 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/UsAsciiReader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/UsAsciiReader.php @@ -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; } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/Utf8Reader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/Utf8Reader.php index 22746bd8575..da37e0da9ab 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/Utf8Reader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReader/Utf8Reader.php @@ -17,8 +17,8 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader { /** Pre-computed for optimization */ - private static $length_map = array( - // N=0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F, + private static $length_map = [ + // 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,10 +34,10 @@ 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 = array( + private static $s_length_map = [ "\x00" => 1, "\x01" => 1, "\x02" => 1, "\x03" => 1, "\x04" => 1, "\x05" => 1, "\x06" => 1, "\x07" => 1, "\x08" => 1, "\x09" => 1, "\x0a" => 1, "\x0b" => 1, "\x0c" => 1, "\x0d" => 1, "\x0e" => 1, "\x0f" => 1, "\x10" => 1, "\x11" => 1, "\x12" => 1, "\x13" => 1, "\x14" => 1, "\x15" => 1, "\x16" => 1, "\x17" => 1, @@ -70,7 +70,7 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader "\xe8" => 3, "\xe9" => 3, "\xea" => 3, "\xeb" => 3, "\xec" => 3, "\xed" => 3, "\xee" => 3, "\xef" => 3, "\xf0" => 4, "\xf1" => 4, "\xf2" => 4, "\xf3" => 4, "\xf4" => 4, "\xf5" => 4, "\xf6" => 4, "\xf7" => 4, "\xf8" => 5, "\xf9" => 5, "\xfa" => 5, "\xfb" => 5, "\xfc" => 6, "\xfd" => 6, "\xfe" => 0, "\xff" => 0, - ); + ]; /** * Returns the complete character map. @@ -85,22 +85,22 @@ class Swift_CharacterReader_Utf8Reader implements Swift_CharacterReader public function getCharPositions($string, $startOffset, &$currentMap, &$ignoredChars) { if (!isset($currentMap['i']) || !isset($currentMap['p'])) { - $currentMap['p'] = $currentMap['i'] = array(); + $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) { $char = $string[$i]; $size = self::$s_length_map[$char]; - if ($size == 0) { + if (0 == $size) { /* char is invalid, we must wait for a resync */ $invalid = true; continue; } else { - if ($invalid == true) { + if (true === $invalid) { /* We mark the chars as invalid and start a new char */ $currentMap['p'][$charPos + $foundChars] = $startOffset + $i; $currentMap['i'][$charPos + $foundChars] = true; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php index f3641f46b46..86900894ab1 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterReaderFactory/SimpleCharacterReaderFactory.php @@ -20,14 +20,14 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift * * @var array */ - private static $map = array(); + private static $map = []; /** * Factories which have already been loaded. * * @var Swift_CharacterReaderFactory[] */ - private static $loaded = array(); + private static $loaded = []; /** * Creates a new CharacterReaderFactory. @@ -44,32 +44,32 @@ class Swift_CharacterReaderFactory_SimpleCharacterReaderFactory implements Swift public function init() { - if (count(self::$map) > 0) { + if (\count(self::$map) > 0) { return; } $prefix = 'Swift_CharacterReader_'; - $singleByte = array( + $singleByte = [ 'class' => $prefix.'GenericFixedWidthReader', - 'constructor' => array(1), - ); + 'constructor' => [1], + ]; - $doubleByte = array( + $doubleByte = [ 'class' => $prefix.'GenericFixedWidthReader', - 'constructor' => array(2), - ); + 'constructor' => [2], + ]; - $fourBytes = array( + $fourBytes = [ 'class' => $prefix.'GenericFixedWidthReader', - 'constructor' => array(4), - ); + 'constructor' => [4], + ]; // Utf-8 - self::$map['utf-?8'] = array( + self::$map['utf-?8'] = [ 'class' => $prefix.'Utf8Reader', - 'constructor' => array(), - ); + 'constructor' => [], + ]; //7-8 bit charsets self::$map['(us-)?ascii'] = $singleByte; @@ -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']); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream.php index 717924f5d63..c9d8a078ee0 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream.php @@ -28,8 +28,6 @@ interface Swift_CharacterStream /** * Set the CharacterReaderFactory for multi charset support. - * - * @param Swift_CharacterReaderFactory $factory */ public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php index e43bd2ed510..5c2869455b8 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/ArrayCharacterStream.php @@ -31,10 +31,10 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea private $charset; /** Array of characters */ - private $array = array(); + private $array = []; /** Size of the array of character */ - private $array_size = array(); + private $array_size = []; /** The current character offset in the stream */ private $offset = 0; @@ -65,8 +65,6 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea /** * Set the CharacterReaderFactory for multi charset support. - * - * @param Swift_CharacterReaderFactory $factory */ public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory) { @@ -87,16 +85,16 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea $startLength = $this->charReader->getInitialByteSize(); while (false !== $bytes = $os->read($startLength)) { - $c = array(); - for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) { + $c = []; + 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]]; } } @@ -132,7 +130,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea } // Don't use array slice - $arrays = array(); + $arrays = []; $end = $length + $this->offset; for ($i = $this->offset; $i < $end; ++$i) { if (!isset($this->array[$i])) { @@ -162,7 +160,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea if ($this->offset == $this->array_size) { return false; } - $arrays = array(); + $arrays = []; $end = $length + $this->offset; for ($i = $this->offset; $i < $end; ++$i) { if (!isset($this->array[$i])) { @@ -172,7 +170,7 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea } $this->offset += ($i - $this->offset); // Limit function calls - return call_user_func_array('array_merge', $arrays); + return array_merge(...$arrays); } /** @@ -194,19 +192,19 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea unset($chars); fseek($fp, 0, SEEK_SET); - $buffer = array(0); + $buffer = [0]; $buf_pos = 1; $buf_len = 1; $has_datas = true; do { - $bytes = array(); + $bytes = []; // Buffer Filing if ($buf_len - $buf_pos < $startLength) { $buf = array_splice($buffer, $buf_pos); $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; @@ -226,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) { @@ -262,15 +260,15 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea public function flushContents() { $this->offset = 0; - $this->array = array(); + $this->array = []; $this->array_size = 0; } private function reloadBuffer($fp, $len) { - if (!feof($fp) && ($bytes = fread($fp, $len)) !== false) { - $buf = array(); - for ($i = 0, $len = strlen($bytes); $i < $len; ++$i) { + if (!feof($fp) && false !== ($bytes = fread($fp, $len))) { + $buf = []; + for ($i = 0, $len = \strlen($bytes); $i < $len; ++$i) { $buf[] = self::$byteMap[$bytes[$i]]; } @@ -283,9 +281,9 @@ class Swift_CharacterStream_ArrayCharacterStream implements Swift_CharacterStrea private static function initializeMaps() { if (!isset(self::$charMap)) { - self::$charMap = array(); + self::$charMap = []; for ($byte = 0; $byte < 256; ++$byte) { - self::$charMap[$byte] = chr($byte); + self::$charMap[$byte] = \chr($byte); } self::$byteMap = array_flip(self::$charMap); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php index 0d62fa68ff3..7578dda9cac 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/CharacterStream/NgCharacterStream.php @@ -81,8 +81,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream /** * Constructor. * - * @param Swift_CharacterReaderFactory $factory - * @param string $charset + * @param string $charset */ public function __construct(Swift_CharacterReaderFactory $factory, $charset) { @@ -106,8 +105,6 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream /** * Set the CharacterReaderFactory for multi charset support. - * - * @param Swift_CharacterReaderFactory $factory */ public function setCharacterReaderFactory(Swift_CharacterReaderFactory $factory) { @@ -128,8 +125,6 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream /** * @see Swift_CharacterStream::importByteStream() - * - * @param Swift_OutputByteStream $os */ public function importByteStream(Swift_OutputByteStream $os) { @@ -220,7 +215,7 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream public function readBytes($length) { $read = $this->read($length); - if ($read !== false) { + if (false !== $read) { $ret = array_map('ord', str_split($read, 1)); return $ret; @@ -252,16 +247,16 @@ class Swift_CharacterStream_NgCharacterStream implements Swift_CharacterStream if (!isset($this->charReader)) { $this->charReader = $this->charReaderFactory->getReaderFor( $this->charset); - $this->map = array(); + $this->map = []; $this->mapType = $this->charReader->getMapType(); } $ignored = ''; $this->datas .= $chars; $this->charCount += $this->charReader->getCharPositions(substr($this->datas, $this->datasSize), $this->datasSize, $this->map, $ignored); - if ($ignored !== false) { - $this->datasSize = strlen($this->datas) - strlen($ignored); + if (false !== $ignored) { + $this->datasSize = \strlen($this->datas) - \strlen($ignored); } else { - $this->datasSize = strlen($this->datas); + $this->datasSize = \strlen($this->datas); } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/DependencyContainer.php b/htdocs/includes/swiftmailer/lib/classes/Swift/DependencyContainer.php index b1bc3306f22..3cc885ec03b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/DependencyContainer.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/DependencyContainer.php @@ -16,22 +16,25 @@ class Swift_DependencyContainer { /** Constant for literal value types */ - const TYPE_VALUE = 0x0001; + const TYPE_VALUE = 0x00001; /** Constant for new instance types */ - const TYPE_INSTANCE = 0x0010; + const TYPE_INSTANCE = 0x00010; /** Constant for shared instance types */ - const TYPE_SHARED = 0x0100; + const TYPE_SHARED = 0x00100; /** Constant for aliases */ - const TYPE_ALIAS = 0x1000; + const TYPE_ALIAS = 0x01000; + + /** Constant for arrays */ + const TYPE_ARRAY = 0x10000; /** Singleton instance */ private static $instance = null; /** The data container */ - private $store = array(); + private $store = []; /** The current endpoint in the data container */ private $endPoint; @@ -80,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']); } @@ -98,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']) { @@ -112,6 +113,8 @@ class Swift_DependencyContainer return $this->createNewInstance($itemName); case self::TYPE_SHARED: return $this->createSharedInstance($itemName); + case self::TYPE_ARRAY: + return $this->createDependenciesFor($itemName); } } @@ -124,7 +127,7 @@ class Swift_DependencyContainer */ public function createDependenciesFor($itemName) { - $args = array(); + $args = []; if (isset($this->store[$itemName]['args'])) { $args = $this->resolveArgs($this->store[$itemName]['args']); } @@ -147,7 +150,7 @@ class Swift_DependencyContainer */ public function register($itemName) { - $this->store[$itemName] = array(); + $this->store[$itemName] = []; $this->endPoint = &$this->store[$itemName]; return $this; @@ -227,6 +230,21 @@ class Swift_DependencyContainer return $this; } + /** + * Specify the previously registered item as array of dependencies. + * + * {@link register()} must be called before this will work. + * + * @return $this + */ + public function asArray() + { + $endPoint = &$this->getEndPoint(); + $endPoint['lookupType'] = self::TYPE_ARRAY; + + return $this; + } + /** * Specify a list of injected dependencies for the previously registered item. * @@ -234,14 +252,12 @@ class Swift_DependencyContainer * * @see addConstructorValue(), addConstructorLookup() * - * @param array $lookups - * * @return $this */ public function withDependencies(array $lookups) { $endPoint = &$this->getEndPoint(); - $endPoint['args'] = array(); + $endPoint['args'] = []; foreach ($lookups as $lookup) { $this->addConstructorLookup($lookup); } @@ -263,9 +279,9 @@ class Swift_DependencyContainer { $endPoint = &$this->getEndPoint(); if (!isset($endPoint['args'])) { - $endPoint['args'] = array(); + $endPoint['args'] = []; } - $endPoint['args'][] = array('type' => 'value', 'item' => $value); + $endPoint['args'][] = ['type' => 'value', 'item' => $value]; return $this; } @@ -284,9 +300,9 @@ class Swift_DependencyContainer { $endPoint = &$this->getEndPoint(); if (!isset($this->endPoint['args'])) { - $endPoint['args'] = array(); + $endPoint['args'] = []; } - $endPoint['args'][] = array('type' => 'lookup', 'item' => $lookup); + $endPoint['args'][] = ['type' => 'lookup', 'item' => $lookup]; return $this; } @@ -330,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; @@ -341,7 +355,7 @@ class Swift_DependencyContainer /** Get an argument list with dependencies resolved */ private function resolveArgs(array $args) { - $resolved = array(); + $resolved = []; foreach ($args as $argDefinition) { switch ($argDefinition['type']) { case 'lookup': @@ -359,8 +373,8 @@ class Swift_DependencyContainer /** Resolve a single dependency with an collections */ private function lookupRecursive($item) { - if (is_array($item)) { - $collection = array(); + if (\is_array($item)) { + $collection = []; foreach ($item as $k => $v) { $collection[$k] = $this->lookupRecursive($v); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/EmbeddedFile.php b/htdocs/includes/swiftmailer/lib/classes/Swift/EmbeddedFile.php index 9755a88e176..30fc68ab03e 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/EmbeddedFile.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/EmbeddedFile.php @@ -26,8 +26,8 @@ class Swift_EmbeddedFile extends Swift_Mime_EmbeddedFile */ public function __construct($data = null, $filename = null, $contentType = null) { - call_user_func_array( - array($this, 'Swift_Mime_EmbeddedFile::__construct'), + \call_user_func_array( + [$this, 'Swift_Mime_EmbeddedFile::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('mime.embeddedfile') ); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Base64Encoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Base64Encoder.php index 0e7b2a1b0c8..b1eedaa051b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Base64Encoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Base64Encoder.php @@ -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) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/QpEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/QpEncoder.php index b23b07702ef..f078d6d7c38 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/QpEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/QpEncoder.php @@ -36,7 +36,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder * * @var string[] */ - protected static $qpMap = array( + protected static $qpMap = [ 0 => '=00', 1 => '=01', 2 => '=02', 3 => '=03', 4 => '=04', 5 => '=05', 6 => '=06', 7 => '=07', 8 => '=08', 9 => '=09', 10 => '=0A', 11 => '=0B', 12 => '=0C', 13 => '=0D', 14 => '=0E', @@ -89,16 +89,16 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder 245 => '=F5', 246 => '=F6', 247 => '=F7', 248 => '=F8', 249 => '=F9', 250 => '=FA', 251 => '=FB', 252 => '=FC', 253 => '=FD', 254 => '=FE', 255 => '=FF', - ); + ]; - protected static $safeMapShare = array(); + protected static $safeMapShare = []; /** * A map of non-encoded ascii characters. * * @var string[] */ - protected $safeMap = array(); + protected $safeMap = []; /** * Creates a new QpEncoder for the given CharacterStream. @@ -120,7 +120,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder public function __sleep() { - return array('charStream', 'filter'); + return ['charStream', 'filter']; } public function __wakeup() @@ -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( - array(0x09, 0x20), range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte) { - $this->safeMap[$byte] = chr($byte); + [0x09, 0x20], range(0x21, 0x3C), range(0x3E, 0x7E)) as $byte) { + $this->safeMap[$byte] = \chr($byte); } } @@ -153,9 +153,9 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder * If the first line needs to be shorter, indicate the difference with * $firstLineOffset. * - * @param string $string to encode - * @param int $firstLineOffset, optional - * @param int $maxLineLength, optional 0 indicates the default of 76 chars + * @param string $string to encode + * @param int $firstLineOffset optional + * @param int $maxLineLength optional 0 indicates the default of 76 chars * * @return string */ @@ -167,7 +167,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder $thisLineLength = $maxLineLength - $firstLineOffset; - $lines = array(); + $lines = []; $lNo = 0; $lines[$lNo] = ''; $currentLine = &$lines[$lNo++]; @@ -200,7 +200,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder $enc = $this->encodeByteSequence($bytes, $size); $i = strpos($enc, '=0D=0A'); - $newLineLength = $lineLen + ($i === false ? $size : $i); + $newLineLength = $lineLen + (false === $i ? $size : $i); if ($currentLine && $newLineLength >= $thisLineLength) { $lines[$lNo] = ''; @@ -211,7 +211,7 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder $currentLine .= $enc; - if ($i === false) { + if (false === $i) { $lineLen += $size; } else { // 6 is the length of '=0D=0A'. @@ -278,10 +278,10 @@ class Swift_Encoder_QpEncoder implements Swift_Encoder */ protected function standardize($string) { - $string = str_replace(array("\t=0D=0A", ' =0D=0A', '=0D=0A'), - array("=09\r\n", "=20\r\n", "\r\n"), $string + $string = str_replace(["\t=0D=0A", ' =0D=0A', '=0D=0A'], + ["=09\r\n", "=20\r\n", "\r\n"], $string ); - switch ($end = ord(substr($string, -1))) { + switch ($end = \ord(substr($string, -1))) { case 0x09: case 0x20: $string = substr_replace($string, self::$qpMap[$end], -1); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Rfc2231Encoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Rfc2231Encoder.php index bebb13494bd..7eac36813e0 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Rfc2231Encoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Encoder/Rfc2231Encoder.php @@ -24,8 +24,6 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder /** * Creates a new Rfc2231Encoder using the given character stream instance. - * - * @param Swift_CharacterStream */ public function __construct(Swift_CharacterStream $charStream) { @@ -44,7 +42,7 @@ class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) { - $lines = array(); + $lines = []; $lineCount = 0; $lines[] = ''; $currentLine = &$lines[$lineCount++]; @@ -60,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; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandEvent.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandEvent.php index 9834aa95883..18994c184f3 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandEvent.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandEvent.php @@ -27,16 +27,15 @@ class Swift_Events_CommandEvent extends Swift_Events_EventObject * * @var int[] */ - private $successCodes = array(); + private $successCodes = []; /** * Create a new CommandEvent for $source with $command. * - * @param Swift_Transport $source - * @param string $command - * @param array $successCodes + * @param string $command + * @param array $successCodes */ - public function __construct(Swift_Transport $source, $command, $successCodes = array()) + public function __construct(Swift_Transport $source, $command, $successCodes = []) { parent::__construct($source); $this->command = $command; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandListener.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandListener.php index 7545404e765..b158eab462a 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandListener.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/CommandListener.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventDispatcher.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventDispatcher.php index f602608eeb6..df25a124863 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventDispatcher.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventDispatcher.php @@ -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,20 +25,18 @@ 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 */ - public function createCommandEvent(Swift_Transport $source, $command, $successCodes = array()); + public function createCommandEvent(Swift_Transport $source, $command, $successCodes = []); /** * 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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventObject.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventObject.php index 21e7c8127d6..24a11f44e23 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventObject.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/EventObject.php @@ -43,8 +43,6 @@ class Swift_Events_EventObject implements Swift_Events_Event /** * Prevent this Event from bubbling any further up the stack. - * - * @param bool $cancel, optional */ public function cancelBubble($cancel = true) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseEvent.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseEvent.php index 5ae6c04b627..ff7c37116ba 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseEvent.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseEvent.php @@ -32,9 +32,8 @@ class Swift_Events_ResponseEvent extends Swift_Events_EventObject /** * Create a new ResponseEvent for $source and $response. * - * @param Swift_Transport $source - * @param string $response - * @param bool $valid + * @param string $response + * @param bool $valid */ public function __construct(Swift_Transport $source, $response, $valid = false) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseListener.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseListener.php index c40919d210f..85115a33811 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseListener.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/ResponseListener.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendEvent.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendEvent.php index 5dc8efb1fd6..a435691e0b0 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendEvent.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendEvent.php @@ -42,7 +42,7 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject * * @var string[] */ - private $failedRecipients = array(); + private $failedRecipients = []; /** * The overall result as a bitmask from the class constants. @@ -53,9 +53,6 @@ class Swift_Events_SendEvent extends Swift_Events_EventObject /** * Create a new SendEvent for $source and $message. - * - * @param Swift_Transport $source - * @param Swift_Mime_SimpleMessage $message */ public function __construct(Swift_Transport $source, Swift_Mime_SimpleMessage $message) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendListener.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendListener.php index d922e1bfa96..f7bf55ef56c 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendListener.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SendListener.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SimpleEventDispatcher.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SimpleEventDispatcher.php index 815fa4d922b..6557103c99a 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SimpleEventDispatcher.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/SimpleEventDispatcher.php @@ -16,34 +16,28 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher { /** A map of event types to their associated listener types */ - private $eventMap = array(); + private $eventMap = []; /** Event listeners bound to this dispatcher */ - private $listeners = array(); - - /** Listeners queued to have an Event bubbled up the stack to them */ - private $bubbleQueue = array(); + private $listeners = []; /** * Create a new EventDispatcher. */ public function __construct() { - $this->eventMap = array( + $this->eventMap = [ 'Swift_Events_CommandEvent' => 'Swift_Events_CommandListener', 'Swift_Events_ResponseEvent' => 'Swift_Events_ResponseListener', 'Swift_Events_SendEvent' => 'Swift_Events_SendListener', 'Swift_Events_TransportChangeEvent' => 'Swift_Events_TransportChangeListener', 'Swift_Events_TransportExceptionEvent' => 'Swift_Events_TransportExceptionListener', - ); + ]; } /** * 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) @@ -54,13 +48,12 @@ class Swift_Events_SimpleEventDispatcher implements 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 */ - public function createCommandEvent(Swift_Transport $source, $command, $successCodes = array()) + public function createCommandEvent(Swift_Transport $source, $command, $successCodes = []) { return new Swift_Events_CommandEvent($source, $command, $successCodes); } @@ -68,9 +61,8 @@ class Swift_Events_SimpleEventDispatcher implements 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 */ @@ -82,8 +74,6 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher /** * Create a new TransportChangeEvent for $source. * - * @param Swift_Transport $source - * * @return Swift_Events_TransportChangeEvent */ public function createTransportChangeEvent(Swift_Transport $source) @@ -94,9 +84,6 @@ class Swift_Events_SimpleEventDispatcher implements 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) @@ -106,8 +93,6 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher /** * Bind an event listener to this dispatcher. - * - * @param Swift_Events_EventListener $listener */ public function bindEventListener(Swift_Events_EventListener $listener) { @@ -123,34 +108,35 @@ class Swift_Events_SimpleEventDispatcher implements Swift_Events_EventDispatcher /** * 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) { - $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 = array(); - $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); } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportChangeListener.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportChangeListener.php index 253165de89f..4a7492bc551 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportChangeListener.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportChangeListener.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionEvent.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionEvent.php index 77534e3e033..df442cc70f6 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionEvent.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionEvent.php @@ -24,9 +24,6 @@ class Swift_Events_TransportExceptionEvent extends Swift_Events_EventObject /** * Create a new TransportExceptionEvent for $transport. - * - * @param Swift_Transport $transport - * @param Swift_TransportException $ex */ public function __construct(Swift_Transport $transport, Swift_TransportException $ex) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionListener.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionListener.php index cc3c0993793..ad80eb01d0f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionListener.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Events/TransportExceptionListener.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/FailoverTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/FailoverTransport.php index dc2859f74a0..af0be917903 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/FailoverTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/FailoverTransport.php @@ -20,10 +20,10 @@ class Swift_FailoverTransport extends Swift_Transport_FailoverTransport * * @param Swift_Transport[] $transports */ - public function __construct($transports = array()) + public function __construct($transports = []) { - call_user_func_array( - array($this, 'Swift_Transport_FailoverTransport::__construct'), + \call_user_func_array( + [$this, 'Swift_Transport_FailoverTransport::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('transport.failover') ); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/FileSpool.php b/htdocs/includes/swiftmailer/lib/classes/Swift/FileSpool.php index b0b9eb064c5..7af8471c9d7 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/FileSpool.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/FileSpool.php @@ -121,7 +121,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool foreach (new DirectoryIterator($this->path) as $file) { $file = $file->getRealPath(); - if (substr($file, -16) == '.message.sending') { + if ('.message.sending' == substr($file, -16)) { $lockedtime = filectime($file); if ((time() - $lockedtime) > $timeout) { rename($file, substr($file, 0, -8)); @@ -145,7 +145,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool /* Start the transport only if there are queued files to send */ if (!$transport->isStarted()) { foreach ($directoryIterator as $file) { - if (substr($file->getRealPath(), -8) == '.message') { + if ('.message' == substr($file->getRealPath(), -8)) { $transport->start(); break; } @@ -158,7 +158,7 @@ class Swift_FileSpool extends Swift_ConfigurableSpool foreach ($directoryIterator as $file) { $file = $file->getRealPath(); - if (substr($file, -8) != '.message') { + if ('.message' != substr($file, -8)) { continue; } @@ -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)]; } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Filterable.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Filterable.php index 6b75b52748d..efa1b1def5e 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Filterable.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Filterable.php @@ -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); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/InputByteStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/InputByteStream.php index 56efc7593ac..379a5a17870 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/InputByteStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/InputByteStream.php @@ -52,7 +52,7 @@ interface Swift_InputByteStream * * @param Swift_InputByteStream $is */ - public function bind(Swift_InputByteStream $is); + public function bind(self $is); /** * Remove an already bound stream. @@ -63,7 +63,7 @@ interface Swift_InputByteStream * * @param Swift_InputByteStream $is */ - public function unbind(Swift_InputByteStream $is); + public function unbind(self $is); /** * Flush the contents of the stream (empty it) and set the internal pointer diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/IoException.php b/htdocs/includes/swiftmailer/lib/classes/Swift/IoException.php index c405f352b50..5452bd416a6 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/IoException.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/IoException.php @@ -18,9 +18,8 @@ class Swift_IoException extends Swift_SwiftException /** * Create a new IoException with $message. * - * @param string $message - * @param int $code - * @param Exception $previous + * @param string $message + * @param int $code */ public function __construct($message, $code = 0, Exception $previous = null) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache.php b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache.php index cd6f786df63..87f6a074212 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache.php @@ -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); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/ArrayKeyCache.php b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/ArrayKeyCache.php index cdd08503004..e8fef1c95d4 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/ArrayKeyCache.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/ArrayKeyCache.php @@ -20,7 +20,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache * * @var array */ - private $contents = array(); + private $contents = []; /** * An InputStream for cloning. @@ -32,8 +32,6 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache /** * Create a new ArrayKeyCache with the given $stream for cloning to make * InputByteStreams. - * - * @param Swift_KeyCache_KeyCacheInputStream $stream */ public function __construct(Swift_KeyCache_KeyCacheInputStream $stream) { @@ -64,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); } } @@ -76,10 +71,9 @@ class Swift_KeyCache_ArrayKeyCache implements 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) { @@ -87,6 +81,7 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache switch ($mode) { case self::MODE_WRITE: $this->clearKey($nsKey, $itemKey); + // no break case self::MODE_APPEND: if (!$this->hasKey($nsKey, $itemKey)) { $this->contents[$nsKey][$itemKey] = ''; @@ -96,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); } } @@ -108,9 +100,8 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache * * NOTE: The stream will always write in append mode. * - * @param string $nsKey - * @param string $itemKey - * @param Swift_InputByteStream $writeThrough + * @param string $nsKey + * @param string $itemKey * * @return Swift_InputByteStream */ @@ -168,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]); } /** @@ -199,8 +190,8 @@ class Swift_KeyCache_ArrayKeyCache implements Swift_KeyCache */ private function prepareCache($nsKey) { - if (!array_key_exists($nsKey, $this->contents)) { - $this->contents[$nsKey] = array(); + if (!\array_key_exists($nsKey, $this->contents)) { + $this->contents[$nsKey] = []; } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php index d6a633a1512..33b6367cb8b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php @@ -43,14 +43,13 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache * * @var array */ - private $keys = array(); + private $keys = []; /** * Create a new DiskKeyCache with the given $stream for cloning to make * InputByteStreams, and the given $path to save to. * - * @param Swift_KeyCache_KeyCacheInputStream $stream - * @param string $path to save to + * @param string $path to save to */ public function __construct(Swift_KeyCache_KeyCacheInputStream $stream, $path) { @@ -81,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); @@ -96,10 +92,9 @@ class Swift_KeyCache_DiskKeyCache implements 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 * * @throws Swift_IoException */ @@ -114,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)) { @@ -131,9 +123,8 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache * * NOTE: The stream will always write in append mode. * - * @param string $nsKey - * @param string $itemKey - * @param Swift_InputByteStream $writeThrough + * @param string $nsKey + * @param string $itemKey * * @return Swift_InputByteStream */ @@ -227,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); } @@ -250,7 +241,7 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache if (!mkdir($cacheDir)) { throw new Swift_IoException('Failed to create cache directory '.$cacheDir); } - $this->keys[$nsKey] = array(); + $this->keys[$nsKey] = []; } } @@ -295,4 +286,9 @@ class Swift_KeyCache_DiskKeyCache implements Swift_KeyCache $this->clearAll($nsKey); } } + + public function __wakeup() + { + $this->keys = []; + } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/KeyCacheInputStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/KeyCacheInputStream.php index af80bdca6bf..be2dbba0c58 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/KeyCacheInputStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/KeyCacheInputStream.php @@ -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); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/NullKeyCache.php b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/NullKeyCache.php index 4efe785648f..957b1b2a000 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/NullKeyCache.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/NullKeyCache.php @@ -34,10 +34,9 @@ class Swift_KeyCache_NullKeyCache implements 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) { @@ -48,9 +47,8 @@ class Swift_KeyCache_NullKeyCache implements Swift_KeyCache * * NOTE: The stream will always write in append mode. * - * @param string $nsKey - * @param string $itemKey - * @param Swift_InputByteStream $writeThrough + * @param string $nsKey + * @param string $itemKey * * @return Swift_InputByteStream */ diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php index a74df434c46..03bab481ea3 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php @@ -29,8 +29,6 @@ class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCach /** * Set the KeyCache to wrap. - * - * @param Swift_KeyCache $keyCache */ public function setKeyCache(Swift_KeyCache $keyCache) { @@ -39,8 +37,6 @@ class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCach /** * Specify a stream to write through for each write(). - * - * @param Swift_InputByteStream $is */ public function setWriteThroughStream(Swift_InputByteStream $is) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/LoadBalancedTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/LoadBalancedTransport.php index 03106e55d4e..244b5f60245 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/LoadBalancedTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/LoadBalancedTransport.php @@ -20,10 +20,10 @@ class Swift_LoadBalancedTransport extends Swift_Transport_LoadBalancedTransport * * @param array $transports */ - public function __construct($transports = array()) + public function __construct($transports = []) { - call_user_func_array( - array($this, 'Swift_Transport_LoadBalancedTransport::__construct'), + \call_user_func_array( + [$this, 'Swift_Transport_LoadBalancedTransport::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('transport.loadbalanced') ); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer.php index 3561ec6e68e..57630074cd9 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer.php @@ -20,8 +20,6 @@ class Swift_Mailer /** * Create a new Mailer using $transport for delivery. - * - * @param Swift_Transport $transport */ public function __construct(Swift_Transport $transport) { @@ -54,8 +52,7 @@ class Swift_Mailer * The return value is the number of recipients who were accepted for * delivery. * - * @param Swift_Mime_SimpleMessage $message - * @param array $failedRecipients An array of failures by-reference + * @param array $failedRecipients An array of failures by-reference * * @return int The number of successful recipients. Can be 0 which indicates failure */ @@ -63,6 +60,7 @@ class Swift_Mailer { $failedRecipients = (array) $failedRecipients; + // FIXME: to be removed in 7.0 (as transport must now start itself on send) if (!$this->transport->isStarted()) { $this->transport->start(); } @@ -82,8 +80,6 @@ class Swift_Mailer /** * Register a plugin using a known unique key (e.g. myPlugin). - * - * @param Swift_Events_EventListener $plugin */ public function registerPlugin(Swift_Events_EventListener $plugin) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer/ArrayRecipientIterator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer/ArrayRecipientIterator.php index 84dacb5f185..19aa82a9c40 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer/ArrayRecipientIterator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mailer/ArrayRecipientIterator.php @@ -20,12 +20,10 @@ class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientItera * * @var array */ - private $recipients = array(); + private $recipients = []; /** * Create a new ArrayRecipientIterator from $recipients. - * - * @param array $recipients */ public function __construct(array $recipients) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/MemorySpool.php b/htdocs/includes/swiftmailer/lib/classes/Swift/MemorySpool.php index 9aa62835b32..e3b0894d87a 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/MemorySpool.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/MemorySpool.php @@ -15,7 +15,7 @@ */ class Swift_MemorySpool implements Swift_Spool { - protected $messages = array(); + protected $messages = []; private $flushRetries = 3; /** diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Message.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Message.php index 00f6e160027..5c5834e23d8 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Message.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Message.php @@ -18,17 +18,17 @@ class Swift_Message extends Swift_Mime_SimpleMessage /** * @var Swift_Signers_HeaderSigner[] */ - private $headerSigners = array(); + private $headerSigners = []; /** * @var Swift_Signers_BodySigner[] */ - private $bodySigners = array(); + private $bodySigners = []; /** * @var array */ - private $savedMessage = array(); + private $savedMessage = []; /** * Create a new Message. @@ -42,8 +42,8 @@ class Swift_Message extends Swift_Mime_SimpleMessage */ public function __construct($subject = null, $body = null, $contentType = null, $charset = null) { - call_user_func_array( - array($this, 'Swift_Mime_SimpleMessage::__construct'), + \call_user_func_array( + [$this, 'Swift_Mime_SimpleMessage::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('mime.message') ); @@ -75,9 +75,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * Detach a signature handler from a message. - * - * @param Swift_Signer $signer + * Attach a new signature handler to the message. * * @return $this */ @@ -93,9 +91,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage } /** - * Attach a new signature handler to the message. - * - * @param Swift_Signer $signer + * Detach a signature handler from a message. * * @return $this */ @@ -122,6 +118,19 @@ class Swift_Message extends Swift_Mime_SimpleMessage return $this; } + /** + * Clear all signature handlers attached to the message. + * + * @return $this + */ + public function clearSigners() + { + $this->headerSigners = []; + $this->bodySigners = []; + + return $this; + } + /** * Get this message as a complete string. * @@ -146,8 +155,6 @@ class Swift_Message extends Swift_Mime_SimpleMessage /** * Write this message to a {@link Swift_InputByteStream}. - * - * @param Swift_InputByteStream $is */ public function toByteStream(Swift_InputByteStream $is) { @@ -202,24 +209,22 @@ class Swift_Message extends Swift_Mime_SimpleMessage */ protected function saveMessage() { - $this->savedMessage = array('headers' => array()); + $this->savedMessage = ['headers' => []]; $this->savedMessage['body'] = $this->getBody(); $this->savedMessage['children'] = $this->getChildren(); - if (count($this->savedMessage['children']) > 0 && $this->getBody() != '') { - $this->setChildren(array_merge(array($this->becomeMimePart()), $this->savedMessage['children'])); + if (\count($this->savedMessage['children']) > 0 && '' != $this->getBody()) { + $this->setChildren(array_merge([$this->becomeMimePart()], $this->savedMessage['children'])); $this->setBody(''); } } /** * save the original headers. - * - * @param array $altered */ 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); @@ -252,7 +257,7 @@ class Swift_Message extends Swift_Mime_SimpleMessage $this->setChildren($this->savedMessage['children']); $this->restoreHeaders(); - $this->savedMessage = array(); + $this->savedMessage = []; } /** diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Attachment.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Attachment.php index a36ce7237cf..d994373bd78 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Attachment.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Attachment.php @@ -16,18 +16,14 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity { /** Recognized MIME types */ - private $mimeTypes = array(); + private $mimeTypes = []; /** * Create a new Attachment with $headers, $encoder and $cache. * - * @param Swift_Mime_SimpleHeaderSet $headers - * @param Swift_Mime_ContentEncoder $encoder - * @param Swift_KeyCache $cache - * @param Swift_IdGenerator $idGenerator - * @param array $mimeTypes + * @param array $mimeTypes */ - public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = array()) + public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = []) { parent::__construct($headers, $encoder, $cache, $idGenerator); $this->setDisposition('attachment'); @@ -127,8 +123,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity /** * Set the file that this attachment is for. * - * @param Swift_FileStream $file - * @param string $contentType optional + * @param string $contentType optional * * @return $this */ @@ -139,7 +134,7 @@ class Swift_Mime_Attachment extends Swift_Mime_SimpleMimeEntity if (!isset($contentType)) { $extension = strtolower(substr($file->getPath(), strrpos($file->getPath(), '.') + 1)); - if (array_key_exists($extension, $this->mimeTypes)) { + if (\array_key_exists($extension, $this->mimeTypes)) { $this->setContentType($this->mimeTypes[$extension]); } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php index 8f76d70f358..b7e1e028307 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/Base64ContentEncoder.php @@ -18,10 +18,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 /** * Encode stream $in to stream $out. * - * @param Swift_OutputByteStream $os - * @param Swift_InputByteStream $is - * @param int $firstLineOffset - * @param int $maxLineLength, optional, 0 indicates the default of 76 bytes + * @param int $firstLineOffset */ public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) { @@ -30,7 +27,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 } $remainder = 0; - $base64ReadBufferRemainderBytes = null; + $base64ReadBufferRemainderBytes = ''; // To reduce memory usage, the output buffer is streamed to the input buffer like so: // Output Stream => base64encode => wrap line length => Input Stream @@ -41,17 +38,17 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 // When the OutputStream is empty, we must flush any remainder bytes. while (true) { $readBytes = $os->read(8192); - $atEOF = ($readBytes === false); + $atEOF = (false === $readBytes); if ($atEOF) { $streamTheseBytes = $base64ReadBufferRemainderBytes; } else { $streamTheseBytes = $base64ReadBufferRemainderBytes.$readBytes; } - $base64ReadBufferRemainderBytes = null; - $bytesLength = strlen($streamTheseBytes); + $base64ReadBufferRemainderBytes = ''; + $bytesLength = \strlen($streamTheseBytes); - if ($bytesLength === 0) { // no data left to encode + if (0 === $bytesLength) { // no data left to encode break; } @@ -59,7 +56,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 // and carry over remainder 1-2 bytes to the next loop iteration if (!$atEOF) { $excessBytes = $bytesLength % 3; - if ($excessBytes !== 0) { + if (0 !== $excessBytes) { $base64ReadBufferRemainderBytes = substr($streamTheseBytes, -$excessBytes); $streamTheseBytes = substr($streamTheseBytes, 0, $bytesLength - $excessBytes); } @@ -69,7 +66,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 $encodedTransformed = ''; $thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset; - while ($thisMaxLineLength < strlen($encoded)) { + while ($thisMaxLineLength < \strlen($encoded)) { $encodedTransformed .= substr($encoded, 0, $thisMaxLineLength)."\r\n"; $firstLineOffset = 0; $encoded = substr($encoded, $thisMaxLineLength); @@ -77,7 +74,7 @@ class Swift_Mime_ContentEncoder_Base64ContentEncoder extends Swift_Encoder_Base6 $remainder = 0; } - if (0 < $remainingLength = strlen($encoded)) { + if (0 < $remainingLength = \strlen($encoded)) { $remainder += $remainingLength; $encodedTransformed .= $encoded; $encoded = null; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php index 34de4ef39a4..8dfea605fde 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/NativeQpContentEncoder.php @@ -16,16 +16,16 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_ContentEncoder { /** - * @var null|string + * @var string|null */ private $charset; /** - * @param null|string $charset + * @param string|null $charset */ public function __construct($charset = null) { - $this->charset = $charset ? $charset : 'utf-8'; + $this->charset = $charset ?: 'utf-8'; } /** @@ -50,9 +50,8 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con */ public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) { - if ($this->charset !== 'utf-8') { - throw new RuntimeException( - sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); + if ('utf-8' !== $this->charset) { + throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); } $string = ''; @@ -87,9 +86,8 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) { - if ($this->charset !== 'utf-8') { - throw new RuntimeException( - sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); + if ('utf-8' !== $this->charset) { + throw new RuntimeException(sprintf('Charset "%s" not supported. NativeQpContentEncoder only supports "utf-8"', $this->charset)); } return $this->standardize(quoted_printable_encode($string)); @@ -107,9 +105,9 @@ class Swift_Mime_ContentEncoder_NativeQpContentEncoder implements Swift_Mime_Con // transform CR or LF to CRLF $string = preg_replace('~=0D(?!=0A)|(? + */ +class Swift_Mime_ContentEncoder_NullContentEncoder implements Swift_Mime_ContentEncoder +{ + /** + * The name of this encoding scheme (probably 7bit or 8bit). + * + * @var string + */ + private $name; + + /** + * Creates a new NullContentEncoder with $name (probably 7bit or 8bit). + * + * @param string $name + */ + public function __construct($name) + { + $this->name = $name; + } + + /** + * Encode a given string to produce an encoded string. + * + * @param string $string + * @param int $firstLineOffset ignored + * @param int $maxLineLength ignored + * + * @return string + */ + public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) + { + return $string; + } + + /** + * Encode stream $in to stream $out. + * + * @param int $firstLineOffset ignored + * @param int $maxLineLength ignored + */ + public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) + { + while (false !== ($bytes = $os->read(8192))) { + $is->write($bytes); + } + } + + /** + * Get the name of this encoding scheme. + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Not used. + */ + public function charsetChanged($charset) + { + } +} diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/PlainContentEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/PlainContentEncoder.php index 866b0c7c980..72592fc5894 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/PlainContentEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/PlainContentEncoder.php @@ -11,6 +11,10 @@ /** * Handles binary/7/8-bit Transfer Encoding in Swift Mailer. * + * When sending 8-bit content over SMTP, you should use + * Swift_Transport_Esmtp_EightBitMimeHandler to enable the 8BITMIME SMTP + * extension. + * * @author Chris Corbyn */ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_ContentEncoder @@ -33,7 +37,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten * Creates a new PlainContentEncoder with $name (probably 7bit or 8bit). * * @param string $name - * @param bool $canonical If canonicalization transformation should be done. + * @param bool $canonical if canonicalization transformation should be done */ public function __construct($name, $canonical = false) { @@ -62,10 +66,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten /** * Encode stream $in to stream $out. * - * @param Swift_OutputByteStream $os - * @param Swift_InputByteStream $is - * @param int $firstLineOffset ignored - * @param int $maxLineLength optional, 0 means no wrapping will occur + * @param int $firstLineOffset ignored + * @param int $maxLineLength optional, 0 means no wrapping will occur */ public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) { @@ -82,7 +84,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten $is->write($wrapped); } - if (strlen($leftOver)) { + if (\strlen($leftOver)) { $is->write($leftOver); } } @@ -121,7 +123,7 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten $originalLines = explode($le, $string); - $lines = array(); + $lines = []; $lineCount = 0; foreach ($originalLines as $originalLine) { @@ -132,8 +134,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten $chunks = preg_split('/(?<=\s)/', $originalLine); foreach ($chunks as $chunk) { - if (0 != strlen($currentLine) - && strlen($currentLine.$chunk) > $length) { + if (0 != \strlen($currentLine) + && \strlen($currentLine.$chunk) > $length) { $lines[] = ''; $currentLine = &$lines[$lineCount++]; } @@ -154,8 +156,8 @@ class Swift_Mime_ContentEncoder_PlainContentEncoder implements Swift_Mime_Conten private function canonicalize($string) { return str_replace( - array("\r\n", "\r", "\n"), - array("\n", "\n", "\r\n"), + ["\r\n", "\r", "\n"], + ["\n", "\n", "\r\n"], $string ); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php index b3577dbe61f..465ffd87850 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoder.php @@ -32,12 +32,12 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder public function __sleep() { - return array('charStream', 'filter', 'dotEscape'); + return ['charStream', 'filter', 'dotEscape']; } protected function getSafeMapShareId() { - return get_class($this).($this->dotEscape ? '.dotEscape' : ''); + return static::class.($this->dotEscape ? '.dotEscape' : ''); } protected function initSafeMap() @@ -97,7 +97,7 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder $enc = $this->encodeByteSequence($bytes, $size); $i = strpos($enc, '=0D=0A'); - $newLineLength = $lineLen + ($i === false ? $size : $i); + $newLineLength = $lineLen + (false === $i ? $size : $i); if ($currentLine && $newLineLength >= $thisLineLength) { $is->write($prepend.$this->standardize($currentLine)); @@ -109,14 +109,14 @@ class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder $currentLine .= $enc; - if ($i === false) { + if (false === $i) { $lineLen += $size; } else { // 6 is the length of '=0D=0A'. $lineLen = $size - strrpos($enc, '=0D=0A') - 6; } } - if (strlen($currentLine)) { + if (\strlen($currentLine)) { $is->write($prepend.$this->standardize($currentLine)); } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php index 3214e1cf3fd..f3ece43aecd 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/QpContentEncoderProxy.php @@ -28,16 +28,14 @@ class Swift_Mime_ContentEncoder_QpContentEncoderProxy implements Swift_Mime_Cont private $nativeEncoder; /** - * @var null|string + * @var string|null */ private $charset; /** * Constructor. * - * @param Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder - * @param Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder - * @param string|null $charset + * @param string|null $charset */ public function __construct(Swift_Mime_ContentEncoder_QpContentEncoder $safeEncoder, Swift_Mime_ContentEncoder_NativeQpContentEncoder $nativeEncoder, $charset) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php index 0b8526e38c3..870e7f41a93 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/ContentEncoder/RawContentEncoder.php @@ -11,6 +11,9 @@ /** * Handles raw Transfer Encoding in Swift Mailer. * + * When sending 8-bit content over SMTP, you should use + * Swift_Transport_Esmtp_EightBitMimeHandler to enable the 8BITMIME SMTP + * extension. * * @author Sebastiaan Stok */ @@ -33,10 +36,8 @@ class Swift_Mime_ContentEncoder_RawContentEncoder implements Swift_Mime_ContentE /** * Encode stream $in to stream $out. * - * @param Swift_OutputByteStream $in - * @param Swift_InputByteStream $out - * @param int $firstLineOffset ignored - * @param int $maxLineLength ignored + * @param int $firstLineOffset ignored + * @param int $maxLineLength ignored */ public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EmbeddedFile.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EmbeddedFile.php index 7835a492873..42a51770c76 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EmbeddedFile.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EmbeddedFile.php @@ -18,13 +18,9 @@ class Swift_Mime_EmbeddedFile extends Swift_Mime_Attachment /** * Creates a new Attachment with $headers and $encoder. * - * @param Swift_Mime_SimpleHeaderSet $headers - * @param Swift_Mime_ContentEncoder $encoder - * @param Swift_KeyCache $cache - * @param Swift_IdGenerator $idGenerator - * @param array $mimeTypes optional + * @param array $mimeTypes optional */ - public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = array()) + public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $mimeTypes = []) { parent::__construct($headers, $encoder, $cache, $idGenerator, $mimeTypes); $this->setDisposition('inline'); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EncodingObserver.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EncodingObserver.php index cc44a6efb97..1a952ece12c 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EncodingObserver.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/EncodingObserver.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Header.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Header.php index a8ddd272165..ca712f35aa0 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Header.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Header.php @@ -85,7 +85,7 @@ interface Swift_Mime_Header public function getFieldBody(); /** - * Get this Header rendered as a compliant string. + * Get this Header rendered as a compliant string, including trailing CRLF. * * @return string */ diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php index 83a4f2f3b2d..21c8aaabfea 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/Base64HeaderEncoder.php @@ -41,7 +41,7 @@ class Swift_Mime_HeaderEncoder_Base64HeaderEncoder extends Swift_Encoder_Base64E */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0, $charset = 'utf-8') { - if (strtolower($charset) === 'iso-2022-jp') { + if ('iso-2022-jp' === strtolower($charset ?? '')) { $old = mb_internal_encoding(); mb_internal_encoding('utf-8'); $newstring = mb_encode_mimeheader($string, $charset, $this->getName(), "\r\n"); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php index 062be7d7967..378c4805057 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/HeaderEncoder/QpHeaderEncoder.php @@ -29,9 +29,9 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i { foreach (array_merge( range(0x61, 0x7A), range(0x41, 0x5A), - range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F) + range(0x30, 0x39), [0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F] ) as $byte) { - $this->safeMap[$byte] = chr($byte); + $this->safeMap[$byte] = \chr($byte); } } @@ -58,7 +58,7 @@ class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder i */ public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0) { - return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"), + return str_replace([' ', '=20', "=\r\n"], ['_', '_', "\r\n"], parent::encodeString($string, $firstLineOffset, $maxLineLength) ); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/AbstractHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/AbstractHeader.php index a569f816189..25740d1155c 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/AbstractHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/AbstractHeader.php @@ -109,8 +109,6 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Set the encoder used for encoding the header. - * - * @param Swift_Mime_HeaderEncoder $encoder */ public function setEncoder(Swift_Mime_HeaderEncoder $encoder) { @@ -196,11 +194,9 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Produces a compliant, formatted RFC 2822 'phrase' based on the string given. * - * @param Swift_Mime_Header $header - * @param string $string as displayed - * @param string $charset of the text - * @param Swift_Mime_HeaderEncoder $encoder - * @param bool $shorten the first line to make remove for header name + * @param string $string as displayed + * @param string $charset of the text + * @param bool $shorten the first line to make remove for header name * * @return string */ @@ -214,13 +210,13 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header // .. but it is just ascii text, try escaping some characters // and make it a quoted-string if (preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $phraseStr)) { - $phraseStr = $this->escapeSpecials($phraseStr, array('"')); + $phraseStr = $this->escapeSpecials($phraseStr, ['"']); $phraseStr = '"'.$phraseStr.'"'; } else { // ... otherwise it needs encoding // Determine space remaining on line if first line if ($shorten) { - $usedLength = strlen($header->getFieldName().': '); + $usedLength = \strlen($header->getFieldName().': '); } else { $usedLength = 0; } @@ -239,9 +235,9 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header * * @return string */ - private function escapeSpecials($token, $include = array()) + private function escapeSpecials($token, $include = []) { - foreach (array_merge(array('\\'), $include) as $char) { + foreach (array_merge(['\\'], $include) as $char) { $token = str_replace($char, '\\'.$char, $token); } @@ -251,9 +247,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header /** * Encode needed word tokens within a string of input. * - * @param Swift_Mime_Header $header - * @param string $input - * @param string $usedLength optional + * @param string $input + * @param string $usedLength optional * * @return string */ @@ -276,7 +271,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header } if (-1 == $usedLength) { - $usedLength = strlen($header->getFieldName().': ') + strlen($value); + $usedLength = \strlen($header->getFieldName().': ') + \strlen($value); } $value .= $this->getTokenAsEncodedWord($token, $usedLength); @@ -310,22 +305,22 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header */ protected function getEncodableWordTokens($string) { - $tokens = array(); + $tokens = []; $encodedToken = ''; // Split at all whitespace boundaries - foreach (preg_split('~(?=[\t ])~', $string) as $token) { + foreach (preg_split('~(?=[\t ])~', $string ?? '') as $token) { if ($this->tokenNeedsEncoding($token)) { $encodedToken .= $token; } else { - if (strlen($encodedToken) > 0) { + if (\strlen($encodedToken) > 0) { $tokens[] = $encodedToken; $encodedToken = ''; } $tokens[] = $token; } } - if (strlen($encodedToken)) { + if (\strlen($encodedToken)) { $tokens[] = $encodedToken; } @@ -347,7 +342,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header if (isset($this->lang)) { $charsetDecl .= '*'.$this->lang; } - $encodingWrapperLength = strlen( + $encodingWrapperLength = \strlen( '=?'.$charsetDecl.'?'.$this->encoder->getName().'??=' ); @@ -359,10 +354,10 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header $encodedTextLines = explode("\r\n", $this->encoder->encodeString( $token, $firstLineOffset, 75 - $encodingWrapperLength, $this->charset - ) + ) ?? '' ); - if (strtolower($this->charset) !== 'iso-2022-jp') { + if ('iso-2022-jp' !== strtolower($this->charset ?? '')) { // special encoding for iso-2022-jp using mb_encode_mimeheader foreach ($encodedTextLines as $lineNum => $line) { $encodedTextLines[$lineNum] = '=?'.$charsetDecl. @@ -383,7 +378,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header */ protected function generateTokenLines($token) { - return preg_split('~(\r\n)~', $token, -1, PREG_SPLIT_DELIM_CAPTURE); + return preg_split('~(\r\n)~', $token ?? '', -1, PREG_SPLIT_DELIM_CAPTURE); } /** @@ -431,10 +426,10 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header $string = $this->getFieldBody(); } - $tokens = array(); + $tokens = []; // Generate atoms; split at all invisible boundaries followed by WSP - foreach (preg_split('~(?=[ \t])~', $string) as $token) { + foreach (preg_split('~(?=[ \t])~', $string ?? '') as $token) { $newTokens = $this->generateTokenLines($token); foreach ($newTokens as $newToken) { $tokens[] = $newToken; @@ -455,7 +450,7 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header private function tokensToString(array $tokens) { $lineCount = 0; - $headerLines = array(); + $headerLines = []; $headerLines[] = $this->name.': '; $currentLine = &$headerLines[$lineCount++]; @@ -463,8 +458,8 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header foreach ($tokens as $i => $token) { // Line longer than specified maximum or token was just a new line if (("\r\n" == $token) || - ($i > 0 && strlen($currentLine.$token) > $this->lineLength) - && 0 < strlen($currentLine)) { + ($i > 0 && \strlen($currentLine.$token) > $this->lineLength) + && 0 < \strlen($currentLine)) { $headerLines[] = ''; $currentLine = &$headerLines[$lineCount++]; } @@ -478,4 +473,14 @@ abstract class Swift_Mime_Headers_AbstractHeader implements Swift_Mime_Header // Implode with FWS (RFC 2822, 2.2.3) return implode("\r\n", $headerLines)."\r\n"; } + + /** + * Make a deep copy of object. + */ + public function __clone() + { + if ($this->encoder) { + $this->encoder = clone $this->encoder; + } + } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/DateHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/DateHeader.php index 6dcc92bfdd6..efe1dad6619 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/DateHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/DateHeader.php @@ -79,8 +79,6 @@ class Swift_Mime_Headers_DateHeader extends Swift_Mime_Headers_AbstractHeader * Set the date-time of the Date in this Header. * * If a DateTime instance is provided, it is converted to DateTimeImmutable. - * - * @param DateTimeInterface $dateTime */ public function setDateTime(DateTimeInterface $dateTime) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php index acf794479b6..4fcdff418a7 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/IdentificationHeader.php @@ -9,6 +9,7 @@ */ use Egulias\EmailValidator\EmailValidator; +use Egulias\EmailValidator\Validation\MessageIDValidation; use Egulias\EmailValidator\Validation\RFCValidation; /** @@ -25,7 +26,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac * * @var string[] */ - private $ids = array(); + private $ids = []; /** * The strict EmailValidator. @@ -34,16 +35,18 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac */ private $emailValidator; + private $addressEncoder; + /** * Creates a new IdentificationHeader with the given $name and $id. * - * @param string $name - * @param EmailValidator $emailValidator + * @param string $name */ - public function __construct($name, EmailValidator $emailValidator) + public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) { $this->setFieldName($name); $this->emailValidator = $emailValidator; + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); } /** @@ -94,7 +97,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac */ public function setId($id) { - $this->setIds(is_array($id) ? $id : array($id)); + $this->setIds(\is_array($id) ? $id : [$id]); } /** @@ -106,7 +109,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac */ public function getId() { - if (count($this->ids) > 0) { + if (\count($this->ids) > 0) { return $this->ids[0]; } } @@ -120,7 +123,7 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac */ public function setIds(array $ids) { - $actualIds = array(); + $actualIds = []; foreach ($ids as $id) { $this->assertValidId($id); @@ -156,10 +159,10 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac public function getFieldBody() { if (!$this->getCachedValue()) { - $angleAddrs = array(); + $angleAddrs = []; foreach ($this->ids as $id) { - $angleAddrs[] = '<'.$id.'>'; + $angleAddrs[] = '<'.$this->addressEncoder->encodeString($id).'>'; } $this->setCachedValue(implode(' ', $angleAddrs)); @@ -177,7 +180,9 @@ class Swift_Mime_Headers_IdentificationHeader extends Swift_Mime_Headers_Abstrac */ private function assertValidId($id) { - if (!$this->emailValidator->isValid($id, new RFCValidation())) { + $emailValidation = class_exists(MessageIDValidation::class) ? new MessageIDValidation() : new RFCValidation(); + + if (!$this->emailValidator->isValid($id, $emailValidation)) { throw new Swift_RfcComplianceException('Invalid ID given <'.$id.'>'); } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php index 450e0f25b7e..ddd5e8cffb1 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php @@ -23,7 +23,7 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader * * @var string[] */ - private $mailboxes = array(); + private $mailboxes = []; /** * The strict EmailValidator. @@ -32,18 +32,19 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader */ private $emailValidator; + private $addressEncoder; + /** * Creates a new MailboxHeader with $name. * - * @param string $name of Header - * @param Swift_Mime_HeaderEncoder $encoder - * @param EmailValidator $emailValidator + * @param string $name of Header */ - public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator) + public function __construct($name, Swift_Mime_HeaderEncoder $encoder, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) { $this->setFieldName($name); $this->setEncoder($encoder); $this->emailValidator = $emailValidator; + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); } /** @@ -257,10 +258,10 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader */ protected function normalizeMailboxes(array $mailboxes) { - $actualMailboxes = array(); + $actualMailboxes = []; foreach ($mailboxes as $key => $value) { - if (is_string($key)) { + if (\is_string($key)) { //key is email addr $address = $key; $name = $value; @@ -327,10 +328,10 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader */ private function createNameAddressStrings(array $mailboxes) { - $strings = array(); + $strings = []; foreach ($mailboxes as $email => $name) { - $mailboxStr = $email; + $mailboxStr = $this->addressEncoder->encodeString($email); if (null !== $name) { $nameStr = $this->createDisplayNameString($name, empty($strings)); $mailboxStr = $nameStr.' <'.$mailboxStr.'>'; @@ -346,14 +347,12 @@ class Swift_Mime_Headers_MailboxHeader extends Swift_Mime_Headers_AbstractHeader * * @param string $address * - * @throws Swift_RfcComplianceException If invalid. + * @throws Swift_RfcComplianceException if invalid */ private function assertValidAddress($address) { if (!$this->emailValidator->isValid($address, new RFCValidation())) { - throw new Swift_RfcComplianceException( - 'Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.' - ); + throw new Swift_RfcComplianceException('Address in mailbox given ['.$address.'] does not comply with RFC 2822, 3.6.2.'); } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/OpenDKIMHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/OpenDKIMHeader.php index 29277994c0a..fafb5bae21f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/OpenDKIMHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/OpenDKIMHeader.php @@ -12,6 +12,8 @@ * An OpenDKIM Specific Header using only raw header datas without encoding. * * @author De Cock Xavier + * + * @deprecated since SwiftMailer 6.1.0; use Swift_Signers_DKIMSigner instead. */ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header { @@ -111,7 +113,7 @@ class Swift_Mime_Headers_OpenDKIMHeader implements Swift_Mime_Header */ public function toString() { - return $this->fieldName.': '.$this->value; + return $this->fieldName.': '.$this->value."\r\n"; } /** diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php index 228946a5ee9..47c15e6c05f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/ParameterizedHeader.php @@ -34,14 +34,12 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct * * @var string[] */ - private $params = array(); + private $params = []; /** * Creates a new ParameterizedHeader with $name. * - * @param string $name - * @param Swift_Mime_HeaderEncoder $encoder - * @param Swift_Encoder $paramEncoder, optional + * @param string $name */ public function __construct($name, Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder = null) { @@ -83,7 +81,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct */ public function setParameter($parameter, $value) { - $this->setParameters(array_merge($this->getParameters(), array($parameter => $value))); + $this->setParameters(array_merge($this->getParameters(), [$parameter => $value])); } /** @@ -97,7 +95,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct { $params = $this->getParameters(); - return isset($params[$parameter]) ? $params[$parameter] : null; + return $params[$parameter] ?? null; } /** @@ -157,7 +155,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct foreach ($this->params as $name => $value) { if (null !== $value) { // Add the semi-colon separator - $tokens[count($tokens) - 1] .= ';'; + $tokens[\count($tokens) - 1] .= ';'; $tokens = array_merge($tokens, $this->generateTokenLines( ' '.$this->createParameter($name, $value) )); @@ -181,7 +179,7 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct $encoded = false; // Allow room for parameter name, indices, "=" and DQUOTEs - $maxValueLength = $this->getMaxLineLength() - strlen($name.'=*N"";') - 1; + $maxValueLength = $this->getMaxLineLength() - \strlen($name.'=*N"";') - 1; $firstLineOffset = 0; // If it's not already a valid parameter value... @@ -191,15 +189,15 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct if (!preg_match('/^[\x00-\x08\x0B\x0C\x0E-\x7F]*$/D', $value)) { $encoded = true; // Allow space for the indices, charset and language - $maxValueLength = $this->getMaxLineLength() - strlen($name.'*N*="";') - 1; - $firstLineOffset = strlen( + $maxValueLength = $this->getMaxLineLength() - \strlen($name.'*N*="";') - 1; + $firstLineOffset = \strlen( $this->getCharset()."'".$this->getLanguage()."'" ); } } // Encode if we need to - if ($encoded || strlen($value) > $maxValueLength) { + if ($encoded || \strlen($value) > $maxValueLength) { if (isset($this->paramEncoder)) { $value = $this->paramEncoder->encodeString( $origValue, $firstLineOffset, $maxValueLength, $this->getCharset() @@ -211,14 +209,14 @@ class Swift_Mime_Headers_ParameterizedHeader extends Swift_Mime_Headers_Unstruct } } - $valueLines = isset($this->paramEncoder) ? explode("\r\n", $value) : array($value); + $valueLines = isset($this->paramEncoder) ? explode("\r\n", $value) : [$value]; // Need to add indices - if (count($valueLines) > 1) { - $paramLines = array(); + if (\count($valueLines) > 1) { + $paramLines = []; foreach ($valueLines as $i => $line) { $paramLines[] = $name.'*'.$i. - $this->getEndOfParameterValue($line, true, $i == 0); + $this->getEndOfParameterValue($line, true, 0 == $i); } return implode(";\r\n ", $paramLines); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/PathHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/PathHeader.php index f79e19fd8b3..81b421ee7a8 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/PathHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/PathHeader.php @@ -32,16 +32,18 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader */ private $emailValidator; + private $addressEncoder; + /** * Creates a new PathHeader with the given $name. * - * @param string $name - * @param EmailValidator $emailValidator + * @param string $name */ - public function __construct($name, EmailValidator $emailValidator) + public function __construct($name, EmailValidator $emailValidator, Swift_AddressEncoder $addressEncoder = null) { $this->setFieldName($name); $this->emailValidator = $emailValidator; + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); } /** @@ -127,7 +129,8 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader { if (!$this->getCachedValue()) { if (isset($this->address)) { - $this->setCachedValue('<'.$this->address.'>'); + $address = $this->addressEncoder->encodeString($this->address); + $this->setCachedValue('<'.$address.'>'); } } @@ -144,9 +147,7 @@ class Swift_Mime_Headers_PathHeader extends Swift_Mime_Headers_AbstractHeader private function assertValidAddress($address) { if (!$this->emailValidator->isValid($address, new RFCValidation())) { - throw new Swift_RfcComplianceException( - 'Address set in PathHeader does not comply with addr-spec of RFC 2822.' - ); + throw new Swift_RfcComplianceException('Address set in PathHeader does not comply with addr-spec of RFC 2822.'); } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/UnstructuredHeader.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/UnstructuredHeader.php index d9d9f5e25d3..64f160dec7c 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/UnstructuredHeader.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/Headers/UnstructuredHeader.php @@ -25,8 +25,7 @@ class Swift_Mime_Headers_UnstructuredHeader extends Swift_Mime_Headers_AbstractH /** * Creates a new SimpleHeader with $name. * - * @param string $name - * @param Swift_Mime_HeaderEncoder $encoder + * @param string $name */ public function __construct($name, Swift_Mime_HeaderEncoder $encoder) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/IdGenerator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/IdGenerator.php index 8d9452bd0f0..3ce35f27c03 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/IdGenerator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/IdGenerator.php @@ -13,6 +13,8 @@ */ class Swift_Mime_IdGenerator implements Swift_IdGenerator { + private $idRight; + /** * @param string $idRight */ @@ -46,8 +48,7 @@ class Swift_Mime_IdGenerator implements Swift_IdGenerator */ public function generateId() { - $idLeft = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)); - - return $idLeft.'@'.$this->idRight; + // 32 hex values for the left part + return bin2hex(random_bytes(16)).'@'.$this->idRight; } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/MimePart.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/MimePart.php index d49449fe5be..d0b2e6586b4 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/MimePart.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/MimePart.php @@ -30,11 +30,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity /** * Create a new MimePart with $headers, $encoder and $cache. * - * @param Swift_Mime_SimpleHeaderSet $headers - * @param Swift_Mime_ContentEncoder $encoder - * @param Swift_KeyCache $cache - * @param Swift_IdGenerator $idGenerator - * @param string $charset + * @param string $charset */ public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null) { @@ -173,7 +169,7 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity protected function fixHeaders() { parent::fixHeaders(); - if (count($this->getChildren())) { + if (\count($this->getChildren())) { $this->setHeaderParameter('Content-Type', 'charset', null); $this->setHeaderParameter('Content-Type', 'format', null); $this->setHeaderParameter('Content-Type', 'delsp', null); @@ -193,18 +189,9 @@ class Swift_Mime_MimePart extends Swift_Mime_SimpleMimeEntity /** Encode charset when charset is not utf-8 */ protected function convertString($string) { - $charset = strtolower($this->getCharset()); - if (!in_array($charset, array('utf-8', 'iso-8859-1', 'iso-8859-15', ''))) { - // mb_convert_encoding must be the first one to check, since iconv cannot convert some words. - if (function_exists('mb_convert_encoding')) { - $string = mb_convert_encoding($string, $charset, 'utf-8'); - } elseif (function_exists('iconv')) { - $string = iconv('utf-8//TRANSLIT//IGNORE', $charset, $string); - } else { - throw new Swift_SwiftException('No suitable convert encoding function (use UTF-8 as your charset or install the mbstring or iconv extension).'); - } - - return $string; + $charset = strtolower($this->getCharset() ?? ''); + if (!\in_array($charset, ['utf-8', 'iso-8859-1', 'iso-8859-15', ''])) { + return mb_convert_encoding($string, $charset, 'utf-8'); } return $string; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderFactory.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderFactory.php index e14c9d6f88e..ab3ce6b1914 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderFactory.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderFactory.php @@ -23,29 +23,27 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver /** The Encoder used by parameters */ private $paramEncoder; - /** The Grammar */ - private $grammar; - /** Strict EmailValidator */ private $emailValidator; /** The charset of created Headers */ private $charset; + /** Swift_AddressEncoder */ + private $addressEncoder; + /** * Creates a new SimpleHeaderFactory using $encoder and $paramEncoder. * - * @param Swift_Mime_HeaderEncoder $encoder - * @param Swift_Encoder $paramEncoder - * @param EmailValidator $emailValidator - * @param string|null $charset + * @param string|null $charset */ - public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, EmailValidator $emailValidator, $charset = null) + public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, EmailValidator $emailValidator, $charset = null, Swift_AddressEncoder $addressEncoder = null) { $this->encoder = $encoder; $this->paramEncoder = $paramEncoder; $this->emailValidator = $emailValidator; $this->charset = $charset; + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); } /** @@ -58,7 +56,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver */ public function createMailboxHeader($name, $addresses = null) { - $header = new Swift_Mime_Headers_MailboxHeader($name, $this->encoder, $this->emailValidator); + $header = new Swift_Mime_Headers_MailboxHeader($name, $this->encoder, $this->emailValidator, $this->addressEncoder); if (isset($addresses)) { $header->setFieldBodyModel($addresses); } @@ -70,8 +68,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver /** * Create a new Date header using $dateTime. * - * @param string $name - * @param DateTimeInterface|null $dateTime + * @param string $name * * @return Swift_Mime_Header */ @@ -114,9 +111,9 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver * * @return Swift_Mime_Headers_ParameterizedHeader */ - public function createParameterizedHeader($name, $value = null, $params = array()) + public function createParameterizedHeader($name, $value = null, $params = []) { - $header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, (strtolower($name) == 'content-disposition') ? $this->paramEncoder : null); + $header = new Swift_Mime_Headers_ParameterizedHeader($name, $this->encoder, ('content-disposition' == strtolower($name ?? '')) ? $this->paramEncoder : null); if (isset($value)) { $header->setFieldBodyModel($value); } @@ -185,6 +182,7 @@ class Swift_Mime_SimpleHeaderFactory implements Swift_Mime_CharsetObserver { $this->encoder = clone $this->encoder; $this->paramEncoder = clone $this->paramEncoder; + $this->addressEncoder = clone $this->addressEncoder; } /** Apply the charset to the Header */ diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderSet.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderSet.php index 6f71fcac132..5195bcf48ae 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderSet.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleHeaderSet.php @@ -19,13 +19,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver private $factory; /** Collection of set Headers */ - private $headers = array(); + private $headers = []; /** Field ordering details */ - private $order = array(); + private $order = []; /** List of fields which are required to be displayed */ - private $required = array(); + private $required = []; /** The charset used by Headers */ private $charset; @@ -33,8 +33,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver /** * Create a new SimpleHeaderSet with the given $factory. * - * @param Swift_Mime_SimpleHeaderFactory $factory - * @param string $charset + * @param string $charset */ public function __construct(Swift_Mime_SimpleHeaderFactory $factory, $charset = null) { @@ -69,20 +68,17 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver */ public function addMailboxHeader($name, $addresses = null) { - $this->storeHeader($name, - $this->factory->createMailboxHeader($name, $addresses)); + $this->storeHeader($name, $this->factory->createMailboxHeader($name, $addresses)); } /** * Add a new Date header using $dateTime. * - * @param string $name - * @param DateTimeInterface $dateTime + * @param string $name */ public function addDateHeader($name, DateTimeInterface $dateTime = null) { - $this->storeHeader($name, - $this->factory->createDateHeader($name, $dateTime)); + $this->storeHeader($name, $this->factory->createDateHeader($name, $dateTime)); } /** @@ -93,8 +89,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver */ public function addTextHeader($name, $value = null) { - $this->storeHeader($name, - $this->factory->createTextHeader($name, $value)); + $this->storeHeader($name, $this->factory->createTextHeader($name, $value)); } /** @@ -104,7 +99,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver * @param string $value * @param array $params */ - public function addParameterizedHeader($name, $value = null, $params = array()) + public function addParameterizedHeader($name, $value = null, $params = []) { $this->storeHeader($name, $this->factory->createParameterizedHeader($name, $value, $params)); } @@ -143,18 +138,18 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver */ public function has($name, $index = 0) { - $lowerName = strtolower($name); + $lowerName = strtolower($name ?? ''); - if (!array_key_exists($lowerName, $this->headers)) { + if (!\array_key_exists($lowerName, $this->headers)) { return false; } - if (func_num_args() < 2) { + if (\func_num_args() < 2) { // index was not specified, so we only need to check that there is at least one header value set - return (bool) count($this->headers[$lowerName]); + return (bool) \count($this->headers[$lowerName]); } - return array_key_exists($index, $this->headers[$lowerName]); + return \array_key_exists($index, $this->headers[$lowerName]); } /** @@ -166,8 +161,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver * If $index is specified, the header will be inserted into the set at this * offset. * - * @param Swift_Mime_Header $header - * @param int $index + * @param int $index */ public function set(Swift_Mime_Header $header, $index = 0) { @@ -183,13 +177,13 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver * @param string $name * @param int $index * - * @return Swift_Mime_Header + * @return Swift_Mime_Header|null */ public function get($name, $index = 0) { - $name = strtolower($name); + $name = strtolower($name ?? ''); - if (func_num_args() < 2) { + if (\func_num_args() < 2) { if ($this->has($name)) { $values = array_values($this->headers[$name]); @@ -212,7 +206,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver public function getAll($name = null) { if (!isset($name)) { - $headers = array(); + $headers = []; foreach ($this->headers as $collection) { $headers = array_merge($headers, $collection); } @@ -220,9 +214,9 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver return $headers; } - $lowerName = strtolower($name); - if (!array_key_exists($lowerName, $this->headers)) { - return array(); + $lowerName = strtolower($name ?? ''); + if (!\array_key_exists($lowerName, $this->headers)) { + return []; } return $this->headers[$lowerName]; @@ -237,7 +231,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver { $headers = $this->headers; if ($this->canSort()) { - uksort($headers, array($this, 'sortHeaders')); + uksort($headers, [$this, 'sortHeaders']); } return array_keys($headers); @@ -253,7 +247,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver */ public function remove($name, $index = 0) { - $lowerName = strtolower($name); + $lowerName = strtolower($name ?? ''); unset($this->headers[$lowerName][$index]); } @@ -264,7 +258,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver */ public function removeAll($name) { - $lowerName = strtolower($name); + $lowerName = strtolower($name ?? ''); unset($this->headers[$lowerName]); } @@ -272,8 +266,6 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver * Define a list of Header names as an array in the correct order. * * These Headers will be output in the given order where present. - * - * @param array $sequence */ public function defineOrdering(array $sequence) { @@ -284,8 +276,6 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver * Set a list of header names which must always be displayed when set. * * Usually headers without a field value won't be output unless set here. - * - * @param array $names */ public function setAlwaysDisplayed(array $names) { @@ -312,11 +302,11 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver $string = ''; $headers = $this->headers; if ($this->canSort()) { - uksort($headers, array($this, 'sortHeaders')); + uksort($headers, [$this, 'sortHeaders']); } foreach ($headers as $collection) { foreach ($collection as $header) { - if ($this->isDisplayed($header) || $header->getFieldBody() != '') { + if ($this->isDisplayed($header) || '' != $header->getFieldBody()) { $string .= $header->toString(); } } @@ -340,38 +330,38 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver /** Save a Header to the internal collection */ private function storeHeader($name, Swift_Mime_Header $header, $offset = null) { - if (!isset($this->headers[strtolower($name)])) { - $this->headers[strtolower($name)] = array(); + if (!isset($this->headers[strtolower($name ?? '')])) { + $this->headers[strtolower($name ?? '')] = []; } if (!isset($offset)) { - $this->headers[strtolower($name)][] = $header; + $this->headers[strtolower($name ?? '')][] = $header; } else { - $this->headers[strtolower($name)][$offset] = $header; + $this->headers[strtolower($name ?? '')][$offset] = $header; } } /** Test if the headers can be sorted */ private function canSort() { - return count($this->order) > 0; + return \count($this->order) > 0; } /** uksort() algorithm for Header ordering */ private function sortHeaders($a, $b) { - $lowerA = strtolower($a); - $lowerB = strtolower($b); - $aPos = array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1; - $bPos = array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1; + $lowerA = strtolower($a ?? ''); + $lowerB = strtolower($b ?? ''); + $aPos = \array_key_exists($lowerA, $this->order) ? $this->order[$lowerA] : -1; + $bPos = \array_key_exists($lowerB, $this->order) ? $this->order[$lowerB] : -1; if (-1 === $aPos && -1 === $bPos) { // just be sure to be determinist here return $a > $b ? -1 : 1; } - if ($aPos == -1) { + if (-1 == $aPos) { return 1; - } elseif ($bPos == -1) { + } elseif (-1 == $bPos) { return -1; } @@ -381,7 +371,7 @@ class Swift_Mime_SimpleHeaderSet implements Swift_Mime_CharsetObserver /** Test if the given Header is always displayed */ private function isDisplayed(Swift_Mime_Header $header) { - return array_key_exists(strtolower($header->getFieldName()), $this->required); + return \array_key_exists(strtolower($header->getFieldName() ?? ''), $this->required); } /** Notify all Headers of the new charset */ diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php index f8667954bcf..62da1650a7b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMessage.php @@ -24,16 +24,12 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart /** * Create a new SimpleMessage with $headers, $encoder and $cache. * - * @param Swift_Mime_SimpleHeaderSet $headers - * @param Swift_Mime_ContentEncoder $encoder - * @param Swift_KeyCache $cache - * @param Swift_IdGenerator $idGenerator - * @param string $charset + * @param string $charset */ public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator, $charset = null) { parent::__construct($headers, $encoder, $cache, $idGenerator, $charset); - $this->getHeaders()->defineOrdering(array( + $this->getHeaders()->defineOrdering([ 'Return-Path', 'Received', 'DKIM-Signature', @@ -50,8 +46,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart 'MIME-Version', 'Content-Type', 'Content-Transfer-Encoding', - )); - $this->getHeaders()->setAlwaysDisplayed(array('Date', 'Message-ID', 'From')); + ]); + $this->getHeaders()->setAlwaysDisplayed(['Date', 'Message-ID', 'From']); $this->getHeaders()->addTextHeader('MIME-Version', '1.0'); $this->setDate(new DateTimeImmutable()); $this->setId($this->getId()); @@ -97,8 +93,6 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart /** * Set the date at which this message was created. * - * @param DateTimeInterface $dateTime - * * @return $this */ public function setDate(DateTimeInterface $dateTime) @@ -158,8 +152,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setSender($address, $name = null) { - if (!is_array($address) && isset($name)) { - $address = array($address => $name); + if (!\is_array($address) && isset($name)) { + $address = [$address => $name]; } if (!$this->setHeaderFieldModel('Sender', (array) $address)) { @@ -212,8 +206,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setFrom($addresses, $name = null) { - if (!is_array($addresses) && isset($name)) { - $addresses = array($addresses => $name); + if (!\is_array($addresses) && isset($name)) { + $addresses = [$addresses => $name]; } if (!$this->setHeaderFieldModel('From', (array) $addresses)) { @@ -266,8 +260,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setReplyTo($addresses, $name = null) { - if (!is_array($addresses) && isset($name)) { - $addresses = array($addresses => $name); + if (!\is_array($addresses) && isset($name)) { + $addresses = [$addresses => $name]; } if (!$this->setHeaderFieldModel('Reply-To', (array) $addresses)) { @@ -321,8 +315,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setTo($addresses, $name = null) { - if (!is_array($addresses) && isset($name)) { - $addresses = array($addresses => $name); + if (!\is_array($addresses) && isset($name)) { + $addresses = [$addresses => $name]; } if (!$this->setHeaderFieldModel('To', (array) $addresses)) { @@ -373,8 +367,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setCc($addresses, $name = null) { - if (!is_array($addresses) && isset($name)) { - $addresses = array($addresses => $name); + if (!\is_array($addresses) && isset($name)) { + $addresses = [$addresses => $name]; } if (!$this->setHeaderFieldModel('Cc', (array) $addresses)) { @@ -425,8 +419,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setBcc($addresses, $name = null) { - if (!is_array($addresses) && isset($name)) { - $addresses = array($addresses => $name); + if (!\is_array($addresses) && isset($name)) { + $addresses = [$addresses => $name]; } if (!$this->setHeaderFieldModel('Bcc', (array) $addresses)) { @@ -457,13 +451,13 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function setPriority($priority) { - $priorityMap = array( + $priorityMap = [ self::PRIORITY_HIGHEST => 'Highest', self::PRIORITY_HIGH => 'High', self::PRIORITY_NORMAL => 'Normal', self::PRIORITY_LOW => 'Low', self::PRIORITY_LOWEST => 'Lowest', - ); + ]; $pMapKeys = array_keys($priorityMap); if ($priority > max($pMapKeys)) { $priority = max($pMapKeys); @@ -493,7 +487,7 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart '%[1-5]' ); - return isset($priority) ? $priority : 3; + return $priority ?? 3; } /** @@ -526,13 +520,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart /** * Attach a {@link Swift_Mime_SimpleMimeEntity} such as an Attachment or MimePart. * - * @param Swift_Mime_SimpleMimeEntity $entity - * * @return $this */ public function attach(Swift_Mime_SimpleMimeEntity $entity) { - $this->setChildren(array_merge($this->getChildren(), array($entity))); + $this->setChildren(array_merge($this->getChildren(), [$entity])); return $this; } @@ -540,13 +532,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart /** * Remove an already attached entity. * - * @param Swift_Mime_SimpleMimeEntity $entity - * * @return $this */ public function detach(Swift_Mime_SimpleMimeEntity $entity) { - $newChildren = array(); + $newChildren = []; foreach ($this->getChildren() as $child) { if ($entity !== $child) { $newChildren[] = $child; @@ -559,9 +549,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart /** * Attach a {@link Swift_Mime_SimpleMimeEntity} and return it's CID source. - * This method should be used when embedding images or other data in a message. * - * @param Swift_Mime_SimpleMimeEntity $entity + * This method should be used when embedding images or other data in a message. * * @return string */ @@ -579,8 +568,8 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart */ public function toString() { - if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') { - $this->setChildren(array_merge(array($this->becomeMimePart()), $children)); + if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) { + $this->setChildren(array_merge([$this->becomeMimePart()], $children)); $string = parent::toString(); $this->setChildren($children); } else { @@ -604,13 +593,11 @@ class Swift_Mime_SimpleMessage extends Swift_Mime_MimePart /** * Write this message to a {@link Swift_InputByteStream}. - * - * @param Swift_InputByteStream $is */ public function toByteStream(Swift_InputByteStream $is) { - if (count($children = $this->getChildren()) > 0 && $this->getBody() != '') { - $this->setChildren(array_merge(array($this->becomeMimePart()), $children)); + if (\count($children = $this->getChildren()) > 0 && '' != $this->getBody()) { + $this->setChildren(array_merge([$this->becomeMimePart()], $children)); parent::toByteStream($is); $this->setChildren($children); } else { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php index 980f1cedc1c..03eaf472dd5 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Mime/SimpleMimeEntity.php @@ -43,14 +43,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M private $boundary; /** Mime types to be used based on the nesting level */ - private $compositeRanges = array( - 'multipart/mixed' => array(self::LEVEL_TOP, self::LEVEL_MIXED), - 'multipart/alternative' => array(self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE), - 'multipart/related' => array(self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED), - ); + private $compositeRanges = [ + 'multipart/mixed' => [self::LEVEL_TOP, self::LEVEL_MIXED], + 'multipart/alternative' => [self::LEVEL_MIXED, self::LEVEL_ALTERNATIVE], + 'multipart/related' => [self::LEVEL_ALTERNATIVE, self::LEVEL_RELATED], + ]; /** A set of filter rules to define what level an entity should be nested at */ - private $compoundLevelFilters = array(); + private $compoundLevelFilters = []; /** The nesting level of this entity */ private $nestingLevel = self::LEVEL_ALTERNATIVE; @@ -59,20 +59,20 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M private $cache; /** Direct descendants of this entity */ - private $immediateChildren = array(); + private $immediateChildren = []; /** All descendants of this entity */ - private $children = array(); + private $children = []; /** The maximum line length of the body of this entity */ private $maxLineLength = 78; /** The order in which alternative mime types should appear */ - private $alternativePartOrder = array( + private $alternativePartOrder = [ 'text/plain' => 1, 'text/html' => 2, 'multipart/related' => 3, - ); + ]; /** The CID of this entity */ private $id; @@ -84,20 +84,15 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M /** * Create a new SimpleMimeEntity with $headers, $encoder and $cache. - * - * @param Swift_Mime_SimpleHeaderSet $headers - * @param Swift_Mime_ContentEncoder $encoder - * @param Swift_KeyCache $cache - * @param Swift_IdGenerator $idGenerator */ public function __construct(Swift_Mime_SimpleHeaderSet $headers, Swift_Mime_ContentEncoder $encoder, Swift_KeyCache $cache, Swift_IdGenerator $idGenerator) { - $this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)); + $this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values $this->cache = $cache; $this->headers = $headers; $this->idGenerator = $idGenerator; $this->setEncoder($encoder); - $this->headers->defineOrdering(array('Content-Type', 'Content-Transfer-Encoding')); + $this->headers->defineOrdering(['Content-Type', 'Content-Transfer-Encoding']); // This array specifies that, when the entire MIME document contains // $compoundLevel, then for each child within $level, if its Content-Type @@ -112,14 +107,14 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M // ) // ) - $this->compoundLevelFilters = array( - (self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => array( - self::LEVEL_ALTERNATIVE => array( + $this->compoundLevelFilters = [ + (self::LEVEL_ALTERNATIVE + self::LEVEL_RELATED) => [ + self::LEVEL_ALTERNATIVE => [ 'text/plain' => self::LEVEL_ALTERNATIVE, 'text/html' => self::LEVEL_RELATED, - ), - ), - ); + ], + ], + ]; $this->id = $this->idGenerator->generateId(); } @@ -168,6 +163,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M return $this->getHeaderFieldModel('Content-Type'); } + /** + * Get the Body Content-type of this entity. + * + * @return string + */ + public function getBodyContentType() + { + return $this->userContentType; + } + /** * Set the Content-type of this entity. * @@ -293,16 +298,16 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M public function setChildren(array $children, $compoundLevel = null) { // TODO: Try to refactor this logic - $compoundLevel = isset($compoundLevel) ? $compoundLevel : $this->getCompoundLevel($children); - $immediateChildren = array(); - $grandchildren = array(); + $compoundLevel = $compoundLevel ?? $this->getCompoundLevel($children); + $immediateChildren = []; + $grandchildren = []; $newContentType = $this->userContentType; foreach ($children as $child) { $level = $this->getNeededChildLevel($child, $compoundLevel); if (empty($immediateChildren)) { //first iteration - $immediateChildren = array($child); + $immediateChildren = [$child]; } else { $nextLevel = $this->getNeededChildLevel($immediateChildren[0], $compoundLevel); if ($nextLevel == $level) { @@ -311,7 +316,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M // Re-assign immediateChildren to grandchildren $grandchildren = array_merge($grandchildren, $immediateChildren); // Set new children - $immediateChildren = array($child); + $immediateChildren = [$child]; } else { $grandchildren[] = $child; } @@ -375,7 +380,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M } $this->body = $body; - if (isset($contentType)) { + if (null !== $contentType) { $this->setContentType($contentType); } @@ -395,8 +400,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M /** * Set the encoder used for the body of this entity. * - * @param Swift_Mime_ContentEncoder $encoder - * * @return $this */ public function setEncoder(Swift_Mime_ContentEncoder $encoder) @@ -420,7 +423,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M public function getBoundary() { if (!isset($this->boundary)) { - $this->boundary = '_=_swift_'.time().'_'.md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)).'_=_'; + $this->boundary = '_=_swift_'.time().'_'.bin2hex(random_bytes(16)).'_=_'; } return $this->boundary; @@ -457,8 +460,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M /** * Receive notification that the encoder of this entity or a parent entity * has changed. - * - * @param Swift_Mime_ContentEncoder $encoder */ public function encoderChanged(Swift_Mime_ContentEncoder $encoder) { @@ -522,8 +523,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M /** * Write this entire entity to a {@see Swift_InputByteStream}. - * - * @param Swift_InputByteStream */ public function toByteStream(Swift_InputByteStream $is) { @@ -535,8 +534,6 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M /** * Write this entire entity to a {@link Swift_InputByteStream}. - * - * @param Swift_InputByteStream */ protected function bodyToByteStream(Swift_InputByteStream $is) { @@ -637,7 +634,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M */ protected function fixHeaders() { - if (count($this->immediateChildren)) { + if (\count($this->immediateChildren)) { $this->setHeaderParameter('Content-Type', 'boundary', $this->getBoundary() ); @@ -726,7 +723,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M private function getNeededChildLevel($child, $compoundLevel) { - $filter = array(); + $filter = []; foreach ($this->compoundLevelFilters as $bitmask => $rules) { if (($compoundLevel & $bitmask) === $bitmask) { $filter = $rules + $filter; @@ -734,7 +731,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M } $realLevel = $child->getNestingLevel(); - $lowercaseType = strtolower($child->getContentType()); + $lowercaseType = strtolower($child->getContentType() ?? ''); if (isset($filter[$realLevel]) && isset($filter[$realLevel][$lowercaseType])) { return $filter[$realLevel][$lowercaseType]; @@ -769,7 +766,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M $shouldSort = false; foreach ($this->immediateChildren as $child) { // NOTE: This include alternative parts moved into a related part - if ($child->getNestingLevel() == self::LEVEL_ALTERNATIVE) { + if (self::LEVEL_ALTERNATIVE == $child->getNestingLevel()) { $shouldSort = true; break; } @@ -778,13 +775,13 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M // Sort in order of preference, if there is one if ($shouldSort) { // Group the messages by order of preference - $sorted = array(); + $sorted = []; foreach ($this->immediateChildren as $child) { $type = $child->getContentType(); - $level = array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1; + $level = \array_key_exists($type, $this->alternativePartOrder) ? $this->alternativePartOrder[$type] : max($this->alternativePartOrder) + 1; if (empty($sorted[$level])) { - $sorted[$level] = array(); + $sorted[$level] = []; } $sorted[$level][] = $child; @@ -792,7 +789,7 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M ksort($sorted); - $this->immediateChildren = array_reduce($sorted, 'array_merge', array()); + $this->immediateChildren = array_reduce($sorted, 'array_merge', []); } } @@ -813,11 +810,17 @@ class Swift_Mime_SimpleMimeEntity implements Swift_Mime_CharsetObserver, Swift_M { $this->headers = clone $this->headers; $this->encoder = clone $this->encoder; - $this->cacheKey = md5(getmypid().'.'.time().'.'.uniqid(mt_rand(), true)); - $children = array(); + $this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values + $children = []; foreach ($this->children as $pos => $child) { $children[$pos] = clone $child; } $this->setChildren($children); } + + public function __wakeup() + { + $this->cacheKey = bin2hex(random_bytes(16)); // set 32 hex values + $this->cache = new Swift_KeyCache_ArrayKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream()); + } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/MimePart.php b/htdocs/includes/swiftmailer/lib/classes/Swift/MimePart.php index 8fa0cbebcd2..ea97619ad69 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/MimePart.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/MimePart.php @@ -26,8 +26,8 @@ class Swift_MimePart extends Swift_Mime_MimePart */ public function __construct($body = null, $contentType = null, $charset = null) { - call_user_func_array( - array($this, 'Swift_Mime_MimePart::__construct'), + \call_user_func_array( + [$this, 'Swift_Mime_MimePart::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('mime.part') ); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/NullTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/NullTransport.php index a580dfbefb6..e44b7af982f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/NullTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/NullTransport.php @@ -17,8 +17,8 @@ class Swift_NullTransport extends Swift_Transport_NullTransport { public function __construct() { - call_user_func_array( - array($this, 'Swift_Transport_NullTransport::__construct'), + \call_user_func_array( + [$this, 'Swift_Transport_NullTransport::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('transport.null') ); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php index 06b3109e62c..5b1d7deefff 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/AntiFloodPlugin.php @@ -99,8 +99,6 @@ class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_ /** * Invoked immediately before the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { @@ -108,8 +106,6 @@ class Swift_Plugins_AntiFloodPlugin implements Swift_Events_SendListener, Swift_ /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php index af060a99cc3..36451f44f1f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/BandwidthMonitorPlugin.php @@ -30,7 +30,7 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, private $in = 0; /** Bound byte streams */ - private $mirrors = array(); + private $mirrors = []; /** * Not used. @@ -41,8 +41,6 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { @@ -52,24 +50,20 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, /** * Invoked immediately following a command being sent. - * - * @param Swift_Events_CommandEvent $evt */ public function commandSent(Swift_Events_CommandEvent $evt) { $command = $evt->getCommand(); - $this->out += strlen($command); + $this->out += \strlen($command); } /** * Invoked immediately following a response coming back. - * - * @param Swift_Events_ResponseEvent $evt */ public function responseReceived(Swift_Events_ResponseEvent $evt) { $response = $evt->getResponse(); - $this->in += strlen($response); + $this->in += \strlen($response); } /** @@ -79,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); } @@ -97,8 +91,6 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, * * The stream acts as an observer, receiving all data that is written. * All {@link write()} and {@link flushBuffers()} operations will be mirrored. - * - * @param Swift_InputByteStream $is */ public function bind(Swift_InputByteStream $is) { @@ -111,8 +103,6 @@ class Swift_Plugins_BandwidthMonitorPlugin implements Swift_Events_SendListener, * If $is is not bound, no errors will be raised. * If the stream currently has any buffered data it will be written to $is * before unbinding occurs. - * - * @param Swift_InputByteStream $is */ public function unbind(Swift_InputByteStream $is) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/DecoratorPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/DecoratorPlugin.php index 745ee879003..93124c9a5f4 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/DecoratorPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/DecoratorPlugin.php @@ -23,10 +23,10 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_ private $originalBody; /** The original headers of the message, before replacements */ - private $originalHeaders = array(); + private $originalHeaders = []; /** Bodies of children before they are replaced */ - private $originalChildBodies = array(); + private $originalChildBodies = []; /** The Message that was last replaced */ private $lastMessage; @@ -74,8 +74,6 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_ /** * Invoked immediately before the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { @@ -98,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)) { - $bodyReplaced = array(); + 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); } @@ -159,13 +157,11 @@ class Swift_Plugins_DecoratorPlugin implements Swift_Events_SendListener, Swift_ return $this->replacements->getReplacementsFor($address); } - return isset($this->replacements[$address]) ? $this->replacements[$address] : null; + return $this->replacements[$address] ?? null; } /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { @@ -182,21 +178,21 @@ 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()]); } } - $this->originalHeaders = array(); + $this->originalHeaders = []; } if (!empty($this->originalChildBodies)) { $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]); } } - $this->originalChildBodies = array(); + $this->originalChildBodies = []; } $this->lastMessage = null; } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ImpersonatePlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ImpersonatePlugin.php index b975d36b858..3f4dbbfa40f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ImpersonatePlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ImpersonatePlugin.php @@ -34,8 +34,6 @@ class Swift_Plugins_ImpersonatePlugin implements Swift_Events_SendListener /** * Invoked immediately before the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { @@ -51,8 +49,6 @@ class Swift_Plugins_ImpersonatePlugin implements Swift_Events_SendListener /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/LoggerPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/LoggerPlugin.php index 7ddf1fd16db..e183749b7ec 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/LoggerPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/LoggerPlugin.php @@ -20,8 +20,6 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ /** * Create a new LoggerPlugin using $logger. - * - * @param Swift_Plugins_Logger $logger */ public function __construct(Swift_Plugins_Logger $logger) { @@ -58,8 +56,6 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ /** * Invoked immediately following a command being sent. - * - * @param Swift_Events_CommandEvent $evt */ public function commandSent(Swift_Events_CommandEvent $evt) { @@ -69,8 +65,6 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ /** * Invoked immediately following a response coming back. - * - * @param Swift_Events_ResponseEvent $evt */ public function responseReceived(Swift_Events_ResponseEvent $evt) { @@ -80,52 +74,42 @@ class Swift_Plugins_LoggerPlugin implements Swift_Events_CommandListener, Swift_ /** * Invoked just before a Transport is started. - * - * @param Swift_Events_TransportChangeEvent $evt */ public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) { - $transportName = get_class($evt->getSource()); + $transportName = \get_class($evt->getSource()); $this->logger->add(sprintf('++ Starting %s', $transportName)); } /** * Invoked immediately after the Transport is started. - * - * @param Swift_Events_TransportChangeEvent $evt */ public function transportStarted(Swift_Events_TransportChangeEvent $evt) { - $transportName = get_class($evt->getSource()); + $transportName = \get_class($evt->getSource()); $this->logger->add(sprintf('++ %s started', $transportName)); } /** * Invoked just before a Transport is stopped. - * - * @param Swift_Events_TransportChangeEvent $evt */ public function beforeTransportStopped(Swift_Events_TransportChangeEvent $evt) { - $transportName = get_class($evt->getSource()); + $transportName = \get_class($evt->getSource()); $this->logger->add(sprintf('++ Stopping %s', $transportName)); } /** * Invoked immediately after the Transport is stopped. - * - * @param Swift_Events_TransportChangeEvent $evt */ public function transportStopped(Swift_Events_TransportChangeEvent $evt) { - $transportName = get_class($evt->getSource()); + $transportName = \get_class($evt->getSource()); $this->logger->add(sprintf('++ %s stopped', $transportName)); } /** * Invoked as a TransportException is thrown in the Transport system. - * - * @param Swift_Events_TransportExceptionEvent $evt */ public function exceptionThrown(Swift_Events_TransportExceptionEvent $evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php index 186b6b41bcd..6f595adaa4d 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Loggers/ArrayLogger.php @@ -20,7 +20,7 @@ class Swift_Plugins_Loggers_ArrayLogger implements Swift_Plugins_Logger * * @var array */ - private $log = array(); + private $log = []; /** * Max size of the log. @@ -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); } } @@ -57,7 +57,7 @@ class Swift_Plugins_Loggers_ArrayLogger implements Swift_Plugins_Logger */ public function clear() { - $this->log = array(); + $this->log = []; } /** diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/MessageLogger.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/MessageLogger.php index 5ff1d9321c0..39c48ed18f5 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/MessageLogger.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/MessageLogger.php @@ -16,19 +16,19 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener { /** - * @var Swift_Mime_Message[] + * @var Swift_Mime_SimpleMessage[] */ private $messages; public function __construct() { - $this->messages = array(); + $this->messages = []; } /** * Get the message list. * - * @return Swift_Mime_Message[] + * @return Swift_Mime_SimpleMessage[] */ public function getMessages() { @@ -42,7 +42,7 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener */ public function countMessages() { - return count($this->messages); + return \count($this->messages); } /** @@ -50,13 +50,11 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener */ public function clear() { - $this->messages = array(); + $this->messages = []; } /** * Invoked immediately before the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { @@ -65,8 +63,6 @@ class Swift_Plugins_MessageLogger implements Swift_Events_SendListener /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php index c19403aec61..9448594090b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/PopBeforeSmtpPlugin.php @@ -45,7 +45,8 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Create a new PopBeforeSmtpPlugin for $host and $port. * - * @param string $host + * @param string $host Hostname or IP. Literal IPv6 addresses should be + * wrapped in square brackets. * @param int $port * @param string $crypto as "tls" or "ssl" */ @@ -59,8 +60,6 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Set a Pop3Connection to delegate to instead of connecting directly. * - * @param Swift_Plugins_Pop_Pop3Connection $connection - * * @return $this */ public function setConnection(Swift_Plugins_Pop_Pop3Connection $connection) @@ -72,8 +71,6 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Bind this plugin to a specific SMTP transport instance. - * - * @param Swift_Transport */ public function bindSmtp(Swift_Transport $smtp) { @@ -135,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); @@ -167,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; } @@ -177,8 +168,6 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL /** * Invoked just before a Transport is started. - * - * @param Swift_Events_TransportChangeEvent $evt */ public function beforeTransportStarted(Swift_Events_TransportChangeEvent $evt) { @@ -216,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); @@ -234,17 +219,15 @@ class Swift_Plugins_PopBeforeSmtpPlugin implements Swift_Events_TransportChangeL private function assertOk($response) { - if (substr($response, 0, 3) != '+OK') { - throw new Swift_Plugins_Pop_Pop3Exception( - sprintf('POP3 command failed [%s]', trim($response)) - ); + if ('+OK' != substr($response, 0, 3)) { + 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; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/RedirectingPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/RedirectingPlugin.php index 8d797dd117b..f7373b2424c 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/RedirectingPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/RedirectingPlugin.php @@ -27,15 +27,14 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener * * @var array */ - private $whitelist = array(); + private $whitelist = []; /** * Create a new RedirectingPlugin. * * @param mixed $recipient - * @param array $whitelist */ - public function __construct($recipient, array $whitelist = array()) + public function __construct($recipient, array $whitelist = []) { $this->recipient = $recipient; $this->whitelist = $whitelist; @@ -63,8 +62,6 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener /** * Set a list of regular expressions to whitelist certain recipients. - * - * @param array $whitelist */ public function setWhitelist(array $whitelist) { @@ -83,8 +80,6 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener /** * Invoked immediately before the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { @@ -113,11 +108,11 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener // Add each hard coded recipient $to = $message->getTo(); if (null === $to) { - $to = array(); + $to = []; } foreach ((array) $this->recipient as $recipient) { - if (!array_key_exists($recipient, $to)) { + if (!\array_key_exists($recipient, $to)) { $message->addTo($recipient); } } @@ -126,8 +121,7 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener /** * Filter header set against a whitelist of regular expressions. * - * @param Swift_Mime_SimpleHeaderSet $headerSet - * @param string $type + * @param string $type */ private function filterHeaderSet(Swift_Mime_SimpleHeaderSet $headerSet, $type) { @@ -139,13 +133,11 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener /** * Filtered list of addresses => name pairs. * - * @param array $recipients - * * @return array */ private function filterNameAddresses(array $recipients) { - $filtered = array(); + $filtered = []; foreach ($recipients as $address => $name) { if ($this->isWhitelisted($address)) { @@ -159,13 +151,11 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener /** * Matches address against whitelist of regular expressions. * - * @param $recipient - * * @return bool */ protected function isWhitelisted($recipient) { - if (in_array($recipient, (array) $this->recipient)) { + if (\in_array($recipient, (array) $this->recipient)) { return true; } @@ -180,8 +170,6 @@ class Swift_Plugins_RedirectingPlugin implements Swift_Events_SendListener /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporter.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporter.php index 3a2b6657c09..b8818339722 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporter.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporter.php @@ -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); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ReporterPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ReporterPlugin.php index 5ffca24c61c..c4a016520f6 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ReporterPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ReporterPlugin.php @@ -24,8 +24,6 @@ class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener /** * Create a new ReporterPlugin using $reporter. - * - * @param Swift_Plugins_Reporter $reporter */ public function __construct(Swift_Plugins_Reporter $reporter) { @@ -41,21 +39,19 @@ class Swift_Plugins_ReporterPlugin implements Swift_Events_SendListener /** * Invoked immediately after the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { $message = $evt->getMessage(); $failures = array_flip($evt->getFailedRecipients()); foreach ((array) $message->getTo() as $address => $null) { - $this->reporter->notify($message, $address, (array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); + $this->reporter->notify($message, $address, (\array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); } foreach ((array) $message->getCc() as $address => $null) { - $this->reporter->notify($message, $address, (array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); + $this->reporter->notify($message, $address, (\array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); } foreach ((array) $message->getBcc() as $address => $null) { - $this->reporter->notify($message, $address, (array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); + $this->reporter->notify($message, $address, (\array_key_exists($address, $failures) ? Swift_Plugins_Reporter::RESULT_FAIL : Swift_Plugins_Reporter::RESULT_PASS)); } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php index 67c117ac7c2..249cffbde7b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HitReporter.php @@ -20,16 +20,15 @@ class Swift_Plugins_Reporters_HitReporter implements Swift_Plugins_Reporter * * @var array */ - private $failures = array(); + private $failures = []; - private $failures_cache = array(); + private $failures_cache = []; /** * 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) { @@ -54,6 +53,6 @@ class Swift_Plugins_Reporters_HitReporter implements Swift_Plugins_Reporter */ public function clear() { - $this->failures = $this->failures_cache = array(); + $this->failures = $this->failures_cache = []; } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php index 525eef570a9..1cfc3f974f8 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/Reporters/HtmlReporter.php @@ -18,9 +18,8 @@ class Swift_Plugins_Reporters_HtmlReporter implements Swift_Plugins_Reporter /** * Notifies this ReportNotifier that $address failed or succeeded. * - * @param Swift_Mime_SimpleMessage $message - * @param string $address - * @param int $result from {@see RESULT_PASS, RESULT_FAIL} + * @param string $address + * @param int $result from {@see RESULT_PASS, RESULT_FAIL} */ public function notify(Swift_Mime_SimpleMessage $message, $address, $result) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ThrottlerPlugin.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ThrottlerPlugin.php index 77c2e8db6ec..83d3044927f 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ThrottlerPlugin.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Plugins/ThrottlerPlugin.php @@ -72,7 +72,7 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin * Create a new ThrottlerPlugin. * * @param int $rate - * @param int $mode, defaults to {@link BYTES_PER_MINUTE} + * @param int $mode defaults to {@link BYTES_PER_MINUTE} * @param Swift_Plugins_Sleeper $sleeper (only needed in testing) * @param Swift_Plugins_Timer $timer (only needed in testing) */ @@ -86,8 +86,6 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin /** * Invoked immediately before the Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(Swift_Events_SendEvent $evt) { @@ -119,8 +117,6 @@ class Swift_Plugins_ThrottlerPlugin extends Swift_Plugins_BandwidthMonitorPlugin /** * Invoked when a Message is sent. - * - * @param Swift_Events_SendEvent $evt */ public function sendPerformed(Swift_Events_SendEvent $evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Preferences.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Preferences.php index 79eafde9ad9..16103e11031 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Preferences.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Preferences.php @@ -92,7 +92,7 @@ class Swift_Preferences Swift_DependencyContainer::getInstance() ->register('mime.qpcontentencoder') ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder') - ->withDependencies(array('mime.charstream', 'mime.bytecanonicalizer')) + ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer']) ->addConstructorValue($dotEscape); return $this; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/SendmailTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/SendmailTransport.php index c129281b347..3c756436cc8 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/SendmailTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/SendmailTransport.php @@ -22,8 +22,8 @@ class Swift_SendmailTransport extends Swift_Transport_SendmailTransport */ public function __construct($command = '/usr/sbin/sendmail -bs') { - call_user_func_array( - array($this, 'Swift_Transport_SendmailTransport::__construct'), + \call_user_func_array( + [$this, 'Swift_Transport_SendmailTransport::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('transport.sendmail') ); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signer.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signer.php index 2d8176d905c..26c5e285c03 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signer.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signer.php @@ -11,7 +11,6 @@ /** * Base Class of Signer Infrastructure. * - * * @author Xavier De Cock */ interface Swift_Signer diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/BodySigner.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/BodySigner.php index 8e66e18f4e0..b25c427af83 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/BodySigner.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/BodySigner.php @@ -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); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php index a88daa19815..ec82dc05663 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php @@ -66,7 +66,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner * * @var array */ - protected $ignoredHeaders = array('return-path' => true); + protected $ignoredHeaders = ['return-path' => true]; /** * Signer identity. @@ -124,14 +124,14 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner * * @var array */ - protected $signedHeaders = array(); + protected $signedHeaders = []; /** * If debugHeaders is set store debugData here. * - * @var string + * @var string[] */ - private $debugHeadersData = ''; + private $debugHeadersData = []; /** * Stores the bodyHash. @@ -163,7 +163,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner private $bodyCanonLine = ''; - private $bound = array(); + private $bound = []; /** * Constructor. @@ -190,7 +190,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner public function reset() { $this->headerHash = null; - $this->signedHeaders = array(); + $this->signedHeaders = []; $this->bodyHash = null; $this->bodyHashHandler = null; $this->bodyCanonIgnoreStart = 2; @@ -236,10 +236,9 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * Attach $is to this stream. + * * The stream acts as an observer, receiving all data that is written. * All {@link write()} and {@link flushBuffers()} operations will be mirrored. - * - * @param Swift_InputByteStream $is */ public function bind(Swift_InputByteStream $is) { @@ -251,11 +250,10 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * Remove an already bound stream. + * * If $is is not bound, no errors will be raised. * If the stream currently has any buffered data it will be written to $is * before unbinding occurs. - * - * @param Swift_InputByteStream $is */ public function unbind(Swift_InputByteStream $is) { @@ -297,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; @@ -317,7 +315,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner */ public function setBodyCanon($canon) { - if ($canon == 'relaxed') { + if ('relaxed' == $canon) { $this->bodyCanon = 'relaxed'; } else { $this->bodyCanon = 'simple'; @@ -335,7 +333,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner */ public function setHeaderCanon($canon) { - if ($canon == 'relaxed') { + if ('relaxed' == $canon) { $this->headerCanon = 'relaxed'; } else { $this->headerCanon = 'simple'; @@ -367,10 +365,10 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner */ public function setBodySignedLen($len) { - if ($len === true) { + if (true === $len) { $this->showLen = true; $this->maxLen = PHP_INT_MAX; - } elseif ($len === false) { + } elseif (false === $len) { $this->showLen = false; $this->maxLen = PHP_INT_MAX; } else { @@ -456,9 +454,9 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner public function getAlteredHeaders() { if ($this->debugHeaders) { - return array('DKIM-Signature', 'X-DebugHash'); + return ['DKIM-Signature', 'X-DebugHash']; } else { - return array('DKIM-Signature'); + return ['DKIM-Signature']; } } @@ -471,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; } @@ -479,8 +477,6 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * Set the headers to sign. * - * @param Swift_Mime_SimpleHeaderSet $headers - * * @return Swift_Signers_DKIMSigner */ public function setHeaders(Swift_Mime_SimpleHeaderSet $headers) @@ -490,11 +486,11 @@ 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) { - if ($header->getFieldBody() != '') { + if ('' != $header->getFieldBody()) { $this->addHeader($header->toString()); $this->signedHeaders[] = $header->getFieldName(); } @@ -509,32 +505,30 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner /** * Add the signature to the given Headers. * - * @param Swift_Mime_SimpleHeaderSet $headers - * * @return Swift_Signers_DKIMSigner */ public function addSignature(Swift_Mime_SimpleHeaderSet $headers) { // Prepare the DKIM-Signature - $params = array('v' => '1', 'a' => $this->hashAlgorithm, 'bh' => base64_encode($this->bodyHash), 'd' => $this->domainName, 'h' => implode(': ', $this->signedHeaders), 'i' => $this->signerIdentity, 's' => $this->selector); - if ($this->bodyCanon != 'simple') { + $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 ($this->headerCanon != 'simple') { + } elseif ('simple' != $this->headerCanon) { $params['c'] = $this->headerCanon; } if ($this->showLen) { $params['l'] = $this->bodyLen; } - if ($this->signatureTimestamp === true) { + if (true === $this->signatureTimestamp) { $params['t'] = time(); - if ($this->signatureExpiration !== false) { + if (false !== $this->signatureExpiration) { $params['x'] = $params['t'] + $this->signatureExpiration; } } else { - if ($this->signatureTimestamp !== false) { + if (false !== $this->signatureTimestamp) { $params['t'] = $this->signatureTimestamp; } - if ($this->signatureExpiration !== false) { + if (false !== $this->signatureExpiration) { $params['x'] = $this->signatureExpiration; } } @@ -550,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; } @@ -571,6 +565,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner $value = str_replace("\r\n", '', $exploded[1]); $value = preg_replace("/[ \t][ \t]+/", ' ', $value); $header = $name.':'.trim($value).($is_sig ? '' : "\r\n"); + // no break case 'simple': // Nothing to do } @@ -579,9 +574,9 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner protected function canonicalizeBody($string) { - $len = strlen($string); + $len = \strlen($string); $canon = ''; - $method = ($this->bodyCanon == 'relaxed'); + $method = ('relaxed' == $this->bodyCanon); for ($i = 0; $i < $len; ++$i) { if ($this->bodyCanonIgnoreStart > 0) { --$this->bodyCanonIgnoreStart; @@ -592,11 +587,11 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner $this->bodyCanonLastChar = "\r"; break; case "\n": - if ($this->bodyCanonLastChar == "\r") { + if ("\r" == $this->bodyCanonLastChar) { if ($method) { $this->bodyCanonSpace = false; } - if ($this->bodyCanonLine == '') { + if ('' == $this->bodyCanonLine) { ++$this->bodyCanonEmptyCounter; } else { $this->bodyCanonLine = ''; @@ -613,6 +608,7 @@ class Swift_Signers_DKIMSigner implements Swift_Signers_HeaderSigner $this->bodyCanonSpace = true; break; } + // no break default: if ($this->bodyCanonEmptyCounter > 0) { $canon .= str_repeat("\r\n", $this->bodyCanonEmptyCounter); @@ -633,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); @@ -641,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; @@ -653,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; } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DomainKeySigner.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DomainKeySigner.php index 40654987f9b..5e2b67b6520 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DomainKeySigner.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/DomainKeySigner.php @@ -55,7 +55,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * * @var array */ - protected $ignoredHeaders = array(); + protected $ignoredHeaders = []; /** * Signer identity. @@ -77,7 +77,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner * * @var array */ - private $signedHeaders = array(); + private $signedHeaders = []; /** * Stores the signature header. @@ -93,8 +93,6 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner */ private $hashHandler; - private $hash; - private $canonData = ''; private $bodyCanonEmptyCounter = 0; @@ -107,7 +105,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner private $bodyCanonLine = ''; - private $bound = array(); + private $bound = []; /** * Constructor. @@ -131,7 +129,6 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner */ public function reset() { - $this->hash = null; $this->hashHandler = null; $this->bodyCanonIgnoreStart = 2; $this->bodyCanonEmptyCounter = 0; @@ -185,11 +182,10 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner /** * Attach $is to this stream. + * * The stream acts as an observer, receiving all data that is written. * All {@link write()} and {@link flushBuffers()} operations will be mirrored. * - * @param Swift_InputByteStream $is - * * @return $this */ public function bind(Swift_InputByteStream $is) @@ -202,12 +198,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner /** * Remove an already bound stream. + * * If $is is not bound, no errors will be raised. * If the stream currently has any buffered data it will be written to $is * before unbinding occurs. * - * @param Swift_InputByteStream $is - * * @return $this */ public function unbind(Swift_InputByteStream $is) @@ -262,7 +257,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner */ public function setCanon($canon) { - if ($canon == 'nofws') { + if ('nofws' == $canon) { $this->canon = 'nofws'; } else { $this->canon = 'simple'; @@ -322,10 +317,10 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner public function getAlteredHeaders() { if ($this->debugHeaders) { - return array('DomainKey-Signature', 'X-DebugHash'); + return ['DomainKey-Signature', 'X-DebugHash']; } - return array('DomainKey-Signature'); + return ['DomainKey-Signature']; } /** @@ -337,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; } @@ -345,8 +340,6 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner /** * Set the headers to sign. * - * @param Swift_Mime_SimpleHeaderSet $headers - * * @return $this */ public function setHeaders(Swift_Mime_SimpleHeaderSet $headers) @@ -357,11 +350,11 @@ 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) { - if ($header->getFieldBody() != '') { + if ('' != $header->getFieldBody()) { $this->addHeader($header->toString()); $this->signedHeaders[] = $header->getFieldName(); } @@ -377,14 +370,12 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner /** * Add the signature to the given Headers. * - * @param Swift_Mime_SimpleHeaderSet $headers - * * @return $this */ public function addSignature(Swift_Mime_SimpleHeaderSet $headers) { // Prepare the DomainKey-Signature Header - $params = array('a' => $this->hashAlgorithm, 'b' => chunk_split(base64_encode($this->getEncryptedHash()), 73, ' '), 'c' => $this->canon, 'd' => $this->domainName, 'h' => implode(': ', $this->signedHeaders), 'q' => 'dns', 's' => $this->selector); + $params = ['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.'; '; @@ -407,6 +398,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner $value = str_replace("\r\n", '', $exploded[1]); $value = preg_replace("/[ \t][ \t]+/", ' ', $value); $header = $name.':'.trim($value)."\r\n"; + // no break case 'simple': // Nothing to do } @@ -420,9 +412,9 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner protected function canonicalizeBody($string) { - $len = strlen($string); + $len = \strlen($string); $canon = ''; - $nofws = ($this->canon == 'nofws'); + $nofws = ('nofws' == $this->canon); for ($i = 0; $i < $len; ++$i) { if ($this->bodyCanonIgnoreStart > 0) { --$this->bodyCanonIgnoreStart; @@ -433,11 +425,11 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner $this->bodyCanonLastChar = "\r"; break; case "\n": - if ($this->bodyCanonLastChar == "\r") { + if ("\r" == $this->bodyCanonLastChar) { if ($nofws) { $this->bodyCanonSpace = false; } - if ($this->bodyCanonLine == '') { + if ('' == $this->bodyCanonLine) { ++$this->bodyCanonEmptyCounter; } else { $this->bodyCanonLine = ''; @@ -455,6 +447,7 @@ class Swift_Signers_DomainKeySigner implements Swift_Signers_HeaderSigner $this->bodyCanonSpace = true; break; } + // no break default: if ($this->bodyCanonEmptyCounter > 0) { $canon .= str_repeat("\r\n", $this->bodyCanonEmptyCounter); @@ -469,10 +462,9 @@ 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"); } - $this->hash = hash_final($this->hashHandler, true); } private function addToHash($string) diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php index 6104e34f3f5..6f5c20923dc 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php @@ -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); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/OpenDKIMSigner.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/OpenDKIMSigner.php index deb29f575f2..520bcc15e8b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/OpenDKIMSigner.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/OpenDKIMSigner.php @@ -13,6 +13,8 @@ * Takes advantage of pecl extension. * * @author Xavier De Cock + * + * @deprecated since SwiftMailer 6.1.0; use Swift_Signers_DKIMSigner instead. */ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner { @@ -29,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'); } @@ -42,7 +44,7 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner { $header = new Swift_Mime_Headers_OpenDKIMHeader('DKIM-Signature'); $headerVal = $this->dkimHandler->getSignatureHeader(); - if (!$headerVal) { + if (false === $headerVal || \is_int($headerVal)) { throw new Swift_SwiftException('OpenDKIM Error: '.$this->dkimHandler->getError()); } $header->setValue($headerVal); @@ -53,14 +55,10 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner public function setHeaders(Swift_Mime_SimpleHeaderSet $headers) { - $bodyLen = $this->bodyLen; - if (is_bool($bodyLen)) { - $bodyLen = -1; - } - $hash = $this->hashAlgorithm == 'rsa-sha1' ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256; - $bodyCanon = $this->bodyCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; - $headerCanon = $this->headerCanon == 'simple' ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; - $this->dkimHandler = new OpenDKIMSign($this->privateKey, $this->selector, $this->domainName, $headerCanon, $bodyCanon, $hash, $bodyLen); + $hash = 'rsa-sha1' == $this->hashAlgorithm ? OpenDKIMSign::ALG_RSASHA1 : OpenDKIMSign::ALG_RSASHA256; + $bodyCanon = 'simple' == $this->bodyCanon ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; + $headerCanon = 'simple' == $this->headerCanon ? OpenDKIMSign::CANON_SIMPLE : OpenDKIMSign::CANON_RELAXED; + $this->dkimHandler = new OpenDKIMSign($this->privateKey, $this->selector, $this->domainName, $headerCanon, $bodyCanon, $hash, -1); // Hardcode signature Margin for now $this->dkimHandler->setMargin(78); @@ -77,11 +75,11 @@ 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) { - if ($header->getFieldBody() != '') { + if ('' != $header->getFieldBody()) { $htosign = $header->toString(); $this->dkimHandler->header($htosign); $this->signedHeaders[] = $header->getFieldName(); @@ -172,13 +170,13 @@ class Swift_Signers_OpenDKIMSigner extends Swift_Signers_DKIMSigner if (!$this->peclLoaded) { return parent::canonicalizeBody($string); } - if (false && $this->dropFirstLF === true) { - if ($string[0] == "\r" && $string[1] == "\n") { + if (true === $this->dropFirstLF) { + if ("\r" == $string[0] && "\n" == $string[1]) { $string = substr($string, 2); } } $this->dropFirstLF = false; - if (strlen($string)) { + if (\strlen($string)) { $this->dkimHandler->body($string); } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php index e2231151993..3dd3cd05f04 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php @@ -11,9 +11,9 @@ /** * MIME Message Signer used to apply S/MIME Signature/Encryption to a message. * - * * @author Romain-Geissler * @author Sebastiaan Stok + * @author Jan Flora */ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner { @@ -27,6 +27,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner protected $encryptOptions; protected $encryptCipher; protected $extraCerts = null; + protected $wrapFullMessage = false; /** * @var Swift_StreamFilters_StringReplacementFilterFactory @@ -65,7 +66,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * Set the certificate location to use for signing. * - * @see http://www.php.net/manual/en/openssl.pkcs7.flags.php + * @see https://secure.php.net/manual/en/openssl.pkcs7.flags.php * * @param string $certificate * @param string|array $privateKey If the key needs an passphrase use array('file-location', 'passphrase') instead @@ -79,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 { @@ -88,9 +89,7 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner } $this->signOptions = $signOptions; - if (null !== $extraCerts) { - $this->extraCerts = str_replace('\\', '/', realpath($extraCerts)); - } + $this->extraCerts = $extraCerts ? realpath($extraCerts) : null; return $this; } @@ -98,8 +97,8 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner /** * Set the certificate location to use for encryption. * - * @see http://www.php.net/manual/en/openssl.pkcs7.flags.php - * @see http://nl3.php.net/manual/en/openssl.ciphers.php + * @see https://secure.php.net/manual/en/openssl.pkcs7.flags.php + * @see https://secure.php.net/manual/en/openssl.ciphers.php * * @param string|array $recipientCerts Either an single X.509 certificate, or an assoc array of X.509 certificates. * @param int $cipher @@ -108,8 +107,8 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner */ public function setEncryptCertificate($recipientCerts, $cipher = null) { - if (is_array($recipientCerts)) { - $this->encryptCert = array(); + if (\is_array($recipientCerts)) { + $this->encryptCert = []; foreach ($recipientCerts as $cert) { $this->encryptCert[] = 'file://'.str_replace('\\', '/', realpath($cert)); @@ -178,9 +177,27 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner } /** - * Change the Swift_Message to apply the signing. + * Specify whether to wrap the entire MIME message in the S/MIME message. * - * @param Swift_Message $message + * According to RFC5751 section 3.1: + * In order to protect outer, non-content-related message header fields + * (for instance, the "Subject", "To", "From", and "Cc" fields), the + * sending client MAY wrap a full MIME message in a message/rfc822 + * wrapper in order to apply S/MIME security services to these header + * fields. It is up to the receiving client to decide how to present + * this "inner" header along with the unprotected "outer" header. + * + * @param bool $wrap + * + * @return $this + */ + public function setWrapFullMessage($wrap) + { + $this->wrapFullMessage = $wrap; + } + + /** + * Change the Swift_Message to apply the signing. * * @return $this */ @@ -190,17 +207,13 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner return $this; } - // Store the message using ByteStream to a file{1} - // Remove all Children - // Sign file{1}, parse the new MIME headers and set them on the primary MimeEntity - // Set the singed-body as the new body (without boundary) - - $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); - $this->toSMimeByteStream($messageStream, $message); - $message->setEncoder(Swift_DependencyContainer::getInstance()->lookup('mime.rawcontentencoder')); - - $message->setChildren(array()); - $this->streamToMime($messageStream, $message); + if ($this->signThenEncrypt) { + $this->smimeSignMessage($message); + $this->smimeEncryptMessage($message); + } else { + $this->smimeEncryptMessage($message); + $this->smimeSignMessage($message); + } } /** @@ -210,102 +223,303 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner */ public function getAlteredHeaders() { - return array('Content-Type', 'Content-Transfer-Encoding', 'Content-Disposition'); + return ['Content-Type', 'Content-Transfer-Encoding', 'Content-Disposition']; } /** - * @param Swift_InputByteStream $inputStream - * @param Swift_Message $mimeEntity + * Sign a Swift message. */ - protected function toSMimeByteStream(Swift_InputByteStream $inputStream, Swift_Message $message) + protected function smimeSignMessage(Swift_Message $message) { - $mimeEntity = $this->createMessage($message); - $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); - - $mimeEntity->toByteStream($messageStream); - $messageStream->commit(); - - if (null !== $this->signCertificate && null !== $this->encryptCert) { - $temporaryStream = new Swift_ByteStream_TemporaryFileByteStream(); - - if ($this->signThenEncrypt) { - $this->messageStreamToSignedByteStream($messageStream, $temporaryStream); - $this->messageStreamToEncryptedByteStream($temporaryStream, $inputStream); - } else { - $this->messageStreamToEncryptedByteStream($messageStream, $temporaryStream); - $this->messageStreamToSignedByteStream($temporaryStream, $inputStream); - } - } elseif ($this->signCertificate !== null) { - $this->messageStreamToSignedByteStream($messageStream, $inputStream); - } else { - $this->messageStreamToEncryptedByteStream($messageStream, $inputStream); + // If we don't have a certificate we can't sign the message + if (null === $this->signCertificate) { + return; } - } - /** - * @param Swift_Message $message - * - * @return Swift_Message - */ - protected function createMessage(Swift_Message $message) - { - $mimeEntity = new Swift_Message('', $message->getBody(), $message->getContentType(), $message->getCharset()); - $mimeEntity->setChildren($message->getChildren()); + // Work on a clone of the original message + $signMessage = clone $message; + $signMessage->clearSigners(); - $messageHeaders = $mimeEntity->getHeaders(); - $messageHeaders->remove('Message-ID'); - $messageHeaders->remove('Date'); - $messageHeaders->remove('Subject'); - $messageHeaders->remove('MIME-Version'); - $messageHeaders->remove('To'); - $messageHeaders->remove('From'); + if ($this->wrapFullMessage) { + // The original message essentially becomes the body of the new + // wrapped message + $signMessage = $this->wrapMimeMessage($signMessage); + } else { + // Only keep header needed to parse the body correctly + $this->clearAllHeaders($signMessage); + $this->copyHeaders( + $message, + $signMessage, + [ + 'Content-Type', + 'Content-Transfer-Encoding', + 'Content-Disposition', + ] + ); + } - return $mimeEntity; - } - - /** - * @param Swift_FileStream $outputStream - * @param Swift_InputByteStream $inputStream - * - * @throws Swift_IoException - */ - protected function messageStreamToSignedByteStream(Swift_FileStream $outputStream, Swift_InputByteStream $inputStream) - { + // Copy the cloned message into a temporary file stream + $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); + $signMessage->toByteStream($messageStream); + $messageStream->commit(); $signedMessageStream = new Swift_ByteStream_TemporaryFileByteStream(); - $args = array($outputStream->getPath(), $signedMessageStream->getPath(), $this->signCertificate, $this->signPrivateKey, array(), $this->signOptions); - if (null !== $this->extraCerts) { - $args[] = $this->extraCerts; - } - - if (!call_user_func_array('openssl_pkcs7_sign', $args)) { + // Sign the message using openssl + if (!openssl_pkcs7_sign( + $messageStream->getPath(), + $signedMessageStream->getPath(), + $this->signCertificate, + $this->signPrivateKey, + [], + $this->signOptions, + $this->extraCerts + ) + ) { throw new Swift_IoException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string())); } - $this->copyFromOpenSSLOutput($signedMessageStream, $inputStream); + // Parse the resulting signed message content back into the Swift message + // preserving the original headers + $this->parseSSLOutput($signedMessageStream, $message); } /** - * @param Swift_FileStream $outputStream - * @param Swift_InputByteStream $is - * - * @throws Swift_IoException + * Encrypt a Swift message. */ - protected function messageStreamToEncryptedByteStream(Swift_FileStream $outputStream, Swift_InputByteStream $is) + protected function smimeEncryptMessage(Swift_Message $message) { + // If we don't have a certificate we can't encrypt the message + if (null === $this->encryptCert) { + return; + } + + // Work on a clone of the original message + $encryptMessage = clone $message; + $encryptMessage->clearSigners(); + + if ($this->wrapFullMessage) { + // The original message essentially becomes the body of the new + // wrapped message + $encryptMessage = $this->wrapMimeMessage($encryptMessage); + } else { + // Only keep header needed to parse the body correctly + $this->clearAllHeaders($encryptMessage); + $this->copyHeaders( + $message, + $encryptMessage, + [ + 'Content-Type', + 'Content-Transfer-Encoding', + 'Content-Disposition', + ] + ); + } + + // Convert the message content (including headers) to a string + // and place it in a temporary file + $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); + $encryptMessage->toByteStream($messageStream); + $messageStream->commit(); $encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream(); - if (!openssl_pkcs7_encrypt($outputStream->getPath(), $encryptedMessageStream->getPath(), $this->encryptCert, array(), 0, $this->encryptCipher)) { + // Encrypt the message + if (!openssl_pkcs7_encrypt( + $messageStream->getPath(), + $encryptedMessageStream->getPath(), + $this->encryptCert, + [], + 0, + $this->encryptCipher + ) + ) { throw new Swift_IoException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string())); } - $this->copyFromOpenSSLOutput($encryptedMessageStream, $is); + // Parse the resulting signed message content back into the Swift message + // preserving the original headers + $this->parseSSLOutput($encryptedMessageStream, $message); } /** - * @param Swift_OutputByteStream $fromStream - * @param Swift_InputByteStream $toStream + * Copy named headers from one Swift message to another. */ + protected function copyHeaders( + Swift_Message $fromMessage, + Swift_Message $toMessage, + array $headers = [] + ) { + foreach ($headers as $header) { + $this->copyHeader($fromMessage, $toMessage, $header); + } + } + + /** + * Copy a single header from one Swift message to another. + * + * @param string $headerName + */ + protected function copyHeader(Swift_Message $fromMessage, Swift_Message $toMessage, $headerName) + { + $header = $fromMessage->getHeaders()->get($headerName); + if (!$header) { + return; + } + $headers = $toMessage->getHeaders(); + switch ($header->getFieldType()) { + case Swift_Mime_Header::TYPE_TEXT: + $headers->addTextHeader($header->getFieldName(), $header->getValue()); + break; + case Swift_Mime_Header::TYPE_PARAMETERIZED: + $headers->addParameterizedHeader( + $header->getFieldName(), + $header->getValue(), + $header->getParameters() + ); + break; + } + } + + /** + * Remove all headers from a Swift message. + */ + protected function clearAllHeaders(Swift_Message $message) + { + $headers = $message->getHeaders(); + foreach ($headers->listAll() as $header) { + $headers->removeAll($header); + } + } + + /** + * Wraps a Swift_Message in a message/rfc822 MIME part. + * + * @return Swift_MimePart + */ + protected function wrapMimeMessage(Swift_Message $message) + { + // Start by copying the original message into a message stream + $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); + $message->toByteStream($messageStream); + $messageStream->commit(); + + // Create a new MIME part that wraps the original stream + $wrappedMessage = new Swift_MimePart($messageStream, 'message/rfc822'); + $wrappedMessage->setEncoder(new Swift_Mime_ContentEncoder_PlainContentEncoder('7bit')); + + return $wrappedMessage; + } + + protected function parseSSLOutput(Swift_InputByteStream $inputStream, Swift_Message $message) + { + $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); + $this->copyFromOpenSSLOutput($inputStream, $messageStream); + + $this->streamToMime($messageStream, $message); + } + + /** + * Merges an OutputByteStream from OpenSSL to a Swift_Message. + */ + protected function streamToMime(Swift_OutputByteStream $fromStream, Swift_Message $message) + { + // Parse the stream into headers and body + list($headers, $messageStream) = $this->parseStream($fromStream); + + // Get the original message headers + $messageHeaders = $message->getHeaders(); + + // Let the stream determine the headers describing the body content, + // since the body of the original message is overwritten by the body + // coming from the stream. + // These are all content-* headers. + + // Default transfer encoding is 7bit if not set + $encoding = ''; + // Remove all existing transfer encoding headers + $messageHeaders->removeAll('Content-Transfer-Encoding'); + // See whether the stream sets the transfer encoding + if (isset($headers['content-transfer-encoding'])) { + $encoding = $headers['content-transfer-encoding']; + } + + // We use the null content encoder, since the body is already encoded + // according to the transfer encoding specified in the stream + $message->setEncoder(new Swift_Mime_ContentEncoder_NullContentEncoder($encoding)); + + // Set the disposition, if present + if (isset($headers['content-disposition'])) { + $messageHeaders->addTextHeader('Content-Disposition', $headers['content-disposition']); + } + + // Copy over the body from the stream using the content type dictated + // by the stream content + $message->setChildren([]); + $message->setBody($messageStream, $headers['content-type']); + } + + /** + * This message will parse the headers of a MIME email byte stream + * and return an array that contains the headers as an associative + * array and the email body as a string. + * + * @return array + */ + protected function parseStream(Swift_OutputByteStream $emailStream) + { + $bufferLength = 78; + $headerData = ''; + $headerBodySeparator = "\r\n\r\n"; + + $emailStream->setReadPointer(0); + + // Read out the headers section from the stream to a string + while (false !== ($buffer = $emailStream->read($bufferLength))) { + $headerData .= $buffer; + + $headersPosEnd = strpos($headerData, $headerBodySeparator); + + // Stop reading if we found the end of the headers + if (false !== $headersPosEnd) { + break; + } + } + + // Split the header data into lines + $headerData = trim(substr($headerData, 0, $headersPosEnd)); + $headerLines = explode("\r\n", $headerData); + unset($headerData); + + $headers = []; + $currentHeaderName = ''; + + // Transform header lines into an associative array + foreach ($headerLines as $headerLine) { + // Handle headers that span multiple lines + if (false === strpos($headerLine, ':')) { + $headers[$currentHeaderName] .= ' '.trim($headerLine ?? ''); + continue; + } + + $header = explode(':', $headerLine, 2); + $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)); + + while (false !== ($buffer = $emailStream->read($bufferLength))) { + $bodyStream->write($buffer); + } + + $bodyStream->commit(); + + return [$headers, $bodyStream]; + } + protected function copyFromOpenSSLOutput(Swift_OutputByteStream $fromStream, Swift_InputByteStream $toStream) { $bufferLength = 4096; @@ -325,93 +539,4 @@ class Swift_Signers_SMimeSigner implements Swift_Signers_BodySigner $toStream->commit(); } - - /** - * Merges an OutputByteStream to Swift_Message. - * - * @param Swift_OutputByteStream $fromStream - * @param Swift_Message $message - */ - protected function streamToMime(Swift_OutputByteStream $fromStream, Swift_Message $message) - { - $bufferLength = 78; - $headerData = ''; - - $fromStream->setReadPointer(0); - - while (($buffer = $fromStream->read($bufferLength)) !== false) { - $headerData .= $buffer; - - if (false !== strpos($buffer, "\r\n\r\n")) { - break; - } - } - - $headersPosEnd = strpos($headerData, "\r\n\r\n"); - $headerData = trim($headerData); - $headerData = substr($headerData, 0, $headersPosEnd); - $headerLines = explode("\r\n", $headerData); - unset($headerData); - - $headers = array(); - $currentHeaderName = ''; - - foreach ($headerLines as $headerLine) { - // Line separated - if (ctype_space($headerLines[0]) || false === strpos($headerLine, ':')) { - $headers[$currentHeaderName] .= ' '.trim($headerLine); - continue; - } - - $header = explode(':', $headerLine, 2); - $currentHeaderName = strtolower($header[0]); - $headers[$currentHeaderName] = trim($header[1]); - } - - $messageStream = new Swift_ByteStream_TemporaryFileByteStream(); - $messageStream->addFilter($this->replacementFactory->createFilter("\r\n", "\n"), 'CRLF to LF'); - $messageStream->addFilter($this->replacementFactory->createFilter("\n", "\r\n"), 'LF to CRLF'); - - $messageHeaders = $message->getHeaders(); - - // No need to check for 'application/pkcs7-mime', as this is always base64 - if ('multipart/signed;' === substr($headers['content-type'], 0, 17)) { - if (!preg_match('/boundary=("[^"]+"|(?:[^\s]+|$))/is', $headers['content-type'], $contentTypeData)) { - throw new Swift_SwiftException('Failed to find Boundary parameter'); - } - - $boundary = trim($contentTypeData['1'], '"'); - - // Skip the header and CRLF CRLF - $fromStream->setReadPointer($headersPosEnd + 4); - - while (false !== ($buffer = $fromStream->read($bufferLength))) { - $messageStream->write($buffer); - } - - $messageStream->commit(); - - $messageHeaders->remove('Content-Transfer-Encoding'); - $message->setContentType($headers['content-type']); - $message->setBoundary($boundary); - $message->setBody($messageStream); - } else { - $fromStream->setReadPointer($headersPosEnd + 4); - - if (null === $this->headerFactory) { - $this->headerFactory = Swift_DependencyContainer::getInstance()->lookup('mime.headerfactory'); - } - - $message->setContentType($headers['content-type']); - $messageHeaders->set($this->headerFactory->createTextHeader('Content-Transfer-Encoding', $headers['content-transfer-encoding'])); - $messageHeaders->set($this->headerFactory->createTextHeader('Content-Disposition', $headers['content-disposition'])); - - while (false !== ($buffer = $fromStream->read($bufferLength))) { - $messageStream->write($buffer); - } - - $messageStream->commit(); - $message->setBody($messageStream); - } - } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/SmtpTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/SmtpTransport.php index 011c03ab188..56b62323ad7 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/SmtpTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/SmtpTransport.php @@ -23,22 +23,23 @@ class Swift_SmtpTransport extends Swift_Transport_EsmtpTransport { /** - * Create a new SmtpTransport, optionally with $host, $port and $security. - * * @param string $host * @param int $port - * @param string $security + * @param string|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, $security = null) + public function __construct($host = 'localhost', $port = 25, $encryption = null) { - call_user_func_array( - array($this, 'Swift_Transport_EsmtpTransport::__construct'), + \call_user_func_array( + [$this, 'Swift_Transport_EsmtpTransport::__construct'], Swift_DependencyContainer::getInstance() ->createDependenciesFor('transport.smtp') - ); + ); $this->setHost($host); $this->setPort($port); - $this->setEncryption($security); + $this->setEncryption($encryption); } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/SpoolTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/SpoolTransport.php index f92567ba021..c08e0fb17d5 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/SpoolTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/SpoolTransport.php @@ -17,8 +17,6 @@ class Swift_SpoolTransport extends Swift_Transport_SpoolTransport { /** * Create a new SpoolTransport. - * - * @param Swift_Spool $spool */ public function __construct(Swift_Spool $spool) { @@ -27,8 +25,8 @@ class Swift_SpoolTransport extends Swift_Transport_SpoolTransport $arguments[] = $spool; - call_user_func_array( - array($this, 'Swift_Transport_SpoolTransport::__construct'), + \call_user_func_array( + [$this, 'Swift_Transport_SpoolTransport::__construct'], $arguments ); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php b/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php index ba1f6d323fc..7e5ddf1b7da 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/ByteArrayReplacementFilter.php @@ -17,9 +17,6 @@ */ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilter { - /** The needle(s) to search for */ - private $search; - /** The replacement(s) to make */ private $replace; @@ -27,7 +24,7 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt private $index; /** The Search Tree */ - private $tree = array(); + private $tree = []; /** Gives the size of the largest search */ private $treeMaxLen = 0; @@ -42,26 +39,25 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt */ public function __construct($search, $replace) { - $this->search = $search; - $this->index = array(); - $this->tree = array(); - $this->replace = array(); - $this->repSize = array(); + $this->index = []; + $this->tree = []; + $this->replace = []; + $this->repSize = []; $tree = null; $i = null; $last_size = $size = 0; foreach ($search as $i => $search_element) { - if ($tree !== null) { - $tree[-1] = min(count($replace) - 1, $i - 1); + if (null !== $tree) { + $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])) { - $tree[$char] = array(); + $tree[$char] = []; } $tree = &$tree[$char]; } @@ -70,27 +66,27 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt } else { $last_size = 1; if (!isset($tree[$search_element])) { - $tree[$search_element] = array(); + $tree[$search_element] = []; } $tree = &$tree[$search_element]; $size = max($last_size, $size); $this->index[$search_element] = true; } } - if ($i !== null) { - $tree[-1] = min(count($replace) - 1, $i); + if (null !== $i) { + $tree[-1] = min(\count($replace) - 1, $i); $tree[-2] = $last_size; $this->treeMaxLen = $size; } foreach ($replace as $rep) { - if (!is_array($rep)) { - $rep = array($rep); + 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); } } @@ -118,12 +114,12 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt */ public function filter($buffer, $minReplaces = -1) { - if ($this->treeMaxLen == 0) { + if (0 == $this->treeMaxLen) { return $buffer; } - $newBuffer = array(); - $buf_size = count($buffer); + $newBuffer = []; + $buf_size = \count($buffer); $last_size = 0; for ($i = 0; $i < $buf_size; ++$i) { $search_pos = $this->tree; @@ -141,7 +137,7 @@ class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilt } } // We got a complete pattern - elseif ($last_found !== PHP_INT_MAX) { + elseif (PHP_INT_MAX !== $last_found) { // Adding replacement datas to output buffer $rep_size = $this->repSize[$last_found]; for ($j = 0; $j < $rep_size; ++$j) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/StringReplacementFilterFactory.php b/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/StringReplacementFilterFactory.php index f60f0cf8218..783b8896dd7 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/StringReplacementFilterFactory.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/StreamFilters/StringReplacementFilterFactory.php @@ -16,7 +16,7 @@ class Swift_StreamFilters_StringReplacementFilterFactory implements Swift_ReplacementFilterFactory { /** Lazy-loaded filters */ - private $filters = array(); + private $filters = []; /** * Create a new StreamFilter to replace $search with $replace in a string. @@ -30,11 +30,11 @@ class Swift_StreamFilters_StringReplacementFilterFactory implements Swift_Replac { if (!isset($this->filters[$search][$replace])) { if (!isset($this->filters[$search])) { - $this->filters[$search] = array(); + $this->filters[$search] = []; } if (!isset($this->filters[$search][$replace])) { - $this->filters[$search][$replace] = array(); + $this->filters[$search][$replace] = []; } $this->filters[$search][$replace] = new Swift_StreamFilters_StringReplacementFilter($search, $replace); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/SwiftException.php b/htdocs/includes/swiftmailer/lib/classes/Swift/SwiftException.php index db3d31093ef..15e68b18e79 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/SwiftException.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/SwiftException.php @@ -18,9 +18,8 @@ class Swift_SwiftException extends Exception /** * Create a new SwiftException with $message. * - * @param string $message - * @param int $code - * @param Exception $previous + * @param string $message + * @param int $code */ public function __construct($message, $code = 0, Exception $previous = null) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport.php index f6214b7bfc5..bc324e8685a 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport.php @@ -61,8 +61,9 @@ interface Swift_Transport * Recipient/sender data will be retrieved from the Message API. * The return value is the number of recipients who were accepted for delivery. * - * @param Swift_Mime_SimpleMessage $message - * @param string[] $failedRecipients An array of failures by-reference + * This is the responsibility of the send method to start the transport if needed. + * + * @param string[] $failedRecipients An array of failures by-reference * * @return int */ @@ -70,8 +71,6 @@ interface Swift_Transport /** * Register a plugin in the Transport. - * - * @param Swift_Events_EventListener $plugin */ public function registerPlugin(Swift_Events_EventListener $plugin); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php index 34c3323fdba..d2dbd7a66a0 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php @@ -27,6 +27,14 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport /** The event dispatching layer */ protected $eventDispatcher; + protected $addressEncoder; + + /** Whether the PIPELINING SMTP extension is enabled (RFC 2920) */ + protected $pipelining = null; + + /** The pipelined commands waiting for response */ + protected $pipeline = []; + /** Source Ip */ protected $sourceIp; @@ -36,14 +44,13 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport /** * Creates a new EsmtpTransport using the given I/O buffer. * - * @param Swift_Transport_IoBuffer $buf - * @param Swift_Events_EventDispatcher $dispatcher - * @param string $localDomain + * @param string $localDomain */ - public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1') + public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null) { - $this->eventDispatcher = $dispatcher; $this->buffer = $buf; + $this->eventDispatcher = $dispatcher; + $this->addressEncoder = $addressEncoder ?? new Swift_AddressEncoder_IdnAddressEncoder(); $this->setLocalDomain($localDomain); } @@ -63,7 +70,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport */ public function setLocalDomain($domain) { - if (substr($domain, 0, 1) !== '[') { + if ('[' !== substr($domain, 0, 1)) { if (filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $domain = '['.$domain.']'; } elseif (filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { @@ -109,6 +116,16 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport return $this->sourceIp; } + public function setAddressEncoder(Swift_AddressEncoder $addressEncoder) + { + $this->addressEncoder = $addressEncoder; + } + + public function getAddressEncoder() + { + return $this->addressEncoder; + } + /** * Start the SMTP connection. */ @@ -154,13 +171,16 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport * Recipient/sender data will be retrieved from the Message API. * The return value is the number of recipients who were accepted for delivery. * - * @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 */ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) { + if (!$this->isStarted()) { + $this->start(); + } + $sent = 0; $failedRecipients = (array) $failedRecipients; @@ -172,31 +192,24 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport } if (!$reversePath = $this->getReversePath($message)) { - $this->throwException(new Swift_TransportException( - 'Cannot send message without a sender address' - ) - ); + $this->throwException(new Swift_TransportException('Cannot send message without a sender address')); } $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(array()); + $message->setBcc([]); try { $sent += $this->sendTo($message, $reversePath, $tos, $failedRecipients); - $sent += $this->sendBcc($message, $reversePath, $bcc, $failedRecipients); - } catch (Exception $e) { + } finally { $message->setBcc($bcc); - throw $e; } - $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); @@ -226,7 +239,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport } try { - $this->executeCommand("QUIT\r\n", array(221)); + $this->executeCommand("QUIT\r\n", [221]); } catch (Swift_TransportException $e) { } @@ -253,7 +266,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport $this->start(); } - $this->executeCommand("NOOP\r\n", array(250)); + $this->executeCommand("NOOP\r\n", [250]); } catch (Swift_TransportException $e) { try { $this->stop(); @@ -268,8 +281,6 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport /** * Register a plugin. - * - * @param Swift_Events_EventListener $plugin */ public function registerPlugin(Swift_Events_EventListener $plugin) { @@ -281,7 +292,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport */ public function reset() { - $this->executeCommand("RSET\r\n", array(250)); + $this->executeCommand("RSET\r\n", [250], $failures, true); } /** @@ -299,22 +310,46 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport * * If no response codes are given, the response will not be validated. * If codes are given, an exception will be thrown on an invalid response. + * If the command is RCPT TO, and the pipeline is non-empty, no exception + * will be thrown; instead the failing address is added to $failures. * * @param string $command * @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 * - * @return string + * @return string|null The server response, or null if pipelining is enabled */ - public function executeCommand($command, $codes = array(), &$failures = null) + public function executeCommand($command, $codes = [], &$failures = null, $pipeline = false, $address = null) { $failures = (array) $failures; $seq = $this->buffer->write($command); - $response = $this->getFullResponse($seq); if ($evt = $this->eventDispatcher->createCommandEvent($this, $command, $codes)) { $this->eventDispatcher->dispatchEvent($evt, 'commandSent'); } - $this->assertResponseCode($response, $codes); + + $this->pipeline[] = [$command, $seq, $codes, $address]; + + if ($pipeline && $this->pipelining) { + 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); + } + } + } return $response; } @@ -322,51 +357,53 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport /** Read the opening SMTP greeting */ protected function readGreeting() { - $this->assertResponseCode($this->getFullResponse(0), array(220)); + $this->assertResponseCode($this->getFullResponse(0), [220]); } /** Send the HELO welcome */ protected function doHeloCommand() { $this->executeCommand( - sprintf("HELO %s\r\n", $this->domain), array(250) + sprintf("HELO %s\r\n", $this->domain), [250] ); } /** Send the MAIL FROM command */ protected function doMailFromCommand($address) { + $address = $this->addressEncoder->encodeString($address); $this->executeCommand( - sprintf("MAIL FROM:<%s>\r\n", $address), array(250) + sprintf("MAIL FROM:<%s>\r\n", $address), [250], $failures, true ); } /** Send the RCPT TO command */ protected function doRcptToCommand($address) { + $address = $this->addressEncoder->encodeString($address); $this->executeCommand( - sprintf("RCPT TO:<%s>\r\n", $address), array(250, 251, 252) + sprintf("RCPT TO:<%s>\r\n", $address), [250, 251, 252], $failures, true, $address ); } /** Send the DATA command */ - protected function doDataCommand() + protected function doDataCommand(&$failedRecipients) { - $this->executeCommand("DATA\r\n", array(354)); + $this->executeCommand("DATA\r\n", [354], $failedRecipients); } /** Stream the contents of the message over the buffer */ protected function streamMessage(Swift_Mime_SimpleMessage $message) { - $this->buffer->setWriteTranslations(array("\r\n." => "\r\n..")); + $this->buffer->setWriteTranslations(["\r\n." => "\r\n.."]); try { $message->toByteStream($this->buffer); $this->buffer->flushBuffers(); } catch (Swift_TransportException $e) { $this->throwException($e); } - $this->buffer->setWriteTranslations(array()); - $this->executeCommand("\r\n.\r\n", array(250)); + $this->buffer->setWriteTranslations([]); + $this->executeCommand("\r\n.\r\n", [250]); } /** Determine the best-use reverse path for this message */ @@ -406,8 +443,12 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport /** Throws an Exception if a response code is incorrect */ protected function assertResponseCode($response, $wanted) { + if (!$response) { + $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got an empty response')); + } + 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)) { @@ -415,12 +456,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport } if (!$valid) { - $this->throwException( - new Swift_TransportException( - 'Expected response code '.implode('/', $wanted).' but got code '. - '"'.$code.'", with message "'.$response.'"', - $code) - ); + $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got code "'.$code.'", with message "'.$response.'"', $code)); } } @@ -436,10 +472,7 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport } catch (Swift_TransportException $e) { $this->throwException($e); } catch (Swift_IoException $e) { - $this->throwException( - new Swift_TransportException( - $e->getMessage()) - ); + $this->throwException(new Swift_TransportException($e->getMessage(), 0, $e)); } return $response; @@ -456,11 +489,16 @@ abstract class Swift_Transport_AbstractSmtpTransport implements Swift_Transport ++$sent; } catch (Swift_TransportException $e) { $failedRecipients[] = $forwardPath; + } catch (Swift_AddressEncoderException $e) { + $failedRecipients[] = $forwardPath; } } - if ($sent != 0) { - $this->doDataCommand(); + if (0 != $sent) { + $sent += \count($failedRecipients); + $this->doDataCommand($failedRecipients); + $sent -= \count($failedRecipients); + $this->streamMessage($message); } else { $this->reset(); @@ -480,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(array($forwardPath => $name)); - $sent += $this->doMailTransaction( - $message, $reversePath, array($forwardPath), $failedRecipients - ); - } - - return $sent; - } - /** * Destructor. */ @@ -504,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__); + } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php index 26c2d745a95..bb3a1615096 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/CramMd5Authenticator.php @@ -26,29 +26,23 @@ class Swift_Transport_Esmtp_Auth_CramMd5Authenticator implements Swift_Transport } /** - * Try to authenticate the user with $username and $password. - * - * @param Swift_Transport_SmtpAgent $agent - * @param string $username - * @param string $password - * - * @return bool + * {@inheritdoc} */ public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password) { try { - $challenge = $agent->executeCommand("AUTH CRAM-MD5\r\n", array(334)); + $challenge = $agent->executeCommand("AUTH CRAM-MD5\r\n", [334]); $challenge = base64_decode(substr($challenge, 4)); $message = base64_encode( $username.' '.$this->getResponse($password, $challenge) - ); - $agent->executeCommand(sprintf("%s\r\n", $message), array(235)); + ); + $agent->executeCommand(sprintf("%s\r\n", $message), [235]); return true; } catch (Swift_TransportException $e) { - $agent->executeCommand("RSET\r\n", array(250)); + $agent->executeCommand("RSET\r\n", [250]); - return false; + throw $e; } } @@ -62,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); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php index 6ab6e3337e2..0b9d81b8ad6 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/LoginAuthenticator.php @@ -26,26 +26,20 @@ class Swift_Transport_Esmtp_Auth_LoginAuthenticator implements Swift_Transport_E } /** - * Try to authenticate the user with $username and $password. - * - * @param Swift_Transport_SmtpAgent $agent - * @param string $username - * @param string $password - * - * @return bool + * {@inheritdoc} */ public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password) { try { - $agent->executeCommand("AUTH LOGIN\r\n", array(334)); - $agent->executeCommand(sprintf("%s\r\n", base64_encode($username)), array(334)); - $agent->executeCommand(sprintf("%s\r\n", base64_encode($password)), array(235)); + $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]); return true; } catch (Swift_TransportException $e) { - $agent->executeCommand("RSET\r\n", array(250)); + $agent->executeCommand("RSET\r\n", [250]); - return false; + throw $e; } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php index 7b8608d4a1b..41931fdd226 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/NTLMAuthenticator.php @@ -31,63 +31,57 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es } /** - * Try to authenticate the user with $username and $password. - * - * @param Swift_Transport_SmtpAgent $agent - * @param string $username - * @param string $password - * - * @return bool + * {@inheritdoc} * * @throws \LogicException */ 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) : $this->getRandomBytes(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); return true; } catch (Swift_TransportException $e) { - $agent->executeCommand("RSET\r\n", array(250)); + $agent->executeCommand("RSET\r\n", [250]); - return false; + throw $e; } } 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; } @@ -100,15 +94,13 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es /** * Send our auth message and returns the response. * - * @param Swift_Transport_SmtpAgent $agent - * * @return string SMTP Response */ protected function sendMessage1(Swift_Transport_SmtpAgent $agent) { $message = $this->createMessage1(); - return $agent->executeCommand(sprintf("AUTH %s %s\r\n", $this->getAuthKeyword(), base64_encode($message)), array(334)); + return $agent->executeCommand(sprintf("AUTH %s %s\r\n", $this->getAuthKeyword(), base64_encode($message)), [334]); } /** @@ -131,7 +123,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $targetInfoBlock = substr($responseHex, $offset); list($domainName, $serverName, $DNSDomainName, $DNSServerName, $terminatorByte) = $this->readSubBlock($targetInfoBlock); - return array( + return [ $challenge, $context, $targetInfoH, @@ -142,14 +134,12 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $DNSServerName, hex2bin($targetInfoBlock), $terminatorByte, - ); + ]; } /** * Read the blob information in from message2. * - * @param $block - * * @return array */ protected function readSubBlock($block) @@ -157,9 +147,9 @@ 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 = array(); + $data = []; while ($offset < $length) { $blockLength = hexdec(substr(substr($block, $offset, 8), -4)) / 256; $offset += 8; @@ -167,7 +157,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $offset += $blockLength * 2; } - if (count($data) == 3) { + if (3 == \count($data)) { $data[] = $data[2]; $data[2] = ''; } @@ -180,13 +170,12 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es /** * Send our final message with all our data. * - * @param string $response Message 1 response (message 2) - * @param string $username - * @param string $password - * @param string $timestamp - * @param string $client - * @param Swift_Transport_SmtpAgent $agent - * @param bool $v2 Use version2 of the protocol + * @param string $response Message 1 response (message 2) + * @param string $username + * @param string $password + * @param string $timestamp + * @param string $client + * @param bool $v2 Use version2 of the protocol * * @return string */ @@ -210,7 +199,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $message = $this->createMessage3($domain, $username, $workstation, $lmResponse, $ntlmResponse); - return $agent->executeCommand(sprintf("%s\r\n", base64_encode($message)), array(235)); + return $agent->executeCommand(sprintf("%s\r\n", base64_encode($message)), [235]); } /** @@ -294,18 +283,18 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es */ protected function getDomainAndUsername($name) { - if (strpos($name, '\\') !== false) { + if (false !== strpos($name, '\\')) { return explode('\\', $name); } if (false !== strpos($name, '@')) { list($user, $domain) = explode('@', $name); - return array($domain, $user); + return [$domain, $user]; } // no domain passed - return array('', $name); + return ['', $name]; } /** @@ -375,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; @@ -396,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)); @@ -436,21 +425,21 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es protected function createDesKey($key) { - $material = array(bin2hex($key[0])); - $len = strlen($key); + $material = [bin2hex($key[0])]; + $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) { $b = $this->castToByte(hexdec($v)); - $needsParity = (($this->uRShift($b, 7) ^ $this->uRShift($b, 6) ^ $this->uRShift($b, 5) + $needsParity = 0 == (($this->uRShift($b, 7) ^ $this->uRShift($b, 6) ^ $this->uRShift($b, 5) ^ $this->uRShift($b, 4) ^ $this->uRShift($b, 3) ^ $this->uRShift($b, 2) - ^ $this->uRShift($b, 1)) & 0x01) == 0; + ^ $this->uRShift($b, 1)) & 0x01); list($high, $low) = str_split($v); if ($needsParity) { @@ -476,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); @@ -495,7 +484,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $length = floor(hexdec(substr($value, 0, 4)) / 256) * 2; $offset = floor(hexdec(substr($value, 8, 4)) / 256) * 2; - return array($length, $offset); + return [$length, $offset]; } /** @@ -521,7 +510,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es */ protected function uRShift($a, $b) { - if ($b == 0) { + if (0 == $b) { return $a; } @@ -548,22 +537,6 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es return $byte; } - /** - * Create random bytes. - * - * @param $length - * - * @return string - */ - protected function getRandomBytes($length) - { - $bytes = openssl_random_pseudo_bytes($length, $strong); - if (false !== $bytes && true === $strong) { - return $bytes; - } - throw new RuntimeException('OpenSSL did not produce a secure random number.'); - } - /** ENCRYPTION ALGORITHMS */ /** @@ -590,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)); } @@ -608,13 +581,13 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es * * @return string * - * @see http://php.net/manual/en/ref.hash.php + * @see https://secure.php.net/manual/en/ref.hash.php */ protected function md4Encrypt($input) { $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); } /** @@ -639,8 +612,8 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es echo substr($message, 0, 16)." NTLMSSP Signature
\n"; echo $messageId." Type Indicator
\n"; - if ($messageId == '02000000') { - $map = array( + if ('02000000' == $messageId) { + $map = [ 'Challenge', 'Context', 'Target Information Security Buffer', @@ -651,14 +624,14 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es 'DNS Server Name', 'BLOB', 'Target Information Terminator', - ); + ]; $data = $this->parseMessage2(hex2bin($message)); foreach ($map as $key => $value) { echo bin2hex($data[$key]).' - '.$data[$key].' ||| '.$value."
\n"; } - } elseif ($messageId == '03000000') { + } elseif ('03000000' == $messageId) { $i = 0; $data[$i++] = substr($message, 24, 16); list($lmLength, $lmOffset) = $this->readSecurityBuffer($data[$i - 1]); @@ -683,7 +656,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es $data[$i++] = substr($message, $lmOffset, $lmLength); $data[$i] = substr($message, $ntmlOffset, $ntmlLength); - $map = array( + $map = [ 'LM Response Security Buffer', 'NTLM Response Security Buffer', 'Target Name Security Buffer', @@ -696,7 +669,7 @@ class Swift_Transport_Esmtp_Auth_NTLMAuthenticator implements Swift_Transport_Es 'Workstation Name Data', 'LM Response Data', 'NTLM Response Data', - ); + ]; foreach ($map as $key => $value) { echo $data[$key].' - '.hex2bin($data[$key]).' ||| '.$value."
\n"; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php index 43219f93445..41d0a50a82b 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php @@ -26,25 +26,19 @@ class Swift_Transport_Esmtp_Auth_PlainAuthenticator implements Swift_Transport_E } /** - * Try to authenticate the user with $username and $password. - * - * @param Swift_Transport_SmtpAgent $agent - * @param string $username - * @param string $password - * - * @return bool + * {@inheritdoc} */ public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password) { try { - $message = base64_encode($username.chr(0).$username.chr(0).$password); - $agent->executeCommand(sprintf("AUTH PLAIN %s\r\n", $message), array(235)); + $message = base64_encode($username.\chr(0).$username.\chr(0).$password); + $agent->executeCommand(sprintf("AUTH PLAIN %s\r\n", $message), [235]); return true; } catch (Swift_TransportException $e) { - $agent->executeCommand("RSET\r\n", array(250)); + $agent->executeCommand("RSET\r\n", [250]); - return false; + throw $e; } } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php index d1a4cc3d774..859f22f3d5e 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/XOAuth2Authenticator.php @@ -36,25 +36,19 @@ class Swift_Transport_Esmtp_Auth_XOAuth2Authenticator implements Swift_Transport } /** - * Try to authenticate the user with $email and $token. - * - * @param Swift_Transport_SmtpAgent $agent - * @param string $email - * @param string $token - * - * @return bool + * {@inheritdoc} */ public function authenticate(Swift_Transport_SmtpAgent $agent, $email, $token) { try { $param = $this->constructXOAuth2Params($email, $token); - $agent->executeCommand('AUTH XOAUTH2 '.$param."\r\n", array(235)); + $agent->executeCommand('AUTH XOAUTH2 '.$param."\r\n", [235]); return true; } catch (Swift_TransportException $e) { - $agent->executeCommand("RSET\r\n", array(250)); + $agent->executeCommand("RSET\r\n", [250]); - return false; + throw $e; } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php index 94387f01a2e..53a90a87383 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php @@ -9,7 +9,7 @@ */ /** - * An ESMTP handler for AUTH support. + * An ESMTP handler for AUTH support (RFC 5248). * * @author Chris Corbyn */ @@ -20,7 +20,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler * * @var Swift_Transport_Esmtp_Authenticator[] */ - private $authenticators = array(); + private $authenticators = []; /** * The username for authentication. @@ -48,7 +48,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler * * @var string[] */ - private $esmtpParams = array(); + private $esmtpParams = []; /** * Create a new AuthHandler with $authenticators for support. @@ -143,7 +143,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler /** * Get the name of the ESMTP extension this handles. * - * @return bool + * @return string */ public function getHandledKeyword() { @@ -169,19 +169,26 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler { if ($this->username) { $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; - if ($authenticator->authenticate($agent, $this->username, $this->password)) { - return; + try { + if ($authenticator->authenticate($agent, $this->username, $this->password)) { + return; + } + } catch (Swift_TransportException $e) { + // keep the error message, but tries the other authenticators + $errors[] = [$authenticator->getAuthKeyword(), $e->getMessage()]; } } } - throw new Swift_TransportException( - 'Failed to authenticate on SMTP server with username "'. - $this->username.'" using '.$count.' possible authenticators' - ); + + $message = 'Failed to authenticate on SMTP server with username "'.$this->username.'" using '.$count.' possible authenticators.'; + foreach ($errors as $error) { + $message .= ' Authenticator '.$error[0].' returned '.$error[1].'.'; + } + throw new Swift_TransportException($message); } } @@ -190,7 +197,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler */ public function getMailParams() { - return array(); + return []; } /** @@ -198,13 +205,13 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler */ public function getRcptParams() { - return array(); + return []; } /** * Not used. */ - public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = array(), &$failedRecipients = null, &$stop = false) + public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false) { } @@ -229,7 +236,7 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler */ public function exposeMixinMethods() { - return array('setUsername', 'getUsername', 'setPassword', 'getPassword', 'setAuthMode', 'getAuthMode'); + return ['setUsername', 'getUsername', 'setPassword', 'getPassword', 'setAuthMode', 'getAuthMode']; } /** @@ -242,19 +249,17 @@ class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler /** * Returns the authenticator list for the given agent. * - * @param Swift_Transport_SmtpAgent $agent - * * @return array */ 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) { - return array($authenticator); + if (strtolower($authenticator->getAuthKeyword() ?? '') == $mode) { + return [$authenticator]; } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Authenticator.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Authenticator.php index 12a9abf8199..f692a6fe40d 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Authenticator.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/Authenticator.php @@ -25,11 +25,12 @@ 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 + * @return bool true if authentication worked (returning false is deprecated, throw a Swift_TransportException instead) + * + * @throws Swift_TransportException Allows the message to bubble up when authentication was not successful */ public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/EightBitMimeHandler.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/EightBitMimeHandler.php new file mode 100644 index 00000000000..63f70866939 --- /dev/null +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/EightBitMimeHandler.php @@ -0,0 +1,113 @@ +encoding = $encoding; + } + + /** + * Get the name of the ESMTP extension this handles. + * + * @return string + */ + public function getHandledKeyword() + { + return '8BITMIME'; + } + + /** + * Not used. + */ + public function setKeywordParams(array $parameters) + { + } + + /** + * Not used. + */ + public function afterEhlo(Swift_Transport_SmtpAgent $agent) + { + } + + /** + * Get params which are appended to MAIL FROM:<>. + * + * @return string[] + */ + public function getMailParams() + { + return ['BODY='.$this->encoding]; + } + + /** + * Not used. + */ + public function getRcptParams() + { + return []; + } + + /** + * Not used. + */ + public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false) + { + } + + /** + * Returns +1, -1 or 0 according to the rules for usort(). + * + * This method is called to ensure extensions can be execute in an appropriate order. + * + * @param string $esmtpKeyword to compare with + * + * @return int + */ + public function getPriorityOver($esmtpKeyword) + { + return 0; + } + + /** + * Not used. + */ + public function exposeMixinMethods() + { + return []; + } + + /** + * Not used. + */ + public function resetState() + { + } +} diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/SmtpUtf8Handler.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/SmtpUtf8Handler.php new file mode 100644 index 00000000000..7d0252a01bf --- /dev/null +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/Esmtp/SmtpUtf8Handler.php @@ -0,0 +1,107 @@ +. + * + * @return string[] + */ + public function getMailParams() + { + return ['SMTPUTF8']; + } + + /** + * Not used. + */ + public function getRcptParams() + { + return []; + } + + /** + * Not used. + */ + public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false) + { + } + + /** + * Returns +1, -1 or 0 according to the rules for usort(). + * + * This method is called to ensure extensions can be execute in an appropriate order. + * + * @param string $esmtpKeyword to compare with + * + * @return int + */ + public function getPriorityOver($esmtpKeyword) + { + return 0; + } + + /** + * Not used. + */ + public function exposeMixinMethods() + { + return []; + } + + /** + * Not used. + */ + public function resetState() + { + } +} diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpHandler.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpHandler.php index c17ef8feb3b..b8ea36e2fa8 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpHandler.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpHandler.php @@ -18,7 +18,7 @@ interface Swift_Transport_EsmtpHandler /** * Get the name of the ESMTP extension this handles. * - * @return bool + * @return string */ public function getHandledKeyword(); @@ -59,7 +59,7 @@ interface Swift_Transport_EsmtpHandler * @param string[] $failedRecipients to collect failures * @param bool $stop to be set true by-reference if the command is now sent */ - public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = array(), &$failedRecipients = null, &$stop = false); + public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = [], &$failedRecipients = null, &$stop = false); /** * Returns +1, -1 or 0 according to the rules for usort(). diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php index 56d9c748769..36545f51feb 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php @@ -20,21 +20,21 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo * * @var Swift_Transport_EsmtpHandler[] */ - private $handlers = array(); + private $handlers = []; /** * ESMTP capabilities. * * @var string[] */ - private $capabilities = array(); + private $capabilities = []; /** * Connection buffer parameters. * * @var array */ - private $params = array( + private $params = [ 'protocol' => 'tcp', 'host' => 'localhost', 'port' => 25, @@ -42,26 +42,26 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo 'blocking' => 1, 'tls' => false, 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET, - 'stream_context_options' => array(), - ); + 'stream_context_options' => [], + ]; /** * Creates a new EsmtpTransport using the given I/O buffer. * - * @param Swift_Transport_IoBuffer $buf * @param Swift_Transport_EsmtpHandler[] $extensionHandlers - * @param Swift_Events_EventDispatcher $dispatcher * @param string $localDomain */ - public function __construct(Swift_Transport_IoBuffer $buf, array $extensionHandlers, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1') + public function __construct(Swift_Transport_IoBuffer $buf, array $extensionHandlers, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null) { - parent::__construct($buf, $dispatcher, $localDomain); + parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder); $this->setExtensionHandlers($extensionHandlers); } /** * Set the host to connect to. * + * Literal IPv6 addresses should be wrapped in square brackets. + * * @param string $host * * @return $this @@ -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; @@ -190,6 +190,8 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo /** * Sets the source IP. * + * IPv6 addresses should be wrapped in square brackets. + * * @param string $source * * @return $this @@ -208,7 +210,36 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo */ public function getSourceIp() { - return isset($this->params['sourceIp']) ? $this->params['sourceIp'] : null; + return $this->params['sourceIp'] ?? null; + } + + /** + * Sets whether SMTP pipelining is enabled. + * + * By default, support is auto-detected using the PIPELINING SMTP extension. + * Use this function to override that in the unlikely event of compatibility + * issues. + * + * @param bool $enabled + * + * @return $this + */ + public function setPipelining($enabled) + { + $this->pipelining = $enabled; + + return $this; + } + + /** + * 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 + */ + public function getPipelining() + { + return $this->pipelining; } /** @@ -220,7 +251,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo */ public function setExtensionHandlers(array $handlers) { - $assoc = array(); + $assoc = []; foreach ($handlers as $handler) { $assoc[$handler->getHandledKeyword()] = $handler; } @@ -252,10 +283,12 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo * @param string $command * @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 * - * @return string + * @return string|null The server response, or null if pipelining is enabled */ - public function executeCommand($command, $codes = array(), &$failures = null) + public function executeCommand($command, $codes = [], &$failures = null, $pipeline = false, $address = null) { $failures = (array) $failures; $stopSignal = false; @@ -269,19 +302,19 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo } } - return parent::executeCommand($command, $codes, $failures); + return parent::executeCommand($command, $codes, $failures, $pipeline, $address); } /** Mixin handling method for ESMTP handlers */ 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(array($handler, $method), $args); + $return = \call_user_func_array([$handler, $method], $args); // Allow fluid method calls - if (null === $return && substr($method, 0, 3) == 'set') { + if (null === $return && 'set' == substr($method, 0, 3)) { return $this; } else { return $return; @@ -302,7 +335,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo { try { $response = $this->executeCommand( - sprintf("EHLO %s\r\n", $this->domain), array(250) + sprintf("EHLO %s\r\n", $this->domain), [250] ); } catch (Swift_TransportException $e) { return parent::doHeloCommand(); @@ -310,7 +343,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo if ($this->params['tls']) { try { - $this->executeCommand("STARTTLS\r\n", array(220)); + $this->executeCommand("STARTTLS\r\n", [220]); if (!$this->buffer->startTLS()) { throw new Swift_TransportException('Unable to connect with TLS encryption'); @@ -318,7 +351,7 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo try { $response = $this->executeCommand( - sprintf("EHLO %s\r\n", $this->domain), array(250) + sprintf("EHLO %s\r\n", $this->domain), [250] ); } catch (Swift_TransportException $e) { return parent::doHeloCommand(); @@ -329,6 +362,10 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo } $this->capabilities = $this->getCapabilities($response); + if (!isset($this->pipelining)) { + $this->pipelining = isset($this->capabilities['PIPELINING']); + } + $this->setHandlerParams(); foreach ($this->getActiveHandlers() as $handler) { $handler->afterEhlo($this); @@ -338,43 +375,45 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo /** Overridden to add Extension support */ protected function doMailFromCommand($address) { + $address = $this->addressEncoder->encodeString($address); $handlers = $this->getActiveHandlers(); - $params = array(); + $params = []; foreach ($handlers as $handler) { $params = array_merge($params, (array) $handler->getMailParams()); } $paramStr = !empty($params) ? ' '.implode(' ', $params) : ''; $this->executeCommand( - sprintf("MAIL FROM:<%s>%s\r\n", $address, $paramStr), array(250) + sprintf("MAIL FROM:<%s>%s\r\n", $address, $paramStr), [250], $failures, true ); } /** Overridden to add Extension support */ protected function doRcptToCommand($address) { + $address = $this->addressEncoder->encodeString($address); $handlers = $this->getActiveHandlers(); - $params = array(); + $params = []; foreach ($handlers as $handler) { $params = array_merge($params, (array) $handler->getRcptParams()); } $paramStr = !empty($params) ? ' '.implode(' ', $params) : ''; $this->executeCommand( - sprintf("RCPT TO:<%s>%s\r\n", $address, $paramStr), array(250, 251, 252) + sprintf("RCPT TO:<%s>%s\r\n", $address, $paramStr), [250, 251, 252], $failures, true, $address ); } /** Determine ESMTP capabilities by function group */ private function getCapabilities($ehloResponse) { - $capabilities = array(); - $ehloResponse = trim($ehloResponse); + $capabilities = []; + $ehloResponse = trim($ehloResponse ?? ''); $lines = explode("\r\n", $ehloResponse); array_shift($lines); foreach ($lines as $line) { if (preg_match('/^[0-9]{3}[ -]([A-Z0-9-]+)((?:[ =].*)?)$/Di', $line, $matches)) { $keyword = strtoupper($matches[1]); $paramStr = strtoupper(ltrim($matches[2], ' =')); - $params = !empty($paramStr) ? explode(' ', $paramStr) : array(); + $params = !empty($paramStr) ? explode(' ', $paramStr) : []; $capabilities[$keyword] = $params; } } @@ -386,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]); } } @@ -395,9 +434,9 @@ class Swift_Transport_EsmtpTransport extends Swift_Transport_AbstractSmtpTranspo /** Get ESMTP handlers which are currently ok to use */ private function getActiveHandlers() { - $handlers = array(); + $handlers = []; foreach ($this->handlers as $keyword => $handler) { - if (array_key_exists($keyword, $this->capabilities)) { + if (\array_key_exists($keyword, $this->capabilities)) { $handlers[] = $handler; } } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php index 94151f89fef..1a4b4754f07 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/FailoverTransport.php @@ -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; } /** @@ -52,14 +52,13 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran * Recipient/sender data will be retrieved from the Message API. * The return value is the number of recipients who were accepted for delivery. * - * @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 */ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) { - $maxTransports = count($this->transports); + $maxTransports = \count($this->transports); $sent = 0; $this->lastUsedTransport = null; @@ -80,10 +79,8 @@ class Swift_Transport_FailoverTransport extends Swift_Transport_LoadBalancedTran } } - if (count($this->transports) == 0) { - 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; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/IoBuffer.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/IoBuffer.php index af97adf1f8f..50f1e5e403c 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/IoBuffer.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/IoBuffer.php @@ -25,8 +25,6 @@ interface Swift_Transport_IoBuffer extends Swift_InputByteStream, Swift_OutputBy * Perform any initialization needed, using the given $params. * * Parameters will vary depending upon the type of IoBuffer used. - * - * @param array $params */ public function initialize(array $params); diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/LoadBalancedTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/LoadBalancedTransport.php index dc6a2149bab..0b5ba9d304e 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/LoadBalancedTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/LoadBalancedTransport.php @@ -20,14 +20,14 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport * * @var Swift_Transport[] */ - private $deadTransports = array(); + private $deadTransports = []; /** * The Transports which are used in rotation. * * @var Swift_Transport[] */ - protected $transports = array(); + protected $transports = []; /** * The Transport used in the last successful send operation. @@ -49,7 +49,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport public function setTransports(array $transports) { $this->transports = $transports; - $this->deadTransports = array(); + $this->deadTransports = []; } /** @@ -79,7 +79,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport */ public function isStarted() { - return count($this->transports) > 0; + return \count($this->transports) > 0; } /** @@ -111,7 +111,7 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport } } - return count($this->transports) > 0; + return \count($this->transports) > 0; } /** @@ -120,14 +120,13 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport * Recipient/sender data will be retrieved from the Message API. * The return value is the number of recipients who were accepted for delivery. * - * @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 */ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null) { - $maxTransports = count($this->transports); + $maxTransports = \count($this->transports); $sent = 0; $this->lastUsedTransport = null; @@ -146,10 +145,8 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport } } - if (count($this->transports) == 0) { - throw new Swift_TransportException( - 'All Transports in LoadBalancedTransport failed, or no Transports available' - ); + if (0 == \count($this->transports)) { + throw new Swift_TransportException('All Transports in LoadBalancedTransport failed, or no Transports available'); } return $sent; @@ -157,8 +154,6 @@ class Swift_Transport_LoadBalancedTransport implements Swift_Transport /** * Register a plugin. - * - * @param Swift_Events_EventListener $plugin */ public function registerPlugin(Swift_Events_EventListener $plugin) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/NullTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/NullTransport.php index dc38078c3c3..7d910db5a58 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/NullTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/NullTransport.php @@ -61,8 +61,7 @@ class Swift_Transport_NullTransport implements Swift_Transport /** * Sends the given message. * - * @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 The number of sent emails */ @@ -81,9 +80,9 @@ class Swift_Transport_NullTransport implements Swift_Transport } $count = ( - count((array) $message->getTo()) - + count((array) $message->getCc()) - + count((array) $message->getBcc()) + \count((array) $message->getTo()) + + \count((array) $message->getCc()) + + \count((array) $message->getBcc()) ); return $count; @@ -91,8 +90,6 @@ class Swift_Transport_NullTransport implements Swift_Transport /** * Register a plugin. - * - * @param Swift_Events_EventListener $plugin */ public function registerPlugin(Swift_Events_EventListener $plugin) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php index 807538505bf..65a434d1173 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SendmailTransport.php @@ -24,23 +24,21 @@ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTran * * @var array */ - private $params = array( + private $params = [ 'timeout' => 30, 'blocking' => 1, 'command' => '/usr/sbin/sendmail -bs', 'type' => Swift_Transport_IoBuffer::TYPE_PROCESS, - ); + ]; /** * Create a new SendmailTransport with $buf for I/O. * - * @param Swift_Transport_IoBuffer $buf - * @param Swift_Events_EventDispatcher $dispatcher - * @param string $localDomain + * @param string $localDomain */ - public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1') + public function __construct(Swift_Transport_IoBuffer $buf, Swift_Events_EventDispatcher $dispatcher, $localDomain = '127.0.0.1', Swift_AddressEncoder $addressEncoder = null) { - parent::__construct($buf, $dispatcher, $localDomain); + parent::__construct($buf, $dispatcher, $localDomain, $addressEncoder); } /** @@ -93,8 +91,7 @@ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTran * NOTE: If using 'sendmail -t' you will not be aware of any failures until * they bounce (i.e. send() will always return 100% success). * - * @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 */ @@ -114,24 +111,24 @@ class Swift_Transport_SendmailTransport extends Swift_Transport_AbstractSmtpTran } if (false === strpos($command, ' -f')) { - $command .= ' -f'.escapeshellarg($this->getReversePath($message)); + $command .= ' -f'.escapeshellarg($this->getReversePath($message) ?? ''); } - $buffer->initialize(array_merge($this->params, array('command' => $command))); + $buffer->initialize(array_merge($this->params, ['command' => $command])); if (false === strpos($command, ' -i') && false === strpos($command, ' -oi')) { - $buffer->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n..")); + $buffer->setWriteTranslations(["\r\n" => "\n", "\n." => "\n.."]); } else { - $buffer->setWriteTranslations(array("\r\n" => "\n")); + $buffer->setWriteTranslations(["\r\n" => "\n"]); } - $count = count((array) $message->getTo()) - + count((array) $message->getCc()) - + count((array) $message->getBcc()) + $count = \count((array) $message->getTo()) + + \count((array) $message->getCc()) + + \count((array) $message->getBcc()) ; $message->toByteStream($buffer); $buffer->flushBuffers(); - $buffer->setWriteTranslations(array()); + $buffer->setWriteTranslations([]); $buffer->terminate(); if ($evt) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SmtpAgent.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SmtpAgent.php index 90e913f8edb..e8ce65c2648 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SmtpAgent.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SmtpAgent.php @@ -32,5 +32,5 @@ interface Swift_Transport_SmtpAgent * @param int[] $codes * @param string[] $failures An array of failures by-reference */ - public function executeCommand($command, $codes = array(), &$failures = null); + public function executeCommand($command, $codes = [], &$failures = null); } diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SpoolTransport.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SpoolTransport.php index 9a1d07115e3..0cb6a5b80a9 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SpoolTransport.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/SpoolTransport.php @@ -33,8 +33,6 @@ class Swift_Transport_SpoolTransport implements Swift_Transport /** * Sets the spool object. * - * @param Swift_Spool $spool - * * @return $this */ public function setSpool(Swift_Spool $spool) @@ -89,8 +87,7 @@ class Swift_Transport_SpoolTransport implements Swift_Transport /** * Sends the given message. * - * @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 The number of sent e-mail's */ @@ -115,8 +112,6 @@ class Swift_Transport_SpoolTransport implements Swift_Transport /** * Register a plugin. - * - * @param Swift_Events_EventListener $plugin */ public function registerPlugin(Swift_Events_EventListener $plugin) { diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php index bc6ed5a34b4..70782ada044 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php @@ -25,18 +25,16 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn private $out; /** Buffer initialization parameters */ - private $params = array(); + private $params = []; /** The ReplacementFilterFactory */ private $replacementFactory; /** Translations performed on data being streamed into the buffer */ - private $translations = array(); + private $translations = []; /** * Create a new StreamBuffer using $replacementFactory for transformations. - * - * @param Swift_ReplacementFilterFactory $replacementFactory */ public function __construct(Swift_ReplacementFilterFactory $replacementFactory) { @@ -47,8 +45,6 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn * Perform any initialization needed, using the given $params. * * Parameters will vary depending upon the type of IoBuffer used. - * - * @param array $params */ public function initialize(array $params) { @@ -91,7 +87,11 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn public function startTLS() { - return stream_socket_enable_crypto($this->stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT); + // STREAM_CRYPTO_METHOD_TLS_CLIENT only allow tls1.0 connections (some php versions) + // To support modern tls we allow explicit tls1.0, tls1.1, tls1.2 + // Ssl3 and older are not allowed because they are vulnerable + // @TODO make tls arguments configurable + return stream_socket_enable_crypto($this->stream, true, STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT); } /** @@ -160,14 +160,10 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn { if (isset($this->out) && !feof($this->out)) { $line = fgets($this->out); - if (strlen($line) == 0) { + if (0 == \strlen($line)) { $metas = stream_get_meta_data($this->out); if ($metas['timed_out']) { - throw new Swift_IoException( - 'Connection to '. - $this->getReadConnectionDescription(). - ' Timed Out' - ); + throw new Swift_IoException('Connection to '.$this->getReadConnectionDescription().' Timed Out'); } } @@ -192,14 +188,10 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn { if (isset($this->out) && !feof($this->out)) { $ret = fread($this->out, $length); - if (strlen($ret) == 0) { + if (0 == \strlen($ret)) { $metas = stream_get_meta_data($this->out); if ($metas['timed_out']) { - throw new Swift_IoException( - 'Connection to '. - $this->getReadConnectionDescription(). - ' Timed Out' - ); + throw new Swift_IoException('Connection to '.$this->getReadConnectionDescription().' Timed Out'); } } @@ -224,7 +216,7 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn protected function doCommit($bytes) { if (isset($this->in)) { - $bytesToWrite = strlen($bytes); + $bytesToWrite = \strlen($bytes); $totalBytesWritten = 0; while ($totalBytesWritten < $bytesToWrite) { @@ -255,7 +247,7 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn if (!empty($this->params['timeout'])) { $timeout = $this->params['timeout']; } - $options = array(); + $options = []; if (!empty($this->params['sourceIp'])) { $options['socket']['bindto'] = $this->params['sourceIp'].':0'; } @@ -264,13 +256,16 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn $options = array_merge($options, $this->params['stream_context_options']); } $streamContext = stream_context_create($options); - $this->stream = @stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext); - if (false === $this->stream) { - throw new Swift_TransportException( - 'Connection could not be established with host '.$this->params['host']. - ' ['.$errstr.' #'.$errno.']' - ); + + set_error_handler(function ($type, $msg) { + throw new Swift_TransportException('Connection could not be established with host '.$this->params['host'].' :'.$msg); + }); + try { + $this->stream = stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext); + } finally { + restore_error_handler(); } + if (!empty($this->params['blocking'])) { stream_set_blocking($this->stream, 1); } else { @@ -287,18 +282,16 @@ class Swift_Transport_StreamBuffer extends Swift_ByteStream_AbstractFilterableIn private function establishProcessConnection() { $command = $this->params['command']; - $descriptorSpec = array( - 0 => array('pipe', 'r'), - 1 => array('pipe', 'w'), - 2 => array('pipe', 'w'), - ); - $pipes = array(); + $descriptorSpec = [ + 0 => ['pipe', 'r'], + 1 => ['pipe', 'w'], + 2 => ['pipe', 'w'], + ]; + $pipes = []; $this->stream = proc_open($command, $descriptorSpec, $pipes); stream_set_blocking($pipes[2], 0); if ($err = stream_get_contents($pipes[2])) { - throw new Swift_TransportException( - 'Process could not be started ['.$err.']' - ); + throw new Swift_TransportException('Process could not be started ['.$err.']'); } $this->in = &$pipes[0]; $this->out = &$pipes[1]; diff --git a/htdocs/includes/swiftmailer/lib/classes/Swift/TransportException.php b/htdocs/includes/swiftmailer/lib/classes/Swift/TransportException.php index 4ae2412e62a..c7417455b3e 100644 --- a/htdocs/includes/swiftmailer/lib/classes/Swift/TransportException.php +++ b/htdocs/includes/swiftmailer/lib/classes/Swift/TransportException.php @@ -18,9 +18,8 @@ class Swift_TransportException extends Swift_IoException /** * Create a new TransportException with $message. * - * @param string $message - * @param int $code - * @param Exception $previous + * @param string $message + * @param int $code */ public function __construct($message, $code = 0, Exception $previous = null) { diff --git a/htdocs/includes/swiftmailer/lib/dependency_maps/cache_deps.php b/htdocs/includes/swiftmailer/lib/dependency_maps/cache_deps.php index 6023448e85e..9d94d774014 100644 --- a/htdocs/includes/swiftmailer/lib/dependency_maps/cache_deps.php +++ b/htdocs/includes/swiftmailer/lib/dependency_maps/cache_deps.php @@ -12,11 +12,11 @@ Swift_DependencyContainer::getInstance() ->register('cache.array') ->asSharedInstanceOf('Swift_KeyCache_ArrayKeyCache') - ->withDependencies(array('cache.inputstream')) + ->withDependencies(['cache.inputstream']) ->register('cache.disk') ->asSharedInstanceOf('Swift_KeyCache_DiskKeyCache') - ->withDependencies(array('cache.inputstream', 'tempdir')) + ->withDependencies(['cache.inputstream', 'tempdir']) ->register('cache.inputstream') ->asNewInstanceOf('Swift_KeyCache_SimpleKeyCacheInputStream') diff --git a/htdocs/includes/swiftmailer/lib/dependency_maps/mime_deps.php b/htdocs/includes/swiftmailer/lib/dependency_maps/mime_deps.php index 4ce9c7cbbc5..307756c89f3 100644 --- a/htdocs/includes/swiftmailer/lib/dependency_maps/mime_deps.php +++ b/htdocs/includes/swiftmailer/lib/dependency_maps/mime_deps.php @@ -13,101 +13,105 @@ Swift_DependencyContainer::getInstance() // As SERVER_NAME can come from the user in certain configurations, check that // it does not contain forbidden characters (see RFC 952 and RFC 2181). Use // preg_replace() instead of preg_match() to prevent DoS attacks with long host names. - ->asValue(!empty($_SERVER['SERVER_NAME']) && preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) === '' ? $_SERVER['SERVER_NAME'] : 'swift.generated') + ->asValue(!empty($_SERVER['SERVER_NAME']) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'swift.generated') ->register('mime.idgenerator') ->asSharedInstanceOf('Swift_Mime_IdGenerator') - ->withDependencies(array( + ->withDependencies([ 'mime.idgenerator.idright', - )) + ]) ->register('mime.message') ->asNewInstanceOf('Swift_Mime_SimpleMessage') - ->withDependencies(array( + ->withDependencies([ 'mime.headerset', - 'mime.qpcontentencoder', + 'mime.textcontentencoder', 'cache', 'mime.idgenerator', 'properties.charset', - )) + ]) ->register('mime.part') ->asNewInstanceOf('Swift_Mime_MimePart') - ->withDependencies(array( + ->withDependencies([ 'mime.headerset', - 'mime.qpcontentencoder', + 'mime.textcontentencoder', 'cache', 'mime.idgenerator', 'properties.charset', - )) + ]) ->register('mime.attachment') ->asNewInstanceOf('Swift_Mime_Attachment') - ->withDependencies(array( + ->withDependencies([ 'mime.headerset', 'mime.base64contentencoder', 'cache', 'mime.idgenerator', - )) + ]) ->addConstructorValue($swift_mime_types) ->register('mime.embeddedfile') ->asNewInstanceOf('Swift_Mime_EmbeddedFile') - ->withDependencies(array( + ->withDependencies([ 'mime.headerset', 'mime.base64contentencoder', 'cache', 'mime.idgenerator', - )) + ]) ->addConstructorValue($swift_mime_types) ->register('mime.headerfactory') ->asNewInstanceOf('Swift_Mime_SimpleHeaderFactory') - ->withDependencies(array( - 'mime.qpheaderencoder', - 'mime.rfc2231encoder', - 'email.validator', - 'properties.charset', - )) + ->withDependencies([ + 'mime.qpheaderencoder', + 'mime.rfc2231encoder', + 'email.validator', + 'properties.charset', + 'address.idnaddressencoder', + ]) ->register('mime.headerset') ->asNewInstanceOf('Swift_Mime_SimpleHeaderSet') - ->withDependencies(array('mime.headerfactory', 'properties.charset')) + ->withDependencies(['mime.headerfactory', 'properties.charset']) ->register('mime.qpheaderencoder') ->asNewInstanceOf('Swift_Mime_HeaderEncoder_QpHeaderEncoder') - ->withDependencies(array('mime.charstream')) + ->withDependencies(['mime.charstream']) ->register('mime.base64headerencoder') ->asNewInstanceOf('Swift_Mime_HeaderEncoder_Base64HeaderEncoder') - ->withDependencies(array('mime.charstream')) + ->withDependencies(['mime.charstream']) ->register('mime.charstream') ->asNewInstanceOf('Swift_CharacterStream_NgCharacterStream') - ->withDependencies(array('mime.characterreaderfactory', 'properties.charset')) + ->withDependencies(['mime.characterreaderfactory', 'properties.charset']) ->register('mime.bytecanonicalizer') ->asSharedInstanceOf('Swift_StreamFilters_ByteArrayReplacementFilter') - ->addConstructorValue(array(array(0x0D, 0x0A), array(0x0D), array(0x0A))) - ->addConstructorValue(array(array(0x0A), array(0x0A), array(0x0D, 0x0A))) + ->addConstructorValue([[0x0D, 0x0A], [0x0D], [0x0A]]) + ->addConstructorValue([[0x0A], [0x0A], [0x0D, 0x0A]]) ->register('mime.characterreaderfactory') ->asSharedInstanceOf('Swift_CharacterReaderFactory_SimpleCharacterReaderFactory') + ->register('mime.textcontentencoder') + ->asAliasOf('mime.qpcontentencoder') + ->register('mime.safeqpcontentencoder') ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoder') - ->withDependencies(array('mime.charstream', 'mime.bytecanonicalizer')) + ->withDependencies(['mime.charstream', 'mime.bytecanonicalizer']) ->register('mime.rawcontentencoder') ->asNewInstanceOf('Swift_Mime_ContentEncoder_RawContentEncoder') ->register('mime.nativeqpcontentencoder') - ->withDependencies(array('properties.charset')) + ->withDependencies(['properties.charset']) ->asNewInstanceOf('Swift_Mime_ContentEncoder_NativeQpContentEncoder') ->register('mime.qpcontentencoder') ->asNewInstanceOf('Swift_Mime_ContentEncoder_QpContentEncoderProxy') - ->withDependencies(array('mime.safeqpcontentencoder', 'mime.nativeqpcontentencoder', 'properties.charset')) + ->withDependencies(['mime.safeqpcontentencoder', 'mime.nativeqpcontentencoder', 'properties.charset']) ->register('mime.7bitcontentencoder') ->asNewInstanceOf('Swift_Mime_ContentEncoder_PlainContentEncoder') @@ -124,7 +128,7 @@ Swift_DependencyContainer::getInstance() ->register('mime.rfc2231encoder') ->asNewInstanceOf('Swift_Encoder_Rfc2231Encoder') - ->withDependencies(array('mime.charstream')) + ->withDependencies(['mime.charstream']) ; unset($swift_mime_types); diff --git a/htdocs/includes/swiftmailer/lib/dependency_maps/transport_deps.php b/htdocs/includes/swiftmailer/lib/dependency_maps/transport_deps.php index 15772abb255..34a63c78e51 100644 --- a/htdocs/includes/swiftmailer/lib/dependency_maps/transport_deps.php +++ b/htdocs/includes/swiftmailer/lib/dependency_maps/transport_deps.php @@ -5,24 +5,25 @@ Swift_DependencyContainer::getInstance() // As SERVER_NAME can come from the user in certain configurations, check that // it does not contain forbidden characters (see RFC 952 and RFC 2181). Use // preg_replace() instead of preg_match() to prevent DoS attacks with long host names. - ->asValue(!empty($_SERVER['SERVER_NAME']) && preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) === '' ? trim($_SERVER['SERVER_NAME'], '[]') : '127.0.0.1') + ->asValue(!empty($_SERVER['SERVER_NAME']) && '' === preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $_SERVER['SERVER_NAME']) ? trim($_SERVER['SERVER_NAME'], '[]') : '127.0.0.1') ->register('transport.smtp') ->asNewInstanceOf('Swift_Transport_EsmtpTransport') - ->withDependencies(array( + ->withDependencies([ 'transport.buffer', - array('transport.authhandler'), + 'transport.smtphandlers', 'transport.eventdispatcher', 'transport.localdomain', - )) + 'address.idnaddressencoder', + ]) ->register('transport.sendmail') ->asNewInstanceOf('Swift_Transport_SendmailTransport') - ->withDependencies(array( + ->withDependencies([ 'transport.buffer', 'transport.eventdispatcher', 'transport.localdomain', - )) + ]) ->register('transport.loadbalanced') ->asNewInstanceOf('Swift_Transport_LoadBalancedTransport') @@ -32,27 +33,40 @@ Swift_DependencyContainer::getInstance() ->register('transport.spool') ->asNewInstanceOf('Swift_Transport_SpoolTransport') - ->withDependencies(array('transport.eventdispatcher')) + ->withDependencies(['transport.eventdispatcher']) ->register('transport.null') ->asNewInstanceOf('Swift_Transport_NullTransport') - ->withDependencies(array('transport.eventdispatcher')) + ->withDependencies(['transport.eventdispatcher']) ->register('transport.buffer') ->asNewInstanceOf('Swift_Transport_StreamBuffer') - ->withDependencies(array('transport.replacementfactory')) + ->withDependencies(['transport.replacementfactory']) + + ->register('transport.smtphandlers') + ->asArray() + ->withDependencies(['transport.authhandler']) ->register('transport.authhandler') ->asNewInstanceOf('Swift_Transport_Esmtp_AuthHandler') - ->withDependencies(array( - array( - 'transport.crammd5auth', - 'transport.loginauth', - 'transport.plainauth', - 'transport.ntlmauth', - 'transport.xoauth2auth', - ), - )) + ->withDependencies(['transport.authhandlers']) + + ->register('transport.authhandlers') + ->asArray() + ->withDependencies([ + 'transport.crammd5auth', + 'transport.loginauth', + 'transport.plainauth', + 'transport.ntlmauth', + 'transport.xoauth2auth', + ]) + + ->register('transport.smtputf8handler') + ->asNewInstanceOf('Swift_Transport_Esmtp_SmtpUtf8Handler') + + ->register('transport.8bitmimehandler') + ->asNewInstanceOf('Swift_Transport_Esmtp_EightBitMimeHandler') + ->addConstructorValue('8BITMIME') ->register('transport.crammd5auth') ->asNewInstanceOf('Swift_Transport_Esmtp_Auth_CramMd5Authenticator') @@ -74,4 +88,10 @@ Swift_DependencyContainer::getInstance() ->register('transport.replacementfactory') ->asSharedInstanceOf('Swift_StreamFilters_StringReplacementFilterFactory') + + ->register('address.idnaddressencoder') + ->asNewInstanceOf('Swift_AddressEncoder_IdnAddressEncoder') + + ->register('address.utf8addressencoder') + ->asNewInstanceOf('Swift_AddressEncoder_Utf8AddressEncoder') ; diff --git a/htdocs/includes/swiftmailer/lib/mime_types.php b/htdocs/includes/swiftmailer/lib/mime_types.php index b42c1cc1a3e..72c6fd2afa6 100644 --- a/htdocs/includes/swiftmailer/lib/mime_types.php +++ b/htdocs/includes/swiftmailer/lib/mime_types.php @@ -17,7 +17,7 @@ // You may add or take away what you like (lowercase required) -$swift_mime_types = array( +$swift_mime_types = [ '3dml' => 'text/vnd.in3d.3dml', '3ds' => 'image/x-3ds', '3g2' => 'video/3gpp2', @@ -1004,4 +1004,4 @@ $swift_mime_types = array( 'zirz' => 'application/vnd.zul', 'zmm' => 'application/vnd.handheld-entertainment+xml', '123' => 'application/vnd.lotus-1-2-3', -); +]; diff --git a/htdocs/includes/swiftmailer/lib/swiftmailer_generate_mimes_config.php b/htdocs/includes/swiftmailer/lib/swiftmailer_generate_mimes_config.php index 85f2d69f21c..ad8fd2aa0d5 100644 --- a/htdocs/includes/swiftmailer/lib/swiftmailer_generate_mimes_config.php +++ b/htdocs/includes/swiftmailer/lib/swiftmailer_generate_mimes_config.php @@ -1,8 +1,8 @@ #!/usr/bin/php 'application/x-php', 'php3' => 'application/x-php', 'php4' => 'application/x-php', @@ -95,7 +95,7 @@ function generateUpToDateMimeArray() 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xml' => 'application/xml', - ); + ]; // wrap array for generating file foreach ($valid_mime_types_preset as $extension => $mime_type) { @@ -103,17 +103,14 @@ function generateUpToDateMimeArray() $valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'"; } - // collect extensions - $valid_extensions = array(); - // all extensions from second match foreach ($matches[2] as $i => $extensions) { // explode multiple extensions from string - $extensions = explode(' ', strtolower($extensions)); + $extensions = explode(' ', strtolower($extensions ?? '')); // force array for foreach - if (!is_array($extensions)) { - $extensions = array($extensions); + if (!\is_array($extensions)) { + $extensions = [$extensions]; } foreach ($extensions as $extension) { @@ -121,10 +118,7 @@ function generateUpToDateMimeArray() $mime_type = $matches[1][$i]; // check if string length lower than 10 - if (strlen($extension) < 10) { - // add extension - $valid_extensions[] = $extension; - + if (\strlen($extension) < 10) { if (!isset($valid_mime_types[$mime_type])) { // generate array for mimetype to extension resolver (only first match) $valid_mime_types[$extension] = "'{$extension}' => '{$mime_type}'"; @@ -145,29 +139,24 @@ function generateUpToDateMimeArray() // get all matching extensions from match foreach ((array) $node->glob['pattern'] as $extension) { // skip none glob extensions - if (strpos($extension, '.') === false) { + if (false === strpos($extension ?? '', '.')) { continue; } // remove get only last part - $extension = explode('.', strtolower($extension)); + $extension = explode('.', strtolower($extension ?? '')); $extension = end($extension); - - // maximum length in database column - if (strlen($extension) <= 9) { - $valid_extensions[] = $extension; - } } if (isset($node->glob['pattern'][0])) { // mime type - $mime_type = strtolower((string) $node['type']); + $mime_type = strtolower((string) $node['type'] ?? ''); // get first extension - $extension = strtolower(trim($node->glob['ddpattern'][0], '*.')); + $extension = strtolower(trim($node->glob['ddpattern'][0] ?? '', '*.')); // skip none glob extensions and check if string length between 1 and 10 - if (strpos($extension, '.') !== false || strlen($extension) < 1 || strlen($extension) > 9) { + if (false !== strpos($extension, '.') || \strlen($extension) < 1 || \strlen($extension) > 9) { continue; } @@ -184,7 +173,7 @@ function generateUpToDateMimeArray() ksort($valid_mime_types); // combine mime types and extensions array - $output = "$preamble\$swift_mime_types = array(\n ".implode($valid_mime_types, ",\n ")."\n);"; + $output = "$preamble\$swift_mime_types = array(\n ".implode(",\n ", $valid_mime_types)."\n);"; // write mime_types.php config file @file_put_contents('./mime_types.php', $output); From a250c72ff360c8cb4cdc2875426bbaaf813cf88f Mon Sep 17 00:00:00 2001 From: kamel Date: Wed, 22 Dec 2021 15:29:11 +0100 Subject: [PATCH 2/3] FIX: Edit card not permitted when invoice is validated and INVOICE_CAN_ALWAYS_BE_EDITED is set to 0 --- htdocs/compta/facture/card.php | 88 ++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 5ae4f00c66e..8da9b2c92dc 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -122,6 +122,7 @@ $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancr $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send); $usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen); $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate))); +$usercanmodify = $usercancreate && ($object->statut == Facture::STATUS_DRAFT || ($object->statut == Facture::STATUS_VALIDATED && !empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED))); $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)); $usercancreatemargin = $user->rights->margins->creer; @@ -345,13 +346,13 @@ if (empty($reshook)) } } - elseif ($action == 'classin' && $usercancreate) + elseif ($action == 'classin' && $usercanmodify) { $object->fetch($id); $object->setProject($_POST['projectid']); } - elseif ($action == 'setmode' && $usercancreate) + elseif ($action == 'setmode' && $usercanmodify) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); @@ -359,7 +360,7 @@ if (empty($reshook)) dol_print_error($db, $object->error); } - elseif ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) + elseif ($action == 'setretainedwarrantyconditions' && $usercanmodify) { $object->fetch($id); $object->retained_warranty_fk_cond_reglement = 0; // To clean property @@ -374,7 +375,7 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } - elseif ($action == 'setretainedwarranty' && $user->rights->facture->creer) + elseif ($action == 'setretainedwarranty' && $usercanmodify) { $object->fetch($id); $result = $object->setRetainedWarranty(GETPOST('retained_warranty', 'float')); @@ -382,7 +383,7 @@ if (empty($reshook)) dol_print_error($db, $object->error); } - elseif ($action == 'setretainedwarrantydatelimit' && $user->rights->facture->creer) + elseif ($action == 'setretainedwarrantydatelimit' && $usercanmodify) { $object->fetch($id); $result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float')); @@ -392,16 +393,16 @@ if (empty($reshook)) // Multicurrency Code - elseif ($action == 'setmulticurrencycode' && $usercancreate) { + elseif ($action == 'setmulticurrencycode' && $usercanmodify) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); } // Multicurrency rate - elseif ($action == 'setmulticurrencyrate' && $usercancreate) { + elseif ($action == 'setmulticurrencyrate' && $usercanmodify) { $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); } - elseif ($action == 'setinvoicedate' && $usercancreate) + elseif ($action == 'setinvoicedate' && $usercanmodify) { $object->fetch($id); $old_date_lim_reglement = $object->date_lim_reglement; @@ -422,7 +423,7 @@ if (empty($reshook)) } } - elseif ($action == 'setdate_pointoftax' && $usercancreate) + elseif ($action == 'setdate_pointoftax' && $usercanmodify) { $object->fetch($id); $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); @@ -433,7 +434,7 @@ if (empty($reshook)) } } - elseif ($action == 'setconditions' && $usercancreate) + elseif ($action == 'setconditions' && $usercanmodify) { $object->fetch($id); $object->cond_reglement_code = 0; // To clean property @@ -470,7 +471,7 @@ if (empty($reshook)) } } - elseif ($action == 'setpaymentterm' && $usercancreate) + elseif ($action == 'setpaymentterm' && $usercanmodify) { $object->fetch($id); $object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST['paymenttermmonth'], $_POST['paymenttermday'], $_POST['paymenttermyear']); @@ -484,7 +485,7 @@ if (empty($reshook)) } } - elseif ($action == 'setrevenuestamp' && $usercancreate) + elseif ($action == 'setrevenuestamp' && $usercanmodify) { $object->fetch($id); $object->revenuestamp = GETPOST('revenuestamp'); @@ -515,24 +516,24 @@ if (empty($reshook)) } // Set incoterm - elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) + elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled) && $usercanmodify) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); } // bank account - elseif ($action == 'setbankaccount' && $usercancreate) + elseif ($action == 'setbankaccount' && $usercanmodify) { $result = $object->setBankAccount(GETPOST('fk_account', 'int')); } - elseif ($action == 'setremisepercent' && $usercancreate) + elseif ($action == 'setremisepercent' && $usercanmodify) { $object->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']); } - elseif ($action == "setabsolutediscount" && $usercancreate) + elseif ($action == "setabsolutediscount" && $usercanmodify) { // POST[remise_id] or POST[remise_id_for_payment] @@ -590,13 +591,13 @@ if (empty($reshook)) } } - elseif ($action == 'setref' && $usercancreate) + elseif ($action == 'setref' && $usercanmodify) { $object->fetch($id); $object->setValueFrom('ref', GETPOST('ref'), '', null, '', '', $user, 'BILL_MODIFY'); } - elseif ($action == 'setref_client' && $usercancreate) + elseif ($action == 'setref_client' && $usercanmodify) { $object->fetch($id); $object->set_ref_client(GETPOST('ref_client')); @@ -1971,7 +1972,7 @@ if (empty($reshook)) } // Add a new line - elseif ($action == 'addline' && $usercancreate) + elseif ($action == 'addline' && $usercanmodify) { $langs->load('errors'); $error = 0; @@ -2300,7 +2301,7 @@ if (empty($reshook)) } } - elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) + elseif ($action == 'updateline' && $usercanmodify && !GETPOST('cancel', 'alpha')) { if (!$object->fetch($id) > 0) dol_print_error($db); $object->fetch_thirdparty(); @@ -2510,7 +2511,7 @@ if (empty($reshook)) } } - elseif ($action == 'updatealllines' && $usercancreate && $_POST['all_percent'] == $langs->trans('Modifier')) // Update all lines of situation invoice + elseif ($action == 'updatealllines' && $usercanmodify && $_POST['all_percent'] == $langs->trans('Modifier')) // Update all lines of situation invoice { if (!$object->fetch($id) > 0) dol_print_error($db); if (GETPOST('all_progress') != "") @@ -2529,7 +2530,7 @@ if (empty($reshook)) } } - elseif ($action == 'updateline' && $usercancreate && $_POST['cancel'] == $langs->trans('Cancel')) { + elseif ($action == 'updateline' && $usercanmodify && $_POST['cancel'] == $langs->trans('Cancel')) { header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); // To show again edited page exit(); } @@ -2755,7 +2756,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; - if ($action == 'update_extras') { + if ($action == 'update_extras' && $usercanmodify) { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from add form @@ -3764,6 +3765,9 @@ elseif ($id > 0 || !empty($ref)) exit; } + // Reassign, case when status is reset to draft + $usercanmodify = $usercancreate && ($object->statut == Facture::STATUS_DRAFT || ($object->statut == Facture::STATUS_VALIDATED && !empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED))); + /* * Show object in view mode */ @@ -4131,13 +4135,13 @@ elseif ($id > 0 || !empty($ref)) $morehtmlref = '
'; // Ref invoice if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) { - $morehtmlref .= $form->editfieldkey("Ref", 'ref', $object->ref, $object, $usercancreate, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("Ref", 'ref', $object->ref, $object, $usercancreate, 'string', '', null, null, '', 1); + $morehtmlref .= $form->editfieldkey("Ref", 'ref', $object->ref, $object, $usercanmodify, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("Ref", 'ref', $object->ref, $object, $usercanmodify, 'string', '', null, null, '', 1); $morehtmlref .= '
'; } // Ref customer - $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', null, null, '', 1); + $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercanmodify, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercanmodify, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; @@ -4146,7 +4150,7 @@ elseif ($id > 0 || !empty($ref)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($usercancreate) + if ($usercanmodify) { if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; @@ -4262,7 +4266,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $usercanmodify && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) print ''; print '
'; print $langs->trans('DateInvoice'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; @@ -4287,7 +4291,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - print ''; + if ($usercanmodify) print ''; print '
'; print $langs->trans('DatePointOfTax'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; if ($action == 'editdate_pointoftax') { @@ -4303,7 +4307,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercancreate) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercanmodify) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; print ''; @@ -4324,7 +4328,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercancreate) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercanmodify) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; @@ -4348,7 +4352,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($action != 'editmode' && $usercancreate) + if ($action != 'editmode' && $usercanmodify) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; print ''; @@ -4371,7 +4375,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($usercancreate && $action != 'editmulticurrencycode' && !empty($object->brouillon)) + if ($usercanmodify && $action != 'editmulticurrencycode' && !empty($object->brouillon)) print ''; print '
'; print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; print ''; @@ -4387,7 +4391,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($usercancreate && $action != 'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) + if ($usercanmodify && $action != 'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) print ''; print '
'; print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; print ''; @@ -4395,7 +4399,7 @@ elseif ($id > 0 || !empty($ref)) if ($action == 'actualizemulticurrencyrate') { list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); } - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ? 'multicurrency_tx' : 'none'), $object->multicurrency_code); + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, ($usercanmodify ? 'multicurrency_tx' : 'none'), $object->multicurrency_code); } else { $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { @@ -4413,7 +4417,7 @@ elseif ($id > 0 || !empty($ref)) print ''; print '
'; print $langs->trans('BankAccount'); print ''; - if (($action != 'editbankaccount') && $usercancreate) + if (($action != 'editbankaccount') && $usercanmodify) print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; print ''; @@ -4435,7 +4439,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('IncotermLabel'); print ''; - if ($usercancreate) print ''.img_edit().''; + if ($usercanmodify) print ''.img_edit().''; else print ' '; print '
'; print ''; @@ -4465,7 +4469,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($action != 'editretainedwarranty' && $user->rights->facture->creer) { + if ($action != 'editretainedwarranty' && $usercanmodify) { print ''; } @@ -4491,7 +4495,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('RetainedWarranty'); print 'id.'">'.img_edit($langs->trans('setretainedwarranty'), 1).'
'; - if ($action != 'editretainedwarrantypaymentterms' && $user->rights->facture->creer) { + if ($action != 'editretainedwarrantypaymentterms' && $usercanmodify) { print ''; } @@ -4529,7 +4533,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('PaymentConditionsShortRetainedWarranty'); print 'id.'">'.img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1).'
'; - if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer) { + if ($action != 'editretainedwarrantydatelimit' && $usercanmodify) { print ''; } @@ -4616,7 +4620,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('RetainedWarrantyDateLimit'); print 'id.'">'.img_edit($langs->trans('setretainedwarrantyDateLimit'), 1).'
'; - if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) + if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $usercanmodify) { print ''; } From 551e187b21e1963a4223c896ed747eed5d65b5ed Mon Sep 17 00:00:00 2001 From: kamel Date: Wed, 22 Dec 2021 15:35:41 +0100 Subject: [PATCH 3/3] Revert "FIX: Edit card not permitted when invoice is validated and INVOICE_CAN_ALWAYS_BE_EDITED is set to 0" This reverts commit a250c72ff360c8cb4cdc2875426bbaaf813cf88f. --- htdocs/compta/facture/card.php | 88 ++++++++++++++++------------------ 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 8da9b2c92dc..5ae4f00c66e 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -122,7 +122,6 @@ $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancr $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send); $usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen); $usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate))); -$usercanmodify = $usercancreate && ($object->statut == Facture::STATUS_DRAFT || ($object->statut == Facture::STATUS_VALIDATED && !empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED))); $usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)); $usercancreatemargin = $user->rights->margins->creer; @@ -346,13 +345,13 @@ if (empty($reshook)) } } - elseif ($action == 'classin' && $usercanmodify) + elseif ($action == 'classin' && $usercancreate) { $object->fetch($id); $object->setProject($_POST['projectid']); } - elseif ($action == 'setmode' && $usercanmodify) + elseif ($action == 'setmode' && $usercancreate) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); @@ -360,7 +359,7 @@ if (empty($reshook)) dol_print_error($db, $object->error); } - elseif ($action == 'setretainedwarrantyconditions' && $usercanmodify) + elseif ($action == 'setretainedwarrantyconditions' && $user->rights->facture->creer) { $object->fetch($id); $object->retained_warranty_fk_cond_reglement = 0; // To clean property @@ -375,7 +374,7 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } - elseif ($action == 'setretainedwarranty' && $usercanmodify) + elseif ($action == 'setretainedwarranty' && $user->rights->facture->creer) { $object->fetch($id); $result = $object->setRetainedWarranty(GETPOST('retained_warranty', 'float')); @@ -383,7 +382,7 @@ if (empty($reshook)) dol_print_error($db, $object->error); } - elseif ($action == 'setretainedwarrantydatelimit' && $usercanmodify) + elseif ($action == 'setretainedwarrantydatelimit' && $user->rights->facture->creer) { $object->fetch($id); $result = $object->setRetainedWarrantyDateLimit(GETPOST('retained_warranty_date_limit', 'float')); @@ -393,16 +392,16 @@ if (empty($reshook)) // Multicurrency Code - elseif ($action == 'setmulticurrencycode' && $usercanmodify) { + elseif ($action == 'setmulticurrencycode' && $usercancreate) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); } // Multicurrency rate - elseif ($action == 'setmulticurrencyrate' && $usercanmodify) { + elseif ($action == 'setmulticurrencyrate' && $usercancreate) { $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); } - elseif ($action == 'setinvoicedate' && $usercanmodify) + elseif ($action == 'setinvoicedate' && $usercancreate) { $object->fetch($id); $old_date_lim_reglement = $object->date_lim_reglement; @@ -423,7 +422,7 @@ if (empty($reshook)) } } - elseif ($action == 'setdate_pointoftax' && $usercanmodify) + elseif ($action == 'setdate_pointoftax' && $usercancreate) { $object->fetch($id); $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); @@ -434,7 +433,7 @@ if (empty($reshook)) } } - elseif ($action == 'setconditions' && $usercanmodify) + elseif ($action == 'setconditions' && $usercancreate) { $object->fetch($id); $object->cond_reglement_code = 0; // To clean property @@ -471,7 +470,7 @@ if (empty($reshook)) } } - elseif ($action == 'setpaymentterm' && $usercanmodify) + elseif ($action == 'setpaymentterm' && $usercancreate) { $object->fetch($id); $object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST['paymenttermmonth'], $_POST['paymenttermday'], $_POST['paymenttermyear']); @@ -485,7 +484,7 @@ if (empty($reshook)) } } - elseif ($action == 'setrevenuestamp' && $usercanmodify) + elseif ($action == 'setrevenuestamp' && $usercancreate) { $object->fetch($id); $object->revenuestamp = GETPOST('revenuestamp'); @@ -516,24 +515,24 @@ if (empty($reshook)) } // Set incoterm - elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled) && $usercanmodify) + elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); } // bank account - elseif ($action == 'setbankaccount' && $usercanmodify) + elseif ($action == 'setbankaccount' && $usercancreate) { $result = $object->setBankAccount(GETPOST('fk_account', 'int')); } - elseif ($action == 'setremisepercent' && $usercanmodify) + elseif ($action == 'setremisepercent' && $usercancreate) { $object->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']); } - elseif ($action == "setabsolutediscount" && $usercanmodify) + elseif ($action == "setabsolutediscount" && $usercancreate) { // POST[remise_id] or POST[remise_id_for_payment] @@ -591,13 +590,13 @@ if (empty($reshook)) } } - elseif ($action == 'setref' && $usercanmodify) + elseif ($action == 'setref' && $usercancreate) { $object->fetch($id); $object->setValueFrom('ref', GETPOST('ref'), '', null, '', '', $user, 'BILL_MODIFY'); } - elseif ($action == 'setref_client' && $usercanmodify) + elseif ($action == 'setref_client' && $usercancreate) { $object->fetch($id); $object->set_ref_client(GETPOST('ref_client')); @@ -1972,7 +1971,7 @@ if (empty($reshook)) } // Add a new line - elseif ($action == 'addline' && $usercanmodify) + elseif ($action == 'addline' && $usercancreate) { $langs->load('errors'); $error = 0; @@ -2301,7 +2300,7 @@ if (empty($reshook)) } } - elseif ($action == 'updateline' && $usercanmodify && !GETPOST('cancel', 'alpha')) + elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) { if (!$object->fetch($id) > 0) dol_print_error($db); $object->fetch_thirdparty(); @@ -2511,7 +2510,7 @@ if (empty($reshook)) } } - elseif ($action == 'updatealllines' && $usercanmodify && $_POST['all_percent'] == $langs->trans('Modifier')) // Update all lines of situation invoice + elseif ($action == 'updatealllines' && $usercancreate && $_POST['all_percent'] == $langs->trans('Modifier')) // Update all lines of situation invoice { if (!$object->fetch($id) > 0) dol_print_error($db); if (GETPOST('all_progress') != "") @@ -2530,7 +2529,7 @@ if (empty($reshook)) } } - elseif ($action == 'updateline' && $usercanmodify && $_POST['cancel'] == $langs->trans('Cancel')) { + elseif ($action == 'updateline' && $usercancreate && $_POST['cancel'] == $langs->trans('Cancel')) { header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); // To show again edited page exit(); } @@ -2756,7 +2755,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; - if ($action == 'update_extras' && $usercanmodify) { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from add form @@ -3765,9 +3764,6 @@ elseif ($id > 0 || !empty($ref)) exit; } - // Reassign, case when status is reset to draft - $usercanmodify = $usercancreate && ($object->statut == Facture::STATUS_DRAFT || ($object->statut == Facture::STATUS_VALIDATED && !empty($conf->global->INVOICE_CAN_ALWAYS_BE_EDITED))); - /* * Show object in view mode */ @@ -4135,13 +4131,13 @@ elseif ($id > 0 || !empty($ref)) $morehtmlref = '
'; // Ref invoice if ($object->status == $object::STATUS_DRAFT && !$mysoc->isInEEC() && !empty($conf->global->INVOICE_ALLOW_FREE_REF)) { - $morehtmlref .= $form->editfieldkey("Ref", 'ref', $object->ref, $object, $usercanmodify, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("Ref", 'ref', $object->ref, $object, $usercanmodify, 'string', '', null, null, '', 1); + $morehtmlref .= $form->editfieldkey("Ref", 'ref', $object->ref, $object, $usercancreate, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("Ref", 'ref', $object->ref, $object, $usercancreate, 'string', '', null, null, '', 1); $morehtmlref .= '
'; } // Ref customer - $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercanmodify, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercanmodify, 'string', '', null, null, '', 1); + $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1); + $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'customer'); if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref .= ' ('.$langs->trans("OtherBills").')'; @@ -4150,7 +4146,7 @@ elseif ($id > 0 || !empty($ref)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($usercanmodify) + if ($usercancreate) { if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; @@ -4266,7 +4262,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('RevenueStamp'); print 'id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'
'; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $usercanmodify && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && !empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) print ''; print '
'; print $langs->trans('DateInvoice'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; @@ -4291,7 +4287,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($usercanmodify) print ''; + print ''; print '
'; print $langs->trans('DatePointOfTax'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; if ($action == 'editdate_pointoftax') { @@ -4307,7 +4303,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercanmodify) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercancreate) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; print ''; @@ -4328,7 +4324,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercanmodify) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercancreate) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id.'">'.img_edit($langs->trans('SetDate'), 1).'
'; print ''; @@ -4352,7 +4348,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($action != 'editmode' && $usercanmodify) + if ($action != 'editmode' && $usercancreate) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; print ''; @@ -4375,7 +4371,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($usercanmodify && $action != 'editmulticurrencycode' && !empty($object->brouillon)) + if ($usercancreate && $action != 'editmulticurrencycode' && !empty($object->brouillon)) print ''; print '
'; print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0); print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; print ''; @@ -4391,7 +4387,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($usercanmodify && $action != 'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) + if ($usercancreate && $action != 'editmulticurrencyrate' && !empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) print ''; print '
'; print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0); print 'id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'
'; print ''; @@ -4399,7 +4395,7 @@ elseif ($id > 0 || !empty($ref)) if ($action == 'actualizemulticurrencyrate') { list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); } - $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, ($usercanmodify ? 'multicurrency_tx' : 'none'), $object->multicurrency_code); + $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, ($usercancreate ? 'multicurrency_tx' : 'none'), $object->multicurrency_code); } else { $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) { @@ -4417,7 +4413,7 @@ elseif ($id > 0 || !empty($ref)) print ''; print '
'; print $langs->trans('BankAccount'); print ''; - if (($action != 'editbankaccount') && $usercanmodify) + if (($action != 'editbankaccount') && $usercancreate) print 'id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'
'; print ''; @@ -4439,7 +4435,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('IncotermLabel'); print ''; - if ($usercanmodify) print ''.img_edit().''; + if ($usercancreate) print ''.img_edit().''; else print ' '; print '
'; print ''; @@ -4469,7 +4465,7 @@ elseif ($id > 0 || !empty($ref)) print ''; - if ($action != 'editretainedwarranty' && $usercanmodify) { + if ($action != 'editretainedwarranty' && $user->rights->facture->creer) { print ''; } @@ -4495,7 +4491,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('RetainedWarranty'); print 'id.'">'.img_edit($langs->trans('setretainedwarranty'), 1).'
'; - if ($action != 'editretainedwarrantypaymentterms' && $usercanmodify) { + if ($action != 'editretainedwarrantypaymentterms' && $user->rights->facture->creer) { print ''; } @@ -4533,7 +4529,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('PaymentConditionsShortRetainedWarranty'); print 'id.'">'.img_edit($langs->trans('setPaymentConditionsShortRetainedWarranty'), 1).'
'; - if ($action != 'editretainedwarrantydatelimit' && $usercanmodify) { + if ($action != 'editretainedwarrantydatelimit' && $user->rights->facture->creer) { print ''; } @@ -4620,7 +4616,7 @@ elseif ($id > 0 || !empty($ref)) print '
'; print $langs->trans('RetainedWarrantyDateLimit'); print 'id.'">'.img_edit($langs->trans('setretainedwarrantyDateLimit'), 1).'
'; - if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $usercanmodify) + if ($action != 'editrevenuestamp' && !empty($object->brouillon) && $usercancreate) { print ''; }
'; print $langs->trans('RevenueStamp'); print 'id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'