From 83a58623b116cd3f8c79f751a3df5963b3392692 Mon Sep 17 00:00:00 2001 From: Anna Larch Date: Thu, 4 Mar 2021 17:31:21 +0100 Subject: Add tagging to messages Signed-off-by: Anna Larch --- lib/Controller/MessagesController.php | 67 +++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'lib/Controller/MessagesController.php') diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index 6361d415e..0cfa3a8eb 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -41,7 +41,6 @@ use OCA\Mail\Exception\ClientException; use OCA\Mail\Exception\ServiceException; use OCA\Mail\Http\AttachmentDownloadResponse; use OCA\Mail\Http\HtmlResponse; -use OCA\Mail\Model\IMAPMessage; use OCA\Mail\Service\AccountService; use OCA\Mail\Service\ItineraryService; use OCP\AppFramework\Controller; @@ -649,6 +648,68 @@ class MessagesController extends Controller { return new JSONResponse(); } + /** + * @NoAdminRequired + * @TrapError + * + * @param int $id + * @param string $imapLabel + * + * @return JSONResponse + * + * @throws ClientException + * @throws ServiceException + */ + public function setTag(int $id, string $imapLabel): JSONResponse { + try { + $message = $this->mailManager->getMessage($this->currentUserId, $id); + $mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId()); + $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); + } catch (DoesNotExistException $e) { + return new JSONResponse([], Http::STATUS_FORBIDDEN); + } + + try { + $tag = $this->mailManager->getTagByImapLabel($imapLabel, $this->currentUserId); + } catch (DoesNotExistException $e) { + return new JSONResponse([], Http::STATUS_FORBIDDEN); + } + + $this->mailManager->tagMessage($account, $mailbox->getName(), $message, $tag, true); + return new JSONResponse(); + } + + /** + * @NoAdminRequired + * @TrapError + * + * @param int $id + * @param string $imapLabel + * + * @return JSONResponse + * + * @throws ClientException + * @throws ServiceException + */ + public function removeTag(int $id, string $imapLabel): JSONResponse { + try { + $message = $this->mailManager->getMessage($this->currentUserId, $id); + $mailbox = $this->mailManager->getMailbox($this->currentUserId, $message->getMailboxId()); + $account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId()); + } catch (DoesNotExistException $e) { + return new JSONResponse([], Http::STATUS_FORBIDDEN); + } + + try { + $tag = $this->mailManager->getTagByImapLabel($imapLabel, $this->currentUserId); + } catch (DoesNotExistException $e) { + return new JSONResponse([], Http::STATUS_FORBIDDEN); + } + + $this->mailManager->tagMessage($account, $mailbox->getName(), $message, $tag, false); + return new JSONResponse(); + } + /** * @NoAdminRequired * @TrapError @@ -705,10 +766,10 @@ class MessagesController extends Controller { } /** - * @param array $attachment - * * Determines if the content of this attachment is an image * + * @param array $attachment + * * @return boolean */ private function attachmentIsImage(array $attachment): bool { -- cgit v1.2.3