diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-04-04 09:39:01 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-04-04 12:07:15 +0300 |
commit | a23e8238dffd46115c04fd43d835f6db32510023 (patch) | |
tree | 567f985ebdf2b7185a61f93feb349b7ee29ca540 /lib/Listener | |
parent | 9640827c2b7239abded0dcd228a0c866bc70aa98 (diff) |
Handle IMAP disconnects more explicitly
This changes the IMAP client usages to be used as a *resource* that is
freed after finished use. Previously we just memoized connections to the
same account to lower the number of connections, but that has still
shown to cause too many open connections during tests but possibly also
in production.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Listener')
-rw-r--r-- | lib/Listener/DeleteDraftListener.php | 2 | ||||
-rw-r--r-- | lib/Listener/FlagRepliedMessageListener.php | 4 | ||||
-rw-r--r-- | lib/Listener/SaveSentMessageListener.php | 5 |
3 files changed, 9 insertions, 2 deletions
diff --git a/lib/Listener/DeleteDraftListener.php b/lib/Listener/DeleteDraftListener.php index 8d89d229b..61ffe386b 100644 --- a/lib/Listener/DeleteDraftListener.php +++ b/lib/Listener/DeleteDraftListener.php @@ -90,6 +90,8 @@ class DeleteDraftListener implements IEventListener { } catch (DoesNotExistException $e) { $this->logger->warning("Account has no draft mailbox set, can't delete the draft"); return; + } finally { + $client->logout(); } try { diff --git a/lib/Listener/FlagRepliedMessageListener.php b/lib/Listener/FlagRepliedMessageListener.php index 977b95faf..367ec1f7e 100644 --- a/lib/Listener/FlagRepliedMessageListener.php +++ b/lib/Listener/FlagRepliedMessageListener.php @@ -78,8 +78,8 @@ class FlagRepliedMessageListener implements IEventListener { return; } + $client = $this->imapClientFactory->getClient($event->getAccount()); try { - $client = $this->imapClientFactory->getClient($event->getAccount()); $this->messageMapper->addFlag( $client, $mailbox, @@ -90,6 +90,8 @@ class FlagRepliedMessageListener implements IEventListener { $this->logger->warning('Could not flag replied message: ' . $e, [ 'exception' => $e, ]); + } finally { + $client->logout(); } } } diff --git a/lib/Listener/SaveSentMessageListener.php b/lib/Listener/SaveSentMessageListener.php index 37eedd93c..307cc939a 100644 --- a/lib/Listener/SaveSentMessageListener.php +++ b/lib/Listener/SaveSentMessageListener.php @@ -83,14 +83,17 @@ class SaveSentMessageListener implements IEventListener { return; } + $client = $this->imapClientFactory->getClient($event->getAccount()); try { $this->messageMapper->save( - $this->imapClientFactory->getClient($event->getAccount()), + $client, $sentMailbox, $event->getMail() ); } catch (Horde_Imap_Client_Exception $e) { throw new ServiceException('Could not save sent message on IMAP', 0, $e); + } finally { + $client->logout(); } } } |