From 7f80f4608cdb5526834dcea95e53bc0016d799c8 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:07:12 -0800 Subject: [PATCH] Fix: close the temp file descriptor when saving mail as eml --- src/paperless_mail/mail.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/paperless_mail/mail.py b/src/paperless_mail/mail.py index cdc0fa34d..37debb779 100644 --- a/src/paperless_mail/mail.py +++ b/src/paperless_mail/mail.py @@ -2,6 +2,7 @@ import datetime import imaplib import itertools import logging +import os import socket import ssl import tempfile @@ -1135,12 +1136,12 @@ class MailAccountHandler(LoggingMixin): doc_type, ): settings.SCRATCH_DIR.mkdir(parents=True, exist_ok=True) - _, temp_filename = tempfile.mkstemp( + fd, temp_filename = tempfile.mkstemp( prefix="paperless-mail-", dir=settings.SCRATCH_DIR, suffix=".eml", ) - with Path(temp_filename).open("wb") as f: + with os.fdopen(fd, "wb") as f: # Move "From"-header to beginning of file # TODO: This ugly workaround is needed because the parser is # chosen only by the mime_type detected via magic