diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-08-31 16:42:59 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-09-01 11:23:44 +0300 |
commit | 9d1365ef776f816eb2da83fd34d2e9dd36d29c19 (patch) | |
tree | 012e89eee5be17854e903e7dcd51fd6d8e3c1f70 /lib/IMAP | |
parent | df94a5ee2109c42aa135d3e7326fb081610b6f7f (diff) |
Detect and persist the personal namespace
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/IMAP')
-rw-r--r-- | lib/IMAP/MailboxSync.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/IMAP/MailboxSync.php b/lib/IMAP/MailboxSync.php index ad4093473..baeadae88 100644 --- a/lib/IMAP/MailboxSync.php +++ b/lib/IMAP/MailboxSync.php @@ -25,7 +25,10 @@ declare(strict_types=1); namespace OCA\Mail\IMAP; +use Horde_Imap_Client; +use Horde_Imap_Client_Data_Namespace; use Horde_Imap_Client_Exception; +use Horde_Imap_Client_Namespace_List; use OCA\Mail\Exception\ServiceException; use function in_array; use function json_encode; @@ -81,6 +84,16 @@ class MailboxSync { } $client = $this->imapClientFactory->getClient($account); + try { + $namespaces = $client->getNamespaces([], [ + 'ob_return' => true, + ]); + $account->getMailAccount()->setPersonalNamespace( + $this->getPersonalNamespace($namespaces) + ); + } catch (Horde_Imap_Client_Exception $e) { + $this->logger->debug('Getting namespaces for account ' . $account->getId() . ' failed: ' . $e->getMessage()); + } try { $folders = $this->folderMapper->getFolders($account, $client); @@ -125,6 +138,16 @@ class MailboxSync { $this->mailAccountMapper->update($account->getMailAccount()); } + private function getPersonalNamespace(Horde_Imap_Client_Namespace_List $namespaces): ?string { + foreach ($namespaces as $namespace) { + /** @var Horde_Imap_Client_Data_Namespace $namespace */ + if ($namespace->type === Horde_Imap_Client::NS_PERSONAL) { + return $namespace->name; + } + } + return null; + } + private function updateMailboxFromFolder(Folder $folder, Mailbox $mailbox): void { $mailbox->setDelimiter($folder->getDelimiter()); $mailbox->setAttributes(json_encode($folder->getAttributes())); |