Merge pull request #765 from p-h-a-i-l/fix-mail-action-mixup

fix Mail actions mixup
This commit is contained in:
shamoon 2022-04-18 16:23:34 -07:00 committed by GitHub
commit 68e3612d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 21 deletions

View File

@ -62,13 +62,13 @@ class FlagMailAction(BaseMailAction):
def get_rule_action(rule):
if rule.action == MailRule.AttachmentAction.FLAG:
if rule.action == MailRule.MailAction.FLAG:
return FlagMailAction()
elif rule.action == MailRule.AttachmentAction.DELETE:
elif rule.action == MailRule.MailAction.DELETE:
return DeleteMailAction()
elif rule.action == MailRule.AttachmentAction.MOVE:
elif rule.action == MailRule.MailAction.MOVE:
return MoveMailAction()
elif rule.action == MailRule.AttachmentAction.MARK_READ:
elif rule.action == MailRule.MailAction.MARK_READ:
return MarkReadMailAction()
else:
raise NotImplementedError("Unknown action.") # pragma: nocover

View File

@ -0,0 +1,27 @@
# Generated by Django 4.0.4 on 2022-04-18 22:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("paperless_mail", "0013_merge_20220412_1051"),
]
operations = [
migrations.AlterField(
model_name="mailrule",
name="action",
field=models.PositiveIntegerField(
choices=[
(1, "Delete"),
(2, "Move to specified folder"),
(3, "Mark as read, don't process read mails"),
(4, "Flag the mail, don't process flagged mails"),
],
default=3,
verbose_name="action",
),
),
]

View File

@ -60,11 +60,11 @@ class MailRule(models.Model):
ATTACHMENTS_ONLY = 1, _("Only process attachments.")
EVERYTHING = 2, _("Process all files, including 'inline' " "attachments.")
class AttachmentAction(models.IntegerChoices):
DELETE = 1, _("Mark as read, don't process read mails")
MOVE = 2, _("Flag the mail, don't process flagged mails")
MARK_READ = 3, _("Move to specified folder")
FLAG = 4, _("Delete")
class MailAction(models.IntegerChoices):
DELETE = 1, _("Delete")
MOVE = 2, _("Move to specified folder")
MARK_READ = 3, _("Mark as read, don't process read mails")
FLAG = 4, _("Flag the mail, don't process flagged mails")
class TitleSource(models.IntegerChoices):
FROM_SUBJECT = 1, _("Use subject as title")
@ -146,8 +146,8 @@ class MailRule(models.Model):
action = models.PositiveIntegerField(
_("action"),
choices=AttachmentAction.choices,
default=AttachmentAction.MARK_READ,
choices=MailAction.choices,
default=MailAction.MARK_READ,
)
action_parameter = models.CharField(

View File

@ -478,7 +478,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.MARK_READ,
action=MailRule.MailAction.MARK_READ,
)
self.assertEqual(len(self.bogus_mailbox.messages), 3)
@ -501,7 +501,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.DELETE,
action=MailRule.MailAction.DELETE,
filter_subject="Invoice",
)
@ -522,7 +522,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.FLAG,
action=MailRule.MailAction.FLAG,
filter_subject="Invoice",
)
@ -545,7 +545,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.MOVE,
action=MailRule.MailAction.MOVE,
action_parameter="spam",
filter_subject="Claim",
)
@ -591,7 +591,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.MOVE,
action=MailRule.MailAction.MOVE,
action_parameter="spam",
filter_subject="Claim",
)
@ -612,7 +612,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.MOVE,
action=MailRule.MailAction.MOVE,
action_parameter="spam",
filter_subject="Claim",
order=1,
@ -621,7 +621,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule2",
account=account,
action=MailRule.AttachmentAction.MOVE,
action=MailRule.MailAction.MOVE,
action_parameter="spam",
filter_subject="Claim",
order=2,
@ -651,7 +651,7 @@ class TestMail(DirectoriesMixin, TestCase):
_ = MailRule.objects.create(
name="testrule",
account=account,
action=MailRule.AttachmentAction.MOVE,
action=MailRule.MailAction.MOVE,
action_parameter="spam",
)
@ -676,7 +676,7 @@ class TestMail(DirectoriesMixin, TestCase):
name="testrule",
filter_from="amazon@amazon.de",
account=account,
action=MailRule.AttachmentAction.MOVE,
action=MailRule.MailAction.MOVE,
action_parameter="spam",
assign_correspondent_from=MailRule.CorrespondentSource.FROM_EMAIL,
)
@ -713,7 +713,7 @@ class TestMail(DirectoriesMixin, TestCase):
rule = MailRule.objects.create(
name="testrule3",
account=account,
action=MailRule.AttachmentAction.DELETE,
action=MailRule.MailAction.DELETE,
filter_subject="Claim",
)