mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
added some result processing
This commit is contained in:
parent
8c3ff4fa26
commit
292a76137d
@ -79,6 +79,8 @@ def handle_mail_account(account):
|
||||
else:
|
||||
raise ValueError("Unknown IMAP security")
|
||||
|
||||
total_processed_files = 0
|
||||
|
||||
with mailbox as M:
|
||||
|
||||
try:
|
||||
@ -121,14 +123,15 @@ def handle_mail_account(account):
|
||||
|
||||
for message in messages:
|
||||
try:
|
||||
result = handle_message(message, rule)
|
||||
processed_files = handle_message(message, rule)
|
||||
except Exception:
|
||||
raise MailError(
|
||||
f"Rule {rule.name}: Error while processing mail "
|
||||
f"{message.uid} of account {account.name}")
|
||||
if result:
|
||||
if processed_files > 0:
|
||||
post_consume_messages.append(message.uid)
|
||||
|
||||
total_processed_files += processed_files
|
||||
try:
|
||||
action.post_consume(
|
||||
M,
|
||||
@ -140,10 +143,12 @@ def handle_mail_account(account):
|
||||
f"Rule {rule.name}: Error while processing post-consume "
|
||||
f"actions for account {account.name}")
|
||||
|
||||
return total_processed_files
|
||||
|
||||
|
||||
def handle_message(message, rule):
|
||||
if not message.attachments:
|
||||
return False
|
||||
return 0
|
||||
|
||||
if rule.assign_correspondent_from == MailRule.CORRESPONDENT_FROM_NOTHING:
|
||||
correspondent = None
|
||||
@ -200,9 +205,10 @@ def handle_message(message, rule):
|
||||
force_title=title,
|
||||
force_correspondent_id=correspondent.id if correspondent else None,
|
||||
force_document_type_id=doc_type.id if doc_type else None,
|
||||
force_tag_ids=[tag.id] if tag else None
|
||||
force_tag_ids=[tag.id] if tag else None,
|
||||
task_name=f"Mail: {att.filename}"
|
||||
)
|
||||
|
||||
processed_attachments += 1
|
||||
|
||||
return processed_attachments > 0
|
||||
return processed_attachments
|
||||
|
@ -5,8 +5,14 @@ from paperless_mail.models import MailAccount
|
||||
|
||||
|
||||
def process_mail_accounts():
|
||||
total_new_documents = 0
|
||||
for account in MailAccount.objects.all():
|
||||
mail.handle_mail_account(account)
|
||||
total_new_documents += mail.handle_mail_account(account)
|
||||
|
||||
if total_new_documents > 0:
|
||||
return f"Added {total_new_documents} document(s)."
|
||||
else:
|
||||
return "No new documents were added."
|
||||
|
||||
|
||||
def process_mail_account(name):
|
||||
|
Loading…
x
Reference in New Issue
Block a user