From ecf3e612ee40ab6dee6000fcd72a631b215f83a8 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Fri, 10 Aug 2012 16:53:12 +0200 Subject: [PATCH] Re: [PATCH v2] emacs: add function to toggle display of all multipart/alternative parts --- b6/26c4fb4cec7a9d79861d0b7a0aac1157bd5f83 | 219 ++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 b6/26c4fb4cec7a9d79861d0b7a0aac1157bd5f83 diff --git a/b6/26c4fb4cec7a9d79861d0b7a0aac1157bd5f83 b/b6/26c4fb4cec7a9d79861d0b7a0aac1157bd5f83 new file mode 100644 index 000000000..7f39ecec3 --- /dev/null +++ b/b6/26c4fb4cec7a9d79861d0b7a0aac1157bd5f83 @@ -0,0 +1,219 @@ +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 2431F431FBC + for ; Fri, 10 Aug 2012 07:53:22 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.677 +X-Spam-Level: +X-Spam-Status: No, score=-0.677 tagged_above=-999 required=5 + tests=[HS_INDEX_PARAM=0.023, RCVD_IN_DNSWL_LOW=-0.7] + 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 cCjr1N5vJdwK for ; + Fri, 10 Aug 2012 07:53:20 -0700 (PDT) +Received: from mail-yw0-f53.google.com (mail-yw0-f53.google.com + [209.85.213.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 66FB5431FAF + for ; Fri, 10 Aug 2012 07:53:20 -0700 (PDT) +Received: by yhp3 with SMTP id 3so2028522yhp.26 + for ; Fri, 10 Aug 2012 07:53:18 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:subject:in-reply-to:references:user-agent:date:message-id + :mime-version:content-type:x-gm-message-state; + bh=JK/vlRaiy4MlvP0zRjGnqjq0OJWIoMUde6YnHPlTXVU=; + b=kEjkfgI2zo1Yo6e6O9vxKddZGgJ8RKIHQQdeQDpZOL/Ql4aKXY9eRF/uT50Dclo10w + UW9dsiICAtF7w45+ZQFjSlq5M6qvM4cklQ6Rfr7v58eoPZDSpkFtEhdm0CU5kU7l8aec + g5wu79SmaOob3zhQtClC4POd44QMjYhi8ZhXrf5FBl7uax/QlwPh3IJphOKtOaXxsmxa + +7By1iWgqzhuW46AZXl1U2wjzcjYsarvYSUjOdtQlhCc+idduTDMoZ/b05UyX0aP/ggH + 5oFfUX7eNfv454WBCana9JqoMrePTxsaeuMpOntxwK9CiNUCxHmx9f0gKGfW2ba09fir + jNvw== +Received: by 10.236.186.101 with SMTP id v65mr3209371yhm.23.1344610398762; + Fri, 10 Aug 2012 07:53:18 -0700 (PDT) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPS id i3sm3653530anl.0.2012.08.10.07.53.16 + (version=SSLv3 cipher=OTHER); Fri, 10 Aug 2012 07:53:17 -0700 (PDT) +From: Jani Nikula +To: Mark Walters , + Jameson Graef Rollins , notmuch@notmuchmail.org +Subject: Re: [PATCH v2] emacs: add function to toggle display of all + multipart/alternative parts +In-Reply-To: <87r4rf9q8x.fsf@qmul.ac.uk> +References: <1339775751-18002-1-git-send-email-jani@nikula.org> + <87zk80gvmb.fsf@servo.finestructure.net> + <87pq8vokmp.fsf@qmul.ac.uk> + <87ipcrvlcw.fsf@servo.finestructure.net> + <87r4rf9q8x.fsf@qmul.ac.uk> +User-Agent: Notmuch/0.13.2+131~gff9267e (http://notmuchmail.org) Emacs/23.2.1 + (x86_64-pc-linux-gnu) +Date: Fri, 10 Aug 2012 16:53:12 +0200 +Message-ID: <877gt67q93.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Gm-Message-State: + ALoCoQlAf/cic/cOUKGoUfYaPl3/PzEptcbWoIYWC9WP87ry3XHKpLT+4CPFfu6dm8pzDzl1GkXs +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: Fri, 10 Aug 2012 14:53:22 -0000 + +On Fri, 10 Aug 2012, Mark Walters wrote: +> Some messages are sent as multipart/alternative but the alternatives +> contain different information. This allows the user to cycle which +> part to view. By default this is bound to 'W'. +> --- +> +> On Thu, 09 Aug 2012, Jameson Graef Rollins wrote: +>> On Mon, Jun 18 2012, Mark Walters wrote: +>>> I agree with this cycling approach but I think it needs to be per +>>> message rather than per buffer. I attach a rather hacky attempt at this +>>> below: on minimal testing it seems to work. But the lisp is really a bit +>>> gross. In particular I have no idea if I should be escaping the message +>>> ids (so this could break in unfortunate/insecure ways) +>> +>> Thanks to broken Apple mail clients, I'm getting more and more messages +>> that have attachments hidden in multipart/"alternatives" to text/plain +>> parts. So I would really like to revive this patch. +>> +>> I just tested it and it still applies to current master, and actually +>> seems to work great. 'W' cycles through which part is displayed in the +>> current message. Pretty much exactly what I want. +>> +>> Mark seems to think this patch is less than ideal. One issue is that +>> it's trying to store a setting for a single displayed message in a +>> variable of full buffer scope. So he's storing a list of message ids +>> there: +>> +>>> +(defvar notmuch-show-message-multipart/alternative nil) +>>> +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative) +>>> +(put 'notmuch-show-message-multipart/alternative 'permanent-local t) +>> ... +>>> + (lax-plist-put notmuch-show-message-multipart/alternative (plist-get msg :id) 0))) +>> +>> I can see that might get a little hairy. Can any elisp experts out +>> there think of a better way to do this? (actually, this is making me +>> again want a show mode that only displays one message at a time (which I +>> guess means I need to try pick again)). +> +> This version at least uses the notmuch escaping for message-id which +> makes me a bit happier: it probably doesn't have any nasty security +> flaws. I do still feel that the lisp is a bit ugly though. +> +> Incidentally, Austin suggested I might be able to use text-properties +> rather than this big list. Unfortunately, I use +> notmuch-show-refresh-view to do the redisplay and that deletes all +> text-properties. +> +> Note this is not very well tested as I have very few +> multipart/alternative messages. + +How would this work together with something like [1] (rationale in [2])? + +[1] id:"ab777cf0fa83778d3399ac52094df9230738819d.1328798471.git.jani@nikula.org" +[2] id:"cover.1328719309.git.jani@nikula.org" + +If you introduce a mechanism to store the state, could it be extended to +store the state of each individual part? That, in turn, could be used to +add support for expanding/collapsing each alternative part through the +buttons (e.g. [ text/html (not shown) ]). Each button could toggle the +state of the part, and refresh buffer. + +I guess basically the above are related. If you stored a list of parts +to display per each message id, the initial list could be created based +on customized regexps, the buttons could be used for toggling each +individual part (adding/removing the type from the list), and you could +have a function that would cycle the list to your heart's content. + +BR, +Jani. + + + +> +> Best wishes +> +> Mark +> +> +> emacs/notmuch-show.el | 31 ++++++++++++++++++++++++++++--- +> 1 files changed, 28 insertions(+), 3 deletions(-) +> +> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +> index dcfc190..dee6b85 100644 +> --- a/emacs/notmuch-show.el +> +++ b/emacs/notmuch-show.el +> @@ -154,6 +154,10 @@ indentation." +> (make-variable-buffer-local 'notmuch-show-indent-content) +> (put 'notmuch-show-indent-content 'permanent-local t) +> +> +(defvar notmuch-show-message-multipart/alternative-display-part nil) +> +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-part) +> +(put 'notmuch-show-message-multipart/alternative-display-part 'permanent-local t) +> + +> (defcustom notmuch-show-stash-mlarchive-link-alist +> '(("Gmane" . "http://mid.gmane.org/") +> ("MARC" . "http://marc.info/?i=") +> @@ -536,9 +540,19 @@ message at DEPTH in the current thread." +> +> (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type) +> (notmuch-show-insert-part-header nth declared-type content-type nil) +> - (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) +> - (inner-parts (plist-get part :content)) +> - (start (point))) +> + (let* ((chosen-nth (or (lax-plist-get notmuch-show-message-multipart/alternative-display-part +> + (notmuch-id-to-query (plist-get msg :id))) 0)) +> + (chosen-type (nth chosen-nth +> + (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) +> + (inner-parts (plist-get part :content)) +> + (start (point))) +> + ;; If we have run out of possible content-types restart from the beginning +> + (unless chosen-type +> + (setq chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part)))) +> + (setq notmuch-show-message-multipart/alternative-display-part +> + (lax-plist-put notmuch-show-message-multipart/alternative-display-part +> + (notmuch-id-to-query (plist-get msg :id)) 0))) +> + +> ;; This inserts all parts of the chosen type rather than just one, +> ;; but it's not clear that this is the wrong thing to do - which +> ;; should be chosen if there are more than one that match? +> @@ -942,6 +956,16 @@ message at DEPTH in the current thread." +> "Not processing cryptographic MIME parts.")) +> (notmuch-show-refresh-view)) +> +> +(defun notmuch-show-cycle-message-multipart () +> + "Cycle which part to display of a multipart messageToggle the display of non-matching messages." +> + (interactive) +> + (let* ((msg-id (notmuch-show-get-message-id)) +> + (next-part (1+ (or (lax-plist-get notmuch-show-message-multipart/alternative-display-part msg-id) 0)))) +> + (setq notmuch-show-message-multipart/alternative-display-part +> + (lax-plist-put notmuch-show-message-multipart/alternative-display-part msg-id next-part)) +> + (message "Cycling multipart/alternative for current message") +> + (notmuch-show-refresh-view))) +> + +> (defun notmuch-show-toggle-elide-non-matching () +> "Toggle the display of non-matching messages." +> (interactive) +> @@ -1151,6 +1175,7 @@ reset based on the original query." +> (define-key map "R" 'notmuch-show-reply) +> (define-key map "|" 'notmuch-show-pipe-message) +> (define-key map "w" 'notmuch-show-save-attachments) +> + (define-key map "W" 'notmuch-show-cycle-message-multipart) +> (define-key map "V" 'notmuch-show-view-raw-message) +> (define-key map "v" 'notmuch-show-view-all-mime-parts) +> (define-key map "c" 'notmuch-show-stash-map) +> -- +> 1.7.9.1 -- 2.26.2