Re: [PATCH 1/1] Store and search for canonical Unicode text [WIP]
[notmuch-archives.git] / 20 / 99c3badc1348e10ae8ef1d0dfc13ae01e85e7f
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 1CDD2429E25\r
6         for <notmuch@notmuchmail.org>; Thu, 26 May 2011 16:32:37 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.424\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.424 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=2.223, 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 S9jR3Ak2HU7I for <notmuch@notmuchmail.org>;\r
18         Thu, 26 May 2011 16:32:35 -0700 (PDT)\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  E9F30429E33    for <notmuch@notmuchmail.org>; Thu, 26 May 2011 16:32:34 -0700\r
23  (PDT)\r
24 Received: by wwi36 with SMTP id 36so1070600wwi.2\r
25         for <notmuch@notmuchmail.org>; Thu, 26 May 2011 16:32:33 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
27         h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer\r
28         :in-reply-to:references;\r
29         bh=xGtWyzzQPvm5A/tGXug/4AW5/fDDiXblQNMVBweZ5pk=;\r
30         b=nAGkFjKnPy3wZicovDtMxSwOd66r2o9N8fZR5fuVh35jET0FKf5j3Y4uWhlCkJZCjF\r
31         BKCpJ1449eS3NWLqX8S7huFcshWXfgiZmdu9QmIuh0AgRl4iOCHlTrjdn7tOr7dwNbwB\r
32         Iw1liQQ3x+elg5EgVVbpUOs+a040LeUiGb/ho=\r
33 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
34         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
35         b=pxXWt/sCSpABRRalM22oyy2H2EeWTg4wgjrtX4d9CeWoAMi+6rdhm02yqALyOumrcy\r
36         C6NaAMqqa5p2AHfjOvnfCuJnFJ/AqZ8CL+79qj9EssqPqS3r0EOntpvYE+fxX6zayUFo\r
37         erEaHgI7cKk2l40imqr9Y08AqlAt3zXnWSpLQ=\r
38 Received: by 10.227.198.10 with SMTP id em10mr1385458wbb.108.1306452753667;\r
39         Thu, 26 May 2011 16:32:33 -0700 (PDT)\r
40 Received: from localhost.localdomain (93-97-25-209.zone5.bethere.co.uk\r
41         [93.97.25.209])\r
42         by mx.google.com with ESMTPS id fw15sm804800wbb.27.2011.05.26.16.32.31\r
43         (version=TLSv1/SSLv3 cipher=OTHER);\r
44         Thu, 26 May 2011 16:32:32 -0700 (PDT)\r
45 From: Mark Walters <markwalters1009@gmail.com>\r
46 To: notmuch@notmuchmail.org\r
47 Subject: [PATCH v2 1/3] Adds the option "--reply-to=" to notmuch reply.\r
48 Date: Fri, 27 May 2011 00:31:55 +0100\r
49 Message-Id: <1306452717-19934-2-git-send-email-markwalters1009@gmail.com>\r
50 X-Mailer: git-send-email 1.7.2.5\r
51 In-Reply-To: <87pqn5cg4g.fsf@yoom.home.cworth.org>\r
52 References: <87pqn5cg4g.fsf@yoom.home.cworth.org>\r
53 X-BeenThere: notmuch@notmuchmail.org\r
54 X-Mailman-Version: 2.1.13\r
55 Precedence: list\r
56 List-Id: "Use and development of the notmuch mail system."\r
57         <notmuch.notmuchmail.org>\r
58 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
60 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
61 List-Post: <mailto:notmuch@notmuchmail.org>\r
62 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
63 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
64         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
65 X-List-Received-Date: Thu, 26 May 2011 23:32:37 -0000\r
66 \r
67 Possible values are "sender" which replies just to sender and\r
68 "all" (the default).\r
69 \r
70 More precisely reply to sender follows these rules:\r
71 reply only to sender unless it was the user\r
72 reply only to all people on the to line unless they were all the user\r
73 reply to all people on the cc line\r
74 \r
75 Implementation details\r
76 \r
77 Note we continue parsing addresses beyond the ones we reply to because\r
78 we want to make sure the from address is correct. (At the very least it\r
79 is the same as it would be if we replied to all.)\r
80 \r
81 We overload the message variable in add_recipients_for_address_list so\r
82 if it is NULL we parse the address (looking for the users address)\r
83 but do not add to the message recipients list\r
84 \r
85 We add the variable reply_to_all to the function chain to keep track\r
86 of whether we should reply to everyone.\r
87 ---\r
88  notmuch-reply.c |   46 +++++++++++++++++++++++++++++++++++-----------\r
89  1 files changed, 35 insertions(+), 11 deletions(-)\r
90 \r
91 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
92 index ab15650..98ae94a 100644\r
93 --- a/notmuch-reply.c\r
94 +++ b/notmuch-reply.c\r
95 @@ -191,7 +191,8 @@ add_recipients_for_address_list (GMimeMessage *message,\r
96                 if (ret == NULL)\r
97                     ret = addr;\r
98             } else {\r
99 -               g_mime_message_add_recipient (message, type, name, addr);\r
100 +                if (message)\r
101 +                     g_mime_message_add_recipient (message, type, name, addr);\r
102             }\r
103         }\r
104      }\r
105 @@ -271,7 +272,8 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
106  static const char *\r
107  add_recipients_from_message (GMimeMessage *reply,\r
108                              notmuch_config_t *config,\r
109 -                            notmuch_message_t *message)\r
110 +                            notmuch_message_t *message,\r
111 +                            int reply_to_all)\r
112  {\r
113      struct {\r
114         const char *header;\r
115 @@ -311,9 +313,20 @@ add_recipients_from_message (GMimeMessage *reply,\r
116             recipients = notmuch_message_get_header (message,\r
117                                                      reply_to_map[i].fallback);\r
118  \r
119 -       addr = add_recipients_for_string (reply, config,\r
120 -                                         reply_to_map[i].recipient_type,\r
121 -                                         recipients);\r
122 +\r
123 +       /* We add the addresses if we are replying to all or we have not yet found\r
124 +        * a non-user address. We have to keep parsing to make sure we do find the\r
125 +        * correct from address for the user, but we pass a NULL message\r
126 +        */\r
127 +       if ((reply_to_all) || (g_mime_message_get_all_recipients (reply) == NULL))\r
128 +           addr = add_recipients_for_string (reply, config,\r
129 +                                             reply_to_map[i].recipient_type,\r
130 +                                             recipients);\r
131 +       else\r
132 +            addr = add_recipients_for_string (NULL, config,\r
133 +                                              reply_to_map[i].recipient_type,\r
134 +                                              recipients);\r
135 +\r
136         if (from_addr == NULL)\r
137             from_addr = addr;\r
138      }\r
139 @@ -453,7 +466,7 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
140  }\r
141  \r
142  static int\r
143 -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
144 +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all)\r
145  {\r
146      GMimeMessage *reply;\r
147      notmuch_messages_t *messages;\r
148 @@ -484,7 +497,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
149             g_mime_message_set_subject (reply, subject);\r
150         }\r
151  \r
152 -       from_addr = add_recipients_from_message (reply, config, message);\r
153 +       from_addr = add_recipients_from_message (reply, config, message, reply_to_all);\r
154  \r
155         if (from_addr == NULL)\r
156             from_addr = guess_from_received_header (config, message);\r
157 @@ -531,7 +544,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_\r
158  \r
159  /* This format is currently tuned for a git send-email --notmuch hook */\r
160  static int\r
161 -notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query)\r
162 +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all)\r
163  {\r
164      GMimeMessage *reply;\r
165      notmuch_messages_t *messages;\r
166 @@ -571,7 +584,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q\r
167         g_mime_object_set_header (GMIME_OBJECT (reply),\r
168                                   "References", references);\r
169  \r
170 -       (void)add_recipients_from_message (reply, config, message);\r
171 +       (void)add_recipients_from_message (reply, config, message, reply_to_all);\r
172  \r
173         reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));\r
174         printf ("%s", reply_headers);\r
175 @@ -593,7 +606,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
176      notmuch_query_t *query;\r
177      char *opt, *query_string;\r
178      int i, ret = 0;\r
179 -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query);\r
180 +    int reply_to_all = 1;\r
181 +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all);\r
182  \r
183      reply_format_func = notmuch_reply_format_default;\r
184  \r
185 @@ -612,6 +626,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
186                 fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
187                 return 1;\r
188             }\r
189 +       } else if (STRNCMP_LITERAL (argv[i], "--reply-to=") == 0) {\r
190 +           opt = argv[i] + sizeof ("--reply-to=") - 1;\r
191 +           if (strcmp (opt, "sender") == 0) {\r
192 +                reply_to_all = 0;\r
193 +           } else if (strcmp (opt, "all") == 0) {\r
194 +                reply_to_all = 1;\r
195 +           } else {\r
196 +                fprintf (stderr, "Invalid value for --reply-to: %s\n", opt);\r
197 +                return 1;\r
198 +           }\r
199         } else {\r
200             fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
201             return 1;\r
202 @@ -647,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
203         return 1;\r
204      }\r
205  \r
206 -    if (reply_format_func (ctx, config, query) != 0)\r
207 +    if (reply_format_func (ctx, config, query, reply_to_all) != 0)\r
208         return 1;\r
209  \r
210      notmuch_query_destroy (query);\r
211 -- \r
212 1.7.2.5\r
213 \r