Process all IMAP namespaces

This commit is contained in:
the-djmaze 2024-02-12 17:58:24 +01:00
parent ba55b328ea
commit ec111defbb
3 changed files with 35 additions and 49 deletions

View file

@ -384,10 +384,15 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
public function GetPersonalNamespace() : string public function GetPrivateNamespace() : string
{ {
$oNamespace = $this->GetNamespace(); $oNamespace = $this->GetNamespace();
return $oNamespace ? $oNamespace->GetPersonalNamespace() : ''; return $oNamespace ? $oNamespace->GetPrivateNamespace() : '';
}
/** Deprecated */
public function GetPersonalNamespace() : string
{
return $this->GetPrivateNamespace();
} }
/** /**

View file

@ -17,59 +17,40 @@ namespace MailSo\Imap;
*/ */
class NamespaceResult 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) function __construct(Response $oImapResponse)
{ {
$space = static::getNamespace($oImapResponse, 2); // * NAMESPACE (("" ".")("virtual." ".")) (("shared." ".")) NIL\r\n
if ($space) { $i = 1;
$this->sPersonal = $space[0]; while (isset($oImapResponse->ResponseList[++$i])) {
$this->sPersonalDelimiter = $space[1]; $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; $sName = '';
} if (isset($oImapResponse->ResponseList[2][0][0])) {
$sName = $oImapResponse->ResponseList[2][0][0];
private static function getNamespace(Response $oImapResponse, int $section) : ?array $sSeparator = $oImapResponse->ResponseList[2][0][1];
{ if ('INBOX'.$sSeparator === \substr(\strtoupper($sName), 0, 6)) {
if (isset($oImapResponse->ResponseList[$section][0]) $sName = 'INBOX'.$sSeparator.\substr($sName, 6);
&& \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];
} }
return null; return $sName;
} }
} }

View file

@ -77,7 +77,7 @@ trait Folders
array( array(
'quotaUsage' => $aQuota ? $aQuota[0] * 1024 : null, 'quotaUsage' => $aQuota ? $aQuota[0] * 1024 : null,
'quotaLimit' => $aQuota ? $aQuota[1] * 1024 : null, 'quotaLimit' => $aQuota ? $aQuota[1] * 1024 : null,
'namespace' => $this->ImapClient()->GetPersonalNamespace(), 'namespace' => $this->ImapClient()->GetPrivateNamespace(),
'capabilities' => $aCapabilities 'capabilities' => $aCapabilities
) )
); );