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 F1D24421167
\r
6 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:41 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 I78OYBw5lfWZ for <notmuch@notmuchmail.org>;
\r
17 Sat, 14 Jan 2012 06:46:38 -0800 (PST)
\r
18 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com
\r
19 [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
20 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
21 603EF421164 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:33 -0800
\r
23 Received: by mail-ee0-f53.google.com with SMTP id d41so20490eek.26
\r
24 for <notmuch@notmuchmail.org>; Sat, 14 Jan 2012 06:46:33 -0800 (PST)
\r
25 Received: by 10.213.113.14 with SMTP id y14mr764170ebp.0.1326552391290;
\r
26 Sat, 14 Jan 2012 06:46:31 -0800 (PST)
\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
29 by mx.google.com with ESMTPS id a60sm44669190eeb.4.2012.01.14.06.46.29
\r
30 (version=SSLv3 cipher=OTHER); Sat, 14 Jan 2012 06:46:30 -0800 (PST)
\r
31 From: Jani Nikula <jani@nikula.org>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH v5 2/5] cli: add support for replying just to the sender in
\r
35 Date: Sat, 14 Jan 2012 16:46:16 +0200
\r
37 <2a6d0eb5a441719155bf001feb3b68553d7c3c55.1326551350.git.jani@nikula.org>
\r
38 X-Mailer: git-send-email 1.7.5.4
\r
39 In-Reply-To: <cover.1326551350.git.jani@nikula.org>
\r
40 References: <cover.1326551350.git.jani@nikula.org>
\r
41 In-Reply-To: <cover.1326551350.git.jani@nikula.org>
\r
42 References: <cover.1325794371.git.jani@nikula.org>
\r
43 <cover.1326551350.git.jani@nikula.org>
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Sat, 14 Jan 2012 14:46:42 -0000
\r
58 Add new option --reply-to=(all|sender) to "notmuch reply" to select whether
\r
59 to reply to all (sender and all recipients), or just sender. Reply to all
\r
60 remains the default.
\r
62 Credits to Mark Walters <markwalters1009@gmail.com> for his similar earlier
\r
63 work where I picked up the basic idea of handling reply-to-sender in
\r
64 add_recipients_from_message(). All bugs are mine, though.
\r
66 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
70 Settled on --reply-to=(all|sender) per Carl's earlier suggestion
\r
71 (id:87pqn5cg4g.fsf@yoom.home.cworth.org) and David's approval on IRC.
\r
73 man/man1/notmuch-reply.1 | 28 ++++++++++++++++++----
\r
74 notmuch-reply.c | 57 ++++++++++++++++++++++++++++++++++++---------
\r
75 2 files changed, 68 insertions(+), 17 deletions(-)
\r
77 diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1
\r
78 index db464d8..5160ece 100644
\r
79 --- a/man/man1/notmuch-reply.1
\r
80 +++ b/man/man1/notmuch-reply.1
\r
81 @@ -14,11 +14,13 @@ Constructs a reply template for a set of messages.
\r
82 To make replying to email easier,
\r
84 takes an existing set of messages and constructs a suitable mail
\r
85 -template. The Reply-to header (if any, otherwise From:) is used for
\r
86 -the To: address. Vales from the To: and Cc: headers are copied, but
\r
87 -not including any of the current user's email addresses (as configured
\r
88 -in primary_mail or other_email in the .notmuch\-config file) in the
\r
90 +template. The Reply-to: header (if any, otherwise From:) is used for
\r
91 +the To: address. Unless
\r
92 +.BR \-\-reply-to=sender
\r
93 +is specified, values from the To: and Cc: headers are copied, but not
\r
94 +including any of the current user's email addresses (as configured in
\r
95 +primary_mail or other_email in the .notmuch\-config file) in the
\r
98 It also builds a suitable new subject, including Re: at the front (if
\r
99 not already present), and adding the message IDs of the messages being
\r
100 @@ -45,6 +47,22 @@ Includes subject and quoted message body.
\r
101 Only produces In\-Reply\-To, References, To, Cc, and Bcc headers.
\r
106 +.BR \-\-reply\-to= ( all | sender )
\r
109 +.BR all " (default)"
\r
110 +Replies to all addresses.
\r
113 +Replies only to the sender. If replying to user's own message
\r
114 +(Reply-to: or From: header is one of the user's configured email
\r
115 +addresses), try To:, Cc:, and Bcc: headers in this order, and copy
\r
116 +values from the first that contains something other than only the
\r
121 See \fBnotmuch-search-terms\fR(7)
\r
122 for details of the supported syntax for <search-terms>.
\r
123 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
124 index a8d6a94..da3acce 100644
\r
125 --- a/notmuch-reply.c
\r
126 +++ b/notmuch-reply.c
\r
127 @@ -291,15 +291,23 @@ reply_to_header_is_redundant (notmuch_message_t *message)
\r
131 -/* Augments the recipients of reply from the headers of message.
\r
132 +/* Augment the recipients of 'reply' from the "Reply-to:", "From:",
\r
133 + * "To:", "Cc:", and "Bcc:" headers of 'message'.
\r
135 - * If any of the user's addresses were found in these headers, the first
\r
136 - * of these returned, otherwise NULL is returned.
\r
137 + * If 'reply_all' is true, use sender and all recipients, otherwise
\r
138 + * scan the headers for the first that contains something other than
\r
139 + * the user's addresses and add the recipients from this header
\r
140 + * (typically this would be reply-to-sender, but also handles reply to
\r
141 + * user's own message in a sensible way).
\r
143 + * If any of the user's addresses were found in these headers, the
\r
144 + * first of these returned, otherwise NULL is returned.
\r
146 static const char *
\r
147 add_recipients_from_message (GMimeMessage *reply,
\r
148 notmuch_config_t *config,
\r
149 - notmuch_message_t *message)
\r
150 + notmuch_message_t *message,
\r
151 + notmuch_bool_t reply_all)
\r
154 const char *header;
\r
155 @@ -313,6 +321,7 @@ add_recipients_from_message (GMimeMessage *reply,
\r
157 const char *from_addr = NULL;
\r
159 + unsigned int n = 0;
\r
161 /* Some mailing lists munge the Reply-To header despite it being A Bad
\r
162 * Thing, see http://www.unicom.com/pw/reply-to-harmful.html
\r
163 @@ -339,8 +348,24 @@ add_recipients_from_message (GMimeMessage *reply,
\r
164 recipients = notmuch_message_get_header (message,
\r
165 reply_to_map[i].fallback);
\r
167 - scan_address_string (recipients, config, reply,
\r
168 - reply_to_map[i].recipient_type, &from_addr);
\r
169 + n += scan_address_string (recipients, config, reply,
\r
170 + reply_to_map[i].recipient_type, &from_addr);
\r
172 + if (!reply_all && n) {
\r
173 + /* Stop adding new recipients in reply-to-sender mode if
\r
174 + * we have added some recipient(s) above.
\r
176 + * This also handles the case of user replying to his own
\r
177 + * message, where reply-to/from is not a recipient. In
\r
178 + * this case there may be more than one recipient even if
\r
179 + * not replying to all.
\r
183 + /* From address and some recipients are enough, bail out. */
\r
190 @@ -484,7 +509,8 @@ static int
\r
191 notmuch_reply_format_default(void *ctx,
\r
192 notmuch_config_t *config,
\r
193 notmuch_query_t *query,
\r
194 - notmuch_show_params_t *params)
\r
195 + notmuch_show_params_t *params,
\r
196 + notmuch_bool_t reply_all)
\r
198 GMimeMessage *reply;
\r
199 notmuch_messages_t *messages;
\r
200 @@ -513,7 +539,8 @@ notmuch_reply_format_default(void *ctx,
\r
201 g_mime_message_set_subject (reply, subject);
\r
204 - from_addr = add_recipients_from_message (reply, config, message);
\r
205 + from_addr = add_recipients_from_message (reply, config, message,
\r
208 if (from_addr == NULL)
\r
209 from_addr = guess_from_received_header (config, message);
\r
210 @@ -562,7 +589,8 @@ static int
\r
211 notmuch_reply_format_headers_only(void *ctx,
\r
212 notmuch_config_t *config,
\r
213 notmuch_query_t *query,
\r
214 - unused (notmuch_show_params_t *params))
\r
215 + unused (notmuch_show_params_t *params),
\r
216 + notmuch_bool_t reply_all)
\r
218 GMimeMessage *reply;
\r
219 notmuch_messages_t *messages;
\r
220 @@ -602,7 +630,7 @@ notmuch_reply_format_headers_only(void *ctx,
\r
221 g_mime_object_set_header (GMIME_OBJECT (reply),
\r
222 "References", references);
\r
224 - (void)add_recipients_from_message (reply, config, message);
\r
225 + (void)add_recipients_from_message (reply, config, message, reply_all);
\r
227 reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));
\r
228 printf ("%s", reply_headers);
\r
229 @@ -629,9 +657,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
230 notmuch_query_t *query;
\r
231 char *query_string;
\r
232 int opt_index, ret = 0;
\r
233 - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);
\r
234 + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);
\r
235 notmuch_show_params_t params = { .part = -1 };
\r
236 int format = FORMAT_DEFAULT;
\r
237 + int reply_all = TRUE;
\r
238 notmuch_bool_t decrypt = FALSE;
\r
240 notmuch_opt_desc_t options[] = {
\r
241 @@ -639,6 +668,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
242 (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
\r
243 { "headers-only", FORMAT_HEADERS_ONLY },
\r
245 + { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',
\r
246 + (notmuch_keyword_t []){ { "all", TRUE },
\r
247 + { "sender", FALSE },
\r
249 { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },
\r
252 @@ -692,7 +725,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
\r
256 - if (reply_format_func (ctx, config, query, ¶ms) != 0)
\r
257 + if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0)
\r
260 notmuch_query_destroy (query);
\r