mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Fix: skip accounts without enabled rules
This commit is contained in:
parent
54293bedb1
commit
e49ed58f1a
@ -5,6 +5,7 @@ from celery import shared_task
|
||||
from paperless_mail.mail import MailAccountHandler
|
||||
from paperless_mail.mail import MailError
|
||||
from paperless_mail.models import MailAccount
|
||||
from paperless_mail.models import MailRule
|
||||
|
||||
logger = logging.getLogger("paperless.mail.tasks")
|
||||
|
||||
@ -13,6 +14,9 @@ logger = logging.getLogger("paperless.mail.tasks")
|
||||
def process_mail_accounts():
|
||||
total_new_documents = 0
|
||||
for account in MailAccount.objects.all():
|
||||
if not MailRule.objects.filter(account=account, enabled=True).exists():
|
||||
logger.info(f"No rules enabled for account {account}. Skipping.")
|
||||
continue
|
||||
try:
|
||||
total_new_documents += MailAccountHandler().handle_mail_account(account)
|
||||
except MailError:
|
||||
|
@ -1543,6 +1543,14 @@ class TestTasks(TestCase):
|
||||
username="A",
|
||||
password="A",
|
||||
)
|
||||
MailRule.objects.create(
|
||||
name="A",
|
||||
account=MailAccount.objects.get(name="A"),
|
||||
)
|
||||
MailRule.objects.create(
|
||||
name="B",
|
||||
account=MailAccount.objects.get(name="B"),
|
||||
)
|
||||
|
||||
result = tasks.process_mail_accounts()
|
||||
|
||||
@ -1552,3 +1560,33 @@ class TestTasks(TestCase):
|
||||
m.side_effect = lambda account: 0
|
||||
result = tasks.process_mail_accounts()
|
||||
self.assertIn("No new", result)
|
||||
|
||||
@mock.patch("paperless_mail.tasks.MailAccountHandler.handle_mail_account")
|
||||
def test_accounts_no_enabled_rules(self, m):
|
||||
m.side_effect = lambda account: 6
|
||||
|
||||
MailAccount.objects.create(
|
||||
name="A",
|
||||
imap_server="A",
|
||||
username="A",
|
||||
password="A",
|
||||
)
|
||||
MailAccount.objects.create(
|
||||
name="B",
|
||||
imap_server="A",
|
||||
username="A",
|
||||
password="A",
|
||||
)
|
||||
MailRule.objects.create(
|
||||
name="A",
|
||||
account=MailAccount.objects.get(name="A"),
|
||||
enabled=False,
|
||||
)
|
||||
MailRule.objects.create(
|
||||
name="B",
|
||||
account=MailAccount.objects.get(name="B"),
|
||||
enabled=False,
|
||||
)
|
||||
|
||||
tasks.process_mail_accounts()
|
||||
self.assertEqual(m.call_count, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user