[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 62 / 40ecdcd7f87db329159f9d0d3a5c7d6aa54db9
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 1CE81429E25\r
6         for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:40:35 -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
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \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 8-dgIgG4XyGR for <notmuch@notmuchmail.org>;\r
17         Thu, 12 Jan 2012 13:40:33 -0800 (PST)\r
18 Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
19         [209.85.212.181]) (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 EAC9B429E35\r
22         for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:40:31 -0800 (PST)\r
23 Received: by mail-wi0-f181.google.com with SMTP id hr12so1742120wib.26\r
24         for <notmuch@notmuchmail.org>; Thu, 12 Jan 2012 13:40:31 -0800 (PST)\r
25 Received: by 10.180.77.200 with SMTP id u8mr9522342wiw.18.1326404431620;\r
26         Thu, 12 Jan 2012 13:40:31 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id bj10sm1864001wib.9.2012.01.12.13.40.29\r
30         (version=SSLv3 cipher=OTHER); Thu, 12 Jan 2012 13:40:30 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH v4 2/5] cli: add support for replying just to the sender in\r
34         "notmuch reply"\r
35 Date: Thu, 12 Jan 2012 23:40:16 +0200\r
36 Message-Id:\r
37  <9be66534c17fbffe00b0c1201f378e60fadd11d1.1326403905.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <cover.1326403905.git.jani@nikula.org>\r
40 References: <cover.1326403905.git.jani@nikula.org>\r
41 In-Reply-To: <cover.1326403905.git.jani@nikula.org>\r
42 References: <cover.1325794371.git.jani@nikula.org>\r
43         <cover.1326403905.git.jani@nikula.org>\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\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: Thu, 12 Jan 2012 21:40:35 -0000\r
57 \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
61 \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
65 \r
66 Signed-off-by: Jani Nikula <jani@nikula.org>\r
67 \r
68 ---\r
69 \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
72 ---\r
73  man/man1/notmuch-reply.1 |   28 ++++++++++++++++++++----\r
74  notmuch-reply.c          |   52 +++++++++++++++++++++++++++++++++++++--------\r
75  2 files changed, 65 insertions(+), 15 deletions(-)\r
76 \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
83  .B notmuch reply\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
89 -recipient list\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
96 +recipient list.\r
97  \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
102  .RE\r
103  .RE\r
104 +.RS\r
105 +.TP 4\r
106 +.BR \-\-reply\-to= ( all | sender )\r
107 +.RS\r
108 +.TP 4\r
109 +.BR all " (default)"\r
110 +Replies to all addresses.\r
111 +.TP 4\r
112 +.BR sender\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
117 +user's addresses.\r
118 +.RE\r
119 +.RE\r
120  \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 4fae66f..b4c81de 100644\r
125 --- a/notmuch-reply.c\r
126 +++ b/notmuch-reply.c\r
127 @@ -289,7 +289,14 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
128      return 0;\r
129  }\r
130  \r
131 -/* Augments the recipients of reply from the headers of message.\r
132 +/* Augment the recipients of 'reply' from the "Reply-to:", "From:", "To:",\r
133 + * "Cc:", and "Bcc:" headers of 'message'.\r
134 + *\r
135 + * If 'reply_all' is true, use sender and all recipients, otherwise scan the\r
136 + * headers for the first that contains something other than the user's addresses\r
137 + * and add the recipients from this header (typically this would be\r
138 + * reply-to-sender, but also handles reply to user's own message in a sensible\r
139 + * way).\r
140   *\r
141   * If any of the user's addresses were found in these headers, the first\r
142   * of these returned, otherwise NULL is returned.\r
143 @@ -297,7 +304,8 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
144  static const char *\r
145  add_recipients_from_message (GMimeMessage *reply,\r
146                              notmuch_config_t *config,\r
147 -                            notmuch_message_t *message)\r
148 +                            notmuch_message_t *message,\r
149 +                            notmuch_bool_t reply_all)\r
150  {\r
151      struct {\r
152         const char *header;\r
153 @@ -311,6 +319,7 @@ add_recipients_from_message (GMimeMessage *reply,\r
154      };\r
155      const char *from_addr = NULL;\r
156      unsigned int i;\r
157 +    unsigned int n = 0;\r
158  \r
159      /* Some mailing lists munge the Reply-To header despite it being A Bad\r
160       * Thing, see http://www.unicom.com/pw/reply-to-harmful.html\r
161 @@ -337,8 +346,23 @@ add_recipients_from_message (GMimeMessage *reply,\r
162             recipients = notmuch_message_get_header (message,\r
163                                                      reply_to_map[i].fallback);\r
164  \r
165 -       scan_address_string (recipients, config, reply,\r
166 -                            reply_to_map[i].recipient_type, &from_addr);\r
167 +       n += scan_address_string (recipients, config, reply,\r
168 +                                 reply_to_map[i].recipient_type, &from_addr);\r
169 +\r
170 +       if (!reply_all && n) {\r
171 +           /* Stop adding new recipients in reply-to-sender mode if we have\r
172 +            * added some recipient(s) above.\r
173 +            *\r
174 +            * This also handles the case of user replying to his own message,\r
175 +            * where reply-to/from is not a recipient. In this case there may be\r
176 +            * more than one recipient even if not replying to all.\r
177 +            */\r
178 +           reply = NULL;\r
179 +\r
180 +           /* From address and some recipients are enough, bail out. */\r
181 +           if (from_addr)\r
182 +               break;\r
183 +       }\r
184      }\r
185  \r
186      return from_addr;\r
187 @@ -482,7 +506,8 @@ static int\r
188  notmuch_reply_format_default(void *ctx,\r
189                              notmuch_config_t *config,\r
190                              notmuch_query_t *query,\r
191 -                            notmuch_show_params_t *params)\r
192 +                            notmuch_show_params_t *params,\r
193 +                            notmuch_bool_t reply_all)\r
194  {\r
195      GMimeMessage *reply;\r
196      notmuch_messages_t *messages;\r
197 @@ -511,7 +536,8 @@ notmuch_reply_format_default(void *ctx,\r
198             g_mime_message_set_subject (reply, subject);\r
199         }\r
200  \r
201 -       from_addr = add_recipients_from_message (reply, config, message);\r
202 +       from_addr = add_recipients_from_message (reply, config, message,\r
203 +                                                reply_all);\r
204  \r
205         if (from_addr == NULL)\r
206             from_addr = guess_from_received_header (config, message);\r
207 @@ -560,7 +586,8 @@ static int\r
208  notmuch_reply_format_headers_only(void *ctx,\r
209                                   notmuch_config_t *config,\r
210                                   notmuch_query_t *query,\r
211 -                                 unused (notmuch_show_params_t *params))\r
212 +                                 unused (notmuch_show_params_t *params),\r
213 +                                 notmuch_bool_t reply_all)\r
214  {\r
215      GMimeMessage *reply;\r
216      notmuch_messages_t *messages;\r
217 @@ -600,7 +627,7 @@ notmuch_reply_format_headers_only(void *ctx,\r
218         g_mime_object_set_header (GMIME_OBJECT (reply),\r
219                                   "References", references);\r
220  \r
221 -       (void)add_recipients_from_message (reply, config, message);\r
222 +       (void)add_recipients_from_message (reply, config, message, reply_all);\r
223  \r
224         reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));\r
225         printf ("%s", reply_headers);\r
226 @@ -627,9 +654,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
227      notmuch_query_t *query;\r
228      char *query_string;\r
229      int opt_index, ret = 0;\r
230 -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
231 +    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
232      notmuch_show_params_t params = { .part = -1 };\r
233      int format = FORMAT_DEFAULT;\r
234 +    int reply_all = TRUE;\r
235      notmuch_bool_t decrypt = FALSE;\r
236  \r
237      notmuch_opt_desc_t options[] = {\r
238 @@ -637,6 +665,10 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
239           (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
240                                   { "headers-only", FORMAT_HEADERS_ONLY },\r
241                                   { 0, 0 } } },\r
242 +       { NOTMUCH_OPT_KEYWORD, &reply_all, "reply-to", 'r',\r
243 +         (notmuch_keyword_t []){ { "all", TRUE },\r
244 +                                 { "sender", FALSE },\r
245 +                                 { 0, 0 } } },\r
246         { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
247         { 0, 0, 0, 0, 0 }\r
248      };\r
249 @@ -690,7 +722,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
250         return 1;\r
251      }\r
252  \r
253 -    if (reply_format_func (ctx, config, query, &params) != 0)\r
254 +    if (reply_format_func (ctx, config, query, &params, reply_all) != 0)\r
255         return 1;\r
256  \r
257      notmuch_query_destroy (query);\r
258 -- \r
259 1.7.5.4\r
260 \r