Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-03-04 19:31:21 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-03-22 20:06:02 +0300
commit83a58623b116cd3f8c79f751a3df5963b3392692 (patch)
tree8f9660e75ea8748057e752c4f1573e3c618b5b85 /lib/Controller/MessagesController.php
parentf27fb61c0fe15ef6a278a40d7774cde4b7c748b8 (diff)
Add tagging to messages
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/Controller/MessagesController.php')
-rwxr-xr-xlib/Controller/MessagesController.php67
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 {