Re: [PATCH v2] emacs: add function to toggle display of all multipart/alternative...
authorJani Nikula <jani@nikula.org>
Fri, 10 Aug 2012 14:53:12 +0000 (16:53 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:49:01 +0000 (09:49 -0800)
b6/26c4fb4cec7a9d79861d0b7a0aac1157bd5f83 [new file with mode: 0644]

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