From ab748aab99d51b95110505982c60c1f7bb7134cb Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 26 Feb 2024 16:44:25 +0100 Subject: [PATCH] Small StorageType change --- plugins/nextcloud/storage.php | 2 +- .../app/libraries/RainLoop/Model/Account.php | 7 ++ .../libraries/RainLoop/Model/MainAccount.php | 7 ++ .../Storage/Enumerations/StorageType.php | 13 ++- .../Providers/Storage/FileStorage.php | 99 +++++++++---------- 5 files changed, 70 insertions(+), 58 deletions(-) diff --git a/plugins/nextcloud/storage.php b/plugins/nextcloud/storage.php index 05f38fb82..c8c71e1fc 100644 --- a/plugins/nextcloud/storage.php +++ b/plugins/nextcloud/storage.php @@ -12,7 +12,7 @@ class NextcloudStorage extends \RainLoop\Providers\Storage\FileStorage $sDataPath = parent::GenerateFilePath($mAccount, $iStorageType, $bMkDir); if (StorageType::CONFIG === $iStorageType) { $sUID = \OC::$server->getUserSession()->getUser()->getUID(); - $sDataPath .= "/.config/{$sUID}/"; + $sDataPath .= ".config/{$sUID}/"; if ($bMkDir && !\is_dir($sDataPath) && !\mkdir($sDataPath, 0700, true)) { throw new \RainLoop\Exceptions\Exception('Can\'t make storage directory "'.$sDataPath.'"'); } 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 26b73bb16..05564db93 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 @@ -306,4 +306,11 @@ abstract class Account implements \JsonSerializable return $bResult; } +/* + // Stores settings in AdditionalAccount else MainAccount + public function settingsLocal() : \RainLoop\Settings + { + return \RainLoop\Api::Actions()->SettingsProvider(true)->Load($this); + } +*/ } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php index e2823c1a9..f48a3b2b1 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Model/MainAccount.php @@ -63,4 +63,11 @@ class MainAccount extends Account { $this->sCryptKey = new SensitiveString($sKey); } +/* + // Stores settings in MainAccount + public function settings() : \RainLoop\Settings + { + return \RainLoop\Api::Actions()->SettingsProvider()->Load($this); + } +*/ } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/Enumerations/StorageType.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/Enumerations/StorageType.php index 3d02b13a3..f2337ba41 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/Enumerations/StorageType.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Storage/Enumerations/StorageType.php @@ -10,11 +10,10 @@ enum StorageType: int { */ abstract class StorageType { - const USER = 1; - const CONFIG = 2; - const NOBODY = 3; - const SIGN_ME = 4; - const SESSION = 5; - const PGP = 6; - const ROOT = 7; + const CONFIG = 1; + const NOBODY = 2; + const SIGN_ME = 3; + const SESSION = 4; + const PGP = 5; + const ROOT = 6; } 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 04f9948fd..5a3a7830f 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 @@ -90,58 +90,57 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage */ public function GenerateFilePath($mAccount, int $iStorageType, bool $bMkDir = false) : string { - $sEmail = $sSubFolder = ''; - if (null === $mAccount) { - $iStorageType = StorageType::NOBODY; - } else if ($mAccount instanceof \RainLoop\Model\MainAccount) { - $sEmail = $mAccount->Email(); - } else if ($mAccount instanceof \RainLoop\Model\AdditionalAccount) { - $sEmail = $mAccount->ParentEmail(); - if ($this->bLocal) { - $sSubFolder = $mAccount->Email(); - } - } else if (\is_string($mAccount)) { - $sEmail = $mAccount; - } - - if ($sEmail) { - if (StorageType::SIGN_ME === $iStorageType) { - $sSubFolder = '.sign_me'; - } else if (StorageType::SESSION === $iStorageType) { - $sSubFolder = '.sessions'; - } else if (StorageType::PGP === $iStorageType) { - $sSubFolder = '.pgp'; - } else if (StorageType::ROOT === $iStorageType) { - $sSubFolder = ''; - } - } - - $sFilePath = ''; - switch ($iStorageType) - { - case StorageType::NOBODY: - $sFilePath = $this->sDataPath.'/__nobody__/'; - break; - case StorageType::SIGN_ME: - case StorageType::SESSION: - case StorageType::CONFIG: - case StorageType::PGP: - case StorageType::ROOT: - if (empty($sEmail)) { - return ''; + $sEmail = $sSubFolder = $sFilePath = ''; + if (null === $mAccount || StorageType::NOBODY === $iStorageType) { + $sFilePath = $this->sDataPath.'/__nobody__/'; + } else { + if ($mAccount instanceof \RainLoop\Model\MainAccount) { + $sEmail = $mAccount->Email(); + } else if ($mAccount instanceof \RainLoop\Model\AdditionalAccount) { + $sEmail = $mAccount->ParentEmail(); + if ($this->bLocal) { + $sSubFolder = $mAccount->Email(); } - if (\is_dir("{$this->sDataPath}/cfg")) { - \SnappyMail\Upgrade::FileStorage($this->sDataPath); + } else if (\is_string($mAccount)) { + $sEmail = $mAccount; + } + + if ($sEmail) { + // these are never local + if (StorageType::SIGN_ME === $iStorageType) { + $sSubFolder = '.sign_me'; + } else if (StorageType::SESSION === $iStorageType) { + $sSubFolder = '.sessions'; + } else if (StorageType::PGP === $iStorageType) { + $sSubFolder = '.pgp'; + } else if (StorageType::ROOT === $iStorageType) { + $sSubFolder = ''; } - $aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld'); - $sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : ''); - $sFilePath = $this->sDataPath - .'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld') - .'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown') - .'/'.($sSubFolder ? \MailSo\Base\Utils::SecureFileName($sSubFolder).'/' : ''); - break; - default: - throw new \Exception("Invalid storage type {$iStorageType}"); + } + + switch ($iStorageType) + { + case StorageType::CONFIG: + case StorageType::SIGN_ME: + case StorageType::SESSION: + case StorageType::PGP: + case StorageType::ROOT: + if (empty($sEmail)) { + return ''; + } + if (\is_dir("{$this->sDataPath}/cfg")) { + \SnappyMail\Upgrade::FileStorage($this->sDataPath); + } + $aEmail = \explode('@', $sEmail ?: 'nobody@unknown.tld'); + $sDomain = \trim(1 < \count($aEmail) ? \array_pop($aEmail) : ''); + $sFilePath = $this->sDataPath + .'/'.\MailSo\Base\Utils::SecureFileName($sDomain ?: 'unknown.tld') + .'/'.\MailSo\Base\Utils::SecureFileName(\implode('@', $aEmail) ?: '.unknown') + .'/'.($sSubFolder ? \MailSo\Base\Utils::SecureFileName($sSubFolder).'/' : ''); + break; + default: + throw new \Exception("Invalid storage type {$iStorageType}"); + } } if ($bMkDir && !empty($sFilePath) && !\is_dir($sFilePath) && !\mkdir($sFilePath, 0700, true))