From 159f899e1af201eb751d7486a2380662a7a6b53a Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 4 Nov 2021 21:42:05 +0100 Subject: [PATCH] Replace slow call_user_func()/call_user_func_array() with simple calls and splat --- .../app/libraries/MailSo/Base/HtmlUtils.php | 30 ++++----- .../app/libraries/MailSo/Base/LinkFinder.php | 14 ++--- .../0.0.0/app/libraries/MailSo/Base/Utils.php | 13 ++-- .../v/0.0.0/app/libraries/MailSo/Hooks.php | 2 +- .../libraries/MailSo/Imap/BodyStructure.php | 18 +++--- .../MailSo/Imap/Enumerations/FetchType.php | 4 +- .../app/libraries/MailSo/Imap/ImapClient.php | 1 + .../MailSo/Imap/Traits/ResponseParser.php | 63 +++++++------------ .../libraries/MailSo/Log/Drivers/Callback.php | 4 +- .../app/libraries/MailSo/Mail/MailClient.php | 21 +++---- .../0.0.0/app/libraries/RainLoop/Actions.php | 24 +++---- .../app/libraries/RainLoop/Actions/User.php | 18 +++--- .../libraries/RainLoop/Plugins/Manager.php | 14 ++--- .../0.0.0/app/libraries/RainLoop/Service.php | 8 +-- .../app/libraries/RainLoop/ServiceActions.php | 32 +++++----- .../v/0.0.0/app/libraries/lessphp/lessc.php | 2 +- 16 files changed, 125 insertions(+), 143 deletions(-) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php index dea80a882..49b46e0c2 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php @@ -255,7 +255,7 @@ abstract class HtmlUtils } $aHtmlAllowedTags = isset(\MailSo\Config::$HtmlStrictAllowedTags) && - \is_array(\MailSo\Config::$HtmlStrictAllowedTags) && 0 < \count(\MailSo\Config::$HtmlStrictAllowedTags) ? + \is_array(\MailSo\Config::$HtmlStrictAllowedTags) && \count(\MailSo\Config::$HtmlStrictAllowedTags) ? \MailSo\Config::$HtmlStrictAllowedTags : null; $aRemove = array(); @@ -311,7 +311,7 @@ abstract class HtmlUtils $sValue = 'absolute'; } - if (0 === \strlen($sName) || 0 === \strlen($sValue)) + if (!\strlen($sName) || !\strlen($sValue)) { continue; } @@ -379,8 +379,8 @@ abstract class HtmlUtils if ($fAdditionalExternalFilter) { - $sAdditionalResult = \call_user_func($fAdditionalExternalFilter, $sUrl); - if (0 < \strlen($sAdditionalResult)) + $sAdditionalResult = $fAdditionalExternalFilter($sUrl); + if (\strlen($sAdditionalResult)) { $oElement->setAttribute('data-x-additional-style-url', ('background' === $sName ? 'background-image' : $sName).': url('.$sAdditionalResult.')'); @@ -444,7 +444,7 @@ abstract class HtmlUtils foreach ($aTextNodes as $oTextNode) { - if ($oTextNode && 0 < \strlen($oTextNode->wholeText)/* && \preg_match('/http[s]?:\/\//i', $oTextNode->wholeText)*/) + if ($oTextNode && \strlen($oTextNode->wholeText)/* && \preg_match('/http[s]?:\/\//i', $oTextNode->wholeText)*/) { $sText = (new \MailSo\Base\LinkFinder) ->Text($oTextNode->wholeText) @@ -517,7 +517,7 @@ abstract class HtmlUtils $sHtml = null === $sHtml ? '' : (string) $sHtml; $sHtml = \trim($sHtml); - if (0 === \strlen($sHtml)) + if (!\strlen($sHtml)) { return ''; } @@ -545,7 +545,7 @@ abstract class HtmlUtils if ($fAdditionalDomReader) { - $oResDom = \call_user_func($fAdditionalDomReader, $oDom); + $oResDom = $fAdditionalDomReader($oDom); if ($oResDom) { $oDom = $oResDom; @@ -633,7 +633,7 @@ abstract class HtmlUtils } } - if (0 < \count($aStyles)) + if (\count($aStyles)) { $sStyles .= $sStyles . '; ' . \implode('; ', $aStyles); } @@ -652,7 +652,7 @@ abstract class HtmlUtils if ($oElement->hasAttributes() && isset($oElement->attributes) && $oElement->attributes) { $aHtmlAllowedAttributes = isset(\MailSo\Config::$HtmlStrictAllowedAttributes) && - \is_array(\MailSo\Config::$HtmlStrictAllowedAttributes) && 0 < \count(\MailSo\Config::$HtmlStrictAllowedAttributes) ? + \is_array(\MailSo\Config::$HtmlStrictAllowedAttributes) && \count(\MailSo\Config::$HtmlStrictAllowedAttributes) ? \MailSo\Config::$HtmlStrictAllowedAttributes : null; $sAttrsForRemove = array(); @@ -676,7 +676,7 @@ abstract class HtmlUtils } } - if (0 < \count($sAttrsForRemove)) + if (\count($sAttrsForRemove)) { foreach ($sAttrsForRemove as $sName) { @@ -797,8 +797,8 @@ abstract class HtmlUtils $oElement->setAttribute('data-x-src', $sSrc); if ($fAdditionalExternalFilter) { - $sCallResult = \call_user_func($fAdditionalExternalFilter, $sSrc); - if (0 < \strlen($sCallResult)) + $sCallResult = $fAdditionalExternalFilter($sSrc); + if (\strlen($sCallResult)) { $oElement->setAttribute('data-x-additional-src', $sCallResult); } @@ -849,13 +849,13 @@ abstract class HtmlUtils $aFoundCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, $bDoNotReplaceExternalUrl, $fAdditionalExternalFilter)); } - if (\MailSo\Config::$HtmlStrictDebug && 0 < \count($aRemovedAttrs)) + if (\MailSo\Config::$HtmlStrictDebug && \count($aRemovedAttrs)) { unset($aRemovedAttrs['class'], $aRemovedAttrs['target'], $aRemovedAttrs['id'], $aRemovedAttrs['name'], $aRemovedAttrs['itemprop'], $aRemovedAttrs['itemscope'], $aRemovedAttrs['itemtype']); $aRemovedAttrs = \array_keys($aRemovedAttrs); - if (0 < \count($aRemovedAttrs)) + if (\count($aRemovedAttrs)) { $oElement->setAttribute('data-removed-attrs', \implode(',', $aRemovedAttrs)); } @@ -1006,7 +1006,7 @@ abstract class HtmlUtils public static function ConvertPlainToHtml(string $sText, bool $bLinksWithTargetBlank = true) : string { $sText = \trim($sText); - if (0 === \strlen($sText)) + if (!\strlen($sText)) { return ''; } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/LinkFinder.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/LinkFinder.php index 2d1e805bf..d6286eb87 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/LinkFinder.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/LinkFinder.php @@ -153,7 +153,7 @@ class LinkFinder unset($sText, $sSubText); - if (0 < \count($this->aPrepearPlainStringUrls)) + if (\count($this->aPrepearPlainStringUrls)) { $aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls; $sResult = \preg_replace_callback('/'.\preg_quote(static::OPEN_LINK, '/'). @@ -195,8 +195,8 @@ class LinkFinder } } - $sLinkWithWrap = \call_user_func($fWrapper, $aMatch[2].$aMatch[3]); - if (\is_string($sLinkWithWrap) && 0 < \strlen($sLinkWithWrap)) + $sLinkWithWrap = $fWrapper($aMatch[2].$aMatch[3]); + if (\is_string($sLinkWithWrap) && \strlen($sLinkWithWrap)) { $aPrepearPlainStringUrls[] = \stripslashes($sLinkWithWrap); return $aMatch[1]. @@ -213,7 +213,7 @@ class LinkFinder }, $sText); - if (0 < \count($aPrepearPlainStringUrls)) + if (\count($aPrepearPlainStringUrls)) { $this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls; } @@ -233,8 +233,8 @@ class LinkFinder if (\is_array($aMatch) && isset($aMatch[1])) { - $sMailWithWrap = \call_user_func($fWrapper, $aMatch[1]); - if (\is_string($sMailWithWrap) && 0 < \strlen($sMailWithWrap)) + $sMailWithWrap = $fWrapper($aMatch[1]); + if (\is_string($sMailWithWrap) && \strlen($sMailWithWrap)) { $aPrepearPlainStringUrls[] = \stripslashes($sMailWithWrap); return static::OPEN_LINK. @@ -249,7 +249,7 @@ class LinkFinder }, $sText); - if (0 < \count($aPrepearPlainStringUrls)) + if (\count($aPrepearPlainStringUrls)) { $this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls; } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php index ac5bf5b00..31d0df783 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php @@ -110,7 +110,7 @@ END; }; } - if (!\call_user_func($fFileExistsCallback, $sFilePath)) + if (!$fFileExistsCallback($sFilePath)) { return $sFilePath; } @@ -129,7 +129,7 @@ END; (empty($aFileInfo['extension']) ? '' : '.'.$aFileInfo['extension']) ; - if (!\call_user_func($fFileExistsCallback, $sFilePathNew)) + if (!$fFileExistsCallback($sFilePathNew)) { $sFilePath = $sFilePathNew; break; @@ -152,9 +152,8 @@ END; $aSupportedEncodings = \array_map('strtoupper', \array_unique( \array_merge( $aSupportedEncodings, - \call_user_func_array( - 'array_merge', - \array_map( + array_merge( + ...\array_map( 'mb_encoding_aliases', $aSupportedEncodings ) @@ -1200,7 +1199,7 @@ END; public static function PrepareFetchSequence(array $aSequence) : string { $aResult = array(); - if (0 < \count($aSequence)) + if (\count($aSequence)) { $iStart = null; $iPrev = null; @@ -1276,7 +1275,7 @@ END; public static function MultipleStreamWriter($rRead, array $aWrite, int $iBufferLen = 8192, bool $bResetTimeLimit = true, bool $bFixCrLf = false, bool $bRewindOnComplete = false) : int { $mResult = false; - if ($rRead && 0 < \count($aWrite)) + if ($rRead && \count($aWrite)) { $mResult = 0; while (!\feof($rRead)) diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Hooks.php b/snappymail/v/0.0.0/app/libraries/MailSo/Hooks.php index 75dc0e6ea..bcf0b999c 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Hooks.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Hooks.php @@ -27,7 +27,7 @@ class Hooks { foreach (static::$aCallbacks[$sName] as $mCallback) { - \call_user_func_array($mCallback, $aArg); + $mCallback(...$aArg); } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/BodyStructure.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/BodyStructure.php index 9e11c9f9a..1e07425eb 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/BodyStructure.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/BodyStructure.php @@ -172,7 +172,7 @@ class BodyStructure public function IsInline() : bool { return (null === $this->sDisposition) ? - (0 < \strlen($this->ContentID())) : ('inline' === strtolower($this->sDisposition)); + (\strlen($this->ContentID())) : ('inline' === strtolower($this->sDisposition)); } public function IsImage() : bool @@ -328,7 +328,7 @@ class BodyStructure public function SearchByCallback($fCallback) : array { $aReturn = array(); - if (\call_user_func($fCallback, $this)) + if ($fCallback($this)) { $aReturn[] = $this; } @@ -359,7 +359,7 @@ class BodyStructure public function GetPartByMimeIndex(string $sMimeIndex) : self { $oPart = null; - if (0 < \strlen($sMimeIndex)) + if (\strlen($sMimeIndex)) { if ($sMimeIndex === $this->sPartID) { @@ -419,7 +419,7 @@ class BodyStructure if ($sCharsetIndex < $iIndex && false !== \strpos($sValue, "''")) { $aValueParts = \explode("''", $sValue, 2); - if (2 === \count($aValueParts) && 0 < \strlen($aValueParts[0])) + if (2 === \count($aValueParts) && \strlen($aValueParts[0])) { $sCharsetIndex = $iIndex; $sCharset = $aValueParts[0]; @@ -431,13 +431,13 @@ class BodyStructure } } - if (0 < \count($aFileNames)) + if (\count($aFileNames)) { \ksort($aFileNames, SORT_NUMERIC); $sResult = \implode(\array_values($aFileNames)); $sResult = \urldecode($sResult); - if (0 < \strlen($sCharset)) + if (\strlen($sCharset)) { $sResult = \MailSo\Base\Utils::ConvertEncoding($sResult, $sCharset, \MailSo\Base\Enumerations\Charset::UTF_8); @@ -484,13 +484,13 @@ class BodyStructure $sBodyMainType = 'multipart'; $sSubPartIDPrefix = ''; - if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) + if (!\strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) { // This multi-part is root part of message. $sSubPartIDPrefix = $sPartID; $sPartID .= 'TEXT'; } - else if (0 < \strlen($sPartID)) + else if (\strlen($sPartID)) { // This multi-part is a part of another multi-part. $sSubPartIDPrefix = $sPartID.'.'; @@ -606,7 +606,7 @@ class BodyStructure $iSize = -1; } - if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) + if (!\strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1]) { // This is the only sub-part of the message (otherwise, it would be // one of sub-parts of a multi-part, and partID would already be fully set up). diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php index bf3362efd..8b8a6a0bb 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php @@ -46,7 +46,7 @@ abstract class FetchType { $aReturn[$mType] = ''; } - else if (\is_array($mType) && 2 === count($mType) && \is_string($mType[0]) && + else if (\is_array($mType) && 2 === \count($mType) && \is_string($mType[0]) && \is_callable($mType[1])) { $aReturn[$mType[0]] = $mType[1]; @@ -56,7 +56,7 @@ abstract class FetchType public static function BuildBodyCustomHeaderRequest(array $aHeaders, bool $bPeek = true) : string { $sResult = ''; - if (0 < \count($aHeaders)) + if (\count($aHeaders)) { $aHeaders = \array_map('trim', $aHeaders); $aHeaders = \array_map('strtoupper', $aHeaders); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index 8dbcb2cec..e0b067d8e 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -41,6 +41,7 @@ class ImapClient extends \MailSo\Net\NetClient private $oCurrentFolderInfo = null; /** + * Used by \MailSo\Mail\MailClient::MessageMimeStream * @var array */ private $aFetchCallbacks; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php index b5c41a5ca..5dbeb166d 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php @@ -72,7 +72,7 @@ trait ResponseParser */ private function partialParseResponseBranch(Response $oImapResponse, bool $bTreatAsAtom, - string $sParentToken, + ?string $sParentToken, string $sOpenBracket, bool $bRoot = false) { @@ -147,9 +147,9 @@ trait ResponseParser } case '(': $this->iResponseBufParsedPos = ++$iPos; - $mResult = $this->partialParseResponseBranch($oImapResponse, $bTreatAsAtom, - null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), - $sChar); + $mResult = $this->partialParseResponseBranch( + $oImapResponse, $bTreatAsAtom, $sPreviousAtomUpperCase, $sChar + ); $sPreviousAtomUpperCase = null; $iPos = $this->iResponseBufParsedPos; if ($bTreatAsAtom) { @@ -170,9 +170,7 @@ trait ResponseParser $iLiteralLen = (int) \substr($this->sResponseBuffer, $iPos + 1, $iLength); $iPos += 4 + $iLength; - if ($this->partialResponseLiteralCallbackCallable( - $sParentToken, null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), $iLiteralLen)) - { + if ($this->partialResponseLiteralCallbacks($sParentToken, $sPreviousAtomUpperCase, $iLiteralLen)) { if (!$bTreatAsAtom) { $aList[] = ''; } @@ -277,9 +275,9 @@ trait ResponseParser $this->iResponseBufParsedPos = ++$iPos; - $sListBlock = $this->partialParseResponseBranch($oImapResponse, true, - null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase), - '['); + $sListBlock = $this->partialParseResponseBranch( + $oImapResponse, true, $sPreviousAtomUpperCase, '[' + ); if (null !== $sListBlock) { @@ -305,7 +303,7 @@ trait ResponseParser if (null === $sAtomBuilder) { $aList[] = 'NIL' === $sLastCharBlock ? null : $sLastCharBlock; - $sPreviousAtomUpperCase = $sLastCharBlock; + $sPreviousAtomUpperCase = \strtoupper($sLastCharBlock); } else { @@ -314,7 +312,7 @@ trait ResponseParser if (!$bTreatAsAtom) { $aList[] = $sAtomBuilder; - $sPreviousAtomUpperCase = $sAtomBuilder; + $sPreviousAtomUpperCase = \strtoupper($sAtomBuilder); $sAtomBuilder = null; } } @@ -376,27 +374,21 @@ trait ResponseParser return $sLiteral; } - private function partialResponseLiteralCallbackCallable(string $sParent, string $sLiteralAtomUpperCase, int $iLiteralLen) : bool + private function partialResponseLiteralCallbacks(?string $sParent, ?string $sLiteralAtomUpperCase, int $iLiteralLen) : bool { - if (!$this->aFetchCallbacks) { + if (!$this->aFetchCallbacks || !$sLiteralAtomUpperCase || 'FETCH' !== $sParent) { return false; } $sLiteralAtomUpperCasePeek = ''; - if (0 === \strpos($sLiteralAtomUpperCase, 'BODY')) - { + if (0 === \strpos($sLiteralAtomUpperCase, 'BODY')) { $sLiteralAtomUpperCasePeek = \str_replace('BODY', 'BODY.PEEK', $sLiteralAtomUpperCase); } - $sFetchKey = ''; - if (\strlen($sLiteralAtomUpperCasePeek) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCasePeek])) - { + $sFetchKey = $sLiteralAtomUpperCase; + if ($sLiteralAtomUpperCasePeek && isset($this->aFetchCallbacks[$sLiteralAtomUpperCasePeek])) { $sFetchKey = $sLiteralAtomUpperCasePeek; } - else if (\strlen($sLiteralAtomUpperCase) && isset($this->aFetchCallbacks[$sLiteralAtomUpperCase])) - { - $sFetchKey = $sLiteralAtomUpperCase; - } if (empty($this->aFetchCallbacks[$sFetchKey]) || !\is_callable($this->aFetchCallbacks[$sFetchKey])) { return false; @@ -412,8 +404,7 @@ trait ResponseParser try { - \call_user_func($this->aFetchCallbacks[$sFetchKey], - $sParent, $sLiteralAtomUpperCase, $rImapLiteralStream); + $this->aFetchCallbacks[$sFetchKey]($sParent, $sLiteralAtomUpperCase, $rImapLiteralStream); } catch (\Throwable $oException) { @@ -421,8 +412,7 @@ trait ResponseParser $this->writeLogException($oException); } - if ($rImapLiteralStream) - { + if ($rImapLiteralStream) { $iNotReadLiteralLen = 0; $bFeof = \feof($rImapLiteralStream); @@ -430,13 +420,10 @@ trait ResponseParser ' - feof = '.($bFeof ? 'good' : 'BAD'), $bFeof ? \MailSo\Log\Enumerations\Type::NOTE : \MailSo\Log\Enumerations\Type::WARNING); - if (!$bFeof) - { - while (!\feof($rImapLiteralStream)) - { + if (!$bFeof) { + while (!\feof($rImapLiteralStream)) { $sBuf = \fread($rImapLiteralStream, 1024 * 1024); - if (false === $sBuf || 0 === \strlen($sBuf) || null === $sBuf) - { + if (!\strlen($sBuf)) { break; } @@ -444,22 +431,18 @@ trait ResponseParser $iNotReadLiteralLen += \strlen($sBuf); } - if (!\feof($rImapLiteralStream)) - { + if (!\feof($rImapLiteralStream)) { \stream_get_contents($rImapLiteralStream); } } \fclose($rImapLiteralStream); - if ($iNotReadLiteralLen > 0) - { + if (0 < $iNotReadLiteralLen) { $this->writeLog('Not read literal size is '.$iNotReadLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::WARNING); } - } - else - { + } else { $this->writeLog('Literal stream is not resource after callback.', \MailSo\Log\Enumerations\Type::WARNING); } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php index b185f47d6..27b634ad4 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php @@ -44,7 +44,7 @@ class Callback extends \MailSo\Log\Driver { if ($this->fWriteCallback) { - \call_user_func_array($this->fWriteCallback, array($mDesc)); + ($this->fWriteCallback)($mDesc); } return true; @@ -54,7 +54,7 @@ class Callback extends \MailSo\Log\Driver { if ($this->fClearCallback) { - \call_user_func($this->fClearCallback); + ($this->fClearCallback)(); } return true; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index 3f19f339f..d57d04938 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -369,21 +369,20 @@ class MailClient } $aFetchResponse = $this->oImapClient->Fetch(array( - array(\MailSo\Imap\Enumerations\FetchType::BODY_PEEK.'['.$sMimeIndex.']', + // Push in the aFetchCallbacks array and then called by \MailSo\Imap\Traits\ResponseParser::partialResponseLiteralCallbackCallable + array( + \MailSo\Imap\Enumerations\FetchType::BODY_PEEK.'['.$sMimeIndex.']', function ($sParent, $sLiteralAtomUpperCase, $rImapLiteralStream) use ($mCallback, $sMimeIndex, $sMailEncodingName, $sContentType, $sFileName) { - if (\strlen($sLiteralAtomUpperCase)) + if (\strlen($sLiteralAtomUpperCase) && \is_resource($rImapLiteralStream) && 'FETCH' === $sParent) { - if (\is_resource($rImapLiteralStream) && 'FETCH' === $sParent) - { - $rMessageMimeIndexStream = \strlen($sMailEncodingName) - ? \MailSo\Base\StreamWrappers\Binary::CreateStream($rImapLiteralStream, - \MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName( - $sMailEncodingName, true)) - : $rImapLiteralStream; + $rMessageMimeIndexStream = \strlen($sMailEncodingName) + ? \MailSo\Base\StreamWrappers\Binary::CreateStream($rImapLiteralStream, + \MailSo\Base\StreamWrappers\Binary::GetInlineDecodeOrEncodeFunctionName( + $sMailEncodingName, true)) + : $rImapLiteralStream; - \call_user_func($mCallback, $rMessageMimeIndexStream, $sContentType, $sFileName, $sMimeIndex); - } + $mCallback($rMessageMimeIndexStream, $sContentType, $sFileName, $sMimeIndex); } } )), $iIndex, $bIndexIsUid); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index b3f1e45a6..f3c6ab1b8 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -313,7 +313,7 @@ class Actions return \trim(\trim($sS), ' /'); }, $aSubQuery); - if (0 < \count($aSubQuery)) { + if (\count($aSubQuery)) { $sQuery .= '/' . \implode('/', $aSubQuery); } } @@ -465,7 +465,7 @@ class Actions $sFileName = \preg_replace('/[^a-zA-Z0-9@_+=\-\.\/!()\[\]]/', '', $sFileName); } - if (0 === \strlen($sFileName)) { + if (!\strlen($sFileName)) { $sFileName = 'rainloop-log.txt'; } @@ -485,7 +485,7 @@ class Actions $this->SetSpecAuthToken($sSpecAuthToken); Utils::SetCookie(self::AUTH_SPEC_TOKEN_KEY, $sSpecAuthToken); - if ($oAccount->SignMe() && 0 < \strlen($oAccount->SignMeToken())) { + if ($oAccount->SignMe() && \strlen($oAccount->SignMeToken())) { Utils::SetCookie(self::AUTH_SIGN_ME_TOKEN_KEY, Utils::EncodeKeyValuesQ(array( 'e' => $oAccount->Email(), @@ -861,7 +861,7 @@ class Actions protected function LoginProvide(string $sEmail, string $sLogin, string $sPassword, string $sSignMeToken = '', string $sClientCert = '', bool $bThrowProvideException = false): ?Model\Account { $oAccount = null; - if (0 < \strlen($sEmail) && 0 < \strlen($sLogin) && 0 < \strlen($sPassword)) { + if (\strlen($sEmail) && \strlen($sLogin) && \strlen($sPassword)) { $oDomain = $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true); if ($oDomain) { if ($oDomain->ValidateWhiteList($sEmail, $sLogin)) { @@ -1368,7 +1368,7 @@ class Actions $aDomainParts = \explode('.', $sUserHost); $oDomainProvider = $this->DomainProvider(); - while (0 < \count($aDomainParts) && 0 < $iLimit) { + while (\count($aDomainParts) && 0 < $iLimit) { $sLine = \trim(\implode('.', $aDomainParts), '. '); $oDomain = $oDomainProvider->Load($sLine, false); @@ -1407,7 +1407,7 @@ class Actions } $sDefDomain = \trim($this->Config()->Get('login', 'default_domain', '')); - if (false === \strpos($sEmail, '@') && 0 < \strlen($sDefDomain)) { + if (false === \strpos($sEmail, '@') && \strlen($sDefDomain)) { $this->Logger()->Write('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')', \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); @@ -1417,7 +1417,7 @@ class Actions $this->Plugins()->RunHook('login.credentials.step-2', array(&$sEmail, &$sPassword)); - if (false === \strpos($sEmail, '@') || 0 === \strlen($sPassword)) { + if (false === \strpos($sEmail, '@') || !\strlen($sPassword)) { $this->loginErrorDelay(); throw new Exceptions\ClientException(Notifications::InvalidInputArgument); @@ -1472,7 +1472,7 @@ class Actions $aAccounts = \json_decode($sAccounts, true); } - if (\is_array($aAccounts) && 0 < \count($aAccounts)) { + if (\is_array($aAccounts) && \count($aAccounts)) { if (1 === \count($aAccounts)) { $this->SetAccounts($oAccount, array()); @@ -1571,7 +1571,7 @@ class Actions case 'string': $sValue = (string)$sValue; if ($mStringCallback && is_callable($mStringCallback)) { - $sValue = call_user_func($mStringCallback, $sValue); + $sValue = $mStringCallback($sValue); } $oConfig->Set($sConfigSector, $sConfigName, (string)$sValue); @@ -1615,7 +1615,7 @@ class Actions public function MainClearFileName(string $sFileName, string $sContentType, string $sMimeIndex, int $iMaxLength = 250): string { - $sFileName = 0 === \strlen($sFileName) ? \preg_replace('/[^a-zA-Z0-9]/', '.', (empty($sMimeIndex) ? '' : $sMimeIndex . '.') . $sContentType) : $sFileName; + $sFileName = !\strlen($sFileName) ? \preg_replace('/[^a-zA-Z0-9]/', '.', (empty($sMimeIndex) ? '' : $sMimeIndex . '.') . $sContentType) : $sFileName; $sClearedFileName = \MailSo\Base\Utils::StripSpaces(\preg_replace('/[\.]+/', '.', $sFileName)); $sExt = \MailSo\Base\Utils::GetFileExtension($sClearedFileName); @@ -1736,7 +1736,7 @@ class Actions $rData = $this->FilesProvider()->GetFile($oAccount, $sSavedName); if (\is_resource($rData)) { $sData = \stream_get_contents($rData); - if (!empty($sData) && 0 < \strlen($sData)) { + if (!empty($sData) && \strlen($sData)) { $sName = $aFile['name']; if (empty($sName)) { $sName = '_'; @@ -1826,7 +1826,7 @@ class Actions } } - if (0 < \count($aData)) { + if (\count($aData)) { $this->Logger()->Write('Import contacts from csv'); $iCount = $oAddressBookProvider->ImportCsvArray($oAccount->ParentEmailHelper(), $aData); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php index f07c8b5d5..8453949c0 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/User.php @@ -42,7 +42,7 @@ trait User $this->AuthToken($oAccount); - if ($oAccount && 0 < \strlen($sLanguage)) + if ($oAccount && \strlen($sLanguage)) { $oSettings = $this->SettingsProvider()->Load($oAccount); if ($oSettings) @@ -80,7 +80,7 @@ trait User $bError = false; $aData = false; - if (\is_array($aHashes) && 0 < \count($aHashes)) + if (\is_array($aHashes) && \count($aHashes)) { $aData = array(); foreach ($aHashes as $sZipHash) @@ -99,7 +99,7 @@ trait User } $oFilesProvider = $this->FilesProvider(); - if (!empty($sAction) && !$bError && \is_array($aData) && 0 < \count($aData) && + if (!empty($sAction) && !$bError && \is_array($aData) && \count($aData) && $oFilesProvider && $oFilesProvider->IsActive()) { $bError = false; @@ -397,7 +397,7 @@ trait User $this->Plugins()->RunHook('json.suggestions-pre', array(&$aResult, $sQuery, $oAccount, $iLimit)); - if ($iLimit > \count($aResult) && 0 < \strlen($sQuery)) + if ($iLimit > \count($aResult) && \strlen($sQuery)) { try { @@ -406,7 +406,7 @@ trait User if ($oAddressBookProvider && $oAddressBookProvider->IsActive()) { $aSuggestions = $oAddressBookProvider->GetSuggestions($oAccount->ParentEmailHelper(), $sQuery, $iLimit); - if (0 === \count($aResult)) + if (!\count($aResult)) { $aResult = $aSuggestions; } @@ -422,13 +422,13 @@ trait User } } - if ($iLimit > \count($aResult) && 0 < \strlen($sQuery)) + if ($iLimit > \count($aResult) && \strlen($sQuery)) { $oSuggestionsProvider = $this->SuggestionsProvider(); if ($oSuggestionsProvider && $oSuggestionsProvider->IsActive()) { $aSuggestionsProviderResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iLimit); - if (\is_array($aSuggestionsProviderResult) && 0 < \count($aSuggestionsProviderResult)) + if (\is_array($aSuggestionsProviderResult) && \count($aSuggestionsProviderResult)) { $aResult = \array_merge($aResult, $aSuggestionsProviderResult); } @@ -459,7 +459,7 @@ trait User $mResult = false; $aExternals = $this->GetActionParam('Externals', array()); - if (\is_array($aExternals) && 0 < \count($aExternals)) + if (\is_array($aExternals) && \count($aExternals)) { $oHttp = \MailSo\Base\Http::SingletonInstance(); @@ -590,7 +590,7 @@ trait User $sValue = (string) $sValue; if ($mStringCallback && is_callable($mStringCallback)) { - $sValue = call_user_func($mStringCallback, $sValue); + $sValue = $mStringCallback($sValue); } $oSettings->SetConf($sConfigName, (string) $sValue); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php index 576f038df..5ffa17687 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php @@ -39,7 +39,7 @@ class Manager $this->bIsEnabled = (bool) $oConfig->Get('plugins', 'enable', false); if ($this->bIsEnabled) { $sList = $oConfig->Get('plugins', 'enabled_list', ''); - if (0 < \strlen($sList)) { + if (\strlen($sList)) { $aList = \array_map('trim', \explode(',', $sList)); foreach ($aList as $i => $sName) { $oPlugin = $this->CreatePluginByName($sName); @@ -169,7 +169,7 @@ class Manager public function HaveJs(bool $bAdminScope = false) : bool { - return $this->bIsEnabled && 0 < \count($this->aJs[$bAdminScope ? 1 : 0]); + return $this->bIsEnabled && \count($this->aJs[$bAdminScope ? 1 : 0]); } public function CompileCss(bool $bAdminScope = false) : string @@ -245,7 +245,7 @@ class Manager $oPlugin->FilterAppDataPluginSection($bAdmin, $bAuth, $aConfig); - if (0 < \count($aConfig)) + if (\count($aConfig)) { $aAppData['Plugins'][$oPlugin->Name()] = $aConfig; } @@ -323,7 +323,7 @@ class Manager foreach ($this->aHooks[$sHookName] as $mCallback) { - \call_user_func_array($mCallback, $aArg); + $mCallback(...$aArg); } } } @@ -360,7 +360,7 @@ class Manager { foreach ($this->aAdditionalParts[$sActionName] as $mCallbak) { - $bCallResult = \call_user_func_array($mCallbak, $aParts); + $bCallResult = $mCallbak(...$aParts); if ($bCallResult && !$bResult) { $bResult = true; @@ -404,7 +404,7 @@ class Manager */ public function AddAdditionalJsonAction(string $sActionName, $mCallback) : self { - if ($this->bIsEnabled && \is_callable($mCallback) && 0 < \strlen($sActionName)) + if ($this->bIsEnabled && \is_callable($mCallback) && \strlen($sActionName)) { $sActionName = 'DoPlugin'.$sActionName; @@ -431,7 +431,7 @@ class Manager { if (isset($this->aAdditionalJson[$sActionName])) { - return \call_user_func($this->aAdditionalJson[$sActionName]); + return $this->aAdditionalJson[$sActionName](); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php index 02b7a08c2..e5d40a55d 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Service.php @@ -51,7 +51,7 @@ class Service } $sServer = \trim($this->oActions->Config()->Get('security', 'custom_server_signature', '')); - if (0 < \strlen($sServer)) + if (\strlen($sServer)) { \header('Server: '.$sServer); } @@ -114,7 +114,7 @@ class Service $bIndex = true; $sResult = ''; - if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== \strtolower($aPaths[0])) + if (\count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== \strtolower($aPaths[0])) { if (!\SnappyMail\HTTP\SecFetch::isSameOrigin()) { \MailSo\Base\Http::StatusHeader(403); @@ -129,13 +129,13 @@ class Service $bIndex = false; $sMethodName = 'Service'.\preg_replace('/@.+$/', '', $aPaths[0]); - $sMethodExtra = 0 < \strpos($aPaths[0], '@') ? \preg_replace('/^[^@]+@/', '', $aPaths[0]) : ''; + $sMethodExtra = \strpos($aPaths[0], '@') ? \preg_replace('/^[^@]+@/', '', $aPaths[0]) : ''; if (\method_exists($this->oServiceActions, $sMethodName) && \is_callable(array($this->oServiceActions, $sMethodName))) { $this->oServiceActions->SetQuery($sQuery)->SetPaths($aPaths); - $sResult = \call_user_func(array($this->oServiceActions, $sMethodName), $sMethodExtra); + $sResult = $this->oServiceActions->{$sMethodName}($sMethodExtra); } else if (!$this->oActions->Plugins()->RunAdditionalPart($aPaths[0], $aPaths)) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 7c36c0119..85cebda03 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -99,7 +99,7 @@ class ServiceActions } else if (!empty($sAction)) { - if (0 === stripos($sAction, 'Admin') && 'AdminLogin' !== $sAction && 'AdminLogout' !== $sAction) { + if (0 === \stripos($sAction, 'Admin') && 'AdminLogin' !== $sAction && 'AdminLogout' !== $sAction) { $this->oActions->IsAdminLoggined(); } @@ -140,7 +140,7 @@ class ServiceActions \is_callable(array($this->oActions, $sMethodName))) { $this->Plugins()->RunHook('json.action-pre-call', array($sAction)); - $aResponseItem = \call_user_func(array($this->oActions, $sMethodName)); + $aResponseItem = $this->oActions->{$sMethodName}(); $this->Plugins()->RunHook('json.action-post-call', array($sAction, &$aResponseItem)); } else if ($this->Plugins()->HasAdditionalJson($sMethodName)) @@ -194,7 +194,7 @@ class ServiceActions if ($this->Logger()->IsEnabled()) { - if (0 < \strlen($sObResult)) + if (\strlen($sObResult)) { $this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); } @@ -223,7 +223,7 @@ class ServiceActions \is_callable(array($this->oActions, 'Append'))) { isset($_POST) && $this->oActions->SetActionParams($_POST, 'Append'); - $bResponse = \call_user_func(array($this->oActions, 'Append')); + $bResponse = $this->oActions->Append(); } } catch (\Throwable $oException) @@ -235,7 +235,7 @@ class ServiceActions $sResult = true === $bResponse ? '1' : '0'; $sObResult = \ob_get_clean(); - if (0 < \strlen($sObResult)) + if (\strlen($sObResult)) { $this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); } @@ -279,7 +279,7 @@ class ServiceActions $aFile = $_FILES[$sInputName]; } } - else if (!isset($_FILES) || !is_array($_FILES) || 0 === count($_FILES)) + else if (!isset($_FILES) || !is_array($_FILES) || !\count($_FILES)) { $iError = UPLOAD_ERR_INI_SIZE; } @@ -298,7 +298,7 @@ class ServiceActions $this->oActions->SetActionParams($aActionParams, $sAction); - $aResponseItem = \call_user_func(array($this->oActions, $sAction)); + $aResponseItem = $this->oActions->{$sAction}(); } if (!is_array($aResponseItem)) @@ -317,7 +317,7 @@ class ServiceActions $sResult = \MailSo\Base\Utils::Php2js($aResponseItem, $this->Logger()); $sObResult = \ob_get_clean(); - if (0 < \strlen($sObResult)) + if (\strlen($sObResult)) { $this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); } @@ -402,7 +402,7 @@ class ServiceActions 'Params' => $this->aPaths ), $sMethodName); - if (!\call_user_func(array($this->oActions, $sMethodName))) + if (!$this->oActions->{$sMethodName}()) { $sRawError = 'False result'; } @@ -436,7 +436,7 @@ class ServiceActions $sRawError = 'Exception as result'; } - if (0 < \strlen($sRawError)) + if (\strlen($sRawError)) { $this->oActions->Logger()->Write($sRawError, \MailSo\Log\Enumerations\Type::ERROR); $this->oActions->Logger()->WriteDump($this->aPaths, \MailSo\Log\Enumerations\Type::ERROR, 'PATHS'); @@ -476,10 +476,10 @@ class ServiceActions $sResult = $this->Cacher()->Get($sCacheFileName); } - if (0 === \strlen($sResult)) + if (!\strlen($sResult)) { $sResult = $this->oActions->compileLanguage($sLanguage, $bAdmin); - if ($bCacheEnabled && 0 < \strlen($sCacheFileName)) + if ($bCacheEnabled && \strlen($sCacheFileName)) { $this->Cacher()->Set($sCacheFileName, $sResult); } @@ -514,10 +514,10 @@ class ServiceActions $sResult = $this->Cacher()->Get($sCacheFileName); } - if (0 === strlen($sResult)) + if (!\strlen($sResult)) { $sResult = $this->Plugins()->CompileJs($bAdmin); - if ($bCacheEnabled && 0 < \strlen($sCacheFileName)) + if ($bCacheEnabled && \strlen($sCacheFileName)) { $this->Cacher()->Set($sCacheFileName, $sResult); } @@ -678,7 +678,7 @@ class ServiceActions $sPassword = $mData['Password']; $aAdditionalOptions = isset($mData['AdditionalOptions']) && \is_array($mData['AdditionalOptions']) && - 0 < \count($mData['AdditionalOptions']) ? $mData['AdditionalOptions'] : null; + \count($mData['AdditionalOptions']) ? $mData['AdditionalOptions'] : null; try { @@ -741,7 +741,7 @@ class ServiceActions $sEmail = $_ENV['REMOTE_USER'] ?? ''; $sPassword = $_ENV['REMOTE_PASSWORD'] ?? ''; - if (0 < \strlen($sEmail) && 0 < \strlen(\trim($sPassword))) + if (\strlen($sEmail) && \strlen(\trim($sPassword))) { try { diff --git a/snappymail/v/0.0.0/app/libraries/lessphp/lessc.php b/snappymail/v/0.0.0/app/libraries/lessphp/lessc.php index acfe2b0e4..2dc44c41a 100644 --- a/snappymail/v/0.0.0/app/libraries/lessphp/lessc.php +++ b/snappymail/v/0.0.0/app/libraries/lessphp/lessc.php @@ -1321,7 +1321,7 @@ class lessc { if ($args[0] == 'list') $args = self::compressList($args[2], $args[1]); - $ret = call_user_func($f, $this->reduce($args, true), $this); + $ret = $f($this->reduce($args, true), $this); if (is_null($ret)) { return array("string", "", array(