2023-02-20 11:46:46 +01:00

25 lines
708 B
Python

import logging
from celery import shared_task
from paperless_mail.mail import MailAccountHandler
from paperless_mail.mail import MailError
from paperless_mail.models import MailAccount
logger = logging.getLogger("paperless.mail.tasks")
@shared_task
def process_mail_accounts():
total_new_documents = 0
for account in MailAccount.objects.all():
try:
total_new_documents += MailAccountHandler().handle_mail_account(account)
except MailError:
logger.exception(f"Error while processing mail account {account}")
if total_new_documents > 0:
return f"Added {total_new_documents} document(s)."
else:
return "No new documents were added."