X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.el;h=fecad676a269e1fe7d0fa38b6492fb611bfc8bc6;hp=282932ed7fa9ea9655b8b6056927d63d8a060c74;hb=ea124966e73fdfaf926211c3c499fe1dd522a05c;hpb=07ce64e4352291fb5bd265f20c683c653ab81966 diff --git a/notmuch.el b/notmuch.el index 282932ed..fecad676 100644 --- a/notmuch.el +++ b/notmuch.el @@ -73,7 +73,8 @@ (define-key map "r" 'notmuch-show-reply) (define-key map "s" 'notmuch-search) (define-key map "v" 'notmuch-show-view-all-mime-parts) - (define-key map "w" 'notmuch-show-view-raw-message) + (define-key map "V" 'notmuch-show-view-raw-message) + (define-key map "w" 'notmuch-show-save-attachments) (define-key map "x" 'kill-this-buffer) (define-key map "+" 'notmuch-show-add-tag) (define-key map "-" 'notmuch-show-remove-tag) @@ -300,6 +301,47 @@ buffer." (with-current-notmuch-show-message (mm-display-parts (mm-dissect-buffer)))) +(defun notmuch-foreach-mime-part (function mm-handle) + (cond ((stringp (car mm-handle)) + (dolist (part (cdr mm-handle)) + (notmuch-foreach-mime-part function part))) + ((bufferp (car mm-handle)) + (funcall function mm-handle)) + (t (dolist (part mm-handle) + (notmuch-foreach-mime-part function part))))) + +(defun notmuch-count-attachments (mm-handle) + (let ((count 0)) + (notmuch-foreach-mime-part + (lambda (p) + (let ((disposition (mm-handle-disposition p))) + (and (listp disposition) + (equal (car disposition) "attachment") + (incf count)))) + mm-handle) + count)) + +(defun notmuch-save-attachments (mm-handle &optional queryp) + (notmuch-foreach-mime-part + (lambda (p) + (let ((disposition (mm-handle-disposition p))) + (and (listp disposition) + (equal (car disposition) "attachment") + (or (not queryp) + (y-or-n-p + (concat "Save '" (cdr (assq 'filename disposition)) "' "))) + (mm-save-part p)))) + mm-handle)) + +(defun notmuch-show-save-attachments () + "Save the attachments to a message" + (interactive) + (with-current-notmuch-show-message + (let ((mm-handle (mm-dissect-buffer))) + (notmuch-save-attachments + mm-handle (> (notmuch-count-attachments mm-handle) 1)))) + (message "Done")) + (defun notmuch-reply (query-string) (switch-to-buffer (generate-new-buffer "notmuch-draft")) (call-process notmuch-command nil t nil "reply" query-string)