From ec111defbb29a4e829b89d667853eef8dcdafe3a Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Mon, 12 Feb 2024 17:58:24 +0100 Subject: [PATCH] Process all IMAP namespaces --- .../app/libraries/MailSo/Imap/ImapClient.php | 9 ++- .../libraries/MailSo/Imap/NamespaceResult.php | 73 +++++++------------ .../libraries/RainLoop/Actions/Folders.php | 2 +- 3 files changed, 35 insertions(+), 49 deletions(-) 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 62263d4c8..5323de692 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 @@ -384,10 +384,15 @@ class ImapClient extends \MailSo\Net\NetClient } } - public function GetPersonalNamespace() : string + public function GetPrivateNamespace() : string { $oNamespace = $this->GetNamespace(); - return $oNamespace ? $oNamespace->GetPersonalNamespace() : ''; + return $oNamespace ? $oNamespace->GetPrivateNamespace() : ''; + } + /** Deprecated */ + public function GetPersonalNamespace() : string + { + return $this->GetPrivateNamespace(); } /** diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/NamespaceResult.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/NamespaceResult.php index b5e92a000..73ad92e89 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/NamespaceResult.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/NamespaceResult.php @@ -17,59 +17,40 @@ namespace MailSo\Imap; */ class NamespaceResult { - private string $sPersonal = ''; + // prefix => separator + private array $namespaces = [ +// '' => '.', // default +// 'virtual.' => '.', +// 'shared.' => '.', +// etc. + ]; - private string $sPersonalDelimiter = ''; -/* - private string $sOtherUser = ''; - - private string $sOtherUserDelimiter = ''; - - private string $sShared = ''; - - private string $sSharedDelimiter = ''; -*/ function __construct(Response $oImapResponse) { - $space = static::getNamespace($oImapResponse, 2); - if ($space) { - $this->sPersonal = $space[0]; - $this->sPersonalDelimiter = $space[1]; + // * NAMESPACE (("" ".")("virtual." ".")) (("shared." ".")) NIL\r\n + $i = 1; + while (isset($oImapResponse->ResponseList[++$i])) { + $entries = $oImapResponse->ResponseList[$i]; + if ($entries) { + foreach ($entries as $entry) { + if (\is_array($entry) && 2 <= \count($entry)) { + $this->namespaces[$entry[0]] = $entry[1]; + } + } + } } -/* - $space = static::getNamespace($oImapResponse, 3); - if ($space) { - $this->sOtherUser = $space[0]; - $this->sOtherUserDelimiter = $space[1]; - } - - $space = static::getNamespace($oImapResponse, 4); - if ($space) { - $this->sShared = $space[0]; - $this->sSharedDelimiter = $space[1]; - } -*/ } - public function GetPersonalNamespace() : string + public function GetPrivateNamespace() : string { - return $this->sPersonal; - } - - private static function getNamespace(Response $oImapResponse, int $section) : ?array - { - if (isset($oImapResponse->ResponseList[$section][0]) - && \is_array($oImapResponse->ResponseList[$section][0]) - && 2 <= \count($oImapResponse->ResponseList[$section][0])) - { - $sName = $oImapResponse->ResponseList[$section][0][0]; - $sDelimiter = $oImapResponse->ResponseList[$section][0][1]; - $sName = 'INBOX'.$sDelimiter === \substr(\strtoupper($sName), 0, 6) - ? 'INBOX'.$sDelimiter.\substr($sName, 6) - : $sName; - return [$sName, $sDelimiter]; + $sName = ''; + if (isset($oImapResponse->ResponseList[2][0][0])) { + $sName = $oImapResponse->ResponseList[2][0][0]; + $sSeparator = $oImapResponse->ResponseList[2][0][1]; + if ('INBOX'.$sSeparator === \substr(\strtoupper($sName), 0, 6)) { + $sName = 'INBOX'.$sSeparator.\substr($sName, 6); + }; } - return null; + return $sName; } - } 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 09e9ba7cc..da5d941d1 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 @@ -77,7 +77,7 @@ trait Folders array( 'quotaUsage' => $aQuota ? $aQuota[0] * 1024 : null, 'quotaLimit' => $aQuota ? $aQuota[1] * 1024 : null, - 'namespace' => $this->ImapClient()->GetPersonalNamespace(), + 'namespace' => $this->ImapClient()->GetPrivateNamespace(), 'capabilities' => $aCapabilities ) );