diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php index 51630cddc..fbeab2478 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php @@ -113,8 +113,8 @@ trait Messages if (FetchResponse::isValidImapResponse($oResponse)) { if (FetchResponse::hasUidAndSize($oResponse)) { yield new FetchResponse($oResponse); - } else if ($this->oLogger) { - $this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE); + } else { + $this->logWrite('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE); } } } 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 bcdbf48cf..9349dd732 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 @@ -154,7 +154,7 @@ class ImapClient extends \MailSo\Net\NetClient $sAuthzid = $this->getResponseValue($this->SendRequestGetResponse('AUTHENTICATE', array($type)), Enumerations\ResponseType::CONTINUATION); $this->sendRaw($SASL->authenticate($sLogin, $sPassword/*, $sAuthzid*/), true); $sChallenge = $SASL->challenge($this->getResponseValue($this->getResponse(), Enumerations\ResponseType::CONTINUATION)); - $this->oLogger && $this->oLogger->AddSecret($sChallenge); + $this->logMask($sChallenge); $this->sendRaw($sChallenge); $oResponse = $this->getResponse(); $SASL->verify($this->getResponseValue($oResponse)); @@ -162,16 +162,16 @@ class ImapClient extends \MailSo\Net\NetClient else if ('CRAM-MD5' === $type) { $sChallenge = $this->getResponseValue($this->SendRequestGetResponse('AUTHENTICATE', array($type)), Enumerations\ResponseType::CONTINUATION); - $this->oLogger->Write('challenge: '.\base64_decode($sChallenge)); + $this->logWrite('challenge: '.\base64_decode($sChallenge)); $sAuth = $SASL->authenticate($sLogin, $sPassword, $sChallenge); - $this->oLogger && $this->oLogger->AddSecret($sAuth); + $this->logMask($sAuth); $this->sendRaw($sAuth); $oResponse = $this->getResponse(); } else if ('PLAIN' === $type || 'OAUTHBEARER' === $type /*|| 'PLAIN-CLIENTTOKEN' === $type*/) { $sAuth = $SASL->authenticate($sLogin, $sPassword); - $this->oLogger && $this->oLogger->AddSecret($sAuth); + $this->logMask($sAuth); if ($this->hasCapability('SASL-IR')) { $oResponse = $this->SendRequestGetResponse('AUTHENTICATE', array($type, $sAuth)); } else { @@ -187,8 +187,7 @@ class ImapClient extends \MailSo\Net\NetClient $oR = $oResponse->getLast(); if ($oR && Enumerations\ResponseType::CONTINUATION === $oR->ResponseType) { if (!empty($oR->ResponseList[1]) && preg_match('/^[a-zA-Z0-9=+\/]+$/', $oR->ResponseList[1])) { - $this->Logger()->Write(\base64_decode($oR->ResponseList[1]), - \LOG_WARNING); + $this->logWrite(\base64_decode($oR->ResponseList[1]), \LOG_WARNING); } $this->sendRaw(''); $oResponse = $this->getResponse(); @@ -200,14 +199,14 @@ class ImapClient extends \MailSo\Net\NetClient $this->sendRaw($SASL->authenticate($sLogin, $sPassword, $sB64), true); $this->getResponse(); $sPass = $SASL->challenge(''/*UGFzc3dvcmQ6*/); - $this->oLogger && $this->oLogger->AddSecret($sPass); + $this->logMask($sPass); $this->sendRaw($sPass); $oResponse = $this->getResponse(); } else { $sPassword = $this->EscapeString(\mb_convert_encoding($sPassword, 'ISO-8859-1', 'UTF-8')); - $this->oLogger && $this->oLogger->AddSecret($sPassword); + $this->logMask($sPassword); $oResponse = $this->SendRequestGetResponse('LOGIN', array( $this->EscapeString($sLogin), diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Inherit.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Inherit.php new file mode 100644 index 000000000..521a1b641 --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Inherit.php @@ -0,0 +1,52 @@ +oLogger; + } + + public function SetLogger(?Logger $oLogger): void + { + $this->oLogger = $oLogger; + } + + public function logWrite(string $sDesc, int $iType = \LOG_INFO, + string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false): bool + { + return $this->oLogger && $this->oLogger->Write($sDesc, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); + } + + public function logException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = ''): void + { + $this->oLogger && $this->oLogger->WriteException($oException, $iType, $sName); + } + + public function logMask(string $sWord): void + { + $this->oLogger && $this->oLogger->AddSecret($sWord); + } + +/* + public function logWriteDump($mValue, int $iType = \LOG_INFO, string $sName = '') : bool + public function logWriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '') : void +*/ +} 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 47841e858..96143b7d6 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 @@ -26,7 +26,7 @@ use MailSo\Mime\Enumerations\Parameter as MimeParameter; */ class MailClient { - private ?\MailSo\Log\Logger $oLogger = null; + use \MailSo\Log\Inherit; private \MailSo\Imap\ImapClient $oImapClient; @@ -400,17 +400,13 @@ class MailClient "ThreadsMapSorted/{$sSearch}/{$sFolderName}/{$oMessageCollection->FolderInfo->etag}"; // "ThreadsMapSorted/{$sSearch}/{$iThreadLimit}/{$sFolderName}/{$oMessageCollection->FolderInfo->etag}"; - if ($this->oLogger) { - $this->oLogger->Write($sSerializedHashKey); - } + $this->logWrite($sSerializedHashKey); $sSerializedUids = $oCacher->Get($sSerializedHashKey); if (!empty($sSerializedUids)) { $aSerializedUids = \json_decode($sSerializedUids, true); if (isset($aSerializedUids['ThreadsUids']) && \is_array($aSerializedUids['ThreadsUids'])) { - if ($this->oLogger) { - $this->oLogger->Write('Get Serialized Thread UIDS from cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aSerializedUids['ThreadsUids']).']'); - } + $this->logWrite('Get Serialized Thread UIDS from cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aSerializedUids['ThreadsUids']).']'); return $aSerializedUids['ThreadsUids']; } } @@ -439,9 +435,7 @@ class MailClient 'ThreadsUids' => $aResult ))); - if ($this->oLogger) { - $this->oLogger->Write('Save Serialized Thread UIDS to cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aResult).']'); - } + $this->logWrite('Save Serialized Thread UIDS to cache ("'.$sFolderName.'" / '.$sSearch.') [count:'.\count($aResult).']'); } return $aResult; @@ -571,9 +565,7 @@ class MailClient $sFolderHash === $aSerialized['FolderHash'] && \is_array($aSerialized['Uids']) ) { - if ($this->oLogger) { - $this->oLogger->Write('Get Serialized '.($bReturnUid?'UIDS':'IDS').' from cache ('.$sSerializedLog.') [count:'.\count($aSerialized['Uids']).']'); - } + $this->logWrite('Get Serialized '.($bReturnUid?'UIDS':'IDS').' from cache ('.$sSerializedLog.') [count:'.\count($aSerialized['Uids']).']'); return $aSerialized['Uids']; } } @@ -606,9 +598,7 @@ class MailClient 'Uids' => $aResultUids ))); - if ($this->oLogger) { - $this->oLogger->Write('Save Serialized '.($bReturnUid?'UIDS':'IDS').' to cache ('.$sSerializedLog.') [count:'.\count($aResultUids).']'); - } + $this->logWrite('Save Serialized '.($bReturnUid?'UIDS':'IDS').' to cache ('.$sSerializedLog.') [count:'.\count($aResultUids).']'); } return $aResultUids; @@ -664,9 +654,7 @@ class MailClient // || (!$this->oImapClient->hasCapability('SORT') && !$this->oImapClient->CapabilityValue('THREAD'))) { // Don't use THREAD for speed $oMessageCollection->Limited = true; - if ($this->oLogger) { - $this->oLogger->Write('List optimization (count: '.$oInfo->MESSAGES.', limit:'.$message_list_limit.')'); - } + $this->logWrite('List optimization (count: '.$oInfo->MESSAGES.', limit:'.$message_list_limit.')'); if (\strlen($sSearch)) { // Don't use SORT for speed $aUids = $this->GetUids($oParams, $sSearch, $oInfo->etag/*, $bUseSort*/); @@ -746,8 +734,8 @@ class MailClient $aUids = \array_slice($aUids, $oParams->iOffset, $oParams->iLimit); $this->MessageListByRequestIndexOrUids($oMessageCollection, new SequenceSet($aUids), $aAllThreads); } - } else if ($this->oLogger) { - $this->oLogger->Write('No messages in '.$oMessageCollection->FolderName); + } else { + $this->logWrite('No messages in '.$oMessageCollection->FolderName); } return $oMessageCollection; @@ -775,7 +763,7 @@ class MailClient } if ($bUseListSubscribeStatus && !$this->oImapClient->hasCapability('LIST-EXTENDED')) { -// $this->oLogger && $this->oLogger->Write('RFC5258 not supported, using LSUB'); +// $this->logWrite('RFC5258 not supported, using LSUB'); // \SnappyMail\Log::warning('IMAP', 'RFC5258 not supported, using LSUB'); try { @@ -916,7 +904,7 @@ class MailClient /** * @throws \InvalidArgumentException */ - public function SetLogger(\MailSo\Log\Logger $oLogger) : void + public function SetLogger(?\MailSo\Log\Logger $oLogger) : void { $this->oLogger = $oLogger; $this->oImapClient->SetLogger($oLogger); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index 4595ffaf0..2cc5a8ea1 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -17,6 +17,8 @@ namespace MailSo\Net; */ abstract class NetClient { + use \MailSo\Log\Inherit; + /** * @var resource */ @@ -34,11 +36,6 @@ abstract class NetClient private float $iStartConnectTime = 0; - /** - * @var \MailSo\Log\Logger - */ - protected $oLogger = null; - public ConnectSettings $Settings; public function __destruct() @@ -295,34 +292,22 @@ abstract class NetClient protected function writeLog(string $sDesc, int $iDescType = \LOG_INFO) : void { - $this->oLogger && $this->oLogger->Write($sDesc, $iDescType, $this->getLogName()); + $this->logWrite($sDesc, $iDescType, $this->getLogName()); } protected function writeLogWithCrlf(string $sDesc) : void { - $this->oLogger && $this->oLogger->Write($sDesc, \LOG_INFO, $this->getLogName(), true, true); + $this->logWrite($sDesc, \LOG_INFO, $this->getLogName(), true, true); } protected function writeLogException(\Throwable $oException, int $iDescType = \LOG_NOTICE, bool $bThrowException = true) : void { - if ($this->oLogger) { - if ($oException instanceof Exceptions\SocketCanNotConnectToHostException) { - $this->oLogger->Write('Socket: ['.$oException->getSocketCode().'] '.$oException->getSocketMessage(), $iDescType, $this->getLogName()); - } - $this->oLogger->WriteException($oException, $iDescType, $this->getLogName()); + if ($oException instanceof Exceptions\SocketCanNotConnectToHostException) { + $this->logWrite('Socket: ['.$oException->getSocketCode().'] '.$oException->getSocketMessage(), $iDescType, $this->getLogName()); } + $this->logException($oException, $iDescType, $this->getLogName()); if ($bThrowException) { throw $oException; } } - - public function SetLogger(\MailSo\Log\Logger $oLogger) : void - { - $this->oLogger = $oLogger; - } - - public function Logger() : ?\MailSo\Log\Logger - { - return $this->oLogger; - } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/SieveClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/SieveClient.php index 92a2bb491..bfd074511 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/SieveClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/SieveClient.php @@ -117,7 +117,7 @@ class SieveClient extends \MailSo\Net\NetClient $sAuthzid = $this->getResponseValue($this->SendRequestGetResponse('AUTHENTICATE', array($type)), \MailSo\Imap\Enumerations\ResponseType::CONTINUATION); $this->sendRaw($SASL->authenticate($sLogin, $sPassword/*, $sAuthzid* /), true); $sChallenge = $SASL->challenge($this->getResponseValue($this->getResponse(), \MailSo\Imap\Enumerations\ResponseType::CONTINUATION)); - $this->oLogger && $this->oLogger->AddSecret($sChallenge); + $this->logMask($sChallenge); $this->sendRaw($sChallenge); $oResponse = $this->getResponse(); $SASL->verify($this->getResponseValue($oResponse)); @@ -126,7 +126,7 @@ class SieveClient extends \MailSo\Net\NetClient else if ('PLAIN' === $type || 'OAUTHBEARER' === $type || 'XOAUTH2' === $type) { $sAuth = $SASL->authenticate($sLogin, $sPassword, $sLoginAuthKey); - $this->oLogger && $this->oLogger->AddSecret($sAuth); + $this->logMask($sAuth); if ($oSettings->authPlainLiteral) { $this->sendRaw("AUTHENTICATE \"{$type}\" {".\strlen($sAuth).'+}'); @@ -143,7 +143,7 @@ class SieveClient extends \MailSo\Net\NetClient { $sLogin = $SASL->authenticate($sLogin, $sPassword); $sPassword = $SASL->challenge(''); - $this->oLogger && $this->oLogger->AddSecret($sPassword); + $this->logMask($sPassword); $this->sendRaw('AUTHENTICATE "LOGIN"'); $this->sendRaw('{'.\strlen($sLogin).'+}'); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php index 679e07287..6e3cd2fe2 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php @@ -166,7 +166,7 @@ class SmtpClient extends \MailSo\Net\NetClient // RFC 5802 $sResult = $this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 234, ''); $sChallenge = $SASL->challenge($sResult); - $this->oLogger && $this->oLogger->AddSecret($sChallenge); + $this->logMask($sChallenge); $SASL->verify($this->sendRequestWithCheck($sChallenge, 235, '', true)); } else switch ($type) { // RFC 4616 @@ -174,14 +174,14 @@ class SmtpClient extends \MailSo\Net\NetClient case 'XOAUTH2': case 'OAUTHBEARER': $sAuth = $SASL->authenticate($sLogin, $sPassword); - $this->oLogger && $this->oLogger->AddSecret($sAuth); + $this->logMask($sAuth); $this->sendRequestWithCheck($sAuth, 235, '', true); break; case 'LOGIN': $sResult = $this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 334, ''); $sPassword = $SASL->challenge($sResult); - $this->oLogger && $this->oLogger->AddSecret($sPassword); + $this->logMask($sPassword); $this->sendRequestWithCheck($sPassword, 235, '', true); break; 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 e28259a1a..b6c4a4131 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -12,6 +12,8 @@ class Actions use Actions\Localization; use Actions\Themes; + use \MailSo\Log\Inherit; + const AUTH_MAILTO_TOKEN_KEY = 'smmailtoauth'; /** @@ -56,11 +58,6 @@ class Actions */ protected $oPlugins = null; - /** - * @var \MailSo\Log\Logger - */ - protected $oLogger = null; - /** * @var \MailSo\Log\Logger */ @@ -140,7 +137,7 @@ class Actions $oHttp = $this->Http(); - $this->oLogger->Write( + $this->logWrite( '[SM:' . APP_VERSION . '][IP:' . $oHttp->GetClientIp($this->oConfig->Get('labs', 'http_client_ip_check_proxy', false)) . '][PID:' . (\MailSo\Base\Utils::FunctionCallable('getmypid') ? \getmypid() : 'unknown') @@ -560,11 +557,6 @@ class Actions return $this->oPlugins; } - public function Logger(): \MailSo\Log\Logger - { - return $this->oLogger; - } - public function LoggerAuth(): \MailSo\Log\Logger { if (!$this->oLoggerAuth) { @@ -1130,7 +1122,7 @@ class Actions public function Location(string $sUrl, int $iStatus = 302): void { - $this->oLogger->Write("{$iStatus} Location: {$sUrl}"); + $this->logWrite("{$iStatus} Location: {$sUrl}"); \MailSo\Base\Http::Location($sUrl, $iStatus); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php index 461c29651..33dc8406a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/AdminDomains.php @@ -108,7 +108,7 @@ trait AdminDomains } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); $sImapErrorDesc = $oException->getSocketMessage(); if (empty($sImapErrorDesc)) { $sImapErrorDesc = $oException->getMessage(); @@ -116,7 +116,7 @@ trait AdminDomains } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); $sImapErrorDesc = $oException->getMessage(); } @@ -146,7 +146,7 @@ trait AdminDomains } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); $sSmtpErrorDesc = $oException->getSocketMessage(); if (empty($sSmtpErrorDesc)) { $sSmtpErrorDesc = $oException->getMessage(); @@ -154,7 +154,7 @@ trait AdminDomains } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); $sSmtpErrorDesc = $oException->getMessage(); } } @@ -179,7 +179,7 @@ trait AdminDomains } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); $sSieveErrorDesc = $oException->getSocketMessage(); if (empty($sSieveErrorDesc)) { $sSieveErrorDesc = $oException->getMessage(); @@ -187,7 +187,7 @@ trait AdminDomains } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); $sSieveErrorDesc = $oException->getMessage(); } } else { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php index 81eaaa058..f8694232a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Contacts.php @@ -258,7 +258,7 @@ trait Contacts if (\is_resource($rFile) && $oAddressBookProvider && $oAddressBookProvider->IsActive()) { try { - $this->Logger()->Write('Import contacts from vcf'); + $this->logWrite('Import contacts from vcf'); foreach (\RainLoop\Providers\AddressBook\Utils::VcfStreamToContacts($rFile) as $oContact) { if ($oAddressBookProvider->ContactSave($oContact)) { ++$iCount; @@ -267,7 +267,7 @@ trait Contacts } catch (\Throwable $oExc) { - $this->Logger()->WriteException($oExc); + $this->logException($oExc); } } return $iCount; @@ -280,7 +280,7 @@ trait Contacts if (\is_resource($rFile) && $oAddressBookProvider && $oAddressBookProvider->IsActive()) { try { - $this->Logger()->Write('Import contacts from csv'); + $this->logWrite('Import contacts from csv'); $sDelimiter = ((int)\strpos($sFileStart, ',') > (int)\strpos($sFileStart, ';')) ? ',' : ';'; foreach (\RainLoop\Providers\AddressBook\Utils::CsvStreamToContacts($rFile, $sDelimiter) as $oContact) { if ($oAddressBookProvider->ContactSave($oContact)) { @@ -290,7 +290,7 @@ trait Contacts } catch (\Throwable $oExc) { - $this->Logger()->WriteException($oExc); + $this->logException($oExc); } } return $iCount; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php index c0297f941..64d6f6782 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Folders.php @@ -299,7 +299,7 @@ trait Folders } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException); + $this->logException($oException); } } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index 4adb7298d..7744164f6 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -196,7 +196,7 @@ trait Messages } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); } } @@ -253,7 +253,7 @@ trait Messages } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \LOG_ERR); + $this->logException($oException, \LOG_ERR); } } @@ -297,7 +297,7 @@ trait Messages } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException); + $this->logException($oException); } return $this->TrueResponse(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php index 58fda8ab7..05590dc6b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php @@ -156,7 +156,7 @@ trait Raw $self->cacheByKey($sRawKey); - $self->Logger()->Write(\print_r([ + $self->logWrite(\print_r([ $sFileName, $sContentType, $sFileNameIn, diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php index 567e64112..821bac496 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Response.php @@ -60,7 +60,7 @@ trait Response $sErrorMessage = $oException->getCode().' - '.$oException->getMessage(); } - $this->Logger()->WriteException($oException->getPrevious() ?: $oException); + $this->logException($oException->getPrevious() ?: $oException); return $this->DefaultResponse(false, [ 'ErrorCode' => $iErrorCode, 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 1a699337c..26ae9ad7a 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 @@ -38,7 +38,7 @@ trait User $sPassword = $this->GetActionParam('Password', ''); $bSignMe = !empty($this->GetActionParam('signMe', 0)); - $this->Logger()->AddSecret($sPassword); + $this->logMask($sPassword); try { $oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe); @@ -116,17 +116,17 @@ trait User } if ($bMainCache) { - $this->Logger()->Write('Cacher GC: Begin'); + $this->logWrite('Cacher GC: Begin'); $this->Cacher()->GC(48); - $this->Logger()->Write('Cacher GC: End'); + $this->logWrite('Cacher GC: End'); - $this->Logger()->Write('Storage GC: Begin'); + $this->logWrite('Storage GC: Begin'); $this->StorageProvider()->GC(); - $this->Logger()->Write('Storage GC: End'); + $this->logWrite('Storage GC: End'); } else if ($bFilesCache) { - $this->Logger()->Write('Files GC: Begin'); + $this->logWrite('Files GC: Begin'); $this->FilesProvider()->GC(48); - $this->Logger()->Write('Files GC: End'); + $this->logWrite('Files GC: End'); } $this->Plugins()->RunHook('service.app-delay-start-end'); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php index 77ba1bebc..33f7fa2cf 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php @@ -32,13 +32,13 @@ trait UserAuth } if (!\str_contains($sEmail, '@')) { - $this->Logger()->Write('The email address "' . $sEmail . '" is not complete', \LOG_INFO, 'LOGIN'); + $this->logWrite('The email address "' . $sEmail . '" is not complete', \LOG_INFO, 'LOGIN'); $bAdded = false; if ($this->Config()->Get('login', 'determine_user_domain', false)) { $sUserHost = \trim($this->Http()->GetHost(true, true)); - $this->Logger()->Write('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN'); + $this->logWrite('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN'); $aDomainParts = \explode('.', $sUserHost); $iLimit = \min(\count($aDomainParts), 14); @@ -50,13 +50,13 @@ trait UserAuth $oDomain = $oDomainProvider->Load($sLine, false); if ($oDomain) { $bAdded = true; - $this->Logger()->Write('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')', + $this->logWrite('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')', \LOG_INFO, 'LOGIN'); $sEmail .= '@' . $sLine; break; } else { - $this->Logger()->Write('Check "' . $sLine . '": NO', \LOG_INFO, 'LOGIN'); + $this->logWrite('Check "' . $sLine . '": NO', \LOG_INFO, 'LOGIN'); } \array_shift($aDomainParts); @@ -66,17 +66,17 @@ trait UserAuth $oDomain = $oDomainProvider->Load($sUserHost, true); if ($oDomain) { $bAdded = true; - $this->Logger()->Write('Check "' . $sUserHost . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sUserHost . ')', + $this->logWrite('Check "' . $sUserHost . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sUserHost . ')', \LOG_INFO, 'LOGIN'); $sEmail .= '@' . $sUserHost; } else { - $this->Logger()->Write('Check "' . $sUserHost . '" with wildcard: NO', \LOG_INFO, 'LOGIN'); + $this->logWrite('Check "' . $sUserHost . '" with wildcard: NO', \LOG_INFO, 'LOGIN'); } } if (!$bAdded) { - $this->Logger()->Write('Domain was not found!', \LOG_INFO, 'LOGIN'); + $this->logWrite('Domain was not found!', \LOG_INFO, 'LOGIN'); } } @@ -88,12 +88,12 @@ trait UserAuth } else if ('gethostname' === $sDefDomain) { $sDefDomain = \gethostname(); } - $this->Logger()->Write('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')', + $this->logWrite('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')', \LOG_INFO, 'LOGIN'); $sEmail .= '@' . $sDefDomain; } else { - $this->Logger()->Write('Default domain not configured.', \LOG_INFO, 'LOGIN'); + $this->logWrite('Default domain not configured.', \LOG_INFO, 'LOGIN'); } } } @@ -105,9 +105,9 @@ trait UserAuth $sLogin = \mb_strtolower($sLogin); } - $this->Logger()->AddSecret($sPassword); + $this->logMask($sPassword); $this->Plugins()->RunHook('login.credentials', array(&$sEmail, &$sLogin, &$sPassword)); - $this->Logger()->AddSecret($sPassword); + $this->logMask($sPassword); } /** diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php index 1e7cfeebd..1e547e55c 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php @@ -105,7 +105,7 @@ class ActionsAdmin extends Actions $sLogin = trim($this->GetActionParam('Login', '')); $sPassword = $this->GetActionParam('Password', ''); - $this->Logger()->AddSecret($sPassword); + $this->logMask($sPassword); $totp = $this->Config()->Get('security', 'admin_totp', ''); @@ -172,11 +172,11 @@ class ActionsAdmin extends Actions $oConfig = $this->Config(); $sPassword = $this->GetActionParam('Password', ''); - $this->Logger()->AddSecret($sPassword); + $this->logMask($sPassword); $sNewPassword = $this->GetActionParam('newPassword', ''); if (\strlen($sNewPassword)) { - $this->Logger()->AddSecret($sNewPassword); + $this->logMask($sNewPassword); } $passfile = APP_PRIVATE_DATA.'admin_password.txt'; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php index aef3bb100..9168ff5f7 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php @@ -4,6 +4,8 @@ namespace RainLoop\Common; abstract class PdoAbstract { + use \MailSo\Log\Inherit; + /** * @var \PDO */ @@ -19,11 +21,6 @@ abstract class PdoAbstract */ protected $bSqliteCollate = true; - /** - * @var \MailSo\Log\Logger - */ - protected $oLogger; - /** * @var string */ @@ -34,11 +31,6 @@ abstract class PdoAbstract return !!\class_exists('PDO'); } - public function SetLogger(?\MailSo\Log\Logger $oLogger) - { - $this->oLogger = $oLogger; - } - protected function getPdoAccessData() : array { return array('', '', '', ''); @@ -98,7 +90,7 @@ abstract class PdoAbstract // $bCaseFunc = true; // } // } -// $this->oLogger->Write('PDO:'.$sPdoType.($bCaseFunc ? '/SQLITE_NOCASE_UTF8' : '')); +// $this->logWrite('PDO:'.$sPdoType.($bCaseFunc ? '/SQLITE_NOCASE_UTF8' : '')); $this->oPDO = $oPdo; return $oPdo; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php index a9eb452bf..da028720a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/Account.php @@ -190,18 +190,18 @@ abstract class Account implements \JsonSerializable if (isset($aAccountHash['name'])) { $oAccount->sName = $aAccountHash['name']; } - $oActions->Logger()->AddSecret($oAccount->sPassword); + $oActions->logMask($oAccount->sPassword); // init smtp user/password if (isset($aAccountHash['smtp'])) { $oAccount->sSmtpLogin = $aAccountHash['smtp']['user']; $oAccount->sSmtpPassword = $aAccountHash['smtp']['pass']; - $oActions->Logger()->AddSecret($oAccount->sSmtpPassword); + $oActions->logMask($oAccount->sSmtpPassword); } // init proxy user/password if (isset($aAccountHash['proxy'])) { $oAccount->sProxyAuthUser = $aAccountHash['proxy']['user']; $oAccount->sProxyAuthPassword = $aAccountHash['proxy']['pass']; - $oActions->Logger()->AddSecret($oAccount->sProxyAuthPassword); + $oActions->logMask($oAccount->sProxyAuthPassword); } } } 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 757d4b985..21e213c04 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 @@ -4,6 +4,8 @@ namespace RainLoop\Plugins; class Manager { + use \MailSo\Log\Inherit; + /** * @var \RainLoop\Actions */ @@ -21,14 +23,8 @@ class Manager private bool $bIsEnabled; - /** - * @var \MailSo\Log\Logger - */ - private $oLogger; - public function __construct(\RainLoop\Actions $oActions) { - $this->oLogger = null; $this->oActions = $oActions; $oConfig = $oActions->Config(); @@ -121,8 +117,7 @@ class Manager } } } else { - $this->oActions->Logger()->Write('Cannot get installed plugins from '.APP_PLUGINS_PATH, - \LOG_ERR); + $this->oActions->logWrite('Cannot get installed plugins from '.APP_PLUGINS_PATH, \LOG_ERR); } return $aList; @@ -478,24 +473,13 @@ class Manager return $this->bIsEnabled ? \count($this->aPlugins) : 0; } - public function SetLogger(\MailSo\Log\Logger $oLogger) : self - { - $this->oLogger = $oLogger; - - return $this; - } - public function WriteLog(string $sDesc, int $iType = \LOG_INFO) : void { - if ($this->oLogger) { - $this->oLogger->Write($sDesc, $iType, 'PLUGIN'); - } + $this->logWrite($sDesc, $iType, 'PLUGIN'); } public function WriteException(string $sDesc, int $iType = \LOG_INFO) : void { - if ($this->oLogger) { - $this->oLogger->WriteException($sDesc, $iType, 'PLUGIN'); - } + $this->logException($sDesc, $iType, 'PLUGIN'); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AbstractProvider.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AbstractProvider.php index 91851693e..f499c712e 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AbstractProvider.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AbstractProvider.php @@ -4,16 +4,13 @@ namespace RainLoop\Providers; abstract class AbstractProvider { + use \MailSo\Log\Inherit; + /** * @var \RainLoop\Model\Account */ protected $oAccount; - /** - * @var \MailSo\Log\Logger - */ - protected $oLogger = null; - public function IsActive() : bool { return false; @@ -23,14 +20,4 @@ abstract class AbstractProvider { $this->oAccount = $oAccount; } - - public function SetLogger(?\MailSo\Log\Logger $oLogger) - { - $this->oLogger = $oLogger; - } - - public function Logger() : ?\MailSo\Log\Logger - { - return $this->oLogger; - } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php index eb03e96f3..8c7becdcb 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php @@ -36,7 +36,7 @@ trait CardDAV } catch (\Throwable $oException) { - $this->oLogger->WriteException($oException); + $this->logException($oException); } /** @@ -88,7 +88,7 @@ trait CardDAV { \MailSo\Base\Utils::ResetTimeLimit(); - $this->oLogger->Write($sCmd.' '.$sUrl.(('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData ? ' ('.\strlen($mData).')' : ''), + $this->logWrite($sCmd.' '.$sUrl.(('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData ? ' ('.\strlen($mData).')' : ''), \LOG_INFO, 'DAV'); try @@ -105,7 +105,7 @@ trait CardDAV } catch (\Throwable $oException) { - $this->oLogger->WriteException($oException); + $this->logException($oException); } return null; @@ -124,7 +124,7 @@ trait CardDAV } catch (\Throwable $oException) { - $this->oLogger->WriteException($oException); + $this->logException($oException); } return null; @@ -271,7 +271,7 @@ trait CardDAV } catch (\Throwable $oException) { - $this->oLogger->WriteException($oException); + $this->logException($oException); } $bGood = false; @@ -316,7 +316,7 @@ trait CardDAV 'password' => $sPassword ); - $this->oLogger->AddSecret($sPassword); + $this->logMask($sPassword); if (!empty($sProxy)) { $aSettings['proxy'] = $sProxy; @@ -327,7 +327,7 @@ trait CardDAV $oClient->__UrlPath__ = $aUrl['path']; - $this->oLogger->Write('DavClient: User: '.$aSettings['userName'].', Url: '.$sUrl, \LOG_INFO, 'DAV'); + $this->logWrite('DavClient: User: '.$aSettings['userName'].', Url: '.$sUrl, \LOG_INFO, 'DAV'); return $oClient; } @@ -398,7 +398,7 @@ trait CardDAV $bGood = $sNewPath && $this->checkContactsPath($oClient, $sNewPath); if (!$bGood) { - $this->oLogger->Write('Contacts path not found at: '.$sPath, \LOG_INFO, 'DAV'); + $this->logWrite('Contacts path not found at: '.$sPath, \LOG_INFO, 'DAV'); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php index 63cfbc289..a472bac8f 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/PdoAddressBook.php @@ -275,10 +275,8 @@ class PdoAddressBook try { $oVCard = \Sabre\VObject\Reader::read($sBody); } catch (\Throwable $oExc) { - if ($this->oLogger) { - $this->oLogger->WriteException($oExc); - $this->oLogger->WriteDump($sBody); - } + $this->logException($oExc); + $this->oLogger && $this->oLogger->WriteDump($sBody); } } } @@ -341,7 +339,7 @@ class PdoAddressBook } } } catch (\Throwable $oExc) { - $this->oLogger && $this->oLogger->WriteException($oExc); + $this->logException($oExc); } } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php index 2334c6910..afd36bc59 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Filters/SieveStorage.php @@ -4,12 +4,9 @@ namespace RainLoop\Providers\Filters; class SieveStorage implements FiltersInterface { - const SIEVE_FILE_NAME = 'rainloop.user'; + use \MailSo\Log\Inherit; - /** - * @var \MailSo\Log\Logger - */ - private $oLogger; + const SIEVE_FILE_NAME = 'rainloop.user'; /** * @var \RainLoop\Plugins\Manager @@ -23,8 +20,6 @@ class SieveStorage implements FiltersInterface public function __construct($oPlugins, $oConfig) { - $this->oLogger = null; - $this->oPlugins = $oPlugins; $this->oConfig = $oConfig; } @@ -123,9 +118,4 @@ class SieveStorage implements FiltersInterface } return false; } - - public function SetLogger(?\MailSo\Log\Logger $oLogger) - { - $this->oLogger = $oLogger; - } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php index 9d4d659fc..a9369b391 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/FileStorage.php @@ -6,6 +6,8 @@ use RainLoop\Providers\Storage\Enumerations\StorageType; class FileStorage implements \RainLoop\Providers\Storage\IStorage { + use \MailSo\Log\Inherit; + /** * @var string */ @@ -16,16 +18,10 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage */ private $bLocal; - /** - * @var \MailSo\Log\Logger - */ - protected $oLogger; - public function __construct(string $sStoragePath, bool $bLocal = false) { $this->sDataPath = \rtrim(\trim($sStoragePath), '\\/'); $this->bLocal = $bLocal; - $this->oLogger = null; } /** @@ -169,11 +165,6 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage return $sFilePath; } - public function SetLogger(?\MailSo\Log\Logger $oLogger) - { - $this->oLogger = $oLogger; - } - public function GC() : void { \clearstatcache(); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php index 5b6feef58..cca87d0f4 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions.php @@ -47,7 +47,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider } catch (\Throwable $oException) { - $this->oLogger && $this->oLogger->WriteException($oException); + $this->logException($oException); } // Extensions/Plugins @@ -67,7 +67,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider } } } catch (\Throwable $oException) { - $this->oLogger && $this->oLogger->WriteException($oException); + $this->logException($oException); } } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/imap/sync.php b/snappymail/v/0.0.0/app/libraries/snappymail/imap/sync.php index f042c27bc..d4d0043ba 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/imap/sync.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/imap/sync.php @@ -20,7 +20,7 @@ class Sync $this->oImapSource->TAG_PREFIX = 'S'; $this->oImapTarget->TAG_PREFIX = 'T'; -// $this->oImapTarget->Logger()->Write('Get oImapTarget->FolderList'); +// $this->oImapTarget->logWrite('Get oImapTarget->FolderList'); \SnappyMail\Log::notice('SYNC', 'Get oImapTarget->FolderList'); $aTargetFolders = $this->oImapTarget->FolderList($sParent, $sListPattern); if (!$aTargetFolders) {