From a796a2bd4c692b295e55c778fa470a32c5e24753 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Mon, 6 Nov 2023 21:33:22 +0100 Subject: [PATCH] fixup! feat: delete tags Signed-off-by: hamza221 --- lib/Service/MailManager.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index e320f77d33..c45e0efc45 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -519,16 +519,16 @@ public function tagMessageWithClient(Horde_Imap_Client_Socket $client, Account $ $e ); } - if ($value) { - foreach ($messages as $message) { - $this->tagMapper->tagMessage($tag, $message->getMessageId(), $account->getUserId()); - } - } else { - foreach ($messages as $message) { - $this->tagMapper->untagMessage($tag, $message->getMessageId()); + if ($value) { + foreach ($messages as $message) { + $this->tagMapper->tagMessage($tag, $message->getMessageId(), $account->getUserId()); + } + } else { + foreach ($messages as $message) { + $this->tagMapper->untagMessage($tag, $message->getMessageId()); + } } } - } } /** * Tag (flag) a message on IMAP @@ -873,7 +873,7 @@ public function deleteTagForAccount(int $id, string $userId, Tag $tag, Account $ $messageTags = $this->messageTagsMapper->getMessagesByTag($id); $messages = array_merge(... array_map(function ($messageTag) use ($account) { return $this->getByMessageId($account, $messageTag->getImapMessageId()); - }, [...$messageTags])); + },array_values($messageTags))); } catch (DoesNotExistException $e) { throw new ClientException('Messages not found', 0, $e); } @@ -892,12 +892,15 @@ public function deleteTagForAccount(int $id, string $userId, Tag $tag, Account $ $groupedMessages[$mailboxId] = [$message]; } } - - foreach ($groupedMessages as $mailboxId => $messages) { - $mailbox = $this->getMailbox($userId, $mailboxId); - $this->tagMessageWithClient($client, $account, $mailbox, $messages, $tag, false); + try { + foreach ($groupedMessages as $mailboxId => $messages) { + $mailbox = $this->getMailbox($userId, $mailboxId); + $this->tagMessageWithClient($client, $account, $mailbox, $messages, $tag, false); + } + } finally { + $client->logout(); } - $client->logout(); + } public function moveThread(Account $srcAccount, Mailbox $srcMailbox, Account $dstAccount, Mailbox $dstMailbox, string $threadRootId): array { $mailAccount = $srcAccount->getMailAccount();