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).
This commit is contained in:
Dirk-Jan C. Binnema
2024-12-03 18:59:30 +02:00
parent 8fefc52eee
commit df30f7ed31

View File

@ -32,6 +32,7 @@
(require 'mu4e-vars) (require 'mu4e-vars)
(require 'mu4e-folders) (require 'mu4e-folders)
(require 'gnus-art) (require 'gnus-art)
(require 'crm)
(defcustom mu4e-view-open-program (defcustom mu4e-view-open-program
(pcase system-type (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 that is how the underlying completion mechanism works. If there
are duplicates, only one is recognized. are duplicates, only one is recognized.
Furthermore, file-names that match `crm-separator' (by default, Furthermore, file-names that match `crm-separator' (by default, a
commas) are not supported (see `completing-read-multiple' for comma and some optional whitespace) are not supported (see
further details). `completing-read-multiple' for further details). Hence, when we
detect that, the function bails out and advises to use
For such corner-cases, it is recommended to use `mu4e-view-mime-part-action' instead, which does support such
`mu4e-view-mime-part-action' instead, which does not have this files."
limitation."
(interactive "P") (interactive "P")
(let* ((parts (mu4e-view-mime-parts)) (let* ((parts (mu4e-view-mime-parts))
(candidates (seq-map (candidates (seq-map
(lambda (fpart) (lambda (fpart)
(cons ;; (filename . annotation) (let ((fname (plist-get fpart :filename)))
(plist-get fpart :filename) (when (and crm-separator (string-match-p crm-separator fname))
fpart)) (mu4e-warn (concat "File(s) match `crm-separator'; "
"use mu4e-view-mime-part-action instead")))
;; (filename . annotation)
(cons fname fpart)))
(seq-filter (seq-filter
(lambda (part) (plist-get part :attachment-like)) (lambda (part) (plist-get part :attachment-like))
parts))) parts)))