aboutsummaryrefslogtreecommitdiff
path: root/modules/mu4e-attachments.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-13 23:19:36 -0500
committerCraig Jennings <c@cjennings.net>2026-07-13 23:19:36 -0500
commit00f1246fa32fa65571a141b1b685b95994fbfbc9 (patch)
treec86af3372d6e4c019aeaa782b44d011a4f8e10b5 /modules/mu4e-attachments.el
parent9927367c02c4e8723af27efb1dedbb8f89149c85 (diff)
downloaddotemacs-00f1246fa32fa65571a141b1b685b95994fbfbc9.tar.gz
dotemacs-00f1246fa32fa65571a141b1b685b95994fbfbc9.zip
fix(mu4e-attachments): reject stale MIME handles at save time
The selection buffer captures MIME handles when it opens, but viewing another message kills the buffer a handle points at. Saving through such a handle died deep in mm-decode, or could write another message's bytes. The save path now signals a user-error naming the attachment when its handle's buffer is dead, and it checks before any mu4e MIME support loads, in the same spot as the existing no-handle check. I added tests for the stale-handle error, the healthy live-handle save, and the mid-batch failure behavior (the error propagates and files already written stay).
Diffstat (limited to 'modules/mu4e-attachments.el')
-rw-r--r--modules/mu4e-attachments.el12
1 files changed, 11 insertions, 1 deletions
diff --git a/modules/mu4e-attachments.el b/modules/mu4e-attachments.el
index 6c2be6fb..56b96b87 100644
--- a/modules/mu4e-attachments.el
+++ b/modules/mu4e-attachments.el
@@ -100,11 +100,21 @@ size; an unknown candidate annotates as nil so marginalia shows nothing."
(require 'mu4e-mime-parts)))
(defun cj/mu4e--save-attachment-part (part directory)
- "Save attachment PART to DIRECTORY and return the final path."
+ "Save attachment PART to DIRECTORY and return the final path.
+Signals a `user-error' when PART's MIME handle is stale: a handle's car
+is the buffer holding the part's bytes, and viewing another message kills
+it, so saving through it would error deep in mm-decode or write another
+message's content. The staleness check runs before
+`cj/mu4e--ensure-attachment-save-functions', like the no-handle check."
(let ((handle (plist-get part :handle)))
(unless handle
(user-error "Attachment has no MIME handle: %s"
(or (plist-get part :filename) "<unnamed>")))
+ (when (and (consp handle)
+ (bufferp (car handle))
+ (not (buffer-live-p (car handle))))
+ (user-error "Attachment %s is stale (the message view changed) -- reopen the message and save again"
+ (or (plist-get part :filename) "<unnamed>")))
(cj/mu4e--ensure-attachment-save-functions)
(let* ((path (funcall mu4e-uniquify-save-file-name-function
(mu4e-join-paths directory