Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / b6 / 26c4fb4cec7a9d79861d0b7a0aac1157bd5f83
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 2431F431FBC\r
6         for <notmuch@notmuchmail.org>; Fri, 10 Aug 2012 07:53:22 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.677\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.677 tagged_above=-999 required=5\r
12         tests=[HS_INDEX_PARAM=0.023, RCVD_IN_DNSWL_LOW=-0.7]\r
13         autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id cCjr1N5vJdwK for <notmuch@notmuchmail.org>;\r
17         Fri, 10 Aug 2012 07:53:20 -0700 (PDT)\r
18 Received: from mail-yw0-f53.google.com (mail-yw0-f53.google.com\r
19         [209.85.213.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 66FB5431FAF\r
22         for <notmuch@notmuchmail.org>; Fri, 10 Aug 2012 07:53:20 -0700 (PDT)\r
23 Received: by yhp3 with SMTP id 3so2028522yhp.26\r
24         for <notmuch@notmuchmail.org>; Fri, 10 Aug 2012 07:53:18 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
28         :mime-version:content-type:x-gm-message-state;\r
29         bh=JK/vlRaiy4MlvP0zRjGnqjq0OJWIoMUde6YnHPlTXVU=;\r
30         b=kEjkfgI2zo1Yo6e6O9vxKddZGgJ8RKIHQQdeQDpZOL/Ql4aKXY9eRF/uT50Dclo10w\r
31         UW9dsiICAtF7w45+ZQFjSlq5M6qvM4cklQ6Rfr7v58eoPZDSpkFtEhdm0CU5kU7l8aec\r
32         g5wu79SmaOob3zhQtClC4POd44QMjYhi8ZhXrf5FBl7uax/QlwPh3IJphOKtOaXxsmxa\r
33         +7By1iWgqzhuW46AZXl1U2wjzcjYsarvYSUjOdtQlhCc+idduTDMoZ/b05UyX0aP/ggH\r
34         5oFfUX7eNfv454WBCana9JqoMrePTxsaeuMpOntxwK9CiNUCxHmx9f0gKGfW2ba09fir\r
35         jNvw==\r
36 Received: by 10.236.186.101 with SMTP id v65mr3209371yhm.23.1344610398762;\r
37         Fri, 10 Aug 2012 07:53:18 -0700 (PDT)\r
38 Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
39         by mx.google.com with ESMTPS id i3sm3653530anl.0.2012.08.10.07.53.16\r
40         (version=SSLv3 cipher=OTHER); Fri, 10 Aug 2012 07:53:17 -0700 (PDT)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: Mark Walters <markwalters1009@gmail.com>,\r
43         Jameson Graef Rollins <jrollins@finestructure.net>, notmuch@notmuchmail.org\r
44 Subject: Re: [PATCH v2] emacs: add function to toggle display of all\r
45         multipart/alternative parts\r
46 In-Reply-To: <87r4rf9q8x.fsf@qmul.ac.uk>\r
47 References: <1339775751-18002-1-git-send-email-jani@nikula.org>\r
48         <87zk80gvmb.fsf@servo.finestructure.net>\r
49         <87pq8vokmp.fsf@qmul.ac.uk>\r
50         <87ipcrvlcw.fsf@servo.finestructure.net>\r
51         <87r4rf9q8x.fsf@qmul.ac.uk>\r
52 User-Agent: Notmuch/0.13.2+131~gff9267e (http://notmuchmail.org) Emacs/23.2.1\r
53         (x86_64-pc-linux-gnu)\r
54 Date: Fri, 10 Aug 2012 16:53:12 +0200\r
55 Message-ID: <877gt67q93.fsf@nikula.org>\r
56 MIME-Version: 1.0\r
57 Content-Type: text/plain; charset=us-ascii\r
58 X-Gm-Message-State:\r
59  ALoCoQlAf/cic/cOUKGoUfYaPl3/PzEptcbWoIYWC9WP87ry3XHKpLT+4CPFfu6dm8pzDzl1GkXs\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Fri, 10 Aug 2012 14:53:22 -0000\r
73 \r
74 On Fri, 10 Aug 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
75 > Some messages are sent as multipart/alternative but the alternatives\r
76 > contain different information. This allows the user to cycle which\r
77 > part to view. By default this is bound to 'W'.\r
78 > ---\r
79 >\r
80 > On Thu, 09 Aug 2012, Jameson Graef Rollins <jrollins@finestructure.net> wrote:\r
81 >> On Mon, Jun 18 2012, Mark Walters <markwalters1009@gmail.com> wrote:\r
82 >>> I agree with this cycling approach but I think it needs to be per\r
83 >>> message rather than per buffer. I attach a rather hacky attempt at this\r
84 >>> below: on minimal testing it seems to work. But the lisp is really a bit\r
85 >>> gross. In particular  I have no idea if I should be escaping the message\r
86 >>> ids (so this could break in unfortunate/insecure ways)\r
87 >>\r
88 >> Thanks to broken Apple mail clients, I'm getting more and more messages\r
89 >> that have attachments hidden in multipart/"alternatives" to text/plain\r
90 >> parts.  So I would really like to revive this patch.\r
91 >>\r
92 >> I just tested it and it still applies to current master, and actually\r
93 >> seems to work great.  'W' cycles through which part is displayed in the\r
94 >> current message.  Pretty much exactly what I want.\r
95 >>\r
96 >> Mark seems to think this patch is less than ideal.  One issue is that\r
97 >> it's trying to store a setting for a single displayed message in a\r
98 >> variable of full buffer scope.  So he's storing a list of message ids\r
99 >> there:\r
100 >>\r
101 >>> +(defvar notmuch-show-message-multipart/alternative nil)\r
102 >>> +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative)\r
103 >>> +(put 'notmuch-show-message-multipart/alternative 'permanent-local t)\r
104 >> ...\r
105 >>> +       (lax-plist-put notmuch-show-message-multipart/alternative (plist-get msg :id) 0)))\r
106 >>\r
107 >> I can see that might get a little hairy.  Can any elisp experts out\r
108 >> there think of a better way to do this?  (actually, this is making me\r
109 >> again want a show mode that only displays one message at a time (which I\r
110 >> guess means I need to try pick again)).\r
111 >\r
112 > This version at least uses the notmuch escaping for message-id which\r
113 > makes me a bit happier: it probably doesn't have any nasty security\r
114 > flaws. I do still feel that the lisp is a bit ugly though.\r
115 >\r
116 > Incidentally, Austin suggested I might be able to use text-properties\r
117 > rather than this big list. Unfortunately, I use\r
118 > notmuch-show-refresh-view to do the redisplay and that deletes all\r
119 > text-properties.\r
120 >\r
121 > Note this is not very well tested as I have very few\r
122 > multipart/alternative messages.\r
123 \r
124 How would this work together with something like [1] (rationale in [2])?\r
125 \r
126 [1] id:"ab777cf0fa83778d3399ac52094df9230738819d.1328798471.git.jani@nikula.org"\r
127 [2] id:"cover.1328719309.git.jani@nikula.org"\r
128 \r
129 If you introduce a mechanism to store the state, could it be extended to\r
130 store the state of each individual part? That, in turn, could be used to\r
131 add support for expanding/collapsing each alternative part through the\r
132 buttons (e.g. [ text/html (not shown) ]). Each button could toggle the\r
133 state of the part, and refresh buffer.\r
134 \r
135 I guess basically the above are related. If you stored a list of parts\r
136 to display per each message id, the initial list could be created based\r
137 on customized regexps, the buttons could be used for toggling each\r
138 individual part (adding/removing the type from the list), and you could\r
139 have a function that would cycle the list to your heart's content.\r
140 \r
141 BR,\r
142 Jani.\r
143 \r
144 \r
145 \r
146 >\r
147 > Best wishes\r
148 >\r
149 > Mark\r
150 >\r
151 >\r
152 >  emacs/notmuch-show.el |   31 ++++++++++++++++++++++++++++---\r
153 >  1 files changed, 28 insertions(+), 3 deletions(-)\r
154 >\r
155 > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
156 > index dcfc190..dee6b85 100644\r
157 > --- a/emacs/notmuch-show.el\r
158 > +++ b/emacs/notmuch-show.el\r
159 > @@ -154,6 +154,10 @@ indentation."\r
160 >  (make-variable-buffer-local 'notmuch-show-indent-content)\r
161 >  (put 'notmuch-show-indent-content 'permanent-local t)\r
162 >  \r
163 > +(defvar notmuch-show-message-multipart/alternative-display-part nil)\r
164 > +(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-part)\r
165 > +(put 'notmuch-show-message-multipart/alternative-display-part 'permanent-local t)\r
166 > +\r
167 >  (defcustom notmuch-show-stash-mlarchive-link-alist\r
168 >    '(("Gmane" . "http://mid.gmane.org/")\r
169 >      ("MARC" . "http://marc.info/?i=")\r
170 > @@ -536,9 +540,19 @@ message at DEPTH in the current thread."\r
171 >  \r
172 >  (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
173 >    (notmuch-show-insert-part-header nth declared-type content-type nil)\r
174 > -  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
175 > -     (inner-parts (plist-get part :content))\r
176 > -     (start (point)))\r
177 > +  (let* ((chosen-nth (or (lax-plist-get notmuch-show-message-multipart/alternative-display-part\r
178 > +                                     (notmuch-id-to-query (plist-get msg :id))) 0))\r
179 > +      (chosen-type (nth chosen-nth\r
180 > +                       (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
181 > +      (inner-parts (plist-get part :content))\r
182 > +      (start (point)))\r
183 > +    ;; If we have run out of possible content-types restart from the beginning\r
184 > +    (unless chosen-type\r
185 > +      (setq chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
186 > +      (setq notmuch-show-message-multipart/alternative-display-part\r
187 > +         (lax-plist-put notmuch-show-message-multipart/alternative-display-part\r
188 > +                        (notmuch-id-to-query (plist-get msg :id)) 0)))\r
189 > +\r
190 >      ;; This inserts all parts of the chosen type rather than just one,\r
191 >      ;; but it's not clear that this is the wrong thing to do - which\r
192 >      ;; should be chosen if there are more than one that match?\r
193 > @@ -942,6 +956,16 @@ message at DEPTH in the current thread."\r
194 >            "Not processing cryptographic MIME parts."))\r
195 >    (notmuch-show-refresh-view))\r
196 >  \r
197 > +(defun notmuch-show-cycle-message-multipart ()\r
198 > +  "Cycle which part to display of a multipart messageToggle the display of non-matching messages."\r
199 > +  (interactive)\r
200 > +  (let* ((msg-id (notmuch-show-get-message-id))\r
201 > +      (next-part (1+ (or (lax-plist-get notmuch-show-message-multipart/alternative-display-part msg-id) 0))))\r
202 > +    (setq notmuch-show-message-multipart/alternative-display-part\r
203 > +     (lax-plist-put notmuch-show-message-multipart/alternative-display-part msg-id next-part))\r
204 > +    (message "Cycling multipart/alternative for current message")\r
205 > +    (notmuch-show-refresh-view)))\r
206 > +\r
207 >  (defun notmuch-show-toggle-elide-non-matching ()\r
208 >    "Toggle the display of non-matching messages."\r
209 >    (interactive)\r
210 > @@ -1151,6 +1175,7 @@ reset based on the original query."\r
211 >       (define-key map "R" 'notmuch-show-reply)\r
212 >       (define-key map "|" 'notmuch-show-pipe-message)\r
213 >       (define-key map "w" 'notmuch-show-save-attachments)\r
214 > +     (define-key map "W" 'notmuch-show-cycle-message-multipart)\r
215 >       (define-key map "V" 'notmuch-show-view-raw-message)\r
216 >       (define-key map "v" 'notmuch-show-view-all-mime-parts)\r
217 >       (define-key map "c" 'notmuch-show-stash-map)\r
218 > -- \r
219 > 1.7.9.1\r