From cc68ee44d1eace17859c39e8dd1eb36929b47898 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Wed, 24 Jan 2024 09:18:31 +0100 Subject: [PATCH] Split filter_attachment_filename_exclude by comma --- src/paperless_mail/mail.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index 76e5ed2e7..6c8ba4a0a 100644 --- a/src/paperless_mail/mail.py +++ b/src/paperless_mail/mail.py @@ -646,6 +646,18 @@ class MailAccountHandler(LoggingMixin): return processed_elements + def _matchFilenameExlusion(filter_attachment_filename_exclude, filename) -> bool: + if filter_attachment_filename_exclude: + filter_attachment_filename_exclusions = filter_attachment_filename_exclude.split(",") + + # Force the filename and pattern to the lowercase + # as this is system dependent otherwise + filename = filename.lower() + for filename_exclude in filter_attachment_filename_exclusions: + if filename_exclude and fnmatch(filename, filename_exclude.lower()): + return True + return False + def _process_attachments( self, message: MailMessage, @@ -682,12 +694,9 @@ class MailAccountHandler(LoggingMixin): f"does not match pattern {rule.filter_attachment_filename_include}", ) continue - elif rule.filter_attachment_filename_exclude and fnmatch( - att.filename.lower(), - rule.filter_attachment_filename_exclude.lower(), + elif self._matchFilenameExlusion( + rule.filter_attachment_filename_exclude, att.filename ): - # Force the filename and pattern to the lowercase - # as this is system dependent otherwise self.log.debug( f"Rule {rule}: " f"Skipping attachment {att.filename} "