Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / ea / 93210a93e10f25e6ececf530bbd93828b31125
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 1117F6DE01D0\r
6  for <notmuch@notmuchmail.org>; Thu,  2 Jun 2016 17:58:09 -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.323\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.323 tagged_above=-999 required=5 tests=[AWL=0.247,\r
12   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, RCVD_IN_DNSWL_LOW=-0.7,\r
14  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001]\r
15  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 mN0wW-DIWM9u for <notmuch@notmuchmail.org>;\r
19  Thu,  2 Jun 2016 17:58:01 -0700 (PDT)\r
20 Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com\r
21  [74.125.82.68]) by arlo.cworth.org (Postfix) with ESMTPS id 8E31C6DE00DB for\r
22  <notmuch@notmuchmail.org>; Thu,  2 Jun 2016 17:58:00 -0700 (PDT)\r
23 Received: by mail-wm0-f68.google.com with SMTP id a20so8343045wma.3\r
24  for <notmuch@notmuchmail.org>; Thu, 02 Jun 2016 17:58:00 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26  h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
27  bh=+uaVGQFH7IB3pkUFxo2nEl4IaRrZJdSb3Sfs0Nt70S8=;\r
28  b=xb/W0uSbMvuEE+Go1fmibUKWwS4TCVPEEz41SHy/RyZMPdPgGd3IyzliuyFu7gQrVT\r
29  juG0VxmcpaqENd+Z2O3hCNjfR/xMLTcDiHYCOx8TDZaFjbe/y2HG+pnw7+TUNZ6byYQO\r
30  mRU3jbiwpnLBijswbvUqQL9/+joIYTaoczZLyFCrLqR8WwM/qKs4Ft+QwDK3YWLKNb0M\r
31  c+DIeT2aduEJQOADJMtJW1+iWXBUGIdalWIr9wyT+lxHVXAiHQV1sJGGWo6XjiJioCk5\r
32  a/wgAXXucGoBs0CjMw5CHnarjUF0KtGsbTMXbWkkbFT2QwA5HsgqH8UTuG5EMWrmtfB3\r
33  z0Pg==\r
34 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
35  d=1e100.net; s=20130820;\r
36  h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
37  :references;\r
38  bh=+uaVGQFH7IB3pkUFxo2nEl4IaRrZJdSb3Sfs0Nt70S8=;\r
39  b=GxTtC72+t8zWmg4vTkAwZYx5keaXFFq9fa0IlKD8ZPjg+6jpQkjaZHt/8xBRf1cG/z\r
40  XC59hy0/keLBIx0pGZKCchHax9qkFmHfxe6L/KI5EEmU5u4hP4QeAkMFScJ4hO3V+C1f\r
41  CpbGEB3xWA7EHIRqHq2WMj9N3E8YtJjTFOMv7tHhJ9ARqqgKmsfFM0s+6D0aiQVeu/Ls\r
42  U1u1EeXocKwAho4ji1ufxeYRX+DtKA5hR194ELLJgmDF/LR6gS58ZEID0XDlIkfDev+y\r
43  G1QHqAnydstjvGR8Cm97w3eKLn3+IbdbfArBCpVIIdbXEi13OwwVvIsqAOWfhZ3YU0it\r
44  N6Iw==\r
45 X-Gm-Message-State:\r
46  ALyK8tKt61/2M9L5a7MZMr3pLImfThA1YcOyp1bbO0bX3ODISa1ayaQyGKvO/iZcxbbwww==\r
47 X-Received: by 10.194.235.193 with SMTP id uo1mr714133wjc.1.1464915478853;\r
48  Thu, 02 Jun 2016 17:57:58 -0700 (PDT)\r
49 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
50  by smtp.gmail.com with ESMTPSA id kc2sm3095384wjb.5.2016.06.02.17.57.57\r
51  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
52  Thu, 02 Jun 2016 17:57:58 -0700 (PDT)\r
53 From: Mark Walters <markwalters1009@gmail.com>\r
54 To: notmuch@notmuchmail.org\r
55 Subject: [WIP PATCH] emacs:  postpone/resume support\r
56 Date: Fri,  3 Jun 2016 01:57:52 +0100\r
57 Message-Id: <1464915472-5669-1-git-send-email-markwalters1009@gmail.com>\r
58 X-Mailer: git-send-email 2.1.4\r
59 In-Reply-To: <87mvn330zr.fsf@qmul.ac.uk>\r
60 References: <87mvn330zr.fsf@qmul.ac.uk>\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.20\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65  <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
67  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
72  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Fri, 03 Jun 2016 00:58:09 -0000\r
74 \r
75 This provides preliminary support for postponing and resuming in the\r
76 emacs frontend. On postponing it uses notmuch insert to put the\r
77 message in the notmuch database; resume gets the raw file from notmuch\r
78 and using the emacs function mime-to-mml reconstructs the message\r
79 (including attachments).\r
80 ---\r
81 \r
82 This is a WIP patch enabling postpone/resume. On very light testing so\r
83 far it seems to work surprisingly well.\r
84 \r
85 Please note that it is an early version, so it may eat your draft\r
86 message, mangle (or mysteriously corrupt) your draft message etc; and\r
87 it each draft will remain in your message store unless you manually\r
88 delete it.\r
89 \r
90 To use: to postpone just do M-x notmuch-message-postpone in your\r
91 compose buffer. To resume fo M-x notmuch-message-resume while on the\r
92 correct message in a show buffer. You may want to add "draft" to your\r
93 exclude tags in .notmuch-config so that drafts only show up if you\r
94 search for them explicitly.\r
95 \r
96 CAVEATS:\r
97 \r
98 Attachments work, but the attachment that is sent is the attachment\r
99 that was there when the message was postponed. (Attachments added\r
100 after resume are obviously not added until the message is sent.)\r
101 \r
102 If the database is locked when you try and postpone it will\r
103 mysteriously fail. I think this is actually caused by a bug elsewhere\r
104 in notmuch. But in any case the compose buffer should not be killed in\r
105 this case.\r
106 \r
107 It would probably be nice to delete the messages on resume. Since we\r
108 don't really have that functionality, we just add a deleted tag. This\r
109 will hide them in search buffers but, if you postpone a reply, it ill\r
110 still show up (collapsed) in the show buffer for the thread.\r
111 \r
112 If you resume a postponed message and then postpone again without\r
113 editting then the deleted tag will not be removed so the message may\r
114 be hard to find. (see below for possible fixed for this)\r
115 \r
116 Messages don't get a date header as emacs adds that when it sends it\r
117 so notmuch will list all postponed message as 1 Jan 1970. \r
118 \r
119 If you use signing or encryption then I don't know what will happen --\r
120 I have not tested at all.  You might sign a partial message that you\r
121 didn't mean too; you might expose plain text to someone.\r
122 \r
123 WHAT NEEDS DOING\r
124 \r
125 Trivially we would want some keybindings for the two commands (any\r
126 suggested keybindings gratefully received). More significantly, I\r
127 would either like a flag to notmuch insert to say "make these tag\r
128 changes even if the message already exists"; or perhaps a notmuch\r
129 delete command that (genuinely) deletes a single message.\r
130 \r
131 Best wishes\r
132 \r
133 Mark\r
134 \r
135 \r
136 \r
137 emacs/notmuch-message.el | 90 ++++++++++++++++++++++++++++++++++++++++++++++++\r
138  1 file changed, 90 insertions(+)\r
139 \r
140 diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el\r
141 index d437b85..fdd91c0 100644\r
142 --- a/emacs/notmuch-message.el\r
143 +++ b/emacs/notmuch-message.el\r
144 @@ -25,6 +25,8 @@\r
145  (require 'notmuch-tag)\r
146  (require 'notmuch-mua)\r
147  \r
148 +(declare-function notmuch-show-get-message-id "notmuch-show" (&optional bare))\r
149 +\r
150  (defcustom notmuch-message-replied-tags '("+replied")\r
151    "List of tag changes to apply to a message when it has been replied to.\r
152  \r
153 @@ -38,6 +40,28 @@ the \"inbox\" and \"todo\" tags, you would set:\r
154    :type '(repeat string)\r
155    :group 'notmuch-send)\r
156  \r
157 +(defcustom notmuch-message-draft-tags '("+draft")\r
158 +  "List of tags changes to apply to a draft message when it is saved in the database.\r
159 +\r
160 +Tags starting with \"+\" (or not starting with either \"+\" or\r
161 +\"-\") in the list will be added, and tags starting with \"-\"\r
162 +will be removed from the message being stored.\r
163 +\r
164 +For example, if you wanted to give the message a \"draft\" tag\r
165 +but not the (normally added by default) \"inbox\" tag, you would\r
166 +set:\r
167 +    (\"+draft\" \"-inbox\")"\r
168 +  :type '(repeat string)\r
169 +  :group 'notmuch-send)\r
170 +\r
171 +(defcustom notmuch-message-draft-folder "drafts"\r
172 +  "Folder to save draft messages in.\r
173 +\r
174 +This should be specified relative to the root of the notmuch\r
175 +database. It will be created if necessary."\r
176 +  :type 'string\r
177 +  :group 'notmuch-send)\r
178 +\r
179  (defun notmuch-message-mark-replied ()\r
180    ;; get the in-reply-to header and parse it for the message id.\r
181    (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))\r
182 @@ -45,6 +69,72 @@ the \"inbox\" and \"todo\" tags, you would set:\r
183        (notmuch-tag (notmuch-id-to-query (car (car rep)))\r
184                (notmuch-tag-change-list notmuch-message-replied-tags)))))\r
185  \r
186 +(defun notmuch-message-postpone ()\r
187 +  "Save the current draft message in the notmuch database.\r
188 +\r
189 +This saves the current message in the database with tags\r
190 +`notmuch-message-draft-tags` (in addition to any default tags\r
191 +applied to newly inserted messages)."\r
192 +  ;; This is taken from message-do-fcc but modified for our needs.  In\r
193 +  ;; particular we don't want to process other fcc lines, nor remove\r
194 +  ;; them. Note some of the following may not be needed -- I tried to\r
195 +  ;; stay close to the original function.\r
196 +  (interactive)\r
197 +  (let ((case-fold-search t)\r
198 +       (buf (current-buffer))\r
199 +       (mml-externalize-attachments nil))\r
200 +    (with-current-buffer (get-buffer-create " *message temp*")\r
201 +      (erase-buffer)\r
202 +      (insert-buffer-substring buf)\r
203 +      (message-encode-message-body)\r
204 +      (save-restriction\r
205 +       (message-narrow-to-headers)\r
206 +       (let ((mail-parse-charset message-default-charset)\r
207 +             (rfc2047-header-encoding-alist\r
208 +              (cons '("Newsgroups" . default)\r
209 +                    rfc2047-header-encoding-alist)))\r
210 +         (mail-encode-encoded-word-buffer)))\r
211 +      (goto-char (point-min))\r
212 +      (when (re-search-forward\r
213 +            (concat "^" (regexp-quote mail-header-separator) "$")\r
214 +            nil t)\r
215 +       (replace-match "" t t ))\r
216 +\r
217 +      ;; Unless the user has entered a message-id manually the message\r
218 +      ;; does not have one -- thus notmuch will use the sha1 of the\r
219 +      ;; message. Hence we should only get a collision if the message\r
220 +      ;; is identical to a previous draft. In this case we should\r
221 +      ;; remove the deleted tag, but it is not clear howto.\r
222 +      (apply 'notmuch-call-notmuch-process :stdin-string (buffer-string)\r
223 +            "insert" "--create-folder"\r
224 +            (concat "--folder=" notmuch-message-draft-folder)\r
225 +            notmuch-message-draft-tags)))\r
226 +  ;; The function notmuch-call-notmuch-process signals an error on failure, so\r
227 +  ;; to get to this point it must have succeeded.\r
228 +  (set-buffer-modified-p nil)\r
229 +  (kill-buffer))\r
230 +\r
231 +(defun notmuch-message-resume (&optional id)\r
232 +  "View the original source of the current message."\r
233 +  (interactive)\r
234 +  (let* ((id (or id (notmuch-show-get-message-id)))\r
235 +        (buf (get-buffer-create (concat "*notmuch-draft-" id "*")))\r
236 +        (inhibit-read-only t))\r
237 +    (switch-to-buffer buf)\r
238 +    (setq buffer-read-only nil)\r
239 +    (erase-buffer)\r
240 +    (let ((coding-system-for-read 'no-conversion))\r
241 +      (call-process notmuch-command nil t nil "show" "--format=raw" id))\r
242 +    (mime-to-mml)\r
243 +    (goto-char (point-min))\r
244 +    (when (re-search-forward "^$" nil t)\r
245 +      (replace-match mail-header-separator t t))\r
246 +    (notmuch-message-mode)\r
247 +    (set-buffer-modified-p t)\r
248 +    ;; Delete the message (since we can't do this yet just tag it deleted).\r
249 +    (notmuch-tag id '("+deleted"))))\r
250 +\r
251 +\r
252  (add-hook 'message-send-hook 'notmuch-message-mark-replied)\r
253  \r
254  (provide 'notmuch-message)\r
255 -- \r
256 2.1.4\r
257 \r