Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/IMAP/MailboxSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ public function __construct(MailboxMapper $mailboxMapper,
*/
public function sync(Account $account,
LoggerInterface $logger,
bool $force = false): void {
bool $force = false,
?Horde_Imap_Client_Socket $client = null): void {
if (!$force && $account->getMailAccount()->getLastMailboxSync() >= ($this->timeFactory->getTime() - 7200)) {
$logger->debug('account is up to date, skipping mailbox sync');
return;
}

$client = $this->imapClientFactory->getClient($account);
if ($client === null) {
$client = $this->imapClientFactory->getClient($account);
$ownClient = true;
} else {
$ownClient = false;
}
try {
try {
$namespaces = $client->getNamespaces([], [
Expand Down Expand Up @@ -131,7 +137,9 @@ public function sync(Account $account,
new MailboxesSynchronizedEvent($account)
);
} finally {
$client->logout();
if ($ownClient) {
$client->logout();
}
}
}

Expand Down
25 changes: 12 additions & 13 deletions lib/Service/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public function createMailbox(Account $account, string $name, array $specialUse
try {
$folder = $this->folderMapper->createFolder($client, $name, $specialUse);
$this->folderMapper->fetchFolderAcls([$folder], $client);
$this->folderMapper->detectFolderSpecialUse([$folder]);
$this->mailboxSync->sync($account, $this->logger, true, $client);
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
'Could not get mailbox status: ' . $e->getMessage(),
Expand All @@ -156,9 +158,6 @@ public function createMailbox(Account $account, string $name, array $specialUse
} finally {
$client->logout();
}
$this->folderMapper->detectFolderSpecialUse([$folder]);

$this->mailboxSync->sync($account, $this->logger, true);

return $this->mailboxMapper->find($account, $name);
}
Expand Down Expand Up @@ -413,6 +412,11 @@ public function updateSubscription(Account $account, Mailbox $mailbox, bool $sub
$client = $this->imapClientFactory->getClient($account);
try {
$client->subscribeMailbox($mailbox->getName(), $subscribed);

/**
* 2. Pull changes into the mailbox database cache
*/
$this->mailboxSync->sync($account, $this->logger, true, $client);
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
'Could not set subscription status for mailbox ' . $mailbox->getId() . ' on IMAP: ' . $e->getMessage(),
Expand All @@ -423,11 +427,6 @@ public function updateSubscription(Account $account, Mailbox $mailbox, bool $sub
$client->logout();
}

/**
* 2. Pull changes into the mailbox database cache
*/
$this->mailboxSync->sync($account, $this->logger, true);

/**
* 3. Return the updated object
*/
Expand Down Expand Up @@ -615,15 +614,15 @@ public function renameMailbox(Account $account, Mailbox $mailbox, string $name):
$mailbox->getName(),
$name
);

/**
* 2. Get the IMAP changes into our database cache
*/
$this->mailboxSync->sync($account, $this->logger, true, $client);
} finally {
$client->logout();
}

/**
* 2. Get the IMAP changes into our database cache
*/
$this->mailboxSync->sync($account, $this->logger, true);

/**
* 3. Return the cached object with the new ID
*/
Expand Down
Loading