mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fixes the case where a mail attachment has no filename to use (#5117)
This commit is contained in:
parent
5576a073a5
commit
ffad42615f
@ -703,6 +703,12 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
mime_type = magic.from_buffer(att.payload, mime=True)
|
mime_type = magic.from_buffer(att.payload, mime=True)
|
||||||
|
|
||||||
if is_mime_type_supported(mime_type):
|
if is_mime_type_supported(mime_type):
|
||||||
|
self.log.info(
|
||||||
|
f"Rule {rule}: "
|
||||||
|
f"Consuming attachment {att.filename} from mail "
|
||||||
|
f"{message.subject} from {message.from_}",
|
||||||
|
)
|
||||||
|
|
||||||
os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
|
os.makedirs(settings.SCRATCH_DIR, exist_ok=True)
|
||||||
|
|
||||||
temp_dir = Path(
|
temp_dir = Path(
|
||||||
@ -711,14 +717,15 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
dir=settings.SCRATCH_DIR,
|
dir=settings.SCRATCH_DIR,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
temp_filename = temp_dir / pathvalidate.sanitize_filename(att.filename)
|
|
||||||
temp_filename.write_bytes(att.payload)
|
|
||||||
|
|
||||||
self.log.info(
|
attachment_name = pathvalidate.sanitize_filename(att.filename)
|
||||||
f"Rule {rule}: "
|
if attachment_name:
|
||||||
f"Consuming attachment {att.filename} from mail "
|
temp_filename = temp_dir / attachment_name
|
||||||
f"{message.subject} from {message.from_}",
|
else: # pragma: no cover
|
||||||
)
|
# Some cases may have no name (generally inline)
|
||||||
|
temp_filename = temp_dir / "no-name-attachment"
|
||||||
|
|
||||||
|
temp_filename.write_bytes(att.payload)
|
||||||
|
|
||||||
input_doc = ConsumableDocument(
|
input_doc = ConsumableDocument(
|
||||||
source=DocumentSource.MailFetch,
|
source=DocumentSource.MailFetch,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user