aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-12 00:35:20 -0500
committerCraig Jennings <c@cjennings.net>2026-05-12 00:35:20 -0500
commit6c1cb14c50eb727d9b7ed1acb3b537c9dcb5864c (patch)
treee77ac163b481699aa54736dbc824b22dfbb45171
parenteadd9bfbbbe243216cbcea3911825f263d226975 (diff)
downloaddotemacs-6c1cb14c50eb727d9b7ed1acb3b537c9dcb5864c.tar.gz
dotemacs-6c1cb14c50eb727d9b7ed1acb3b537c9dcb5864c.zip
refactor(mail): fail fast on an attachment part with no MIME handle
`cj/mu4e--save-attachment-part' called `cj/mu4e--ensure-attachment-save-functions' first, so a part with no MIME handle triggered the `mu4e-mime-parts' load before the handle check could fail. The handle check now runs first, so the malformed input is caught right away and the user-error fires the same way whether or not mu4e's MIME support is loadable. The test for that case drops the mu4e stubs it only needed because the load used to come first.
-rw-r--r--modules/mu4e-attachments.el2
-rw-r--r--tests/test-mu4e-attachments.el12
2 files changed, 7 insertions, 7 deletions
diff --git a/modules/mu4e-attachments.el b/modules/mu4e-attachments.el
index 87392681e..8f7110001 100644
--- a/modules/mu4e-attachments.el
+++ b/modules/mu4e-attachments.el
@@ -87,11 +87,11 @@ The result is an alist of display labels to MIME part plists."
(defun cj/mu4e--save-attachment-part (part directory)
"Save attachment PART to DIRECTORY and return the final path."
- (cj/mu4e--ensure-attachment-save-functions)
(let ((handle (plist-get part :handle)))
(unless handle
(user-error "Attachment has no MIME handle: %s"
(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
(plist-get part :filename)))))
diff --git a/tests/test-mu4e-attachments.el b/tests/test-mu4e-attachments.el
index 86a429168..3105d710e 100644
--- a/tests/test-mu4e-attachments.el
+++ b/tests/test-mu4e-attachments.el
@@ -67,13 +67,13 @@
(should (equal saved '("handle" "/downloads/invoice.pdf.unique"))))))
(ert-deftest test-mu4e-attachments-save-part-errors-without-handle ()
- "Error: a malformed part without a MIME handle fails clearly."
- (let ((part (test-mu4e-attachments--part "invoice.pdf" 3 nil))
- (mu4e-uniquify-save-file-name-function #'identity))
+ "Error: a malformed part without a MIME handle fails clearly.
+The handle check runs before `cj/mu4e--ensure-attachment-save-functions',
+so this fails the same way whether or not mu4e's MIME support is loadable."
+ (let ((part (test-mu4e-attachments--part "invoice.pdf" 3 nil)))
(setq part (plist-put part :handle nil))
- (cl-letf (((symbol-function 'mu4e-join-paths) #'list))
- (should-error (cj/mu4e--save-attachment-part part "/downloads")
- :type 'user-error))))
+ (should-error (cj/mu4e--save-attachment-part part "/downloads")
+ :type 'user-error)))
(ert-deftest test-mu4e-attachments-save-all-prompts-once ()
"Normal: the save-all command prompts for a directory once and saves all parts."