From 7d3a707c86968e08b712cc6f16c238eb454a625c Mon Sep 17 00:00:00 2001 From: hamza221 Date: Mon, 2 Oct 2023 14:12:04 +0200 Subject: [PATCH] fixup! feat: delete tags Signed-off-by: hamza221 --- lib/Contracts/IMailManager.php | 5 --- lib/Controller/TagsController.php | 3 -- lib/Service/MailManager.php | 33 ++++++++++++++++++- src/components/DeleteTagModal.vue | 9 ++++-- src/components/TagItem.vue | 6 +--- src/components/TagModal.vue | 53 +++++++++++++++++-------------- src/store/actions.js | 2 +- 7 files changed, 70 insertions(+), 41 deletions(-) diff --git a/lib/Contracts/IMailManager.php b/lib/Contracts/IMailManager.php index 43c55cd2ac..39749c9f0f 100644 --- a/lib/Contracts/IMailManager.php +++ b/lib/Contracts/IMailManager.php @@ -320,11 +320,6 @@ public function updateTag(int $id, string $displayName, string $color, string $u /** * Delete a mail tag * - * @param int $id - * @param string $userId - * @param Account $account - * - * @return Tag * @throws ClientException */ public function deleteTag(int $id, string $userId, Account $account): Tag; diff --git a/lib/Controller/TagsController.php b/lib/Controller/TagsController.php index 909f4a4379..810d2c9eae 100644 --- a/lib/Controller/TagsController.php +++ b/lib/Controller/TagsController.php @@ -91,9 +91,6 @@ public function update(int $id, string $displayName, string $color): JSONRespons /** * @NoAdminRequired * - * @param int $id - * - * @return JSONResponse * @throws ClientException */ #[TrapError] diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index 6c0e14ca51..3c676fd455 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -499,7 +499,30 @@ public function flagMessage(Account $account, string $mailbox, int $uid, string ) ); } + public function tagMessageWithClient(Horde_Imap_Client_Socket $client, Account $account, Mailbox $mailbox, Message $message, Tag $tag, bool $value):void { + if ($this->isPermflagsEnabled($client, $account, $mailbox->getName()) === true) { + try { + if ($value) { + // imap keywords and flags work the same way + $this->imapMessageMapper->addFlag($client, $mailbox, [$message->getUid()], $tag->getImapLabel()); + } else { + $this->imapMessageMapper->removeFlag($client, $mailbox, [$message->getUid()], $tag->getImapLabel()); + } + } catch (Horde_Imap_Client_Exception $e) { + throw new ServiceException( + "Could not set message keyword on IMAP: " . $e->getMessage(), + $e->getCode(), + $e + ); + } + if ($value) { + $this->tagMapper->tagMessage($tag, $message->getMessageId(), $account->getUserId()); + } else { + $this->tagMapper->untagMessage($tag, $message->getMessageId()); + } + } + } /** * Tag (flag) a message on IMAP * @@ -839,10 +862,18 @@ public function deleteTag(int $id, string $userId, Account $account): Tag { } catch (DoesNotExistException $e) { throw new ClientException('Tag not found', 0, $e); } + $client = $this->imapClientFactory->getClient($account); + + foreach ($messageTags as $messageTag) { + $this->messageTagsMapper->delete($messageTag); + } + foreach ($messages as $message) { $mailbox = $this->getMailbox($userId, $message->getMailboxId()); - $this->tagMessage($account, $mailbox->getName(), $message, $tag, false); + $this->tagMessageWithClient($client, $account, $mailbox, $message, $tag, false); } + + $client->logout(); return $this->tagMapper->delete($tag); } diff --git a/src/components/DeleteTagModal.vue b/src/components/DeleteTagModal.vue index a66694ea21..6beb697646 100644 --- a/src/components/DeleteTagModal.vue +++ b/src/components/DeleteTagModal.vue @@ -23,8 +23,10 @@ size="large" container="body" @close="onClose"> -