Re: [PATCH v4 09/16] index encrypted parts when asked.
[notmuch-archives.git] / a4 / 51a99b4eb9c133f8b7a59b84e32b491a71c9fd
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 53BAB4044E2\r
6         for <notmuch@notmuchmail.org>; Fri,  6 Jan 2012 05:34:01 -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 n-4swIhbDmpX for <notmuch@notmuchmail.org>;\r
18         Fri,  6 Jan 2012 05:34:00 -0800 (PST)\r
19 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
20  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
21  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
22  5819E4044C1    for <notmuch@notmuchmail.org>; Fri,  6 Jan 2012 05:34:00 -0800\r
23  (PST)\r
24 Received: by wgbds13 with SMTP id ds13so1456735wgb.2\r
25         for <notmuch@notmuchmail.org>; Fri, 06 Jan 2012 05:33:59 -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=ppYehgf4seoxwcpYC12wdtvnF/gdPhRy17W25ve0VVE=;\r
29         b=Fra+U9adkvsant4I1pbrNGJKg15rpsDwXxzWVLwtibH97XmQ5GWkmwN5St+hpcpdm1\r
30         O/t8hW0z7eo8HYj3sn22xRmTSHsuBEuVSm4kS2K/LEsXDwMaEmkjC84lus6fyEgWbOwu\r
31         DtQQUPkrE5/Q8pMCEjVnKH3d8Y42dISB1Cew4=\r
32 Received: by 10.180.83.104 with SMTP id p8mr7255293wiy.4.1325856839203;\r
33         Fri, 06 Jan 2012 05:33:59 -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  w8sm148026931wiz.4.2012.01.06.05.33.57 (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Fri, 06 Jan 2012 05:33:58 -0800 (PST)\r
38 From: Mark Walters <markwalters1009@gmail.com>\r
39 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org, david@tethera.net\r
40 Subject: [PATCH 1/4] Add the option "--reply-to" to notmuch reply.\r
41 Date: Fri,  6 Jan 2012 13:34:14 +0000\r
42 Message-Id: <1325856857-15969-1-git-send-email-markwalters1009@gmail.com>\r
43 X-Mailer: git-send-email 1.7.2.3\r
44 In-Reply-To: <8739btdkir.fsf@qmul.ac.uk>\r
45 References: <8739btdkir.fsf@qmul.ac.uk>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Fri, 06 Jan 2012 13:34:01 -0000\r
59 \r
60     Possible values for this option are "sender" which replies just to\r
61     sender and "all" (the default).\r
62 \r
63     More precisely reply to sender follows these rules:\r
64     reply only to sender unless it was the user\r
65     reply only to all people on the "to" line unless they were all the user\r
66     reply to all people on the "cc" line\r
67 \r
68     Implementation details\r
69 \r
70     We continue parsing addresses beyond the ones we reply to because\r
71     we want to make sure the from address is correct. (At the very least it\r
72     is the same as it would be if we replied to all.)\r
73 \r
74     We overload the message variable in add_recipients_for_address_list so\r
75     if it is NULL we parse the address (looking for the users address)\r
76     but do not add to the message recipients list\r
77 \r
78     We add the variable reply_to_all to the function chain to keep track\r
79     of whether we should reply to everyone.\r
80 ---\r
81  notmuch-reply.c |   48 +++++++++++++++++++++++++++++++++++++-----------\r
82  1 files changed, 37 insertions(+), 11 deletions(-)\r
83 \r
84 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
85 index f8d5f64..9a77fe6 100644\r
86 --- a/notmuch-reply.c\r
87 +++ b/notmuch-reply.c\r
88 @@ -212,7 +212,8 @@ add_recipients_for_address_list (GMimeMessage *message,\r
89                 if (ret == NULL)\r
90                     ret = addr;\r
91             } else {\r
92 -               g_mime_message_add_recipient (message, type, name, addr);\r
93 +                if (message)\r
94 +                     g_mime_message_add_recipient (message, type, name, addr);\r
95             }\r
96         }\r
97      }\r
98 @@ -292,7 +293,8 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
99  static const char *\r
100  add_recipients_from_message (GMimeMessage *reply,\r
101                              notmuch_config_t *config,\r
102 -                            notmuch_message_t *message)\r
103 +                            notmuch_message_t *message,\r
104 +                            int reply_to_all)\r
105  {\r
106      struct {\r
107         const char *header;\r
108 @@ -332,9 +334,20 @@ add_recipients_from_message (GMimeMessage *reply,\r
109             recipients = notmuch_message_get_header (message,\r
110                                                      reply_to_map[i].fallback);\r
111  \r
112 -       addr = add_recipients_for_string (reply, config,\r
113 -                                         reply_to_map[i].recipient_type,\r
114 -                                         recipients);\r
115 +\r
116 +       /* We add the addresses if we are replying to all or we have not yet found\r
117 +        * a non-user address. We have to keep parsing to make sure we do find the\r
118 +        * correct from address for the user, but we pass a NULL message\r
119 +        */\r
120 +       if ((reply_to_all) || (g_mime_message_get_all_recipients (reply) == NULL))\r
121 +           addr = add_recipients_for_string (reply, config,\r
122 +                                             reply_to_map[i].recipient_type,\r
123 +                                             recipients);\r
124 +       else\r
125 +            addr = add_recipients_for_string (NULL, config,\r
126 +                                              reply_to_map[i].recipient_type,\r
127 +                                              recipients);\r
128 +\r
129         if (from_addr == NULL)\r
130             from_addr = addr;\r
131      }\r
132 @@ -480,7 +493,8 @@ static int\r
133  notmuch_reply_format_default(void *ctx,\r
134                              notmuch_config_t *config,\r
135                              notmuch_query_t *query,\r
136 -                            notmuch_show_params_t *params)\r
137 +                            notmuch_show_params_t *params,\r
138 +                            int reply_to_all)\r
139  {\r
140      GMimeMessage *reply;\r
141      notmuch_messages_t *messages;\r
142 @@ -509,7 +523,7 @@ notmuch_reply_format_default(void *ctx,\r
143             g_mime_message_set_subject (reply, subject);\r
144         }\r
145  \r
146 -       from_addr = add_recipients_from_message (reply, config, message);\r
147 +       from_addr = add_recipients_from_message (reply, config, message, reply_to_all);\r
148  \r
149         if (from_addr == NULL)\r
150             from_addr = guess_from_received_header (config, message);\r
151 @@ -558,7 +572,8 @@ static int\r
152  notmuch_reply_format_headers_only(void *ctx,\r
153                                   notmuch_config_t *config,\r
154                                   notmuch_query_t *query,\r
155 -                                 unused (notmuch_show_params_t *params))\r
156 +                                 unused (notmuch_show_params_t *params),\r
157 +                                 int reply_to_all)\r
158  {\r
159      GMimeMessage *reply;\r
160      notmuch_messages_t *messages;\r
161 @@ -598,7 +613,7 @@ notmuch_reply_format_headers_only(void *ctx,\r
162         g_mime_object_set_header (GMIME_OBJECT (reply),\r
163                                   "References", references);\r
164  \r
165 -       (void)add_recipients_from_message (reply, config, message);\r
166 +       (void)add_recipients_from_message (reply, config, message, reply_to_all);\r
167  \r
168         reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));\r
169         printf ("%s", reply_headers);\r
170 @@ -620,7 +635,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
171      notmuch_query_t *query;\r
172      char *opt, *query_string;\r
173      int i, ret = 0;\r
174 -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
175 +    int reply_to_all = 1;\r
176 +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, int reply_to_all);\r
177      notmuch_show_params_t params;\r
178  \r
179      reply_format_func = notmuch_reply_format_default;\r
180 @@ -654,6 +670,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
181                 g_object_unref (session);\r
182                 session = NULL;\r
183             }\r
184 +       } else if (STRNCMP_LITERAL (argv[i], "--reply-to=") == 0) {\r
185 +           opt = argv[i] + sizeof ("--reply-to=") - 1;\r
186 +           if (strcmp (opt, "sender") == 0) {\r
187 +                reply_to_all = 0;\r
188 +           } else if (strcmp (opt, "all") == 0) {\r
189 +                reply_to_all = 1;\r
190 +           } else {\r
191 +                fprintf (stderr, "Invalid value for --reply-to: %s\n", opt);\r
192 +                return 1;\r
193 +           }\r
194         } else {\r
195             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
196             return 1;\r
197 @@ -689,7 +715,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
198         return 1;\r
199      }\r
200  \r
201 -    if (reply_format_func (ctx, config, query, &params) != 0)\r
202 +    if (reply_format_func (ctx, config, query, &params, reply_to_all) != 0)\r
203         return 1;\r
204  \r
205      notmuch_query_destroy (query);\r
206 -- \r
207 1.7.2.3\r
208 \r