unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: camalot@picnicpark.org
To: notmuch@notmuchmail.org
Cc: Keith Amidon <keith@nicira.com>
Subject: [PATCH 8/9] Provide ability to save attachments
Date: Fri, 27 Nov 2009 05:30:14 -0800	[thread overview]
Message-ID: <1259328615-1445-9-git-send-email-camalot@picnicpark.org> (raw)
In-Reply-To: <1259328615-1445-8-git-send-email-camalot@picnicpark.org>

From: Keith Amidon <keith@nicira.com>

Previously the only way to save an attachment was to attempt to view
it and then save it from within the viewer program.
---
 notmuch.el |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index eaa5798..0c6b527 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -303,6 +303,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)
-- 
1.6.5.3

  reply	other threads:[~2009-11-27 13:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27 13:30 Show mode enhancements camalot
2009-11-27 13:30 ` [PATCH 1/9] Explicitly require the message library camalot
2009-11-27 13:30   ` [PATCH 2/9] Adjust autoload comments camalot
2009-11-27 13:30     ` [PATCH 3/9] Add key binding for notmuch-search in show-mode camalot
2009-11-27 13:30       ` [PATCH 4/9] Factor out message buffer mgmt from notmuch-show-view-all-mime-parts camalot
2009-11-27 13:30         ` [PATCH 5/9] Forward individual messages using message-forward camalot
2009-11-27 13:30           ` [PATCH 6/9] Reply to individual messages using message library camalot
2009-11-27 13:30             ` [PATCH 7/9] Key bindings for message library based replies camalot
2009-11-27 13:30               ` camalot [this message]
2009-11-27 13:30                 ` [PATCH 9/9] Key binding rearrangement for save attachments in show mode camalot
2009-11-28  5:30                   ` Carl Worth
2009-11-28  5:28                 ` [PATCH 8/9] Provide ability to save attachments Carl Worth
     [not found]             ` <87bpiongh5.fsf@linux.vnet.ibm.com>
2009-11-27 16:48               ` [PATCH 6/9] Reply to individual messages using message library Keith Amidon
2009-11-28  5:22             ` Carl Worth
2009-11-29  6:09               ` Keith Amidon
2009-11-28  5:15           ` [PATCH 5/9] Forward individual messages using message-forward Carl Worth
2009-11-28 17:32             ` Keith Amidon
2009-11-28 17:49               ` Carl Worth
2009-11-28 21:14                 ` Keith Amidon
2009-11-28  5:10         ` [PATCH 4/9] Factor out message buffer mgmt from notmuch-show-view-all-mime-parts Carl Worth
2009-11-28  5:23           ` Alexander Botero-Lowry
2009-11-28  5:06     ` [PATCH 2/9] Adjust autoload comments Carl Worth
2009-11-28 17:27       ` Keith Amidon
2009-11-28 17:36         ` Carl Worth
2009-11-30 20:38         ` James Rowe
2009-12-04  1:04           ` Carl Worth
2009-12-04  1:24             ` Jameson Graef Rollins
2009-12-04 17:27               ` Carl Worth
2009-12-04  4:44             ` James Rowe
2009-12-04  1:07           ` Carl Worth
2009-12-17 17:17             ` James Rowe
2009-12-17 17:52               ` Carl Worth
2009-11-28  5:03   ` [PATCH 1/9] Explicitly require the message library Carl Worth
2009-11-28  4:18 ` Show mode enhancements Carl Worth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1259328615-1445-9-git-send-email-camalot@picnicpark.org \
    --to=camalot@picnicpark.org \
    --cc=keith@nicira.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).