From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4668841971B for ; Fri, 27 Nov 2009 05:31:02 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8at0aSBext30 for ; Fri, 27 Nov 2009 05:31:01 -0800 (PST) Received: from mout.perfora.net (mout.perfora.net [74.208.4.195]) by olra.theworths.org (Postfix) with ESMTP id 3E83C41971A for ; Fri, 27 Nov 2009 05:31:01 -0800 (PST) Received: from vps.nicira.com (66.7.219.28.static.dimenoc.com [66.7.219.28]) by mx.perfora.net (node=mxus1) with ESMTP (Nemesis) id 0MPmLS-1NHqf00yCw-0050Pk for notmuch@notmuchmail.org; Fri, 27 Nov 2009 08:31:00 -0500 Received: from [76.210.240.177] (port=36300 helo=kea-nicira-lt) by vps.nicira.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NE0uY-0004d9-AW; Fri, 27 Nov 2009 08:30:59 -0500 Received: by kea-nicira-lt (sSMTP sendmail emulation); Fri, 27 Nov 2009 05:30:57 -0800 From: camalot@picnicpark.org To: notmuch@notmuchmail.org Date: Fri, 27 Nov 2009 05:30:14 -0800 Message-Id: <1259328615-1445-9-git-send-email-camalot@picnicpark.org> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <1259328615-1445-8-git-send-email-camalot@picnicpark.org> References: <1259328615-1445-1-git-send-email-camalot@picnicpark.org> <1259328615-1445-2-git-send-email-camalot@picnicpark.org> <1259328615-1445-3-git-send-email-camalot@picnicpark.org> <1259328615-1445-4-git-send-email-camalot@picnicpark.org> <1259328615-1445-5-git-send-email-camalot@picnicpark.org> <1259328615-1445-6-git-send-email-camalot@picnicpark.org> <1259328615-1445-7-git-send-email-camalot@picnicpark.org> <1259328615-1445-8-git-send-email-camalot@picnicpark.org> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps.nicira.com X-AntiAbuse: Original Domain - notmuchmail.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - picnicpark.org X-Source: X-Source-Args: X-Source-Dir: Cc: Keith Amidon Subject: [PATCH 8/9] Provide ability to save attachments X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Nov 2009 13:31:02 -0000 From: Keith Amidon 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