Cleanup Action reponse handling and use typed properties

This commit is contained in:
the-djmaze
2022-12-21 14:12:35 +01:00
parent 31b1096f4d
commit 219b155ede
20 changed files with 395 additions and 662 deletions

View File

@@ -918,13 +918,12 @@ class Actions
public function DoPing(): array
{
return $this->DefaultResponse(__FUNCTION__, 'Pong');
return $this->DefaultResponse('Pong');
}
public function DoVersion(): array
{
return $this->DefaultResponse(__FUNCTION__,
APP_VERSION === (string)$this->GetActionParam('Version', ''));
return $this->DefaultResponse(APP_VERSION === (string)$this->GetActionParam('Version', ''));
}
public function MainClearFileName(string $sFileName, string $sContentType, string $sMimeIndex, int $iMaxLength = 250): string
@@ -1028,7 +1027,7 @@ class Actions
}
}
return $this->DefaultResponse(__FUNCTION__, $aResponse);
return $this->DefaultResponse($aResponse);
}
public function Capa(bool $bAdmin, ?Model\Account $oAccount = null): array

View File

@@ -15,10 +15,7 @@ use RainLoop\Utils;
trait Accounts
{
/**
* @var RainLoop\Providers\Identities
*/
private $oIdentitiesProvider;
private ?\RainLoop\Providers\Identities $oIdentitiesProvider = null;
protected function GetMainEmail(Account $oAccount)
{
@@ -78,7 +75,7 @@ trait Accounts
$oMainAccount = $this->getMainAccountFromToken();
if (!$this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$aAccounts = $this->GetAccounts($oMainAccount);
@@ -107,7 +104,7 @@ trait Accounts
$this->SetAccounts($oMainAccount, $aAccounts);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
protected function loadAdditionalAccountImapClient(string $sEmail): \MailSo\Imap\ImapClient
@@ -137,7 +134,7 @@ trait Accounts
{
$oImapClient = $this->loadAdditionalAccountImapClient($this->GetActionParam('email', ''));
$oInfo = $oImapClient->FolderStatus('INBOX');
return $this->DefaultResponse(__FUNCTION__, [
return $this->DefaultResponse([
'unreadEmails' => \max(0, $oInfo->UNSEEN)
]);
}
@@ -172,7 +169,7 @@ trait Accounts
$oMainAccount = $this->getMainAccountFromToken();
if (!$this->GetCapa(Capa::ADDITIONAL_ACCOUNTS)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$sEmailToDelete = \trim($this->GetActionParam('EmailToDelete', ''));
@@ -191,10 +188,10 @@ trait Accounts
unset($aAccounts[$sEmailToDelete]);
$this->SetAccounts($oMainAccount, $aAccounts);
return $this->TrueResponse(__FUNCTION__, array('Reload' => $bReload));
return $this->TrueResponse(array('Reload' => $bReload));
}
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
/**
@@ -227,9 +224,9 @@ trait Accounts
}
// $this->Plugins()->InitAppData($bAdmin, $aResult, $oAccount);
return $this->DefaultResponse(__FUNCTION__, $aResult);
return $this->DefaultResponse($aResult);
}
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
/**
@@ -245,7 +242,7 @@ trait Accounts
}
$this->IdentitiesProvider()->UpdateIdentity($oAccount, $oIdentity);
return $this->DefaultResponse(__FUNCTION__, true);
return $this->TrueResponse();
}
/**
@@ -256,7 +253,7 @@ trait Accounts
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(Capa::IDENTITIES)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$sId = \trim($this->GetActionParam('IdToDelete', ''));
@@ -265,7 +262,7 @@ trait Accounts
}
$this->IdentitiesProvider()->DeleteIdentity($oAccount, $sId);
return $this->DefaultResponse(__FUNCTION__, true);
return $this->TrueResponse();
}
/**
@@ -277,7 +274,7 @@ trait Accounts
$aIdentities = $this->GetActionParam('Identities', null);
if (!\is_array($aAccounts) && !\is_array($aIdentities)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
if (\is_array($aAccounts) && 1 < \count($aAccounts)) {
@@ -289,7 +286,7 @@ trait Accounts
$this->SetAccounts($oAccount, $aAccounts);
}
return $this->DefaultResponse(__FUNCTION__, $this->LocalStorageProvider()->Put(
return $this->DefaultResponse($this->LocalStorageProvider()->Put(
$this->getAccountFromToken(),
StorageType::CONFIG,
'identities_order',
@@ -305,7 +302,7 @@ trait Accounts
public function DoAccountsAndIdentities(): array
{
// https://github.com/the-djmaze/snappymail/issues/571
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'Accounts' => \array_values(\array_map(function($value){
return [
'email' => \MailSo\Base\Utils::IdnToUtf8($value['email'] ?? $value[1]),

View File

@@ -11,7 +11,7 @@ use RainLoop\Utils;
trait Admin
{
protected static $AUTH_ADMIN_TOKEN_KEY = 'smadmin';
protected static string $AUTH_ADMIN_TOKEN_KEY = 'smadmin';
public function IsAdminLoggined(bool $bThrowExceptionOnFalse = true) : bool
{
@@ -22,8 +22,7 @@ trait Admin
}
}
if ($bThrowExceptionOnFalse)
{
if ($bThrowExceptionOnFalse) {
throw new ClientException(Notifications::AuthError);
}

View File

@@ -17,7 +17,7 @@ trait Attachments
$aHashes = $this->GetActionParam('Hashes', null);
$oFilesProvider = $this->FilesProvider();
if (empty($sAction) || !$this->GetCapa(Capa::ATTACHMENTS_ACTIONS) || !$oFilesProvider || !$oFilesProvider->IsActive()) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$oAccount = $this->initMailClientConnection();
@@ -42,7 +42,7 @@ trait Attachments
$mUIDs = 1 < \count($mUIDs);
if ($bError || !\count($aData)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$mResult = false;
@@ -130,7 +130,7 @@ trait Attachments
}
// $this->requestSleep();
return $this->DefaultResponse(__FUNCTION__, $bError ? false : $mResult);
return $this->DefaultResponse($bError ? false : $mResult);
}
private function getMimeFileByHash(\RainLoop\Model\Account $oAccount, string $sHash) : array

View File

@@ -10,9 +10,8 @@ trait Contacts
$oAccount = $this->getAccountFromToken();
$oAddressBookProvider = $this->AddressBookProvider($oAccount);
if (!$oAddressBookProvider || !$oAddressBookProvider->IsActive())
{
return $this->FalseResponse(__FUNCTION__);
if (!$oAddressBookProvider || !$oAddressBookProvider->IsActive()) {
return $this->FalseResponse();
}
$sPassword = $this->GetActionParam('Password', '');
@@ -28,7 +27,7 @@ trait Contacts
'Url' => $this->GetActionParam('Url', '')
));
return $this->DefaultResponse(__FUNCTION__, $bResult);
return $this->DefaultResponse($bResult);
}
public function DoContactsSync() : array
@@ -44,7 +43,7 @@ trait Contacts
if (!$oAddressBookProvider->Sync()) {
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'AddressBookProvider->Sync() failed');
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoContacts() : array
@@ -61,13 +60,12 @@ trait Contacts
$mResult = array();
$oAbp = $this->AddressBookProvider($oAccount);
if ($oAbp->IsActive())
{
if ($oAbp->IsActive()) {
$iResultCount = 0;
$mResult = $oAbp->GetContacts($iOffset, $iLimit, $sSearch, $iResultCount);
}
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'Offset' => $iOffset,
'Limit' => $iLimit,
'Count' => $iResultCount,
@@ -84,12 +82,11 @@ trait Contacts
$aFilteredUids = \array_filter(\array_map('intval', $aUids));
$bResult = false;
if (\count($aFilteredUids) && $this->AddressBookProvider($oAccount)->IsActive())
{
if (\count($aFilteredUids) && $this->AddressBookProvider($oAccount)->IsActive()) {
$bResult = $this->AddressBookProvider($oAccount)->DeleteContacts($aFilteredUids);
}
return $this->DefaultResponse(__FUNCTION__, $bResult);
return $this->DefaultResponse($bResult);
}
public function DoContactSave() : array
@@ -116,7 +113,7 @@ trait Contacts
}
}
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'ResultID' => $bResult ? $oContact->id : '',
'Result' => $bResult
));
@@ -131,38 +128,28 @@ trait Contacts
$aFile = $this->GetActionParam('File', null);
$iError = $this->GetActionParam('Error', \RainLoop\Enumerations\UploadError::UNKNOWN);
if ($oAccount && UPLOAD_ERR_OK === $iError && \is_array($aFile))
{
if ($oAccount && UPLOAD_ERR_OK === $iError && \is_array($aFile)) {
$sSavedName = 'upload-post-'.\md5($aFile['name'].$aFile['tmp_name']);
if (!$this->FilesProvider()->MoveUploadedFile($oAccount, $sSavedName, $aFile['tmp_name']))
{
if (!$this->FilesProvider()->MoveUploadedFile($oAccount, $sSavedName, $aFile['tmp_name'])) {
$iError = \RainLoop\Enumerations\UploadError::ON_SAVING;
}
else
{
} else {
\ini_set('auto_detect_line_endings', true);
$mData = $this->FilesProvider()->GetFile($oAccount, $sSavedName);
if ($mData)
{
if ($mData) {
$sFileStart = \fread($mData, 20);
\rewind($mData);
if (false !== $sFileStart)
{
if (false !== $sFileStart) {
$sFileStart = \trim($sFileStart);
if (false !== \strpos($sFileStart, 'BEGIN:VCARD'))
{
if (false !== \strpos($sFileStart, 'BEGIN:VCARD')) {
$mResponse = $this->importContactsFromVcfFile($oAccount, $mData);
}
else if (false !== \strpos($sFileStart, ',') || false !== \strpos($sFileStart, ';'))
{
} else if (false !== \strpos($sFileStart, ',') || false !== \strpos($sFileStart, ';')) {
$mResponse = $this->importContactsFromCsvFile($oAccount, $mData, $sFileStart);
}
}
}
if (\is_resource($mData))
{
if (\is_resource($mData)) {
\fclose($mData);
}
@@ -173,18 +160,15 @@ trait Contacts
}
}
if (UPLOAD_ERR_OK !== $iError)
{
if (UPLOAD_ERR_OK !== $iError) {
$iClientError = \RainLoop\Enumerations\UploadError::NORMAL;
$sError = $this->getUploadErrorMessageByCode($iError, $iClientError);
if (!empty($sError))
{
return $this->FalseResponse(__FUNCTION__, $iClientError, $sError);
if (!empty($sError)) {
return $this->FalseResponse($iClientError, $sError);
}
}
return $this->DefaultResponse(__FUNCTION__, $mResponse);
return $this->DefaultResponse($mResponse);
}
public function setContactsSyncData(\RainLoop\Model\Account $oAccount, array $aData) : bool

View File

@@ -6,10 +6,7 @@ use RainLoop\Enumerations\Capa;
trait Filters
{
/**
* @var \RainLoop\Providers\Filters
*/
private $oFiltersProvider;
private ?\RainLoop\Providers\Filters $oFiltersProvider = null;
/**
* @throws \MailSo\RuntimeException
@@ -18,12 +15,11 @@ trait Filters
{
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(Capa::SIEVE, $oAccount))
{
return $this->FalseResponse(__FUNCTION__);
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse();
}
return $this->DefaultResponse(__FUNCTION__, $this->FiltersProvider()->Load($oAccount));
return $this->DefaultResponse($this->FiltersProvider()->Load($oAccount));
}
/**
@@ -34,7 +30,7 @@ trait Filters
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$sName = $this->GetActionParam('name', '');
@@ -43,7 +39,7 @@ trait Filters
// $this->FiltersProvider()->ActivateScript($oAccount, $sName);
}
return $this->DefaultResponse(__FUNCTION__, $this->FiltersProvider()->Save(
return $this->DefaultResponse($this->FiltersProvider()->Save(
$oAccount, $sName, $this->GetActionParam('body', '')
));
}
@@ -56,10 +52,10 @@ trait Filters
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
return $this->DefaultResponse(__FUNCTION__, $this->FiltersProvider()->ActivateScript(
return $this->DefaultResponse($this->FiltersProvider()->ActivateScript(
$oAccount, $this->GetActionParam('name', '')
));
}
@@ -72,10 +68,10 @@ trait Filters
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(Capa::SIEVE, $oAccount)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
return $this->DefaultResponse(__FUNCTION__, $this->FiltersProvider()->DeleteScript(
return $this->DefaultResponse($this->FiltersProvider()->DeleteScript(
$oAccount, $this->GetActionParam('name', '')
));
}

View File

@@ -38,7 +38,7 @@ trait Folders
}
}
return $this->DefaultResponse(__FUNCTION__, true);
return $this->TrueResponse();
}
public function DoFolders() : array
@@ -79,7 +79,7 @@ trait Folders
);
}
return $this->DefaultResponse(__FUNCTION__, $oFolderCollection);
return $this->DefaultResponse($oFolderCollection);
}
public function DoFolderCreate() : array
@@ -95,7 +95,7 @@ trait Folders
);
// FolderInformation(string $sFolderName, int $iPrevUidNext = 0, array $aUids = array())
return $this->DefaultResponse(__FUNCTION__, $oFolder);
return $this->DefaultResponse($oFolder);
}
catch (\Throwable $oException)
{
@@ -113,7 +113,7 @@ trait Folders
$sMetadataKey => $this->GetActionParam('Value') ?: null
]);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoFolderSubscribe() : array
@@ -135,7 +135,7 @@ trait Folders
);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoFolderCheckable() : array
@@ -143,18 +143,16 @@ trait Folders
$oAccount = $this->getAccountFromToken();
$sFolderFullName = $this->GetActionParam('Folder', '');
$bCheckable = '1' === (string) $this->GetActionParam('Checkable', '0');
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
$sCheckableFolder = $oSettingsLocal->GetConf('CheckableFolder', '[]');
$aCheckableFolder = \json_decode($sCheckableFolder);
$aCheckableFolder = \json_decode($oSettingsLocal->GetConf('CheckableFolder', '[]'));
if (!\is_array($aCheckableFolder)) {
$aCheckableFolder = array();
}
if ($bCheckable) {
if (!empty($this->GetActionParam('Checkable', '0'))) {
$aCheckableFolder[] = $sFolderFullName;
} else {
$aCheckableFolderNew = array();
@@ -170,8 +168,7 @@ trait Folders
$oSettingsLocal->SetConf('CheckableFolder', \json_encode($aCheckableFolder));
return $this->DefaultResponse(__FUNCTION__,
$this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
return $this->DefaultResponse($this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
}
/**
@@ -194,7 +191,7 @@ trait Folders
throw new ClientException(Notifications::CantRenameFolder, $oException);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
/**
@@ -219,7 +216,7 @@ trait Folders
}
// FolderInformation(string $sFolderName, int $iPrevUidNext = 0, array $aUids = array())
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'Name' => $sName,
'FullName' => $sFullName,
));
@@ -245,7 +242,7 @@ trait Folders
throw new ClientException(Notifications::CantDeleteFolder, $oException);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
/**
@@ -264,7 +261,7 @@ trait Folders
throw new ClientException(Notifications::MailServerError, $oException);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
/**
@@ -276,12 +273,11 @@ trait Folders
try
{
$aInboxInformation = $this->MailClient()->FolderInformation(
return $this->DefaultResponse($this->MailClient()->FolderInformation(
$this->GetActionParam('Folder', ''),
(int) $this->GetActionParam('UidNext', 0),
new \MailSo\Imap\SequenceSet($this->GetActionParam('FlagsUids', []))
);
return $this->DefaultResponse(__FUNCTION__, $aInboxInformation);
));
}
catch (\Throwable $oException)
{
@@ -323,7 +319,7 @@ trait Folders
}
}
return $this->DefaultResponse(__FUNCTION__, $aResult);
return $this->DefaultResponse($aResult);
}
public function DoSystemFoldersUpdate() : array
@@ -338,7 +334,6 @@ trait Folders
$oSettingsLocal->SetConf('TrashFolder', $this->GetActionParam('Trash', ''));
$oSettingsLocal->SetConf('ArchiveFolder', $this->GetActionParam('Archive', ''));
return $this->DefaultResponse(__FUNCTION__,
$this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
return $this->DefaultResponse($this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
}
}

View File

@@ -25,8 +25,7 @@ trait Messages
$sRawKey = $this->GetActionParam('RawKey', '');
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($sRawKey), true);
if ($aValues && 6 < \count($aValues))
{
if ($aValues && 6 < \count($aValues)) {
$this->verifyCacheByKey($sRawKey);
// $oParams->sHash = (string) $aValues['Hash'];
@@ -42,9 +41,7 @@ trait Messages
if ($oParams->bUseThreads && isset($aValues['ThreadUid'])) {
$oParams->iThreadUid = $aValues['ThreadUid'];
}
}
else
{
} else {
$oParams->sFolderName = $this->GetActionParam('Folder', '');
$oParams->iOffset = $this->GetActionParam('Offset', 0);
$oParams->iLimit = $this->GetActionParam('Limit', 10);
@@ -57,8 +54,7 @@ trait Messages
}
}
if (!\strlen($oParams->sFolderName))
{
if (!\strlen($oParams->sFolderName)) {
throw new ClientException(Notifications::CantGetMessageList);
}
@@ -85,12 +81,11 @@ trait Messages
throw new ClientException(Notifications::CantGetMessageList, $oException);
}
if ($oMessageList)
{
if ($oMessageList) {
$this->cacheByKey($sRawKey);
}
return $this->DefaultResponse(__FUNCTION__, $oMessageList);
return $this->DefaultResponse($oMessageList);
}
public function DoSaveMessage() : array
@@ -98,8 +93,7 @@ trait Messages
$oAccount = $this->initMailClientConnection();
$sDraftFolder = $this->GetActionParam('SaveFolder', '');
if (!\strlen($sDraftFolder))
{
if (!\strlen($sDraftFolder)) {
throw new ClientException(Notifications::UnknownError);
}
@@ -108,15 +102,13 @@ trait Messages
$this->Plugins()->RunHook('filter.save-message', array($oMessage));
$mResult = false;
if ($oMessage)
{
if ($oMessage) {
$rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
$oMessage->ToStream(false), array($rMessageStream), 8192, true, true);
if (false !== $iMessageStreamSize)
{
if (false !== $iMessageStreamSize) {
$sMessageId = $oMessage->MessageId();
\rewind($rMessageStream);
@@ -126,8 +118,7 @@ trait Messages
$rMessageStream, $iMessageStreamSize, $sDraftFolder, array(MessageFlag::SEEN), $iNewUid
);
if (!empty($sMessageId) && (null === $iNewUid || 0 === $iNewUid))
{
if (!empty($sMessageId) && (null === $iNewUid || 0 === $iNewUid)) {
$iNewUid = $this->MailClient()->FindMessageUidByMessageId($sDraftFolder, $sMessageId);
}
@@ -135,13 +126,11 @@ trait Messages
$sMessageFolder = $this->GetActionParam('MessageFolder', '');
$iMessageUid = (int) $this->GetActionParam('MessageUid', 0);
if (\strlen($sMessageFolder) && 0 < $iMessageUid)
{
if (\strlen($sMessageFolder) && 0 < $iMessageUid) {
$this->MailClient()->MessageDelete($sMessageFolder, new SequenceSet($iMessageUid));
}
if (null !== $iNewUid && 0 < $iNewUid)
{
if (null !== $iNewUid && 0 < $iNewUid) {
$mResult = array(
'NewFolder' => $sDraftFolder,
'NewUid' => $iNewUid
@@ -150,7 +139,7 @@ trait Messages
}
}
return $this->DefaultResponse(__FUNCTION__, $mResult);
return $this->DefaultResponse($mResult);
}
public function DoSendMessage() : array
@@ -169,20 +158,17 @@ trait Messages
$mResult = false;
try
{
if ($oMessage)
{
if ($oMessage) {
$rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
$oMessage->ToStream(true), array($rMessageStream), 8192, true, true, true);
if (false !== $iMessageStreamSize)
{
if (false !== $iMessageStreamSize) {
$bDsn = !empty($this->GetActionParam('Dsn', 0));
$this->smtpSendMessage($oAccount, $oMessage, $rMessageStream, $iMessageStreamSize, $bDsn, true);
if (\is_array($aDraftInfo) && 3 === \count($aDraftInfo))
{
if (\is_array($aDraftInfo) && 3 === \count($aDraftInfo)) {
$sDraftInfoType = $aDraftInfo[0];
$iDraftInfoUid = (int) $aDraftInfo[1];
$sDraftInfoFolder = $aDraftInfo[2];
@@ -206,14 +192,11 @@ trait Messages
}
}
if (\strlen($sSentFolder))
{
if (\strlen($sSentFolder)) {
try
{
if (!$oMessage->GetBcc())
{
if (\is_resource($rMessageStream))
{
if (!$oMessage->GetBcc()) {
if (\is_resource($rMessageStream)) {
\rewind($rMessageStream);
}
@@ -223,9 +206,7 @@ trait Messages
$this->MailClient()->MessageAppendStream(
$rMessageStream, $iMessageStreamSize, $sSentFolder, array(MessageFlag::SEEN)
);
}
else
{
} else {
$rAppendMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iAppendMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
@@ -238,8 +219,7 @@ trait Messages
$rAppendMessageStream, $iAppendMessageStreamSize, $sSentFolder, array(MessageFlag::SEEN)
);
if (\is_resource($rAppendMessageStream))
{
if (\is_resource($rAppendMessageStream)) {
fclose($rAppendMessageStream);
}
}
@@ -250,8 +230,7 @@ trait Messages
}
}
if (\is_resource($rMessageStream))
{
if (\is_resource($rMessageStream)) {
\fclose($rMessageStream);
}
@@ -259,8 +238,7 @@ trait Messages
$sDraftFolder = $this->GetActionParam('MessageFolder', '');
$iDraftUid = (int) $this->GetActionParam('MessageUid', 0);
if (\strlen($sDraftFolder) && 0 < $iDraftUid)
{
if (\strlen($sDraftFolder) && 0 < $iDraftUid) {
try
{
$this->MailClient()->MessageDelete($sDraftFolder, new SequenceSet($iDraftUid));
@@ -284,27 +262,22 @@ trait Messages
throw new ClientException(Notifications::CantSendMessage, $oException);
}
if (false === $mResult)
{
if (false === $mResult) {
throw new ClientException(Notifications::CantSendMessage);
}
try
{
if ($oMessage && $this->AddressBookProvider($oAccount)->IsActive())
{
if ($oMessage && $this->AddressBookProvider($oAccount)->IsActive()) {
$aArrayToFrec = array();
$oToCollection = $oMessage->GetTo();
if ($oToCollection)
{
foreach ($oToCollection as /* @var $oEmail \MailSo\Mime\Email */ $oEmail)
{
if ($oToCollection) {
foreach ($oToCollection as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) {
$aArrayToFrec[$oEmail->GetEmail(true)] = $oEmail->ToString(false, true);
}
}
if (\count($aArrayToFrec))
{
if (\count($aArrayToFrec)) {
$oSettings = $this->SettingsProvider()->Load($oAccount);
$this->AddressBookProvider($oAccount)->IncFrec(
@@ -319,7 +292,7 @@ trait Messages
$this->Logger()->WriteException($oException);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoSendReadReceiptMessage() : array
@@ -333,19 +306,16 @@ trait Messages
$mResult = false;
try
{
if ($oMessage)
{
if ($oMessage) {
$rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
$iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
$oMessage->ToStream(true), array($rMessageStream), 8192, true, true, true);
if (false !== $iMessageStreamSize)
{
if (false !== $iMessageStreamSize) {
$this->smtpSendMessage($oAccount, $oMessage, $rMessageStream, $iMessageStreamSize, false, false);
if (\is_resource($rMessageStream))
{
if (\is_resource($rMessageStream)) {
\fclose($rMessageStream);
}
@@ -356,8 +326,7 @@ trait Messages
$this->Cacher($oAccount)->Set(\RainLoop\KeyPathHelper::ReadReceiptCache($oAccount->Email(), $sFolderFullName, $iUid), '1');
if (\strlen($sFolderFullName) && 0 < $iUid)
{
if (\strlen($sFolderFullName) && 0 < $iUid) {
try
{
$this->MailClient()->MessageSetFlag($sFolderFullName, new SequenceSet($iUid), MessageFlag::MDNSENT, true, true);
@@ -376,17 +345,16 @@ trait Messages
throw new ClientException(Notifications::CantSendMessage, $oException);
}
if (false === $mResult)
{
if (false === $mResult) {
throw new ClientException(Notifications::CantSendMessage);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoMessageSetSeen() : array
{
return $this->messageSetFlag(MessageFlag::SEEN, __FUNCTION__);
return $this->messageSetFlag(MessageFlag::SEEN);
}
public function DoMessageSetSeenToAll() : array
@@ -409,17 +377,17 @@ trait Messages
throw new ClientException(Notifications::MailServerError, $oException);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoMessageSetFlagged() : array
{
return $this->messageSetFlag(MessageFlag::FLAGGED, __FUNCTION__, true);
return $this->messageSetFlag(MessageFlag::FLAGGED, true);
}
public function DoMessageSetKeyword() : array
{
return $this->messageSetFlag($this->GetActionParam('Keyword', ''), __FUNCTION__, true);
return $this->messageSetFlag($this->GetActionParam('Keyword', ''), true);
}
/**
@@ -433,15 +401,12 @@ trait Messages
$iUid = 0;
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($sRawKey), true);
if ($aValues && 2 <= \count($aValues))
{
if ($aValues && 2 <= \count($aValues)) {
$sFolder = (string) $aValues[0];
$iUid = (int) $aValues[1];
$this->verifyCacheByKey($sRawKey);
}
else
{
} else {
$sFolder = $this->GetActionParam('Folder', '');
$iUid = (int) $this->GetActionParam('Uid', 0);
}
@@ -457,14 +422,13 @@ trait Messages
throw new ClientException(Notifications::CantGetMessage, $oException);
}
if ($oMessage)
{
if ($oMessage) {
$this->Plugins()->RunHook('filter.result-message', array($oMessage));
$this->cacheByKey($sRawKey);
}
return $this->DefaultResponse(__FUNCTION__, $oMessage);
return $this->DefaultResponse($oMessage);
}
/**
@@ -496,7 +460,7 @@ trait Messages
\SnappyMail\Log::warning('IMAP', "FolderHash({$sFolder}) Exception: {$oException->getMessage()}");
}
return $this->DefaultResponse(__FUNCTION__, $sHash ? array($sFolder, $sHash) : array($sFromFolder));
return $this->DefaultResponse($sHash ? array($sFolder, $sHash) : array($sFromFolder));
}
/**
@@ -511,8 +475,7 @@ trait Messages
$oUids = new SequenceSet(\explode(',', (string) $this->GetActionParam('Uids', '')));
if (!empty($this->GetActionParam('MarkAsRead', '0')))
{
if (!empty($this->GetActionParam('MarkAsRead', '0'))) {
try
{
$this->MailClient()->MessageSetFlag($sFromFolder, $oUids, MessageFlag::SEEN);
@@ -524,8 +487,7 @@ trait Messages
}
$sLearning = $this->GetActionParam('Learning', '');
if ($sLearning)
{
if ($sLearning) {
try
{
if ('SPAM' === $sLearning) {
@@ -561,7 +523,7 @@ trait Messages
\SnappyMail\Log::warning('IMAP', "FolderHash({$sFromFolder}) Exception: {$oException->getMessage()}");
}
return $this->DefaultResponse(__FUNCTION__, $sHash ? array($sFromFolder, $sHash) : array($sFromFolder));
return $this->DefaultResponse($sHash ? array($sFromFolder, $sHash) : array($sFromFolder));
}
/**
@@ -584,7 +546,7 @@ trait Messages
throw new ClientException(Notifications::CantCopyMessage, $oException);
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoMessageUploadAttachments() : array
@@ -654,7 +616,7 @@ trait Messages
throw new ClientException(Notifications::MailServerError, $oException);
}
return $this->DefaultResponse(__FUNCTION__, $aAttachments);
return $this->DefaultResponse($aAttachments);
}
/**
@@ -770,7 +732,7 @@ trait Messages
}
}
return $this->DefaultResponse(__FUNCTION__, $result);
return $this->DefaultResponse($result);
}
/**
@@ -810,16 +772,12 @@ trait Messages
$bUsePhpMail = false;
$oAccount->SmtpConnectAndLoginHelper($this->Plugins(), $oSmtpClient, $this->Config(), $bUsePhpMail);
if ($bUsePhpMail)
{
if (\MailSo\Base\Utils::FunctionCallable('mail'))
{
if ($bUsePhpMail) {
if (\MailSo\Base\Utils::FunctionCallable('mail')) {
$aToCollection = $oMessage->GetTo();
if ($aToCollection && $oFrom)
{
if ($aToCollection && $oFrom) {
$sRawBody = \stream_get_contents($rMessageStream);
if (!empty($sRawBody))
{
if (!empty($sRawBody)) {
$sMailTo = \trim($aToCollection->ToString(true));
$sMailSubject = \trim($oMessage->GetSubject());
$sMailSubject = 0 === \strlen($sMailSubject) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
@@ -829,8 +787,7 @@ trait Messages
list($sMailHeaders, $sMailBody) = \explode("\r\n\r\n", $sRawBody, 2);
unset($sRawBody);
if ($this->Config()->Get('labs', 'mail_func_clear_headers', true))
{
if ($this->Config()->Get('labs', 'mail_func_clear_headers', true)) {
$sMailHeaders = \MailSo\Base\Utils::RemoveHeaderFromHeaders($sMailHeaders, array(
MimeEnumHeader::TO_,
MimeEnumHeader::SUBJECT
@@ -845,20 +802,15 @@ trait Messages
\mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders, '-f'.$oFrom->GetEmail()) :
\mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders);
if (!$bR)
{
if (!$bR) {
throw new ClientException(Notifications::CantSendMessage);
}
}
}
}
else
{
} else {
throw new ClientException(Notifications::CantSendMessage);
}
}
else if ($oSmtpClient->IsConnected())
{
} else if ($oSmtpClient->IsConnected()) {
if ($iMessageStreamSize && $oSmtpClient->maxSize() && $iMessageStreamSize * 1.33 > $oSmtpClient->maxSize()) {
throw new ClientException(Notifications::ClientViewError, 'Message size '. ($iMessageStreamSize * 1.33) . ' bigger then max ' . $oSmtpClient->maxSize());
}
@@ -904,7 +856,7 @@ trait Messages
}
}
private function messageSetFlag(string $sMessageFlag, string $sResponseFunction, bool $bSkipUnsupportedFlag = false) : array
private function messageSetFlag(string $sMessageFlag, bool $bSkipUnsupportedFlag = false) : array
{
$this->initMailClientConnection();
@@ -923,19 +875,16 @@ trait Messages
throw new ClientException(Notifications::MailServerError, $oException);
}
return $this->TrueResponse($sResponseFunction);
return $this->TrueResponse();
}
private function deleteMessageAttachments(Account $oAccount) : void
{
$aAttachments = $this->GetActionParam('Attachments', null);
if (\is_array($aAttachments))
{
foreach (\array_keys($aAttachments) as $sTempName)
{
if ($this->FilesProvider()->FileExists($oAccount, $sTempName))
{
if (\is_array($aAttachments)) {
foreach (\array_keys($aAttachments) as $sTempName) {
if ($this->FilesProvider()->FileExists($oAccount, $sTempName)) {
$this->FilesProvider()->Clear($oAccount, $sTempName);
}
}
@@ -1080,8 +1029,7 @@ trait Messages
}
$aDraftInfo = $this->GetActionParam('DraftInfo', null);
if ($bWithDraftInfo && \is_array($aDraftInfo) && !empty($aDraftInfo[0]) && !empty($aDraftInfo[1]) && !empty($aDraftInfo[2]))
{
if ($bWithDraftInfo && \is_array($aDraftInfo) && !empty($aDraftInfo[0]) && !empty($aDraftInfo[1]) && !empty($aDraftInfo[2])) {
$oMessage->SetDraftInfo($aDraftInfo[0], $aDraftInfo[1], $aDraftInfo[2]);
}
@@ -1217,10 +1165,8 @@ trait Messages
unset($oPart);
$aAttachments = $this->GetActionParam('Attachments', null);
if (\is_array($aAttachments))
{
foreach ($aAttachments as $sTempName => $aData)
{
if (\is_array($aAttachments)) {
foreach ($aAttachments as $sTempName => $aData) {
$sFileName = (string) $aData['name'];
$bIsInline = (bool) $aData['inline'];
$sCID = (string) $aData['cid'];
@@ -1228,8 +1174,7 @@ trait Messages
$sMimeType = (string) $aData['type'];
$rResource = $this->FilesProvider()->GetFile($oAccount, $sTempName);
if (\is_resource($rResource))
{
if (\is_resource($rResource)) {
$iFileSize = $this->FilesProvider()->FileSize($oAccount, $sTempName);
$oMessage->Attachments()->append(
@@ -1242,8 +1187,7 @@ trait Messages
}
}
foreach ($aFoundDataURL as $sCidHash => $sDataUrlString)
{
foreach ($aFoundDataURL as $sCidHash => $sDataUrlString) {
$aMatch = array();
$sCID = '<'.$sCidHash.'>';
if (\preg_match('/^data:(image\/[a-zA-Z0-9]+);base64,(.+)$/i', $sDataUrlString, $aMatch) &&
@@ -1251,8 +1195,7 @@ trait Messages
{
$sRaw = \MailSo\Base\Utils::Base64Decode($aMatch[2]);
$iFileSize = \strlen($sRaw);
if (0 < $iFileSize)
{
if (0 < $iFileSize) {
$sFileName = \preg_replace('/[^a-z0-9]+/i', '.', $aMatch[1]);
$rResource = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sRaw);

View File

@@ -74,7 +74,7 @@ trait Pgp
{
$GPG = $this->GnuPG();
if (!$GPG) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$GPG->addDecryptKey(
@@ -113,19 +113,19 @@ trait Pgp
// $result['signatures'] = $oPart->SubParts[0];
}
return $this->DefaultResponse(__FUNCTION__, $result);
return $this->DefaultResponse($result);
}
public function DoGnupgGetKeys() : array
{
$GPG = $this->GnuPG();
return $this->DefaultResponse(__FUNCTION__, $GPG ? $GPG->keyInfo('') : false);
return $this->DefaultResponse($GPG ? $GPG->keyInfo('') : false);
}
public function DoGnupgExportKey() : array
{
$GPG = $this->GnuPG();
return $this->DefaultResponse(__FUNCTION__, $GPG ? $GPG->export(
return $this->DefaultResponse($GPG ? $GPG->export(
$this->GetActionParam('KeyId', ''),
$this->GetActionParam('Passphrase', '')
) : false);
@@ -143,7 +143,7 @@ trait Pgp
$this->GetActionParam('Passphrase', '')
);
}
return $this->DefaultResponse(__FUNCTION__, $fingerprint);
return $this->DefaultResponse($fingerprint);
}
public function DoGnupgDeleteKey() : array
@@ -151,7 +151,7 @@ trait Pgp
$GPG = $this->GnuPG();
$sKeyId = $this->GetActionParam('KeyId', '');
$bPrivate = !!$this->GetActionParam('isPrivate', 0);
return $this->DefaultResponse(__FUNCTION__, $GPG ? $GPG->deleteKey($sKeyId, $bPrivate) : false);
return $this->DefaultResponse($GPG ? $GPG->deleteKey($sKeyId, $bPrivate) : false);
}
public function DoGnupgImportKey() : array
@@ -182,7 +182,7 @@ trait Pgp
}
$GPG = $sKey ? $this->GnuPG() : null;
return $this->DefaultResponse(__FUNCTION__, $GPG ? $GPG->import($sKey) : false);
return $this->DefaultResponse($GPG ? $GPG->import($sKey) : false);
}
/**
@@ -219,7 +219,7 @@ trait Pgp
}
}
return $this->DefaultResponse(__FUNCTION__, $keys);
return $this->DefaultResponse($keys);
}
/**
@@ -256,7 +256,7 @@ trait Pgp
}
// $revocationCertificate = $this->GetActionParam('revocationCertificate', '');
return $this->DefaultResponse(__FUNCTION__, $result);
return $this->DefaultResponse($result);
}
/**
@@ -267,7 +267,7 @@ trait Pgp
{
$key = $this->GetActionParam('Key', '');
$keyId = $this->GetActionParam('KeyId', '');
return $this->DefaultResponse(__FUNCTION__, ($key && $keyId && $this->StorePGPKey($key, $keyId)));
return $this->DefaultResponse(($key && $keyId && $this->StorePGPKey($key, $keyId)));
}
private function StorePGPKey(string $key, string $keyId = '') : bool

View File

@@ -83,8 +83,7 @@ trait Raw
$sHash = $sRawKey;
$sData = '';
if (!empty($sHash))
{
if (!empty($sHash)) {
$sData = $this->StorageProvider()->Get(null,
\RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY,
\RainLoop\KeyPathHelper::PublicFile($sHash)
@@ -96,8 +95,7 @@ trait Raw
\preg_match('/^data:([^:]+):/', $sData, $aMatch) && !empty($aMatch[1]))
{
$sContentType = \trim($aMatch[1]);
if (\in_array($sContentType, array('image/png', 'image/jpg', 'image/jpeg')))
{
if (\in_array($sContentType, array('image/png', 'image/jpg', 'image/jpeg'))) {
$this->cacheByKey($sRawKey);
\header('Content-Type: '.$sContentType);
@@ -123,7 +121,8 @@ trait Raw
$sRangeStart = $sRangeEnd = '';
$bIsRangeRequest = false;
if (!empty($sRange) && 'bytes=0-' !== \strtolower($sRange) && \preg_match('/^bytes=([0-9]+)-([0-9]*)/i', \trim($sRange), $aMatch))
if (!empty($sRange) && 'bytes=0-' !== \strtolower($sRange)
&& \preg_match('/^bytes=([0-9]+)-([0-9]*)/i', \trim($sRange), $aMatch))
{
$sRangeStart = $aMatch[1];
$sRangeEnd = $aMatch[2];
@@ -139,8 +138,7 @@ trait Raw
$sFileNameIn = isset($aValues['FileName']) ? (string) $aValues['FileName'] : '';
$sFileHashIn = isset($aValues['FileHash']) ? (string) $aValues['FileHash'] : '';
if (!empty($sFileHashIn))
{
if (!empty($sFileHashIn)) {
$this->verifyCacheByKey($sRawKey);
$oAccount = $this->getAccountFromToken();
@@ -185,8 +183,7 @@ trait Raw
$self, $oAccount, $sRawKey, $sContentTypeIn, $sFileNameIn, $bDownload, $bThumbnail,
$bIsRangeRequest, $sRangeStart, $sRangeEnd
) {
if ($oAccount && \is_resource($rResource))
{
if ($oAccount && \is_resource($rResource)) {
\MailSo\Base\Utils::ResetTimeLimit();
$self->cacheByKey($sRawKey);
@@ -207,24 +204,20 @@ trait Raw
?: 'application/octet-stream';
}
if (!$bDownload)
{
if (!$bDownload) {
$bDetectImageOrientation = $self->Config()->Get('labs', 'image_exif_auto_rotate', false)
// Mostly only JPEG has EXIF metadata
&& 'image/jpeg' == $sContentType;
try
{
if ($bThumbnail)
{
if ($bThumbnail) {
$oImage = static::loadImage($rResource, $bDetectImageOrientation, 48);
\header('Content-Disposition: inline; '.
\trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileName.'_thumb60x60.png')));
$oImage->show('png');
// $oImage->show('webp'); // Little Britain: "Safari says NO"
exit;
}
else if ($bDetectImageOrientation)
{
} else if ($bDetectImageOrientation) {
$oImage = static::loadImage($rResource, $bDetectImageOrientation);
\header('Content-Disposition: inline; '.
\trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileName)));
@@ -263,24 +256,20 @@ trait Raw
\MailSo\Base\Http::StatusHeader(206);
$iRangeStart = (int) $sRangeStart;
$iRangeEnd = (int) $sRangeEnd;
$iRangeStart = \max(0, \intval($sRangeStart));
$iRangeEnd = \max(0, \intval($sRangeEnd));
if ('' === $sRangeEnd) {
$sLoadedData = 0 < $iRangeStart ? \substr($sLoadedData, $iRangeStart) : $sLoadedData;
} else {
if ($iRangeStart < $iRangeEnd) {
$sLoadedData = \substr($sLoadedData, $iRangeStart, $iRangeEnd - $iRangeStart);
} else {
$sLoadedData = 0 < $iRangeStart ? \substr($sLoadedData, $iRangeStart) : $sLoadedData;
}
if ($iRangeEnd && $iRangeStart < $iRangeEnd) {
$sLoadedData = \substr($sLoadedData, $iRangeStart, $iRangeEnd - $iRangeStart);
} else if ($iRangeStart) {
$sLoadedData = \substr($sLoadedData, $iRangeStart);
}
$iContentLength = \strlen($sLoadedData);
if (0 < $iContentLength) {
\header('Content-Length: '.$iContentLength);
\header('Content-Range: bytes '.$sRangeStart.'-'.(0 < $iRangeEnd ? $iRangeEnd : $iFullContentLength - 1).'/'.$iFullContentLength);
\header('Content-Range: bytes '.$sRangeStart.'-'.($iRangeEnd ?: $iFullContentLength - 1).'/'.$iFullContentLength);
}
} else {
\header('Content-Length: '.\strlen($sLoadedData));

View File

@@ -9,98 +9,64 @@ use RainLoop\Utils;
trait Response
{
/**
* @param mixed $mResult = false
* @param mixed $mResult
*/
public function DefaultResponse(string $sActionName, $mResult = false, array $aAdditionalParams = array()) : array
public function DefaultResponse($mResult, array $aAdditionalParams = array(), string $sActionName = '') : array
{
$this->Plugins()->RunHook('main.default-response-data', array($sActionName, &$mResult));
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult, $aAdditionalParams);
$this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem));
return $aResponseItem;
}
public function TrueResponse(string $sActionName, array $aAdditionalParams = array()) : array
{
$mResult = true;
$this->Plugins()->RunHook('main.default-response-data', array($sActionName, &$mResult));
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult, $aAdditionalParams);
$this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem));
return $aResponseItem;
}
public function FalseResponse(string $sActionName, ?int $iErrorCode = null, ?string $sErrorMessage = null, ?string $sAdditionalErrorMessage = null) : array
{
$mResult = false;
$this->Plugins()
->RunHook('main.default-response-data', array($sActionName, &$mResult))
->RunHook('main.default-response-error-data', array($sActionName, &$iErrorCode, &$sErrorMessage))
;
$aAdditionalParams = array();
if (null !== $iErrorCode) {
$aAdditionalParams['ErrorCode'] = (int) $iErrorCode;
$aAdditionalParams['ErrorMessage'] = null === $sErrorMessage ? '' : (string) $sErrorMessage;
$aAdditionalParams['ErrorMessageAdditional'] = null === $sAdditionalErrorMessage ? '' : (string) $sAdditionalErrorMessage;
if (false === $mResult) {
if (!isset($aAdditionalParams['ErrorCode'])) {
$aAdditionalParams['ErrorCode'] = 0;
}
if (!isset($aAdditionalParams['ErrorMessage'])) {
$aAdditionalParams['ErrorMessage'] = '';
}
}
$aResponseItem = $this->mainDefaultResponse($sActionName, $mResult, $aAdditionalParams);
$this->Plugins()->RunHook('main.default-response', array($sActionName, &$aResponseItem));
return $aResponseItem;
return \array_merge(array(
// 'Version' => APP_VERSION,
'Action' => $sActionName,
'Result' => $this->responseObject($mResult)
), $aAdditionalParams);
}
public function ExceptionResponse(string $sActionName, \Throwable $oException) : array
public function TrueResponse(array $aAdditionalParams = array()) : array
{
$iErrorCode = null;
$sErrorMessage = null;
$sErrorMessageAdditional = null;
return $this->DefaultResponse(true, $aAdditionalParams);
}
public function FalseResponse(int $iErrorCode = 0, string $sErrorMessage = '', string $sAdditionalErrorMessage = '') : array
{
return $this->DefaultResponse(false, [
'ErrorCode' => $iErrorCode,
'ErrorMessage' => $sErrorMessage,
'ErrorMessageAdditional' => $sAdditionalErrorMessage
]);
}
public function ExceptionResponse(\Throwable $oException) : array
{
$iErrorCode = 0;
$sErrorMessage = '';
$sErrorMessageAdditional = '';
if ($oException instanceof \RainLoop\Exceptions\ClientException) {
$iErrorCode = $oException->getCode();
$sErrorMessage = null;
if ($iErrorCode === Notifications::ClientViewError) {
$sErrorMessage = $oException->getMessage();
}
$sErrorMessageAdditional = $oException->getAdditionalMessage();
if (empty($sErrorMessageAdditional)) {
$sErrorMessageAdditional = null;
}
} else {
$iErrorCode = Notifications::UnknownError;
$sErrorMessage = $oException->getCode().' - '.$oException->getMessage();
}
$oPrevious = $oException->getPrevious();
if ($oPrevious) {
$this->Logger()->WriteException($oPrevious);
} else {
$this->Logger()->WriteException($oException);
}
$this->Logger()->WriteException($oException->getPrevious() ?: $oException);
return $this->FalseResponse($sActionName, $iErrorCode, $sErrorMessage, $sErrorMessageAdditional);
}
/**
* @param mixed $mResult = false
*/
private function mainDefaultResponse(string $sActionName, $mResult = false, array $aAdditionalParams = array()) : array
{
$sActionName = 'Do' === \substr($sActionName, 0, 2) ? \substr($sActionName, 2) : $sActionName;
$sActionName = \preg_replace('/[^a-zA-Z0-9_]+/', '', $sActionName);
$aResult = array(
// 'Version' => APP_VERSION,
'Action' => $sActionName,
'Result' => $this->responseObject($mResult, $sActionName)
);
foreach ($aAdditionalParams as $sKey => $mValue) {
$aResult[$sKey] = $mValue;
}
return $aResult;
return $this->DefaultResponse(false, [
'ErrorCode' => $iErrorCode,
'ErrorMessage' => $sErrorMessage,
'ErrorMessageAdditional' => $sErrorMessageAdditional
]);
}
private function isFileHasThumbnail(string $sFileName) : bool
@@ -138,7 +104,7 @@ trait Response
if (\is_array($mResponse)) {
foreach ($mResponse as $iKey => $oItem) {
$mResponse[$iKey] = $this->responseObject($oItem, $sParent);
$mResponse[$iKey] = $this->responseObject($oItem, 'Array');
}
}
@@ -159,7 +125,7 @@ trait Response
// \MailSo\Mime\EmailCollection
foreach (['ReplyTo','From','To','Cc','Bcc','Sender','DeliveredTo'] as $prop) {
$mResult[$prop] = $this->responseObject($mResult[$prop], $sParent);
$mResult[$prop] = $this->responseObject($mResult[$prop], $prop);
}
$sSubject = $mResult['subject'];
@@ -172,9 +138,9 @@ trait Response
'FileName' => (\strlen($sSubject) ? \MailSo\Base\Utils::SecureFileName($sSubject) : 'message-'.$mResult['Uid']) . '.eml'
));
$mResult['Attachments'] = $this->responseObject($mResponse->Attachments, $sParent);
$mResult['Attachments'] = $this->responseObject($mResponse->Attachments, 'Attachments');
if ('Message' === $sParent) {
if (!$sParent) {
$mResult['DraftInfo'] = $mResponse->DraftInfo;
$mResult['InReplyTo'] = $mResponse->InReplyTo;
$mResult['UnsubsribeLinks'] = $mResponse->UnsubsribeLinks;
@@ -188,7 +154,6 @@ trait Response
$mResult['PgpEncrypted'] = $mResponse->pgpEncrypted;
$mResult['ReadReceipt'] = $mResponse->ReadReceipt;
if (\strlen($mResult['ReadReceipt']) && !\in_array('$forwarded', $mResult['Flags'])) {
// \in_array('$mdnsent', $mResult['Flags'])
if (\strlen($mResult['ReadReceipt'])) {
@@ -249,7 +214,7 @@ trait Response
if ($mResponse instanceof \MailSo\Base\Collection) {
$mResult = $mResponse->jsonSerialize();
$mResult['@Collection'] = $this->responseObject($mResult['@Collection'], $sParent);
$mResult['@Collection'] = $this->responseObject($mResult['@Collection'], 'Collection');
if ($mResponse instanceof \MailSo\Mail\EmailCollection) {
return \array_slice($mResult['@Collection'], 0, 100);
}

View File

@@ -133,7 +133,7 @@ trait Themes
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(\RainLoop\Enumerations\Capa::USER_BACKGROUND)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$sName = '';
@@ -200,13 +200,12 @@ trait Themes
if (UPLOAD_ERR_OK !== $iError) {
$iClientError = \RainLoop\Enumerations\UploadError::NORMAL;
$sError = $this->getUploadErrorMessageByCode($iError, $iClientError);
if (!empty($sError)) {
return $this->FalseResponse(__FUNCTION__, $iClientError, $sError);
return $this->FalseResponse($iClientError, $sError);
}
}
return $this->DefaultResponse(__FUNCTION__, !empty($sName) && !empty($sHash) ? array(
return $this->DefaultResponse(!empty($sName) && !empty($sHash) ? array(
'Name' => $sName,
'Hash' => $sHash
) : false);

View File

@@ -60,7 +60,7 @@ trait User
}
}
return $this->DefaultResponse(__FUNCTION__, $this->AppData(false));
return $this->DefaultResponse($this->AppData(false));
}
public function DoLogout() : array
@@ -68,7 +68,7 @@ trait User
$bMain = true; // empty($_COOKIE[self::AUTH_ADDITIONAL_TOKEN_KEY]);
$this->Logout($bMain);
$bMain && $this->ClearSignMeData();
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoAppDelayStart() : array
@@ -126,7 +126,7 @@ trait User
$this->Plugins()->RunHook('service.app-delay-start-end');
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoSettingsUpdate() : array
@@ -201,8 +201,7 @@ trait User
$this->setSettingsFromParams($oSettingsLocal, 'HideDeleted', 'bool');
$this->setSettingsFromParams($oSettingsLocal, 'UnhideKolabFolders', 'bool');
return $this->DefaultResponse(__FUNCTION__,
$this->SettingsProvider()->Save($oAccount, $oSettings) &&
return $this->DefaultResponse($this->SettingsProvider()->Save($oAccount, $oSettings) &&
$this->SettingsProvider(true)->Save($oAccount, $oSettingsLocal));
}
@@ -211,7 +210,7 @@ trait User
$oAccount = $this->initMailClientConnection();
if (!$this->GetCapa(Capa::QUOTA)) {
return $this->DefaultResponse(__FUNCTION__, array(0, 0, 0, 0));
return $this->DefaultResponse(array(0, 0, 0, 0));
}
try
@@ -223,7 +222,7 @@ trait User
throw new ClientException(Notifications::MailServerError, $oException);
}
return $this->DefaultResponse(__FUNCTION__, $aQuota);
return $this->DefaultResponse($aQuota);
}
public function DoSuggestions() : array
@@ -275,7 +274,7 @@ trait User
$aResult = \array_slice(\array_values($aResult), 0, $iLimit);
}
return $this->DefaultResponse(__FUNCTION__, $aResult);
return $this->DefaultResponse($aResult);
}
public function DoClearUserBackground() : array
@@ -283,7 +282,7 @@ trait User
$oAccount = $this->getAccountFromToken();
if (!$this->GetCapa(Capa::USER_BACKGROUND)) {
return $this->FalseResponse(__FUNCTION__);
return $this->FalseResponse();
}
$oSettings = $this->SettingsProvider()->Load($oAccount);
@@ -297,7 +296,7 @@ trait User
$oSettings->SetConf('UserBackgroundHash', '');
}
return $this->DefaultResponse(__FUNCTION__, $oAccount && $oSettings ?
return $this->DefaultResponse($oAccount && $oSettings ?
$this->SettingsProvider()->Save($oAccount, $oSettings) : false);
}

View File

@@ -13,7 +13,7 @@ use RainLoop\Exceptions\ClientException;
trait UserAuth
{
/**
* @var string
* @var bool | null | Account
*/
private $oAdditionalAuthAccount = false;
private $oMainAuthAccount = false;
@@ -199,7 +199,7 @@ trait UserAuth
/**
* Returns RainLoop\Model\AdditionalAccount when it exists,
* else returns RainLoop\Model\Account when it exists,
* else returns RainLoop\Model\MainAccount when it exists,
* else null
*
* @throws \RainLoop\Exceptions\ClientException

View File

@@ -14,14 +14,14 @@ class ActionsAdmin extends Actions
if (\is_dir(APP_PRIVATE_DATA . 'cache')) {
\MailSo\Base\Utils::RecRmDir(APP_PRIVATE_DATA.'cache');
}
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoAdminSettingsGet() : array
{
$aConfig = $this->Config()->jsonSerialize();
unset($aConfig['version']);
return $this->DefaultResponse(__FUNCTION__, $aConfig);
return $this->DefaultResponse($aConfig);
}
public function DoAdminSettingsSet() : array
@@ -32,13 +32,13 @@ class ActionsAdmin extends Actions
$oConfig->Set($sSection, $sKey, $mValue);
}
}
return $this->DefaultResponse(__FUNCTION__, $oConfig->Save());
return $this->DefaultResponse($oConfig->Save());
}
public function DoAdminSettingsUpdate() : array
{
// sleep(3);
// return $this->DefaultResponse(__FUNCTION__, false);
// return $this->DefaultResponse(false);
$this->IsAdminLoggined();
@@ -96,7 +96,7 @@ class ActionsAdmin extends Actions
$this->setConfigFromParams($oConfig, 'TokenProtection', 'security', 'csrf_protection', 'bool');
$this->setConfigFromParams($oConfig, 'EnabledPlugins', 'plugins', 'enable', 'bool');
return $this->DefaultResponse(__FUNCTION__, $oConfig->Save());
return $this->DefaultResponse($oConfig->Save());
}
/**
@@ -125,7 +125,7 @@ class ActionsAdmin extends Actions
$sToken = $this->setAdminAuthToken();
return $this->DefaultResponse(__FUNCTION__, $sToken ? $this->AppData(true) : false);
return $this->DefaultResponse($sToken ? $this->AppData(true) : false);
}
public function DoAdminLogout() : array
@@ -135,7 +135,7 @@ class ActionsAdmin extends Actions
$this->Cacher(null, true)->Delete(KeyPathHelper::SessionAdminKey($sAdminKey));
}
Utils::ClearCookie(static::$AUTH_ADMIN_TOKEN_KEY);
return $this->TrueResponse(__FUNCTION__);
return $this->TrueResponse();
}
public function DoAdminContactsTest() : array
@@ -154,7 +154,7 @@ class ActionsAdmin extends Actions
});
$sTestMessage = $this->AddressBookProvider(null, true)->Test();
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'Result' => '' === $sTestMessage,
'Message' => \MailSo\Base\Utils::Utf8Clear($sTestMessage)
));
@@ -195,7 +195,7 @@ class ActionsAdmin extends Actions
$bResult = $oConfig->Save();
}
return $this->DefaultResponse(__FUNCTION__, $bResult
return $this->DefaultResponse($bResult
? array('Weak' => \is_file($passfile))
: false);
}
@@ -204,30 +204,28 @@ class ActionsAdmin extends Actions
{
$this->IsAdminLoggined();
return $this->DefaultResponse(__FUNCTION__,
$this->DomainProvider()->Load($this->GetActionParam('Name', ''), false, false));
return $this->DefaultResponse($this->DomainProvider()->Load($this->GetActionParam('Name', ''), false, false));
}
public function DoAdminDomainList() : array
{
$this->IsAdminLoggined();
$bIncludeAliases = !empty($this->GetActionParam('IncludeAliases', '1'));
return $this->DefaultResponse(__FUNCTION__, $this->DomainProvider()->GetList($bIncludeAliases));
return $this->DefaultResponse($this->DomainProvider()->GetList($bIncludeAliases));
}
public function DoAdminDomainDelete() : array
{
$this->IsAdminLoggined();
return $this->DefaultResponse(__FUNCTION__,
$this->DomainProvider()->Delete((string) $this->GetActionParam('Name', '')));
return $this->DefaultResponse($this->DomainProvider()->Delete((string) $this->GetActionParam('Name', '')));
}
public function DoAdminDomainDisable() : array
{
$this->IsAdminLoggined();
return $this->DefaultResponse(__FUNCTION__, $this->DomainProvider()->Disable(
return $this->DefaultResponse($this->DomainProvider()->Disable(
(string) $this->GetActionParam('Name', ''),
'1' === (string) $this->GetActionParam('Disabled', '0')
));
@@ -239,15 +237,14 @@ class ActionsAdmin extends Actions
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this);
return $this->DefaultResponse(__FUNCTION__,
$oDomain ? $this->DomainProvider()->Save($oDomain) : false);
return $this->DefaultResponse($oDomain ? $this->DomainProvider()->Save($oDomain) : false);
}
public function DoAdminDomainAliasSave() : array
{
$this->IsAdminLoggined();
return $this->DefaultResponse(__FUNCTION__, $this->DomainProvider()->SaveAlias(
return $this->DefaultResponse($this->DomainProvider()->SaveAlias(
(string) $this->GetActionParam('Name', ''),
(string) $this->GetActionParam('Alias', '')
));
@@ -262,7 +259,7 @@ class ActionsAdmin extends Actions
$oDomain = \str_contains($sEmail, '@')
? $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true)
: null;
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'email' => $sEmail,
'login' => $sLogin,
'domain' => $oDomain,
@@ -401,7 +398,7 @@ class ActionsAdmin extends Actions
}
}
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'Imap' => $bImapResult ? true : $sImapErrorDesc,
'Smtp' => $bSmtpResult ? true : $sSmtpErrorDesc,
'Sieve' => $bSieveResult ? true : $sSieveErrorDesc
@@ -434,12 +431,12 @@ class ActionsAdmin extends Actions
'loaded' => \class_exists('PharData'),
'version' => \phpversion('phar')
];
return $this->DefaultResponse(__FUNCTION__, $aResult);
return $this->DefaultResponse($aResult);
}
public function DoAdminPackagesList() : array
{
return $this->DefaultResponse(__FUNCTION__, \SnappyMail\Repository::getPackagesList());
return $this->DefaultResponse(\SnappyMail\Repository::getPackagesList());
}
public function DoAdminPackageDelete() : array
@@ -447,7 +444,7 @@ class ActionsAdmin extends Actions
$sId = $this->GetActionParam('Id', '');
$bResult = \SnappyMail\Repository::deletePackage($sId);
static::pluginEnable($sId, false);
return $this->DefaultResponse(__FUNCTION__, $bResult);
return $this->DefaultResponse($bResult);
}
public function DoAdminPackageInstall() : array
@@ -458,7 +455,7 @@ class ActionsAdmin extends Actions
$this->GetActionParam('Id', ''),
$this->GetActionParam('File', '')
);
return $this->DefaultResponse(__FUNCTION__, $bResult ?
return $this->DefaultResponse($bResult ?
('plugin' !== $sType ? array('Reload' => true) : true) : false);
}
@@ -517,7 +514,7 @@ class ActionsAdmin extends Actions
$aWarnings[] = 'Can not edit: ' . APP_INDEX_ROOT_PATH . 'index.php';
}
return $this->DefaultResponse(__FUNCTION__, array(
return $this->DefaultResponse(array(
'Updatable' => \SnappyMail\Repository::canUpdateCore(),
'Warning' => $bShowWarning,
'Version' => $sVersion,
@@ -528,7 +525,7 @@ class ActionsAdmin extends Actions
public function DoAdminUpgradeCore() : array
{
return $this->DefaultResponse(__FUNCTION__, \SnappyMail\Upgrade::core());
return $this->DefaultResponse(\SnappyMail\Upgrade::core());
}
public function DoAdminPluginDisable() : array
@@ -546,16 +543,16 @@ class ActionsAdmin extends Actions
$sValue = $oPlugin->Supported();
if (\strlen($sValue))
{
return $this->FalseResponse(__FUNCTION__, Notifications::UnsupportedPluginPackage, $sValue);
return $this->FalseResponse(Notifications::UnsupportedPluginPackage, $sValue);
}
}
else
{
return $this->FalseResponse(__FUNCTION__, Notifications::InvalidPluginPackage);
return $this->FalseResponse(Notifications::InvalidPluginPackage);
}
}
return $this->DefaultResponse(__FUNCTION__, $this->pluginEnable($sId, !$bDisable));
return $this->DefaultResponse($this->pluginEnable($sId, !$bDisable));
}
public function DoAdminPluginLoad() : array
@@ -606,7 +603,7 @@ class ActionsAdmin extends Actions
}
}
return $this->DefaultResponse(__FUNCTION__, $mResult);
return $this->DefaultResponse($mResult);
}
public function DoAdminPluginSettingsUpdate() : array
@@ -635,7 +632,7 @@ class ActionsAdmin extends Actions
}
}
if ($oConfig->Save()) {
return $this->DefaultResponse(__FUNCTION__, true);
return $this->TrueResponse();
}
}
}
@@ -653,7 +650,7 @@ class ActionsAdmin extends Actions
// "otpauth://totp/{$user}?secret={$secret}",
\SnappyMail\QRCode::ERROR_CORRECT_LEVEL_M
);
return $this->DefaultResponse(__FUNCTION__, $QR->__toString());
return $this->DefaultResponse($QR->__toString());
}
private function setAdminAuthToken() : string

View File

@@ -70,8 +70,7 @@ class Notifications
static public function GetNotificationsMessage(int $iCode, ?\Throwable $oPrevious = null) : string
{
if (self::ClientViewError === $iCode && $oPrevious)
{
if (self::ClientViewError === $iCode && $oPrevious) {
return $oPrevious->getMessage();
}

View File

@@ -25,25 +25,13 @@ abstract class AbstractPlugin
*/
private $oPluginConfig = null;
/**
* @var bool
*/
private $bLangs = false;
private bool $bLangs = false;
/**
* @var string
*/
private $sName;
private string $sName;
/**
* @var string
*/
private $sPath = '';
private string $sPath = '';
/**
* @var array
*/
private $aConfigMap = null;
private ?array $aConfigMap = null;
public function __construct()
{
@@ -63,8 +51,7 @@ abstract class AbstractPlugin
public function UseLangs(?bool $bLangs = null) : bool
{
if (null !== $bLangs)
{
if (null !== $bLangs) {
$this->bLangs = $bLangs;
}
@@ -113,8 +100,7 @@ abstract class AbstractPlugin
final public function ConfigMap(bool $flatten = false) : array
{
if (null === $this->aConfigMap)
{
if (null === $this->aConfigMap) {
$this->aConfigMap = $this->configMapping();
}
@@ -163,8 +149,7 @@ abstract class AbstractPlugin
final public function SetPluginConfig(\RainLoop\Config\Plugin $oPluginConfig) : self
{
$this->oPluginConfig = $oPluginConfig;
if ($oPluginConfig->IsInited() && !$oPluginConfig->Load())
{
if ($oPluginConfig->IsInited() && !$oPluginConfig->Load()) {
$oPluginConfig->Save();
}
return $this;
@@ -172,8 +157,7 @@ abstract class AbstractPlugin
final protected function addHook(string $sHookName, string $sFunctionName) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddHook($sHookName, array($this, $sFunctionName));
}
@@ -182,8 +166,7 @@ abstract class AbstractPlugin
final protected function addCss(string $sFile, bool $bAdminScope = false) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddCss($this->sPath.'/'.$sFile, $bAdminScope);
}
@@ -192,8 +175,7 @@ abstract class AbstractPlugin
final protected function addJs(string $sFile, bool $bAdminScope = false) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddJs($this->sPath.'/'.$sFile, $bAdminScope);
}
@@ -202,8 +184,7 @@ abstract class AbstractPlugin
final protected function addTemplate(string $sFile, bool $bAdminScope = false) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope);
}
@@ -212,8 +193,7 @@ abstract class AbstractPlugin
final protected function replaceTemplate(string $sFile, bool $bAdminScope = false) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope);
}
@@ -222,8 +202,7 @@ abstract class AbstractPlugin
final protected function addPartHook(string $sActionName, string $sFunctionName) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddAdditionalPartAction($sActionName, array($this, $sFunctionName));
}
@@ -232,8 +211,7 @@ abstract class AbstractPlugin
final protected function addJsonHook(string $sActionName, string $sFunctionName) : self
{
if ($this->oPluginManager)
{
if ($this->oPluginManager) {
$this->oPluginManager->AddAdditionalJsonAction($sActionName, array($this, $sFunctionName));
}

View File

@@ -101,10 +101,8 @@ class Manager
$aList = array();
$aGlob = \glob(APP_PLUGINS_PATH.'*');
if (\is_array($aGlob))
{
foreach ($aGlob as $sPathName)
{
if (\is_array($aGlob)) {
foreach ($aGlob as $sPathName) {
if (\is_dir($sPathName)) {
$sName = \basename($sPathName);
} else if ('.phar' === \substr($sPathName, -5)) {
@@ -122,9 +120,7 @@ class Manager
);
}
}
}
else
{
} else {
$this->oActions->Logger()->Write('Cannot get installed plugins from '.APP_PLUGINS_PATH,
\LOG_ERR);
}
@@ -222,13 +218,10 @@ class Manager
public function CompileTemplate(array &$aList, bool $bAdminScope = false) : void
{
if ($this->bIsEnabled)
{
if ($this->bIsEnabled) {
$aTemplates = $bAdminScope ? $this->aAdminTemplates : $this->aTemplates;
foreach ($aTemplates as $sFile)
{
if (\is_readable($sFile))
{
foreach ($aTemplates as $sFile) {
if (\is_readable($sFile)) {
$sTemplateName = \substr(\basename($sFile), 0, -5);
$aList[$sTemplateName] = $sFile;
}
@@ -238,21 +231,15 @@ class Manager
public function InitAppData(bool $bAdmin, array &$aAppData, ?\RainLoop\Model\Account $oAccount = null) : self
{
if ($this->bIsEnabled && isset($aAppData['Plugins']) && \is_array($aAppData['Plugins']))
{
if ($this->bIsEnabled && isset($aAppData['Plugins']) && \is_array($aAppData['Plugins'])) {
$bAuth = !empty($aAppData['Auth']);
foreach ($this->aPlugins as $oPlugin)
{
if ($oPlugin)
{
foreach ($this->aPlugins as $oPlugin) {
if ($oPlugin) {
$aConfig = array();
$aMap = $oPlugin->ConfigMap(true);
if (\is_array($aMap))
{
foreach ($aMap as /* @var $oPluginProperty \RainLoop\Plugins\Property */ $oPluginProperty)
{
if ($oPluginProperty && $oPluginProperty->AllowedInJs())
{
if (\is_array($aMap)) {
foreach ($aMap as /* @var $oPluginProperty \RainLoop\Plugins\Property */ $oPluginProperty) {
if ($oPluginProperty && $oPluginProperty->AllowedInJs()) {
$aConfig[$oPluginProperty->Name()] =
$oPlugin->Config()->Get('plugin',
$oPluginProperty->Name(),
@@ -263,8 +250,7 @@ class Manager
$oPlugin->FilterAppDataPluginSection($bAdmin, $bAuth, $aConfig);
if (\count($aConfig))
{
if (\count($aConfig)) {
$aAppData['Plugins'][$oPlugin->Name()] = $aConfig;
}
}
@@ -310,14 +296,10 @@ class Manager
public function AddTemplate(string $sFile, bool $bAdminScope = false) : self
{
if ($this->bIsEnabled)
{
if ($bAdminScope)
{
if ($this->bIsEnabled) {
if ($bAdminScope) {
$this->aAdminTemplates[$sFile] = $sFile;
}
else
{
} else {
$this->aTemplates[$sFile] = $sFile;
}
}
@@ -346,11 +328,9 @@ class Manager
*/
public function AddAdditionalPartAction(string $sActionName, $mCallbak) : self
{
if ($this->bIsEnabled && \is_callable($mCallbak))
{
if ($this->bIsEnabled && \is_callable($mCallbak)) {
$sActionName = \strtolower($sActionName);
if (!isset($this->aAdditionalParts[$sActionName]))
{
if (!isset($this->aAdditionalParts[$sActionName])) {
$this->aAdditionalParts[$sActionName] = array();
}
@@ -363,13 +343,10 @@ class Manager
public function RunAdditionalPart(string $sActionName, array $aParts = array()) : bool
{
$bResult = false;
if ($this->bIsEnabled)
{
if ($this->bIsEnabled) {
$sActionName = \strtolower($sActionName);
if (isset($this->aAdditionalParts[$sActionName]))
{
foreach ($this->aAdditionalParts[$sActionName] as $mCallbak)
{
if (isset($this->aAdditionalParts[$sActionName])) {
foreach ($this->aAdditionalParts[$sActionName] as $mCallbak) {
$bResult = !!$mCallbak(...$aParts) || $bResult;
}
}
@@ -405,20 +382,17 @@ class Manager
*/
public function JsonResponseHelper(string $sFunctionName, $mData) : array
{
return $this->oActions->DefaultResponse($sFunctionName, $mData);
return $this->oActions->DefaultResponse($mData, [], $sFunctionName);
}
public function GetUserPluginSettings(string $sPluginName) : array
{
$oAccount = $this->oActions->GetAccount();
if ($oAccount)
{
if ($oAccount) {
$oSettings = $this->oActions->SettingsProvider()->Load($oAccount);
if ($oSettings)
{
if ($oSettings) {
$aData = $oSettings->GetConf('Plugins', array());
if (isset($aData[$sPluginName]) && \is_array($aData[$sPluginName]))
{
if (isset($aData[$sPluginName]) && \is_array($aData[$sPluginName])) {
return $aData[$sPluginName];
}
}
@@ -430,25 +404,20 @@ class Manager
public function SaveUserPluginSettings(string $sPluginName, array $aSettings) : bool
{
$oAccount = $this->oActions->GetAccount();
if ($oAccount)
{
if ($oAccount) {
$oSettings = $this->oActions->SettingsProvider()->Load($oAccount);
if ($oSettings)
{
if ($oSettings) {
$aData = $oSettings->GetConf('Plugins', array());
if (!\is_array($aData))
{
if (!\is_array($aData)) {
$aData = array();
}
$aPluginSettings = array();
if (isset($aData[$sPluginName]) && \is_array($aData[$sPluginName]))
{
if (isset($aData[$sPluginName]) && \is_array($aData[$sPluginName])) {
$aPluginSettings = $aData[$sPluginName];
}
foreach ($aSettings as $sKey => $mValue)
{
foreach ($aSettings as $sKey => $mValue) {
$aPluginSettings[$sKey] = $mValue;
}
@@ -518,16 +487,14 @@ class Manager
public function WriteLog(string $sDesc, int $iType = \LOG_INFO) : void
{
if ($this->oLogger)
{
if ($this->oLogger) {
$this->oLogger->Write($sDesc, $iType, 'PLUGIN');
}
}
public function WriteException(string $sDesc, int $iType = \LOG_INFO) : void
{
if ($this->oLogger)
{
if ($this->oLogger) {
$this->oLogger->WriteException($sDesc, $iType, 'PLUGIN');
}
}

View File

@@ -10,8 +10,7 @@ abstract class Service
public static function Handle() : bool
{
static $bOne = null;
if (null === $bOne)
{
if (null === $bOne) {
$bOne = static::RunResult();
}
@@ -23,8 +22,7 @@ abstract class Service
$oConfig = Api::Config();
$sServer = \trim($oConfig->Get('security', 'custom_server_signature', ''));
if (\strlen($sServer))
{
if (\strlen($sServer)) {
\header('Server: '.$sServer);
}
@@ -40,8 +38,7 @@ abstract class Service
\header('X-XSS-Protection: '.$sXssProtectionOptionsHeader);
$oHttp = \MailSo\Base\Http::SingletonInstance();
if ($oConfig->Get('labs', 'force_https', false) && !$oHttp->IsSecure())
{
if ($oConfig->Get('labs', 'force_https', false) && !$oHttp->IsSecure()) {
\header('Location: https://'.$oHttp->GetHost(false, false).$oHttp->GetUrl());
exit;
}
@@ -67,13 +64,10 @@ abstract class Service
$bAdmin = false;
$sAdminPanelHost = $oConfig->Get('security', 'admin_panel_host', '');
if (empty($sAdminPanelHost))
{
if (empty($sAdminPanelHost)) {
$bAdmin = !empty($aPaths[0]) && ($oConfig->Get('security', 'admin_panel_key', '') ?: 'admin') === $aPaths[0];
$bAdmin && \array_shift($aPaths);
}
else if (empty($aPaths[0]) && \mb_strtolower($sAdminPanelHost) === \mb_strtolower($oHttp->GetHost()))
{
} else if (empty($aPaths[0]) && \mb_strtolower($sAdminPanelHost) === \mb_strtolower($oHttp->GetHost())) {
$bAdmin = true;
}
@@ -81,15 +75,13 @@ abstract class Service
$oActions->Plugins()->RunHook('filter.http-paths', array(&$aPaths));
if ($oHttp->IsPost())
{
if ($oHttp->IsPost()) {
$oHttp->ServerNoCache();
}
$oServiceActions = new ServiceActions($oHttp, $oActions);
if ($bAdmin && !$oConfig->Get('security', 'allow_admin_panel', true))
{
if ($bAdmin && !$oConfig->Get('security', 'allow_admin_panel', true)) {
\MailSo\Base\Http::StatusHeader(403);
echo $oServiceActions->ErrorTemplates('Access Denied.',
'Access to the SnappyMail Admin Panel is not allowed!');
@@ -99,8 +91,7 @@ abstract class Service
$bIndex = true;
$sResult = '';
if (\count($aPaths) && !empty($aPaths[0]) && 'index' !== \strtolower($aPaths[0]))
{
if (\count($aPaths) && !empty($aPaths[0]) && 'index' !== \strtolower($aPaths[0])) {
if ('mailto' !== \strtolower($aPaths[0]) && !\SnappyMail\HTTP\SecFetch::matchAnyRule($oConfig->Get('security', 'secfetch_allow', ''))) {
\MailSo\Base\Http::StatusHeader(403);
echo $oServiceActions->ErrorTemplates('Access Denied.',
@@ -116,20 +107,15 @@ abstract class Service
$sMethodName = 'Service'.\preg_replace('/@.+$/', '', $aPaths[0]);
$sMethodExtra = \strpos($aPaths[0], '@') ? \preg_replace('/^[^@]+@/', '', $aPaths[0]) : '';
if (\method_exists($oServiceActions, $sMethodName) &&
\is_callable(array($oServiceActions, $sMethodName)))
{
if (\method_exists($oServiceActions, $sMethodName) && \is_callable(array($oServiceActions, $sMethodName))) {
$oServiceActions->SetQuery($sQuery)->SetPaths($aPaths);
$sResult = $oServiceActions->{$sMethodName}($sMethodExtra);
}
else if (!$oActions->Plugins()->RunAdditionalPart($aPaths[0], $aPaths))
{
} else if (!$oActions->Plugins()->RunAdditionalPart($aPaths[0], $aPaths)) {
$bIndex = true;
}
}
if ($bIndex)
{
if ($bIndex) {
if (!$bAdmin) {
$login = $oConfig->Get('labs', 'custom_login_link', '');
if ($login && !$oActions->getAccountFromToken(false)) {
@@ -142,8 +128,7 @@ abstract class Service
\header('Content-Type: text/html; charset=utf-8');
$oHttp->ServerNoCache();
if (!\is_dir(APP_DATA_FOLDER_PATH) || !\is_writable(APP_DATA_FOLDER_PATH))
{
if (!\is_dir(APP_DATA_FOLDER_PATH) || !\is_writable(APP_DATA_FOLDER_PATH)) {
echo $oServiceActions->ErrorTemplates(
'Permission denied!',
'SnappyMail can not access the data folder "'.APP_DATA_FOLDER_PATH.'"'
@@ -175,8 +160,7 @@ abstract class Service
);
$sCacheFileName = '';
if ($oConfig->Get('labs', 'cache_system_data', true))
{
if ($oConfig->Get('labs', 'cache_system_data', true)) {
$sCacheFileName = 'TMPL:' . $sLanguage . \md5(
Utils::jsonEncode(array(
$oConfig->Get('cache', 'index', ''),
@@ -217,9 +201,7 @@ abstract class Service
$sScriptHash = 'sha256-'.\base64_encode(\hash('sha256', $script[1], true));
static::setCSP(null, $sScriptHash);
*/
}
else if (!\headers_sent())
{
} else if (!\headers_sent()) {
\header('X-XSS-Protection: 1; mode=block');
}

View File

@@ -4,32 +4,18 @@ namespace RainLoop;
class ServiceActions
{
/**
* @var \MailSo\Base\Http
*/
protected $oHttp;
protected \MailSo\Base\Http $oHttp;
/**
* @var \RainLoop\Actions
*/
protected $oActions;
protected Actions $oActions;
/**
* @var array
*/
protected $aPaths;
protected array $aPaths = array();
/**
* @var string
*/
protected $sQuery;
protected string $sQuery = '';
public function __construct(\MailSo\Base\Http $oHttp, Actions $oActions)
{
$this->oHttp = $oHttp;
$this->oActions = $oActions;
$this->aPaths = array();
$this->sQuery = '';
}
private function Logger() : \MailSo\Log\Logger
@@ -94,8 +80,7 @@ class ServiceActions
$_POST = \json_decode(\file_get_contents('php://input'), true);
$sAction = $_POST['Action'] ?? '';
if (empty($sAction) && $this->oHttp->IsGet() && !empty($this->aPaths[2]))
{
if (empty($sAction) && $this->oHttp->IsGet() && !empty($this->aPaths[2])) {
$sAction = $this->aPaths[2];
}
@@ -103,65 +88,60 @@ class ServiceActions
try
{
if (empty($sAction)) {
throw new Exceptions\ClientException(Notifications::InvalidInputArgument, null, 'Action unknown');
}
if ($this->oHttp->IsPost() &&
$this->Config()->Get('security', 'csrf_protection', false) &&
($_POST['XToken'] ?? '') !== Utils::GetCsrfToken())
{
throw new Exceptions\ClientException(Notifications::InvalidToken, null, 'CSRF failed');
}
if (!empty($sAction))
{
if ($this->oActions instanceof ActionsAdmin && 0 === \stripos($sAction, 'Admin') && !\in_array($sAction, ['AdminLogin', 'AdminLogout'])) {
$this->oActions->IsAdminLoggined();
}
$sMethodName = 'Do'.$sAction;
if ($this->oActions instanceof ActionsAdmin && 0 === \stripos($sAction, 'Admin') && !\in_array($sAction, ['AdminLogin', 'AdminLogout'])) {
$this->oActions->IsAdminLoggined();
}
$this->Logger()->Write('Action: '.$sMethodName, \LOG_INFO, 'JSON');
$sMethodName = 'Do'.$sAction;
$aPost = $_POST ?? null;
if ($aPost)
{
$this->oActions->SetActionParams($aPost, $sMethodName);
foreach ($aPost as $key => $value) {
if (false !== \stripos($key, 'Password')) {
$aPost[$key] = '*******';
}
$this->Logger()->Write('Action: '.$sMethodName, \LOG_INFO, 'JSON');
$aPost = $_POST ?? null;
if ($aPost) {
$this->oActions->SetActionParams($aPost, $sMethodName);
foreach ($aPost as $key => $value) {
if (false !== \stripos($key, 'Password')) {
$aPost[$key] = '*******';
}
}
/*
switch ($sMethodName)
{
case 'DoLogin':
case 'DoAdminLogin':
case 'DoAccountAdd':
$this->Logger()->AddSecret($this->oActions->GetActionParam('Password', ''));
break;
}
switch ($sMethodName)
{
case 'DoLogin':
case 'DoAdminLogin':
case 'DoAccountAdd':
$this->Logger()->AddSecret($this->oActions->GetActionParam('Password', ''));
break;
}
*/
$this->Logger()->Write(Utils::jsonEncode($aPost),
\LOG_INFO, 'POST', true);
}
else if (3 < \count($this->aPaths) && $this->oHttp->IsGet())
{
$this->oActions->SetActionParams(array(
'RawKey' => empty($this->aPaths[3]) ? '' : $this->aPaths[3]
), $sMethodName);
}
$this->Logger()->Write(Utils::jsonEncode($aPost), \LOG_INFO, 'POST', true);
} else if (3 < \count($this->aPaths) && $this->oHttp->IsGet()) {
$this->oActions->SetActionParams(array(
'RawKey' => empty($this->aPaths[3]) ? '' : $this->aPaths[3]
), $sMethodName);
}
if (\method_exists($this->oActions, $sMethodName) &&
\is_callable(array($this->oActions, $sMethodName)))
{
$sAction && $this->Plugins()->RunHook("json.before-{$sAction}");
$aResponse = $this->oActions->{$sMethodName}();
}
else if ($this->Plugins()->HasAdditionalJson($sMethodName))
{
$sAction && $this->Plugins()->RunHook("json.before-{$sAction}");
$aResponse = $this->Plugins()->RunAdditionalJson($sMethodName);
}
if ($sAction && \is_array($aResponse)) {
$this->Plugins()->RunHook("json.after-{$sAction}", array(&$aResponse));
}
if (\method_exists($this->oActions, $sMethodName) && \is_callable(array($this->oActions, $sMethodName))) {
$this->Plugins()->RunHook("json.before-{$sAction}");
$aResponse = $this->oActions->{$sMethodName}();
} else if ($this->Plugins()->HasAdditionalJson($sMethodName)) {
$this->Plugins()->RunHook("json.before-{$sAction}");
$aResponse = $this->Plugins()->RunAdditionalJson($sMethodName);
}
if (\is_array($aResponse)) {
$this->Plugins()->RunHook("json.after-{$sAction}", array(&$aResponse));
}
if (!\is_array($aResponse)) {
@@ -175,10 +155,11 @@ class ServiceActions
\SnappyMail\Log::warning('SERVICE', "- {$e->getMessage()} @ {$e->getFile()}#{$e->getLine()}");
}
$aResponse = $this->oActions->ExceptionResponse(
empty($sAction) ? 'Unknown' : $sAction, $oException);
$aResponse = $this->oActions->ExceptionResponse($oException);
}
$aResponse['Action'] = $sAction ?: 'Unknown';
if (\is_array($aResponse)) {
$aResponse['Time'] = (int) ((\microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000);
}
@@ -191,15 +172,12 @@ class ServiceActions
$sObResult = \ob_get_clean();
if ($this->Logger()->IsEnabled())
{
if (\strlen($sObResult))
{
if ($this->Logger()->IsEnabled()) {
if (\strlen($sObResult)) {
$this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA');
}
if ($oException)
{
if ($oException) {
$this->Logger()->WriteException($oException, \LOG_ERR);
}
@@ -218,9 +196,7 @@ class ServiceActions
$oException = null;
try
{
if (\method_exists($this->oActions, 'Append') &&
\is_callable(array($this->oActions, 'Append')))
{
if (\method_exists($this->oActions, 'Append') && \is_callable(array($this->oActions, 'Append'))) {
isset($_POST) && $this->oActions->SetActionParams($_POST, 'Append');
$bResponse = $this->oActions->Append();
}
@@ -234,13 +210,11 @@ class ServiceActions
$sResult = true === $bResponse ? '1' : '0';
$sObResult = \ob_get_clean();
if (\strlen($sObResult))
{
if (\strlen($sObResult)) {
$this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA');
}
if ($oException)
{
if ($oException) {
$this->Logger()->WriteException($oException, \LOG_ERR);
}
@@ -264,33 +238,24 @@ class ServiceActions
$iError = UPLOAD_ERR_OK;
$_FILES = isset($_FILES) ? $_FILES : null;
if (isset($_FILES[$sInputName], $_FILES[$sInputName]['name'], $_FILES[$sInputName]['tmp_name'], $_FILES[$sInputName]['size']))
{
if (isset($_FILES[$sInputName], $_FILES[$sInputName]['name'], $_FILES[$sInputName]['tmp_name'], $_FILES[$sInputName]['size'])) {
$iError = (isset($_FILES[$sInputName]['error'])) ? (int) $_FILES[$sInputName]['error'] : UPLOAD_ERR_OK;
// \is_uploaded_file($_FILES[$sInputName]['tmp_name'])
if (UPLOAD_ERR_OK === $iError && 0 < $iSizeLimit && $iSizeLimit < (int) $_FILES[$sInputName]['size'])
{
if (UPLOAD_ERR_OK === $iError && 0 < $iSizeLimit && $iSizeLimit < (int) $_FILES[$sInputName]['size']) {
$iError = Enumerations\UploadError::CONFIG_SIZE;
}
if (UPLOAD_ERR_OK === $iError)
{
if (UPLOAD_ERR_OK === $iError) {
$aFile = $_FILES[$sInputName];
}
}
else if (empty($_FILES))
{
} else if (empty($_FILES)) {
$iError = UPLOAD_ERR_INI_SIZE;
}
else
{
} else {
$iError = Enumerations\UploadError::EMPTY_FILES_DATA;
}
if (\method_exists($this->oActions, $sAction) &&
\is_callable(array($this->oActions, $sAction)))
{
if (\method_exists($this->oActions, $sAction) && \is_callable(array($this->oActions, $sAction))) {
$aActionParams = isset($_GET) && \is_array($_GET) ? $_GET : null;
$aActionParams['File'] = $aFile;
@@ -309,9 +274,11 @@ class ServiceActions
}
catch (\Throwable $oException)
{
$aResponse = $this->oActions->ExceptionResponse($sAction, $oException);
$aResponse = $this->oActions->ExceptionResponse($oException);
}
$aResponse['Action'] = $sAction ?: 'Unknown';
\header('Content-Type: application/json; charset=utf-8');
$sResult = Utils::jsonEncode($aResponse);
@@ -392,12 +359,10 @@ class ServiceActions
try
{
$sRawError = 'Invalid action';
if (\strlen($sAction))
{
if (\strlen($sAction)) {
try {
$sMethodName = 'Raw'.$sAction;
if (\method_exists($this->oActions, $sMethodName))
{
if (\method_exists($this->oActions, $sMethodName)) {
\header('X-Raw-Action: '.$sMethodName);
\header('Content-Security-Policy: script-src \'none\'; child-src \'none\'');
@@ -407,22 +372,17 @@ class ServiceActions
'Params' => $this->aPaths
), $sMethodName);
if (!$this->oActions->{$sMethodName}())
{
if (!$this->oActions->{$sMethodName}()) {
$sRawError = 'False result';
}
}
else
{
} else {
$sRawError = 'Unknown action "'.$sAction.'"';
}
} catch (\Throwable $e) {
// error_log(print_r($e,1));
$sRawError = $e->getMessage();
}
}
else
{
} else {
$sRawError = 'Empty action';
}
}
@@ -437,14 +397,12 @@ class ServiceActions
$sRawError = 'Exception as result';
}
if (\strlen($sRawError))
{
if (\strlen($sRawError)) {
$this->Logger()->Write($sRawError, \LOG_ERR);
$this->Logger()->WriteDump($this->aPaths, \LOG_ERR, 'PATHS');
}
if ($oException)
{
if ($oException) {
$this->Logger()->WriteException($oException, \LOG_ERR, 'RAW');
}
@@ -457,37 +415,31 @@ class ServiceActions
$sResult = '';
\header('Content-Type: application/javascript; charset=utf-8');
if (!empty($this->aPaths[3]))
{
if (!empty($this->aPaths[3])) {
$bAdmin = 'Admin' === (isset($this->aPaths[2]) ? (string) $this->aPaths[2] : 'App');
$sLanguage = $this->oActions->ValidateLanguage($this->aPaths[3], '', $bAdmin);
$bCacheEnabled = $this->Config()->Get('labs', 'cache_system_data', true);
if (!empty($sLanguage) && $bCacheEnabled)
{
if (!empty($sLanguage) && $bCacheEnabled) {
$this->oActions->verifyCacheByKey($this->sQuery);
}
$sCacheFileName = '';
if ($bCacheEnabled)
{
if ($bCacheEnabled) {
$sCacheFileName = KeyPathHelper::LangCache(
$sLanguage, $bAdmin, $this->oActions->Plugins()->Hash());
$sResult = $this->Cacher()->Get($sCacheFileName);
}
if (!\strlen($sResult))
{
if (!\strlen($sResult)) {
$sResult = $this->oActions->compileLanguage($sLanguage, $bAdmin);
if ($bCacheEnabled && \strlen($sCacheFileName))
{
if ($bCacheEnabled && \strlen($sCacheFileName)) {
$this->Cacher()->Set($sCacheFileName, $sResult);
}
}
if ($bCacheEnabled)
{
if ($bCacheEnabled) {
$this->oActions->cacheByKey($this->sQuery);
}
}
@@ -653,13 +605,11 @@ class ServiceActions
$oAccount = null;
$sSsoHash = $_REQUEST['hash'] ?? '';
if (!empty($sSsoHash))
{
if (!empty($sSsoHash)) {
$mData = null;
$sSsoSubData = $this->Cacher()->Get(KeyPathHelper::SsoCacherKey($sSsoHash));
if (!empty($sSsoSubData))
{
if (!empty($sSsoSubData)) {
$aData = \SnappyMail\Crypt::DecryptFromJSON($sSsoSubData, $sSsoHash);
$this->Cacher()->Delete(KeyPathHelper::SsoCacherKey($sSsoHash));
@@ -677,29 +627,24 @@ class ServiceActions
{
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
if ($aAdditionalOptions)
{
if ($aAdditionalOptions) {
$bNeedToSettings = false;
$oSettings = $this->SettingsProvider()->Load($oAccount);
if ($oSettings)
{
if ($oSettings) {
$sLanguage = isset($aAdditionalOptions['Language']) ?
$aAdditionalOptions['Language'] : '';
if ($sLanguage)
{
if ($sLanguage) {
$sLanguage = $this->oActions->ValidateLanguage($sLanguage);
if ($sLanguage !== $oSettings->GetConf('Language', ''))
{
if ($sLanguage !== $oSettings->GetConf('Language', '')) {
$bNeedToSettings = true;
$oSettings->SetConf('Language', $sLanguage);
}
}
}
if ($bNeedToSettings)
{
if ($bNeedToSettings) {
$this->SettingsProvider()->Save($oAccount, $oSettings);
}
}