diff options
author | Ricardo Wurmus <rekado@elephly.net> | 2024-01-13 16:20:40 +0100 |
---|---|---|
committer | Ricardo Wurmus <rekado@elephly.net> | 2024-01-13 16:20:40 +0100 |
commit | 3d9f1eb816a19e0a41e87ec25d0ead0b625a570d (patch) | |
tree | d3be37a70c94d3e5627c48a0374261d21f91827b | |
parent | a9650b3c909bdc31d7ec2f7de0bd39ac93451c15 (diff) |
mu4e: Add action to delete attachments.
-rw-r--r-- | init.org | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -1092,6 +1092,47 @@ Integrate mu4e with Org mode. erc-mode) . typo-mode)) #+end_src +Add action to delete attachments (https://emacs.stackexchange.com/a/70992) +#+begin_src elisp +(defun my-mime-part-filename (num) + "Filename of MIME part numbered num in gnus-article-mode." + ;; Check whether the specified part exists. + (when (> num (length gnus-article-mime-handle-alist)) + (error "No such part")) + ;; Move point to MIME part + (when (gnus-article-goto-part num) + ;; Get handle for MIME part at point + (let ((handle (get-text-property (point) 'gnus-data))) + (when handle + ;; Return file name of handle + (mm-handle-filename handle))))) +(defun my-delete-attachment (num) + "Remove email attachment from mu4e using altermime." + (let* ((path (mu4e-message-field (mu4e-message-at-point) :path)) + (filename (my-mime-part-filename num)) + (cmd (format "altermime --input='%s' --remove='%s'" path filename))) + (when (and filename + (yes-or-no-p + (format "Remove '%s'?" filename))) + (shell-command cmd) + (mu4e-message cmd)))) +(defun my-delete-all-attachments (msg) + "Remove all email attachments in mu4e using altermime." + (let* ((path (mu4e-message-field msg :path)) + (subject (mu4e-message-field msg :subject)) + (cmd (format "altermime --input='%s' --removeall" path))) + (when (yes-or-no-p + (format "Remove all attachments from '%s'?" subject)) + (shell-command cmd) + (mu4e-message cmd)))) +(add-to-list 'mu4e-view-mime-part-actions + '(:name "delete-attachment" + :handler my-delete-attachment + :receives index)) +(add-to-list 'mu4e-headers-actions + '("Delete-all-attachments" . my-delete-all-attachments)) +#+end_src + * TODO More stuff This is even more stuff to be done after initialising packages. I still need to process all of this and clean it up. |