Re: [PATCH v3] Make buttons for attachments allow viewing as well as saving
authorAustin Clements <amdragon@MIT.EDU>
Tue, 17 Jan 2012 23:53:18 +0000 (18:53 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:42:31 +0000 (09:42 -0800)
48/fa19e532a312175d525935c2cc5eb36cbaa6e7 [new file with mode: 0644]

diff --git a/48/fa19e532a312175d525935c2cc5eb36cbaa6e7 b/48/fa19e532a312175d525935c2cc5eb36cbaa6e7
new file mode 100644 (file)
index 0000000..7a64dda
--- /dev/null
@@ -0,0 +1,248 @@
+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 A2657429E5F\r
+       for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 15:53:33 -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 Egu9nNRoAjY3 for <notmuch@notmuchmail.org>;\r
+       Tue, 17 Jan 2012 15:53:32 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
+       [18.7.68.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id B890A429E27\r
+       for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 15:53:32 -0800 (PST)\r
+X-AuditID: 12074422-b7fd66d0000008f9-ff-4f1609fc9874\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 91.B6.02297.CF9061F4; Tue, 17 Jan 2012 18:53:32 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q0HNrVqE014300; \r
+       Tue, 17 Jan 2012 18:53:32 -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 q0HNrU9L021213\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Tue, 17 Jan 2012 18:53:31 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1RnIq6-0008Ki-Db; Tue, 17 Jan 2012 18:53:18 -0500\r
+Date: Tue, 17 Jan 2012 18:53:18 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [PATCH v3] Make buttons for attachments allow viewing as well as\r
+       saving\r
+Message-ID: <20120117235318.GZ16740@mit.edu>\r
+References: <87lip5rj43.fsf@qmul.ac.uk>\r
+       <1326843886-18387-1-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: <1326843886-18387-1-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IRYrdT0f3DKeZv8GgHp8XquTwW12/OZHZg\r
+       8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Ms7+/8tUMNWi4nyvTwPjAt0uRk4OCQETic3d\r
+       89ghbDGJC/fWs3UxcnEICexjlPh0eycThLOBUWLZwSesEM5JJokTP+exQDhLGCV+/ZnKAtLP\r
+       IqAq8eLLDWYQm01AQ2Lb/uWMILaIgI7E7UMLwHYwC0hLfPvdzARiCwuESXxt3g5WzwtU8/To\r
+       WrAaIYF0iX/rz7FCxAUlTs58wgLRqyVx499LoF4OsDnL/3GAhDkFvCTeHpkLNkZUQEViyslt\r
+       bBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuqZ6uZkleqkppZsYwUHt\r
+       orSD8edBpUOMAhyMSjy8BZtE/YVYE8uKK3MPMUpyMCmJ8k5mF/MX4kvKT6nMSCzOiC8qzUkt\r
+       PsQowcGsJMLLygyU401JrKxKLcqHSUlzsCiJ86prvfMD+jexJDU7NbUgtQgmK8PBoSTBe4QD\r
+       qFGwKDU9tSItM6cEIc3EwQkynAdoeCfIYt7igsTc4sx0iPwpRkUpcV4FYNoQEgBJZJTmwfXC\r
+       ks4rRnGgV4R5dUGqeIAJC677FdBgJqDBOa1CIINLEhFSUg2ME1dqVp6SfintM/OE4LMt1f7c\r
+       oSd5n2tr1/PEndO9+pmtY8b21JvFWx/xt8h2bpmWcUX6YXXMBB32jqD8gB1WU2MvvKmYbPJa\r
+       /LDh5gkMMYfY1rNe/FrJeEU7uOT4lmiDnY/PbGA7dPL5ssk6ElUMMzJ8w/6Y6bFnLyi9Xp2n\r
+       7PL5M4vMDzcWJZbijERDLeai4kQAtJPkvRUDAAA=\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: Tue, 17 Jan 2012 23:53:33 -0000\r
+\r
+Quoth Mark Walters on Jan 17 at 11:44 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
+Oof, sorry.  Two more tweaks that I really should have caught in the\r
+previous version.  After that this gets my automatic +1.\r
+\r
+> ---\r
+>  emacs/notmuch-show.el |  106 ++++++++++++++++++++++++++++++++++++++-----------\r
+>  1 files changed, 82 insertions(+), 24 deletions(-)\r
+> \r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 03c1f6b..0aaaf79 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -281,10 +281,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
+\r
+Indentation.\r
+\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
+> @@ -299,29 +310,48 @@ 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
+> +      (mm-display-part handle t))))\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
+> @@ -1502,12 +1532,40 @@ 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
+> +(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\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
+defcustoms customarily appear at the top of the file (see the rest of\r
+the defcustoms in notmuch-show.el)\r
+\r
+> +\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