Fix: match Apple Mail tag colors case-insensitively

This commit is contained in:
stumpylog committed 2026-10-30 08:44:56 -07:00
1 parent 9c4c9f2386
commit d091906315
2 files changed
+29 -2

No files matched your search

+2 -2
View File
@@ -169,9 +169,9 @@ class TagMailAction(BaseMailAction):
# The custom tag should look like "apple:<color>"
if "apple:" in parameter.lower():
_, self.color = parameter.split(":")
self.color = self.color.strip()
self.color = self.color.strip().lower()
if self.color.lower() not in APPLE_MAIL_TAG_COLORS:
if self.color not in APPLE_MAIL_TAG_COLORS:
raise MailError("Not a valid AppleMail tag color.")
self.keyword = None
+27
View File
@@ -23,6 +23,7 @@ from rest_framework.test import APITestCase
from documents.models import Correspondent
from documents.models import MatchingModel
from paperless_mail import tasks
from paperless_mail.mail import APPLE_MAIL_TAG_COLORS
from paperless_mail.mail import MailAccountHandler
from paperless_mail.mail import MailError
from paperless_mail.mail import TagMailAction
@@ -1873,6 +1874,32 @@ class TestErrorCallback:
assert processed_mails.get().owner == owner
class TestTagMailActionColor:
@pytest.mark.parametrize(
"parameter",
["apple:green", "apple:Green", "APPLE: GREEN "],
)
def test_color_case_is_ignored(self, parameter: str) -> None:
"""
GIVEN:
- An Apple Mail tag parameter in any letter case
WHEN:
- The action tags a message
THEN:
- The lowercase color's flag bits are set on the message
"""
action = TagMailAction(parameter, supports_gmail_labels=False)
mailbox = mock.Mock()
action.post_consume(mailbox, "1", parameter)
assert mailbox.flag.call_args_list[1] == mock.call(
"1",
APPLE_MAIL_TAG_COLORS["green"],
value=True,
)
class TestManagementCommand(TestCase):
@mock.patch(
"paperless_mail.management.commands.mail_fetcher.tasks.process_mail_accounts",