Paperless will check all emails only once and completely ignore messages
that do not match your filters. It will also only perform the rule action
-on e-mails that it has consumed documents from.
+on e-mails that it has consumed documents from. The filename attachment
+exclusion pattern can include multiple patterns separated by a comma.
The actions all ensure that the same mail is not consumed twice by
different means. These are as follows:
return processed_elements
+ def filename_exclusion_matches(
+ self,
+ filter_attachment_filename_exclude: Optional[str],
+ filename: str,
+ ) -> 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,
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.filename_exclusion_matches(
+ 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} "
exclude_pattern="f1*",
expected_matches=["f2.pdf", "f3.pdf", "file.PDf"],
),
+ FilterTestCase(
+ "PDF Files without f1 and f2",
+ include_pattern="*.pdf",
+ exclude_pattern="f1*,f2*",
+ expected_matches=["f3.pdf", "file.PDf"],
+ ),
+ FilterTestCase(
+ "PDF Files without f1 and f2 and f3",
+ include_pattern="*.pdf",
+ exclude_pattern="f1*,f2*,f3*",
+ expected_matches=["file.PDf"],
+ ),
FilterTestCase(
"All Files, no PNG",
include_pattern="*",