Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 630D3431FD0 for ; Tue, 6 Sep 2011 19:23:23 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.098 X-Spam-Level: X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled 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 ucCi4K6jyL54 for ; Tue, 6 Sep 2011 19:23:22 -0700 (PDT) X-Greylist: delayed 3774 seconds by postgrey-1.32 at olra; Tue, 06 Sep 2011 19:23:22 PDT Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8FC38431FB6 for ; Tue, 6 Sep 2011 19:23:22 -0700 (PDT) Received: from smtp.qmul.ac.uk ([138.37.6.40]) by mail2.qmul.ac.uk with esmtp (Exim 4.71) (envelope-from ) id 1R16oS-0001Cm-Oo; Wed, 07 Sep 2011 02:20:24 +0100 Received: from [82.153.7.131] (helo=localhost) by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1R16oE-0000WM-16; Wed, 07 Sep 2011 02:20:24 +0100 From: Mark Walters To: Notmuch Mail Subject: RFC/PATCH emacs attachment handling User-Agent: Notmuch/0.7-37-g89c28de (http://notmuchmail.org) Emacs/23.2.1 (i486-pc-linux-gnu) Date: Wed, 07 Sep 2011 02:20:14 +0100 Message-ID: <87mxehqhbl.fsf@r102.config> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Sender-Host-Address: 82.153.7.131 X-QM-SPAM-Info: Sender has good ham record. :) X-QM-Body-MD5: b05c930e36bafba0c01871cef296cb2c (of first 20000 bytes) X-QM-Scan-Virus: ClamAV says the message is clean X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Wed, 07 Sep 2011 02:23:23 -0000 Hello I have modified the emacs interface for handling attachments by adding a keymap to the attachment button. For example pressing v when on an attachment button views the attachment (using the mailcap method) and pressing s saves the attachment. I find this makes it a lot easier when dealing with message with lots of attachments. Other comments: "Viewing" a text/html button opens the part in the mailcap defined html viewer. "Viewing" a part with no mailcap entry just offers to save it. In this version I make the button default to viewing: this is obviously trivial to change but I am not sure what the right way to make that user-configurable is. Finally, I have also mapped the key "o" (other/open with) on a button to open with user chosen program. This could be split out into a separate patch if preferred. Best wishes Mark --- emacs/notmuch-show.el | 76 +++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 68 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 90f9af7..3a025c5 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -267,10 +267,21 @@ message at DEPTH in the current thread." (run-hooks 'notmuch-show-markup-headers-hook))))) (define-button-type 'notmuch-show-part-button-type - 'action 'notmuch-show-part-button-action + 'action 'notmuch-show-part-button-view-action + 'keymap 'notmuch-show-part-button-map 'follow-link t 'face 'message-mml) +(defvar notmuch-show-part-button-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map button-map) + (define-key map "s" 'notmuch-show-part-button-save-action) + (define-key map "v" 'notmuch-show-part-button-view-action) + (define-key map "o" 'notmuch-show-part-button-interactively-view-action) + map) + "Submap for button commands") +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map) + (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment) (let ((button)) (setq button @@ -285,7 +296,8 @@ message at DEPTH in the current thread." " ]") :type 'notmuch-show-part-button-type :notmuch-part nth - :notmuch-filename name)) + :notmuch-filename name + :notmuch-content-type content-type)) (insert "\n") ;; return button button)) @@ -309,6 +321,28 @@ message at DEPTH in the current thread." ;; ange-ftp, which is reasonable to use here. (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))) +(defun notmuch-show-view-part (message-id nth content-type) + (let ((process-crypto notmuch-show-process-crypto)) + (with-temp-buffer + (setq notmuch-show-process-crypto process-crypto) + ;; Always acquires the part via `notmuch part', even if it is + ;; available in the JSON output. + (insert (notmuch-show-get-bodypart-internal message-id nth)) + ;; set mm-inlined-types to nil to force an external viewer + (let ((handle (mm-make-handle (current-buffer) (list content-type))) + (mm-inlined-types nil)) + (mm-display-part handle))))) + +(defun notmuch-show-interactively-view-part (message-id nth content-type) + (let ((process-crypto notmuch-show-process-crypto)) + (with-temp-buffer + (setq notmuch-show-process-crypto process-crypto) + ;; Always acquires the part via `notmuch part', even if it is + ;; available in the JSON output. + (insert (notmuch-show-get-bodypart-internal message-id nth)) + (let ((handle (mm-make-handle (current-buffer) (list content-type)))) + (mm-interactively-view-part handle))))) + (defun notmuch-show-mm-display-part-inline (msg part content-type content) "Use the mm-decode/mm-view functions to display a part in the current buffer, if possible." @@ -1418,12 +1452,38 @@ buffer." ;; Commands typically bound to buttons. -(defun notmuch-show-part-button-action (button) - (let ((nth (button-get button :notmuch-part))) - (if nth - (notmuch-show-save-part (notmuch-show-get-message-id) nth - (button-get button :notmuch-filename)) - (message "Not a valid part (is it a fake part?).")))) +(defun notmuch-show-part-button-save-action (&optional button) + (interactive) + (let ((button (or button (button-at (point))))) + (if (not button) + nil + (let ((nth (button-get button :notmuch-part))) + (if nth + (notmuch-show-save-part (notmuch-show-get-message-id) nth + (button-get button :notmuch-filename)) + (message "Not a valid part (is it a fake part?).")))))) + +(defun notmuch-show-part-button-view-action (&optional button) + (interactive) + (let ((button (or button (button-at (point))))) + (if (not button) + nil + (let ((nth (button-get button :notmuch-part))) + (if nth + (notmuch-show-view-part (notmuch-show-get-message-id) nth + (button-get button :notmuch-content-type)) + (message "Not a valid part (is it a fake part?).")))))) + +(defun notmuch-show-part-button-interactively-view-action (&optional button) + (interactive) + (let ((button (or button (button-at (point))))) + (if (not button) + nil + (let ((nth (button-get button :notmuch-part))) + (if nth + (notmuch-show-interactively-view-part (notmuch-show-get-message-id) nth + (button-get button :notmuch-content-type)) + (message "Not a valid part (is it a fake part?).")))))) ;; -- 1.7.1