Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] v1.7.0 RC1 Bug: Mail Actions are mixed up
### Description

Mail Actions are completely mixed up, instead of marking Mails as read, they are being deleted.

https://github.com/paperless-ngx/paperless-ngx/blob/09d62d76b27cc769b289d3f419a1455785c08161/src/paperless_mail/models.py#L63-L67

### Expected behavior

Actions on Mails are performed as selected and described.

### Steps to reproduce

1. Add new Mail rule: http://localhost:8000/admin/paperless_mail/mailrule/add/ 
2. Set Action to mark as read
3. observe Mail being deleted

### Webserver logs

_No response_

### Screenshots

_No response_

### Paperless-ngx version

v1.7.0 RC1

### Host OS

Archlinux

### Installation method

Bare metal

### Browser

_No response_

### Configuration changes

_No response_

### Other

_No response_


Discussion:
Great catch, thank you

@stumpylog I think this is from https://github.com/paperless-ngx/paperless-ngx/commit/f358eda5c5045bd6859f17062e1afcb865d7426e but Im happy to make a PR later, looks like literally just lines need to be moved?
Whoops, I swear I tried to be careful.  Yes, the help text or whatever it is called needs to be moved around to match, then a migration created probably.
already working on a PR. Should this be against beta?
Thank you! Yes to `beta`

Resolving patch:
diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py
--- a/src/paperless_mail/mail.py
+++ b/src/paperless_mail/mail.py
@@ -62,13 +62,13 @@ def post_consume(self, M, message_uids, parameter):
 
 
 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
diff --git a/src/paperless_mail/migrations/0014_alter_mailrule_action.py b/src/paperless_mail/migrations/0014_alter_mailrule_action.py
new file mode 100644
--- /dev/null
+++ b/src/paperless_mail/migrations/0014_alter_mailrule_action.py
@@ -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",
+            ),
+        ),
+    ]
diff --git a/src/paperless_mail/models.py b/src/paperless_mail/models.py
--- a/src/paperless_mail/models.py
+++ b/src/paperless_mail/models.py
@@ -60,11 +60,11 @@ class AttachmentProcessing(models.IntegerChoices):
         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 CorrespondentSource(models.IntegerChoices):
 
     action = models.PositiveIntegerField(
         _("action"),
-        choices=AttachmentAction.choices,
-        default=AttachmentAction.MARK_READ,
+        choices=MailAction.choices,
+        default=MailAction.MARK_READ,
     )
 
     action_parameter = models.CharField(


Test patch:
diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py
--- a/src/paperless_mail/tests/test_mail.py
+++ b/src/paperless_mail/tests/test_mail.py
@@ -478,7 +478,7 @@ def test_handle_mail_account_mark_read(self):
         _ = 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 @@ def test_handle_mail_account_delete(self):
         _ = MailRule.objects.create(
             name="testrule",
             account=account,
-            action=MailRule.AttachmentAction.DELETE,
+            action=MailRule.MailAction.DELETE,
             filter_subject="Invoice",
         )
 
@@ -522,7 +522,7 @@ def test_handle_mail_account_flag(self):
         _ = MailRule.objects.create(
             name="testrule",
             account=account,
-            action=MailRule.AttachmentAction.FLAG,
+            action=MailRule.MailAction.FLAG,
             filter_subject="Invoice",
         )
 
@@ -545,7 +545,7 @@ def test_handle_mail_account_move(self):
         _ = 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 @@ def test_error_skip_account(self):
         _ = 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 @@ def test_error_skip_rule(self):
         _ = 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 @@ def test_error_skip_rule(self):
         _ = 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 @@ def get_correspondent_fake(message, rule):
         _ = MailRule.objects.create(
             name="testrule",
             account=account,
-            action=MailRule.AttachmentAction.MOVE,
+            action=MailRule.MailAction.MOVE,
             action_parameter="spam",
         )
 
@@ -676,7 +676,7 @@ def test_error_create_correspondent(self):
             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 @@ def test_filters(self):
         rule = MailRule.objects.create(
             name="testrule3",
             account=account,
-            action=MailRule.AttachmentAction.DELETE,
+            action=MailRule.MailAction.DELETE,
             filter_subject="Claim",
         )