Support include multiple

This commit is contained in:
shamoon 2024-09-05 13:59:33 -07:00
parent 9f603c3b74
commit 61f65b6f87
5 changed files with 34 additions and 12 deletions

View File

@ -137,7 +137,7 @@ These rules perform the following:
Paperless will check all emails only once and completely ignore messages 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 that do not match your filters. It will also only perform the rule action
on e-mails that it has consumed documents from. The filename attachment on e-mails that it has consumed documents from. The filename attachment
exclusion pattern can include multiple patterns separated by a comma. patterns can include wildcards and multiple patterns separated by a comma.
The actions all ensure that the same mail is not consumed twice by The actions all ensure that the same mail is not consumed twice by
different means. These are as follows: different means. These are as follows:

View File

@ -3752,22 +3752,19 @@
<context context-type="linenumber">43</context> <context context-type="linenumber">43</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="8772833173536287413" datatype="html"> <trans-unit id="7233407036155150477" datatype="html">
<source>Optional. Wildcards e.g. *.pdf or *invoice* allowed. Case insensitive.</source> <source>Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context> <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context>
<context context-type="linenumber">43</context> <context context-type="linenumber">43</context>
</context-group> </context-group>
</trans-unit>
<trans-unit id="1546332577833742677" datatype="html">
<source>Exclude files matching</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context> <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context>
<context context-type="linenumber">44</context> <context context-type="linenumber">44</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="7233407036155150477" datatype="html"> <trans-unit id="1546332577833742677" datatype="html">
<source>Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive.</source> <source>Exclude files matching</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context> <context context-type="sourcefile">src/app/components/common/edit-dialog/mail-rule-edit-dialog/mail-rule-edit-dialog.component.html</context>
<context context-type="linenumber">44</context> <context context-type="linenumber">44</context>

View File

@ -40,7 +40,7 @@
<pngx-input-select [horizontal]="true" i18n-title title="Attachment type" [items]="attachmentTypeOptions" formControlName="attachment_type"></pngx-input-select> <pngx-input-select [horizontal]="true" i18n-title title="Attachment type" [items]="attachmentTypeOptions" formControlName="attachment_type"></pngx-input-select>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<pngx-input-text [horizontal]="true" i18n-title title="Include only files matching" formControlName="filter_attachment_filename_include" i18n-hint hint="Optional. Wildcards e.g. *.pdf or *invoice* allowed. Case insensitive." [error]="error?.filter_attachment_filename_include"></pngx-input-text> <pngx-input-text [horizontal]="true" i18n-title title="Include only files matching" formControlName="filter_attachment_filename_include" i18n-hint hint="Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive." [error]="error?.filter_attachment_filename_include"></pngx-input-text>
<pngx-input-text [horizontal]="true" i18n-title title="Exclude files matching" formControlName="filter_attachment_filename_exclude" i18n-hint hint="Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive." [error]="error?.filter_attachment_filename_exclude"></pngx-input-text> <pngx-input-text [horizontal]="true" i18n-title title="Exclude files matching" formControlName="filter_attachment_filename_exclude" i18n-hint hint="Optional. Wildcards e.g. *.pdf or *invoice* allowed. Can be comma-separated list. Case insensitive." [error]="error?.filter_attachment_filename_exclude"></pngx-input-text>
</div> </div>
</div> </div>

View File

@ -686,6 +686,25 @@ class MailAccountHandler(LoggingMixin):
return processed_elements return processed_elements
def filename_inclusion_matches(
self,
filter_attachment_filename_include: Optional[str],
filename: str,
) -> bool:
if filter_attachment_filename_include:
filter_attachment_filename_inclusions = (
filter_attachment_filename_include.split(",")
)
# Force the filename and pattern to the lowercase
# as this is system dependent otherwise
filename = filename.lower()
for filename_include in filter_attachment_filename_inclusions:
if filename_include and fnmatch(filename, filename_include.lower()):
return True
return False
return True
def filename_exclusion_matches( def filename_exclusion_matches(
self, self,
filter_attachment_filename_exclude: Optional[str], filter_attachment_filename_exclude: Optional[str],
@ -728,9 +747,9 @@ class MailAccountHandler(LoggingMixin):
) )
continue continue
if rule.filter_attachment_filename_include and not fnmatch( if not self.filename_inclusion_matches(
att.filename.lower(), rule.filter_attachment_filename_include,
rule.filter_attachment_filename_include.lower(), att.filename,
): ):
# Force the filename and pattern to the lowercase # Force the filename and pattern to the lowercase
# as this is system dependent otherwise # as this is system dependent otherwise

View File

@ -658,6 +658,12 @@ class TestMail(
exclude_pattern=None, exclude_pattern=None,
expected_matches=["f2.png"], expected_matches=["f2.png"],
), ),
FilterTestCase(
"PDF Files with f2 and f3",
include_pattern="f2.pdf,f3*",
exclude_pattern=None,
expected_matches=["f2.pdf", "f3.pdf"],
),
FilterTestCase( FilterTestCase(
"PDF Files without f1", "PDF Files without f1",
include_pattern="*.pdf", include_pattern="*.pdf",