[PATCH] RFC: all deleting all properties with a given key
[notmuch-archives.git] / 7a / d7cf166df087b87f2bc4f0ddf7d54a1762eedc
1 Return-Path: <markwalters1009@gmail.com>\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 6A797431FAF\r
6         for <notmuch@notmuchmail.org>; Sun, 15 Jan 2012 04:16:12 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id H+p61UoJ6UdC for <notmuch@notmuchmail.org>;\r
18         Sun, 15 Jan 2012 04:16:11 -0800 (PST)\r
19 Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
20         [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 7139B431FAE\r
23         for <notmuch@notmuchmail.org>; Sun, 15 Jan 2012 04:16:11 -0800 (PST)\r
24 Received: by werh12 with SMTP id h12so667281wer.26\r
25         for <notmuch@notmuchmail.org>; Sun, 15 Jan 2012 04:16:10 -0800 (PST)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
27         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
28         bh=zOn2V4o6eiZgnjmfbphBMFOEn/C+j5/YvUzenhJt0Rw=;\r
29         b=g6g56O4d8eDvTWOqaqeYt3eaWBGPGHM5CqkH8XdM2EIAlNh72WvRVqAyretwsCgWAL\r
30         MhEMw2oKPIrAJbnZegapSa+fu1iu0YuIQJekW8nwmxr+gDZ03FlxOEX1UjfPYskvnQ5m\r
31         Mh3bdMPqFlxD/WaREo2YerX6iiSQjLmdSnRRY=\r
32 Received: by 10.216.133.234 with SMTP id q84mr3296415wei.30.1326629770246;\r
33         Sun, 15 Jan 2012 04:16:10 -0800 (PST)\r
34 Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
35  [94.192.233.223])      by mx.google.com with ESMTPS id\r
36  di5sm27566485wib.3.2012.01.15.04.16.08 (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Sun, 15 Jan 2012 04:16:09 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 1/1] Make buttons for attachments allow viewing as well as\r
41         saving\r
42 Date: Sun, 15 Jan 2012 12:16:36 +0000\r
43 Message-Id: <1326629796-11436-2-git-send-email-markwalters1009@gmail.com>\r
44 X-Mailer: git-send-email 1.7.2.3\r
45 In-Reply-To: <1326629796-11436-1-git-send-email-markwalters1009@gmail.com>\r
46 References: <1326629796-11436-1-git-send-email-markwalters1009@gmail.com>\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sun, 15 Jan 2012 12:16:12 -0000\r
60 \r
61 Define a keymap for attachment buttons to allow multiple actions.\r
62 Define 3 possible actions:\r
63     save attachment: exactly as currently,\r
64     view attachment: uses mailcap entry,\r
65     view attachment with user chosen program\r
66 \r
67 Keymap on a button is: s for save, v for view and o for view with\r
68 other program. Default (i.e. enter or mouse button) is save but is\r
69 easily configurable e.g. set to view with\r
70 (setq notmuch-show-part-button-default-action 'notmuch-show-part-view-action)\r
71 \r
72 One implementation detail: the view attachment function forces all\r
73 attachments to be "displayed" using mailcap even if emacs could\r
74 display them itself. Thus, for example, text/html appears in a browser\r
75 and text/plain asks whether to save (on a standard debian setup)\r
76 ---\r
77  emacs/notmuch-show.el |   81 ++++++++++++++++++++++++++++++++++++++----------\r
78  1 files changed, 64 insertions(+), 17 deletions(-)\r
79 \r
80 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
81 index 03c1f6b..a1c0e63 100644\r
82 --- a/emacs/notmuch-show.el\r
83 +++ b/emacs/notmuch-show.el\r
84 @@ -281,10 +281,21 @@ message at DEPTH in the current thread."\r
85         (run-hooks 'notmuch-show-markup-headers-hook)))))\r
86  \r
87  (define-button-type 'notmuch-show-part-button-type\r
88 -  'action 'notmuch-show-part-button-action\r
89 +  'action 'notmuch-show-part-button-default\r
90 +  'keymap 'notmuch-show-part-button-map\r
91    'follow-link t\r
92    'face 'message-mml)\r
93  \r
94 +(defvar notmuch-show-part-button-map\r
95 +  (let ((map (make-sparse-keymap)))\r
96 +       (set-keymap-parent map button-map)\r
97 +       (define-key map "s" 'notmuch-show-part-button-save)\r
98 +       (define-key map "v" 'notmuch-show-part-button-view)\r
99 +       (define-key map "o" 'notmuch-show-part-button-interactively-view)\r
100 +    map)\r
101 +  "Submap for button commands")\r
102 +(fset 'notmuch-show-part-button-map notmuch-show-part-button-map)\r
103 +\r
104  (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)\r
105    (let ((button))\r
106      (setq button\r
107 @@ -299,29 +310,43 @@ message at DEPTH in the current thread."\r
108                    " ]")\r
109            :type 'notmuch-show-part-button-type\r
110            :notmuch-part nth\r
111 -          :notmuch-filename name))\r
112 +          :notmuch-filename name\r
113 +          :notmuch-content-type content-type))\r
114      (insert "\n")\r
115      ;; return button\r
116      button))\r
117  \r
118  ;; Functions handling particular MIME parts.\r
119  \r
120 +;; this function is kept for the tests and any external users\r
121  (defun notmuch-show-save-part (message-id nth &optional filename)\r
122 +  (notmuch-show-part-action 'notmuch-show-part-save-action message-id nth nil filename))\r
123 +\r
124 +(defun notmuch-show-part-action (action message-id nth content-type &optional filename)\r
125    (let ((process-crypto notmuch-show-process-crypto))\r
126      (with-temp-buffer\r
127        (setq notmuch-show-process-crypto process-crypto)\r
128        ;; Always acquires the part via `notmuch part', even if it is\r
129        ;; available in the JSON output.\r
130        (insert (notmuch-show-get-bodypart-internal message-id nth))\r
131 -      (let ((file (read-file-name\r
132 -                  "Filename to save as: "\r
133 -                  (or mailcap-download-directory "~/")\r
134 -                  nil nil\r
135 -                  filename)))\r
136 -       ;; Don't re-compress .gz & al.  Arguably we should make\r
137 -       ;; `file-name-handler-alist' nil, but that would chop\r
138 -       ;; ange-ftp, which is reasonable to use here.\r
139 -       (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))\r
140 +      (cond ((eq action 'notmuch-show-part-save-action)\r
141 +            (let ((file (read-file-name\r
142 +                         "Filename to save as: "\r
143 +                         (or mailcap-download-directory "~/")\r
144 +                         nil nil\r
145 +                         filename)))\r
146 +              ;; Don't re-compress .gz & al.  Arguably we should make\r
147 +              ;; `file-name-handler-alist' nil, but that would chop\r
148 +              ;; ange-ftp, which is reasonable to use here.\r
149 +              (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))\r
150 +           ((eq action 'notmuch-show-part-view-action)\r
151 +            ;; set mm-inlined-types to nil to force an external viewer\r
152 +            (let ((handle (mm-make-handle (current-buffer) (list content-type)))\r
153 +                  (mm-inlined-types nil))\r
154 +              (mm-display-part handle)))\r
155 +           ((eq action 'notmuch-show-part-interactively-view-action)\r
156 +            (let ((handle (mm-make-handle (current-buffer) (list content-type))))\r
157 +              (mm-interactively-view-part handle)))))))\r
158  \r
159  (defun notmuch-show-mm-display-part-inline (msg part nth content-type)\r
160    "Use the mm-decode/mm-view functions to display a part in the\r
161 @@ -1502,12 +1527,34 @@ buffer."\r
162  \r
163  ;; Commands typically bound to buttons.\r
164  \r
165 -(defun notmuch-show-part-button-action (button)\r
166 -  (let ((nth (button-get button :notmuch-part)))\r
167 -    (if nth\r
168 -       (notmuch-show-save-part (notmuch-show-get-message-id) nth\r
169 -                               (button-get button :notmuch-filename))\r
170 -      (message "Not a valid part (is it a fake part?)."))))\r
171 +(defvar notmuch-show-part-button-default-action 'notmuch-show-part-save-action) \r
172 +\r
173 +(defun notmuch-show-part-button-default (&optional button)\r
174 +  (interactive)\r
175 +  (notmuch-show-part-button notmuch-show-part-button-default-action button))\r
176 +\r
177 +(defun notmuch-show-part-button-save (&optional button)\r
178 +  (interactive)\r
179 +  (notmuch-show-part-button 'notmuch-show-part-save-action button))\r
180 +\r
181 +(defun notmuch-show-part-button-view (&optional button)\r
182 +  (interactive)\r
183 +  (notmuch-show-part-button 'notmuch-show-part-view-action button))\r
184 +\r
185 +(defun notmuch-show-part-button-interactively-view (&optional button)\r
186 +  (interactive)\r
187 +  (notmuch-show-part-button 'notmuch-show-part-interactively-view-action button))\r
188 +\r
189 +(defun notmuch-show-part-button (action &optional button)\r
190 +  (interactive)\r
191 +  (let ((button (or button (button-at (point)))))\r
192 +    (if button\r
193 +      (let ((nth (button-get button :notmuch-part)))\r
194 +       (if nth\r
195 +           (notmuch-show-part-action action (notmuch-show-get-message-id) nth\r
196 +                                   (button-get button :notmuch-content-type)\r
197 +                                   (button-get button :notmuch-filename))\r
198 +         (message "Not a valid part (is it a fake part?)."))))))\r
199  \r
200  ;;\r
201  \r
202 -- \r
203 1.7.2.3\r
204 \r