From df30f7ed31163b5a00063d5cdfef0a1b482bca7e Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 3 Dec 2024 18:59:30 +0200 Subject: [PATCH] mu4e-mime-parts: warn when saving files matching crm-separator When files contain crm-separator (by default, some comma with option whitespace), we cannot use mu4e-view-save-attachments since the emacs' completion mechanism gets confused. Luckily, we can still use mu4e-view-mime-part-action instead (which uses numbers for files). --- mu4e/mu4e-mime-parts.el | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mu4e/mu4e-mime-parts.el b/mu4e/mu4e-mime-parts.el index 875f5968..9ec18d8b 100644 --- a/mu4e/mu4e-mime-parts.el +++ b/mu4e/mu4e-mime-parts.el @@ -32,6 +32,7 @@ (require 'mu4e-vars) (require 'mu4e-folders) (require 'gnus-art) +(require 'crm) (defcustom mu4e-view-open-program (pcase system-type @@ -284,20 +285,22 @@ This command assumes unique filenames for the attachments, since that is how the underlying completion mechanism works. If there are duplicates, only one is recognized. -Furthermore, file-names that match `crm-separator' (by default, -commas) are not supported (see `completing-read-multiple' for -further details). - -For such corner-cases, it is recommended to use -`mu4e-view-mime-part-action' instead, which does not have this -limitation." +Furthermore, file-names that match `crm-separator' (by default, a +comma and some optional whitespace) are not supported (see +`completing-read-multiple' for further details). Hence, when we +detect that, the function bails out and advises to use +`mu4e-view-mime-part-action' instead, which does support such +files." (interactive "P") (let* ((parts (mu4e-view-mime-parts)) (candidates (seq-map (lambda (fpart) - (cons ;; (filename . annotation) - (plist-get fpart :filename) - fpart)) + (let ((fname (plist-get fpart :filename))) + (when (and crm-separator (string-match-p crm-separator fname)) + (mu4e-warn (concat "File(s) match `crm-separator'; " + "use mu4e-view-mime-part-action instead"))) + ;; (filename . annotation) + (cons fname fpart))) (seq-filter (lambda (part) (plist-get part :attachment-like)) parts)))