diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index fffa07ac9..d0cc64f1c 100644 --- a/src/paperless_mail/mail.py +++ b/src/paperless_mail/mail.py @@ -101,13 +101,15 @@ class TagMailAction(BaseMailAction): raise MailError("Not a valid AppleMail tag color.") except Exception as e: raise MailError( - """Could not parse the parameters. - Make sure they look like this: apple:""", + """Could not parse parameters. + Make sure they look like this: apple: and + only use allowed colors.""", ) from e self.keyword = None else: self.keyword = parameter + self.color = None def get_criteria(self): diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py index 3a17d7ab3..309e846d4 100644 --- a/src/paperless_mail/tests/test_mail.py +++ b/src/paperless_mail/tests/test_mail.py @@ -24,6 +24,7 @@ from imap_tools import NOT from paperless_mail import tasks from paperless_mail.mail import MailAccountHandler from paperless_mail.mail import MailError +from paperless_mail.mail import TagMailAction from paperless_mail.models import MailAccount from paperless_mail.models import MailRule @@ -674,6 +675,44 @@ class TestMail(DirectoriesMixin, TestCase): self.assertEqual(len(self.bogus_mailbox.fetch(criteria, False)), 0) self.assertEqual(len(self.bogus_mailbox.messages), 3) + def test_tag_mail_action_applemail_wrong_input(self): + + self.assertRaises( + MailError, + TagMailAction, + "apple:black", + ) + self.assertRaises( + MailError, + TagMailAction, + "applegreen", + ) + + def test_handle_mail_account_tag_applemail(self): + # all mails will be FLAGGED afterwards + + account = MailAccount.objects.create( + name="test", + imap_server="", + username="admin", + password="secret", + ) + + _ = MailRule.objects.create( + name="testrule", + account=account, + action=MailRule.MailAction.TAG, + action_parameter="apple:green", + ) + + self.assertEqual(len(self.bogus_mailbox.messages), 3) + self.assertEqual(self.async_task.call_count, 0) + self.assertEqual(len(self.bogus_mailbox.fetch("UNFLAGGED", False)), 2) + self.mail_account_handler.handle_mail_account(account) + self.assertEqual(self.async_task.call_count, 2) + self.assertEqual(len(self.bogus_mailbox.fetch("UNFLAGGED", False)), 0) + self.assertEqual(len(self.bogus_mailbox.messages), 3) + def test_error_login(self): account = MailAccount.objects.create( name="test",