--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 1EF5C431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 10 Aug 2012 00:10:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.075\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.075 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ HS_INDEX_PARAM=0.023, NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3]\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 DlOILAz4Qr0z for <notmuch@notmuchmail.org>;\r
+ Fri, 10 Aug 2012 00:10:41 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id C5637431FAE\r
+ for <notmuch@notmuchmail.org>; Fri, 10 Aug 2012 00:10:40 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SzjMh-0004Uo-FL; Fri, 10 Aug 2012 08:10:35 +0100\r
+Received: from 94.196.1.178.threembb.co.uk ([94.196.1.178] helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SzjMf-000026-CM; Fri, 10 Aug 2012 08:10:35 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Jameson Graef Rollins <jrollins@finestructure.net>,\r
+ Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: [PATCH v2] emacs: add function to toggle display of all\r
+ multipart/alternative parts\r
+In-Reply-To: <87ipcrvlcw.fsf@servo.finestructure.net>\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
+User-Agent: Notmuch/0.13.2+96~g634443c (http://notmuchmail.org) Emacs/23.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Fri, 10 Aug 2012 08:10:22 +0100\r
+Message-ID: <87r4rf9q8x.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.196.1.178\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 897d34d194abf11b27fa6d51cbf86e8a (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * 0.5 QM_SPAMMYURI URI: \".info\" uri is common in spam.\r
+ * 0.0 HS_INDEX_PARAM URI: Link contains a common tracker pattern.\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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 07:10:42 -0000\r
+\r
+\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
+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
+\r