Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 7a / 0674f00dff2f9691dde0937825f0b2d7b1935c
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 arlo.cworth.org (Postfix) with ESMTP id F044A6DE0B44\r
6  for <notmuch@notmuchmail.org>; Tue, 30 Jun 2015 15:17:07 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.57\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.57 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=0.25, FREEMAIL_FROM=0.001,\r
14  RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
15  RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled\r
16 Received: from arlo.cworth.org ([127.0.0.1])\r
17  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
18  with ESMTP id 1mi7kF5JRyST for <notmuch@notmuchmail.org>;\r
19  Tue, 30 Jun 2015 15:17:06 -0700 (PDT)\r
20 Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com\r
21  [209.85.212.177])\r
22  by arlo.cworth.org (Postfix) with ESMTPS id AF8B06DE0948\r
23  for <notmuch@notmuchmail.org>; Tue, 30 Jun 2015 15:17:05 -0700 (PDT)\r
24 Received: by wicgi11 with SMTP id gi11so29392380wic.0\r
25  for <notmuch@notmuchmail.org>; Tue, 30 Jun 2015 15:17:03 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27  h=from:to:cc:subject:date:message-id;\r
28  bh=v2lE64GRA2/7MEmcMxXlftVLMSo3V0NLETjr6vldIXI=;\r
29  b=HSGJIFGFKbuEV0HsRB9VwwCcjlg8mFl4IWfzZo3ze+oimT4oFewTKOJXLEopBT7bi8\r
30  imQ53vY1ocv4RihqmUMFkSVeZreAamcsC1eDncI1lko1TrnxCs5vdmRpQPIixXiLW6JI\r
31  aO9/u8XvnVZgxZzT77GfkiJFE2ut+LKXkbi167n3d1N/u3mp57u0YxP0qN86QE6QrRXG\r
32  ZwGdYPBe8M5kKyibsRAaLrDWgfASkDjaR0fHXKkbN0qJqsFmYiYBU2agPyqaOXGhwBQg\r
33  XPVEvPWjRqaT766isAJICZ/8RASEij61HAGSqJnmNf362AjD7YK2ruvEEbQFEeCtTBQO\r
34  5lcQ==\r
35 X-Received: by 10.194.82.38 with SMTP id f6mr40203477wjy.16.1435702623246;\r
36  Tue, 30 Jun 2015 15:17:03 -0700 (PDT)\r
37 Received: from localhost ([92.54.140.178])\r
38  by mx.google.com with ESMTPSA id jy6sm65857417wjc.4.2015.06.30.15.17.02\r
39  (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
40  Tue, 30 Jun 2015 15:17:02 -0700 (PDT)\r
41 From: Mark Walters <markwalters1009@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH] emacs: show: let the user override the mime-type of an\r
44  attachment\r
45 Date: Tue, 30 Jun 2015 23:16:25 +0100\r
46 Message-Id: <1435702585-27363-1-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 2.1.4\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.18\r
50 Precedence: list\r
51 List-Id: "Use and development of the notmuch mail system."\r
52  <notmuch.notmuchmail.org>\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
54  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
56 List-Post: <mailto:notmuch@notmuchmail.org>\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
59  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
60 X-List-Received-Date: Tue, 30 Jun 2015 22:17:08 -0000\r
61 \r
62 This allows the user to override the mime-type of a part in the show\r
63 buffer. This takes the simple option of displaying the part with the\r
64 specified mime-type in its own buffer (in view mode). This avoids\r
65 further complicating the part handling code.\r
66 \r
67 Bound to ". m" (i.e., m in the part map). Then the user can either\r
68 enter a mime-type or press return for the default choice of\r
69 text/plain.\r
70 ---\r
71 \r
72 Jani and dkg suggested something like this on irc. \r
73 \r
74 As mentioned in the commit message I have taken the simpler option of\r
75 displaying the part in its own buffer: the part handling with lazy\r
76 parts and hidden parts etc is really very complicated and fragile so I\r
77 do not think it sensible to complicate it further for a relatively\r
78 uncommon use case.\r
79 \r
80 It would be nice to have some completions for the mime-type but that\r
81 could always be added later.\r
82 \r
83 Best wishes\r
84 \r
85 Mark\r
86 \r
87 \r
88  emacs/notmuch-show.el | 35 +++++++++++++++++++++++++++++------\r
89  1 file changed, 29 insertions(+), 6 deletions(-)\r
90 \r
91 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
92 index 2a53461..c674e9c 100644\r
93 --- a/emacs/notmuch-show.el\r
94 +++ b/emacs/notmuch-show.el\r
95 @@ -1354,6 +1354,7 @@ reset based on the original query."\r
96      (define-key map "v" 'notmuch-show-view-part)\r
97      (define-key map "o" 'notmuch-show-interactively-view-part)\r
98      (define-key map "|" 'notmuch-show-pipe-part)\r
99 +    (define-key map "m" 'notmuch-show-choose-mime-of-part)\r
100      (define-key map "?" 'notmuch-subkeymap-help)\r
101      map)\r
102    "Submap for part commands")\r
103 @@ -2243,25 +2244,27 @@ omit --in-reply-to=<Message-Id>."\r
104        (insert (notmuch-get-bodypart-binary msg part process-crypto)))\r
105      buf))\r
106  \r
107 -(defun notmuch-show-current-part-handle ()\r
108 +(defun notmuch-show-current-part-handle (&optional mime-type)\r
109    "Return an mm-handle for the part containing point.\r
110  \r
111  This creates a temporary buffer for the part's content; the\r
112 -caller is responsible for killing this buffer as appropriate."\r
113 +caller is responsible for killing this buffer as appropriate.  If\r
114 +MIME-TYPE is given then set the handle's mime-type to MIME-TYPE."\r
115    (let* ((msg (notmuch-show-get-message-properties))\r
116          (part (notmuch-show-get-part-properties))\r
117          (buf (notmuch-show-generate-part-buffer msg part))\r
118 -        (computed-type (plist-get part :computed-type))\r
119 +        (computed-type (or mime-type (plist-get part :computed-type)))\r
120          (filename (plist-get part :filename))\r
121          (disposition (if filename `(attachment (filename . ,filename)))))\r
122      (mm-make-handle buf (list computed-type) nil nil disposition)))\r
123  \r
124 -(defun notmuch-show-apply-to-current-part-handle (fn)\r
125 +(defun notmuch-show-apply-to-current-part-handle (fn &optional mime-type)\r
126    "Apply FN to an mm-handle for the part containing point.\r
127  \r
128  This ensures that the temporary buffer created for the mm-handle\r
129 -is destroyed when FN returns."\r
130 -  (let ((handle (notmuch-show-current-part-handle)))\r
131 +is destroyed when FN returns. If MIME-TYPE is given then force\r
132 +part to be treated as if it had that mime-type."\r
133 +  (let ((handle (notmuch-show-current-part-handle mime-type)))\r
134      ;; emacs 24.3+ puts stdout/stderr into the calling buffer so we\r
135      ;; call it from a temp-buffer, unless\r
136      ;; notmuch-show-attachment-debug is non-nil in which case we put\r
137 @@ -2306,4 +2309,24 @@ is destroyed when FN returns."\r
138    (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))\r
139  \r
140  \r
141 +(defun notmuch-show-internal-mm-display-part (handle)\r
142 +  "Use mm-display-part to display HANDLE in a new buffer.\r
143 +\r
144 +If the part is displayed in an external application then close\r
145 +the new buffer."\r
146 +  (let ((buf (get-buffer-create (generate-new-buffer-name\r
147 +                                (concat " *notmuch-internal-part*")))))\r
148 +    (switch-to-buffer buf)\r
149 +    (if (eq (mm-display-part handle) 'external)\r
150 +       (kill-buffer buf)\r
151 +      (goto-char (point-min))\r
152 +      (set-buffer-modified-p nil)\r
153 +      (view-buffer buf 'kill-buffer-if-not-modified))))\r
154 +\r
155 +(defun notmuch-show-choose-mime-of-part (mime-type)\r
156 +  "Choose the mime type to use for displaying part"\r
157 +  (interactive\r
158 +   (list (read-string "Mime type to use (default text/plain): " nil nil "text/plain")))\r
159 +  (notmuch-show-apply-to-current-part-handle #'notmuch-show-internal-mm-display-part mime-type))\r
160 +\r
161  (provide 'notmuch-show)\r
162 -- \r
163 2.1.4\r
164 \r