--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 56C90431FAF\r
+ for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 20:30:45 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id nn4foO6Av-yu for <notmuch@notmuchmail.org>;\r
+ Thu, 19 Jan 2012 20:30:44 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
+ [18.9.25.14])\r
+ by olra.theworths.org (Postfix) with ESMTP id 374FA431FAE\r
+ for <notmuch@notmuchmail.org>; Thu, 19 Jan 2012 20:30:44 -0800 (PST)\r
+X-AuditID: 1209190e-b7f7c6d0000008c3-f4-4f18edf3a236\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id C0.BD.02243.3FDE81F4; Thu, 19 Jan 2012 23:30:43 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0K4UhRi019618; \r
+ Thu, 19 Jan 2012 23:30:43 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0K4Ugj9013396\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Thu, 19 Jan 2012 23:30:43 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1Ro67L-0004gV-Vb; Thu, 19 Jan 2012 23:30:24 -0500\r
+Date: Thu, 19 Jan 2012 23:30:23 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH v4 1/1] Make buttons for attachments allow viewing as\r
+ well as saving\r
+Message-ID: <20120120043023.GW16740@mit.edu>\r
+References: <id:"20120118192147.GF16740@mit.edu">\r
+ <1327008185-21194-2-git-send-email-markwalters1009@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1327008185-21194-2-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFvrPIsWRmVeSWpSXmKPExsUixG6nrvv5rYS/wdK3ahar5/JYXL85k9mB\r
+ yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyviweyNzwTbbivsbF7A3MC427GLk5JAQMJFY\r
+ 37ySEcIWk7hwbz1bFyMXh5DAPkaJ/zuPMUE4Gxgldn97zA5SJSRwkkli8/FgCHsJo8Tc2Ykg\r
+ NouAqsT7UzNZQWw2AQ2JbfuXg00VEdCRuH1oAVgvs4C0xLffzUwgtrBAlMSBd3NYuhg5OHiB\r
+ aj5uV4cYWSjxb+8isHJeAUGJkzOfsEC0aknc+PeSCaQcZMzyfxwgJqeAl0TPvGqQClEBFYkp\r
+ J7exTWAUmoWkeRaS5lkIzQsYmVcxyqbkVunmJmbmFKcm6xYnJ+blpRbpGuvlZpbopaaUbmIE\r
+ hTOnJN8Oxq8HlQ4xCnAwKvHwcrpK+AuxJpYVV+YeYpTkYFIS5VV+DRTiS8pPqcxILM6ILyrN\r
+ SS0+xCjBwawkwuvwBCjHm5JYWZValA+TkuZgURLnVdN65yckkJ5YkpqdmlqQWgSTleHgUJLg\r
+ dQXGrZBgUWp6akVaZk4JQpqJgxNkOA/Q8BKQGt7igsTc4sx0iPwpRkUpcV55kIQASCKjNA+u\r
+ F5ZuXjGKA70izFsLUsUDTFVw3a+ABjMBDfZoEgMZXJKIkJJqYKxPqj2UoHX+9CSRSC2feu//\r
+ jsIP23lNAtsFY80L5zqrMP3mSZ6bdPPeXW3b8ohUj8Dnm0N0Qk8XrNeavbMxRSOGk7eg0tVE\r
+ QE9kPteRxS77/u44uE9ka8j/+abdyQu/luVabyp5FM5l/mQSx2vPGR33912WV941bbG0uoH7\r
+ jQi/C8m+jpdWKrEUZyQaajEXFScCAGM9q+0SAwAA\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 20 Jan 2012 04:30:45 -0000\r
+\r
+One indentation nit and then this LGTM.\r
+\r
+Quoth Mark Walters on Jan 19 at 9:23 pm:\r
+> Define a keymap for attachment buttons to allow multiple actions.\r
+> Define 3 possible actions:\r
+> save attachment: exactly as currently,\r
+> view attachment: uses mailcap entry,\r
+> view attachment with user chosen program\r
+> \r
+> Keymap on a button is: s for save, v for view and o for view with\r
+> other program. Default (i.e. enter or mouse button) is save but this\r
+> is configurable in notmuch customize.\r
+> \r
+> One implementation detail: the view attachment function forces all\r
+> attachments to be "displayed" using mailcap even if emacs could\r
+> display them itself. Thus, for example, text/html appears in a browser\r
+> and text/plain asks whether to save (on a standard debian setup)\r
+> ---\r
+> emacs/notmuch-show.el | 116 ++++++++++++++++++++++++++++++++++++++----------\r
+> 1 files changed, 92 insertions(+), 24 deletions(-)\r
+> \r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index fc13462..1fcd72a 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -112,6 +112,16 @@ indentation."\r
+> :type 'boolean\r
+> :group 'notmuch-show)\r
+> \r
+> +(defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part\r
+> + "Default part header button action (on ENTER or mouse click)."\r
+> + :group 'notmuch-show\r
+> + :type '(choice (const :tag "Save part"\r
+> + notmuch-show-save-part)\r
+> + (const :tag "View part"\r
+> + notmuch-show-view-part)\r
+> + (const :tag "View interactively"\r
+> + notmuch-show-interactively-view-part)))\r
+> +\r
+> (defmacro with-current-notmuch-show-message (&rest body)\r
+> "Evaluate body with current buffer set to the text of current message"\r
+> `(save-excursion\r
+> @@ -283,10 +293,21 @@ message at DEPTH in the current thread."\r
+> (run-hooks 'notmuch-show-markup-headers-hook)))))\r
+> \r
+> (define-button-type 'notmuch-show-part-button-type\r
+> - 'action 'notmuch-show-part-button-action\r
+> + 'action 'notmuch-show-part-button-default\r
+> + 'keymap 'notmuch-show-part-button-map\r
+> 'follow-link t\r
+> 'face 'message-mml)\r
+> \r
+> +(defvar notmuch-show-part-button-map\r
+> + (let ((map (make-sparse-keymap)))\r
+> + (set-keymap-parent map button-map)\r
+> + (define-key map "s" 'notmuch-show-part-button-save)\r
+> + (define-key map "v" 'notmuch-show-part-button-view)\r
+> + (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
+> + map)\r
+> + "Submap for button commands")\r
+> +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
+> +\r
+> (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
+> (let ((button))\r
+> (setq button\r
+> @@ -301,29 +322,58 @@ message at DEPTH in the current thread."\r
+> " ]")\r
+> :type 'notmuch-show-part-button-type\r
+> :notmuch-part nth\r
+> - :notmuch-filename name))\r
+> + :notmuch-filename name\r
+> + :notmuch-content-type content-type))\r
+> (insert "\n")\r
+> ;; return button\r
+> button))\r
+> \r
+> ;; Functions handling particular MIME parts.\r
+> \r
+> -(defun notmuch-show-save-part (message-id nth &optional filename)\r
+> - (let ((process-crypto notmuch-show-process-crypto))\r
+> - (with-temp-buffer\r
+> - (setq notmuch-show-process-crypto process-crypto)\r
+> - ;; Always acquires the part via `notmuch part', even if it is\r
+> - ;; available in the JSON output.\r
+> - (insert (notmuch-show-get-bodypart-internal message-id nth))\r
+> - (let ((file (read-file-name\r
+> - "Filename to save as: "\r
+> - (or mailcap-download-directory "~/")\r
+> - nil nil\r
+> - filename)))\r
+> - ;; Don't re-compress .gz & al. Arguably we should make\r
+> - ;; `file-name-handler-alist' nil, but that would chop\r
+> - ;; ange-ftp, which is reasonable to use here.\r
+> - (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))\r
+> +(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)\r
+> + (declare (indent 2))\r
+> + (let ((process-crypto (make-symbol "process-crypto")))\r
+> + `(let ((,process-crypto notmuch-show-process-crypto))\r
+> + (with-temp-buffer\r
+> + (setq notmuch-show-process-crypto ,process-crypto)\r
+> + ;; Always acquires the part via `notmuch part', even if it is\r
+> + ;; available in the JSON output.\r
+> + (insert (notmuch-show-get-bodypart-internal ,message-id ,nth))\r
+> + ,@body))))\r
+> +\r
+> +(defun notmuch-show-save-part (message-id nth &optional filename content-type)\r
+> + (notmuch-with-temp-part-buffer message-id nth\r
+> + (let ((file (read-file-name\r
+> + "Filename to save as: "\r
+> + (or mailcap-download-directory "~/")\r
+> + nil nil\r
+> + filename)))\r
+> + ;; Don't re-compress .gz & al. Arguably we should make\r
+> + ;; `file-name-handler-alist' nil, but that would chop\r
+> + ;; ange-ftp, which is reasonable to use here.\r
+> + (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))\r
+> +\r
+> +(defun notmuch-show-view-part (message-id nth &optional filename content-type )\r
+> + (notmuch-with-temp-part-buffer message-id nth\r
+> + ;; set mm-inlined-types to nil to force an external viewer\r
+> + (let ((handle (mm-make-handle (current-buffer) (list content-type)))\r
+> + (mm-inlined-types nil))\r
+> + ;; We override mm-save-part as notmuch-show-save-part is better\r
+> + ;; since it offers the filename. We need to lexically bind\r
+> + ;; everything we need for notmuch-show-save-part to prevent\r
+> + ;; potential dynamic shadowing.\r
+> + (lexical-let ((message-id message-id)\r
+> + (nth nth)\r
+> + (filename filename)\r
+> + (content-type content-type))\r
+> + (flet ((mm-save-part (&rest args) (notmuch-show-save-part\r
+\r
+This body of lexical-let should be indented like a normal let body.\r
+You might have to load cl to get this indentation rule.\r
+\r
+> + message-id nth filename content-type)))\r
+> + (mm-display-part handle))))))\r
+> +\r
+> +(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)\r
+> + (notmuch-with-temp-part-buffer message-id nth\r
+> + (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
+> + (mm-interactively-view-part handle))))\r
+> \r
+> (defun notmuch-show-mm-display-part-inline (msg part nth content-type)\r
+> "Use the mm-decode/mm-view functions to display a part in the\r
+> @@ -1504,12 +1554,30 @@ buffer."\r
+> \r
+> ;; Commands typically bound to buttons.\r
+> \r
+> -(defun notmuch-show-part-button-action (button)\r
+> - (let ((nth (button-get button :notmuch-part)))\r
+> - (if nth\r
+> - (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
+> - (button-get button :notmuch-filename))\r
+> - (message "Not a valid part (is it a fake part?)."))))\r
+> +(defun notmuch-show-part-button-default (&optional button)\r
+> + (interactive)\r
+> + (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))\r
+> +\r
+> +(defun notmuch-show-part-button-save (&optional button)\r
+> + (interactive)\r
+> + (notmuch-show-part-button-internal button #'notmuch-show-save-part))\r
+> +\r
+> +(defun notmuch-show-part-button-view (&optional button)\r
+> + (interactive)\r
+> + (notmuch-show-part-button-internal button #'notmuch-show-view-part))\r
+> +\r
+> +(defun notmuch-show-part-button-interactively-view (&optional button)\r
+> + (interactive)\r
+> + (notmuch-show-part-button-internal button #'notmuch-show-interactively-view-part))\r
+> +\r
+> +(defun notmuch-show-part-button-internal (button handler)\r
+> + (let ((button (or button (button-at (point)))))\r
+> + (if button\r
+> + (let ((nth (button-get button :notmuch-part)))\r
+> + (if nth\r
+> + (funcall handler (notmuch-show-get-message-id) nth\r
+> + (button-get button :notmuch-filename)\r
+> + (button-get button :notmuch-content-type)))))))\r
+> \r
+> ;;\r
+> \r