mu4e: clean up temp file handling

Use a temp file directory per mu4e session

Remove files when a buffer is closed, not after 30 secs
This commit is contained in:
Dirk-Jan C. Binnema
2026-05-26 22:06:02 +03:00
committed by Seth Ladygo
parent 008529696a
commit 8d1919cd36
4 changed files with 40 additions and 28 deletions

View File

@ -534,11 +534,16 @@ string after PROMPT."
(let ((timestr (read-string (mu4e-format "%s" prompt))))
(apply 'encode-time (parse-time-string timestr))))
(defvar mu4e--temp-dir nil "Directory for temporary files.
Created when mu4e starts, and removed when it closes.")
(defun mu4e-make-temp-file (ext)
"Create a self-destructing temporary file with extension EXT.
The file will self-destruct in a short while, enough to open it
in an external program."
(let ((tmpfile (make-temp-file "mu4e-" nil (concat "." ext))))
(let* ((temporary-file-directory (or mu4e--temp-dir temporary-file-directory))
(tmpfile (make-temp-file "mu4e-" nil (concat "." ext))))
(run-at-time "30 sec" nil
(lambda () (ignore-errors (delete-file tmpfile))))
tmpfile))