diff options
Diffstat (limited to 'lib/Controller/MessagesController.php')
-rwxr-xr-x | lib/Controller/MessagesController.php | 67 |
1 files changed, 64 insertions, 3 deletions
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; @@ -653,6 +652,68 @@ class MessagesController extends Controller { * @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 + * * @param int $accountId * @param string $folderId * @param int $id @@ -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 { |