mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-11-10 17:13:38 +08:00
Process all IMAP namespaces
This commit is contained in:
parent
ba55b328ea
commit
ec111defbb
3 changed files with 35 additions and 49 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue