aboutsummaryrefslogtreecommitdiff
path: root/modules/mu4e-attachments.el
diff options
context:
space:
mode:
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