Re: How does notmuch track mails?
[notmuch-archives.git] / a5 / 3429b667d64e41d3838a85c985a0e4440df2ea
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 4D9CB407817\r
6         for <notmuch@notmuchmail.org>; Sun,  8 Jan 2012 04:47:40 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id BCjkc0-9fkzw for <notmuch@notmuchmail.org>;\r
16         Sun,  8 Jan 2012 04:47:39 -0800 (PST)\r
17 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
18  [74.125.83.53])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  C40FF409F31    for <notmuch@notmuchmail.org>; Sun,  8 Jan 2012 04:47:38 -0800\r
21  (PST)\r
22 Received: by eekd41 with SMTP id d41so2303792eek.26\r
23         for <notmuch@notmuchmail.org>; Sun, 08 Jan 2012 04:47:37 -0800 (PST)\r
24 Received: by 10.213.29.2 with SMTP id o2mr694257ebc.54.1326026857459;\r
25         Sun, 08 Jan 2012 04:47:37 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
27         [80.220.92.23])\r
28         by mx.google.com with ESMTPS id a60sm276271993eeb.4.2012.01.08.04.47.35\r
29         (version=SSLv3 cipher=OTHER); Sun, 08 Jan 2012 04:47:36 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: Mark Walters <markwalters1009@gmail.com>, notmuch@notmuchmail.org,\r
32         david@tethera.net\r
33 Subject: Re: [PATCH 1/4] Add the option "--reply-to" to notmuch reply.\r
34 In-Reply-To: <1325856857-15969-1-git-send-email-markwalters1009@gmail.com>\r
35 References: <8739btdkir.fsf@qmul.ac.uk>\r
36         <1325856857-15969-1-git-send-email-markwalters1009@gmail.com>\r
37 User-Agent: Notmuch/0.10.2+182~g93862a2 (http://notmuchmail.org) Emacs/23.3.1\r
38         (i686-pc-linux-gnu)\r
39 Date: Sun, 08 Jan 2012 14:47:33 +0200\r
40 Message-ID: <871urafjiy.fsf@nikula.org>\r
41 MIME-Version: 1.0\r
42 Content-Type: text/plain; charset=us-ascii\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Sun, 08 Jan 2012 12:47:40 -0000\r
56 \r
57 On Fri,  6 Jan 2012 13:34:14 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
58 >     Possible values for this option are "sender" which replies just to\r
59 >     sender and "all" (the default).\r
60\r
61 >     More precisely reply to sender follows these rules:\r
62 >     reply only to sender unless it was the user\r
63 >     reply only to all people on the "to" line unless they were all the user\r
64 >     reply to all people on the "cc" line\r
65\r
66 >     Implementation details\r
67\r
68 >     We continue parsing addresses beyond the ones we reply to because\r
69 >     we want to make sure the from address is correct. (At the very least it\r
70 >     is the same as it would be if we replied to all.)\r
71\r
72 >     We overload the message variable in add_recipients_for_address_list so\r
73 >     if it is NULL we parse the address (looking for the users address)\r
74 >     but do not add to the message recipients list\r
75\r
76 >     We add the variable reply_to_all to the function chain to keep track\r
77 >     of whether we should reply to everyone.\r
78 > ---\r
79 >  notmuch-reply.c |   48 +++++++++++++++++++++++++++++++++++++-----------\r
80 >  1 files changed, 37 insertions(+), 11 deletions(-)\r
81\r
82 > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
83 > index f8d5f64..9a77fe6 100644\r
84 > --- a/notmuch-reply.c\r
85 > +++ b/notmuch-reply.c\r
86 > @@ -212,7 +212,8 @@ add_recipients_for_address_list (GMimeMessage *message,\r
87 >               if (ret == NULL)\r
88 >                   ret = addr;\r
89 >           } else {\r
90 > -             g_mime_message_add_recipient (message, type, name, addr);\r
91 > +              if (message)\r
92 > +                   g_mime_message_add_recipient (message, type, name, addr);\r
93 >           }\r
94 >       }\r
95 >      }\r
96 > @@ -292,7 +293,8 @@ reply_to_header_is_redundant (notmuch_message_t *message)\r
97 >  static const char *\r
98 >  add_recipients_from_message (GMimeMessage *reply,\r
99 >                            notmuch_config_t *config,\r
100 > -                          notmuch_message_t *message)\r
101 > +                          notmuch_message_t *message,\r
102 > +                          int reply_to_all)\r
103 >  {\r
104 >      struct {\r
105 >       const char *header;\r
106 > @@ -332,9 +334,20 @@ add_recipients_from_message (GMimeMessage *reply,\r
107 >           recipients = notmuch_message_get_header (message,\r
108 >                                                    reply_to_map[i].fallback);\r
109 >  \r
110 > -     addr = add_recipients_for_string (reply, config,\r
111 > -                                       reply_to_map[i].recipient_type,\r
112 > -                                       recipients);\r
113 > +\r
114 > +     /* We add the addresses if we are replying to all or we have not yet found\r
115 > +      * a non-user address. We have to keep parsing to make sure we do find the\r
116 > +      * correct from address for the user, but we pass a NULL message\r
117 > +      */\r
118 > +     if ((reply_to_all) || (g_mime_message_get_all_recipients (reply) == NULL))\r
119 \r
120 Looking into this, it occurred to me g_mime_message_get_all_recipients()\r
121 allocates a new InternetAddressList when the return value is\r
122 non-NULL. Thus this leaks memory. OTOH allocating and deallocating for\r
123 this purpose seems suboptimal. I'll think this over.\r
124 \r
125 BR,\r
126 Jani.\r
127 \r
128 \r
129 \r
130 > +         addr = add_recipients_for_string (reply, config,\r
131 > +                                           reply_to_map[i].recipient_type,\r
132 > +                                           recipients);\r
133 > +     else\r
134 > +          addr = add_recipients_for_string (NULL, config,\r
135 > +                                            reply_to_map[i].recipient_type,\r
136 > +                                            recipients);\r
137 > +\r
138 >       if (from_addr == NULL)\r
139 >           from_addr = addr;\r
140 >      }\r
141 > @@ -480,7 +493,8 @@ static int\r
142 >  notmuch_reply_format_default(void *ctx,\r
143 >                            notmuch_config_t *config,\r
144 >                            notmuch_query_t *query,\r
145 > -                          notmuch_show_params_t *params)\r
146 > +                          notmuch_show_params_t *params,\r
147 > +                          int reply_to_all)\r
148 >  {\r
149 >      GMimeMessage *reply;\r
150 >      notmuch_messages_t *messages;\r
151 > @@ -509,7 +523,7 @@ notmuch_reply_format_default(void *ctx,\r
152 >           g_mime_message_set_subject (reply, subject);\r
153 >       }\r
154 >  \r
155 > -     from_addr = add_recipients_from_message (reply, config, message);\r
156 > +     from_addr = add_recipients_from_message (reply, config, message, reply_to_all);\r
157 >  \r
158 >       if (from_addr == NULL)\r
159 >           from_addr = guess_from_received_header (config, message);\r
160 > @@ -558,7 +572,8 @@ static int\r
161 >  notmuch_reply_format_headers_only(void *ctx,\r
162 >                                 notmuch_config_t *config,\r
163 >                                 notmuch_query_t *query,\r
164 > -                               unused (notmuch_show_params_t *params))\r
165 > +                               unused (notmuch_show_params_t *params),\r
166 > +                               int reply_to_all)\r
167 >  {\r
168 >      GMimeMessage *reply;\r
169 >      notmuch_messages_t *messages;\r
170 > @@ -598,7 +613,7 @@ notmuch_reply_format_headers_only(void *ctx,\r
171 >       g_mime_object_set_header (GMIME_OBJECT (reply),\r
172 >                                 "References", references);\r
173 >  \r
174 > -     (void)add_recipients_from_message (reply, config, message);\r
175 > +     (void)add_recipients_from_message (reply, config, message, reply_to_all);\r
176 >  \r
177 >       reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));\r
178 >       printf ("%s", reply_headers);\r
179 > @@ -620,7 +635,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
180 >      notmuch_query_t *query;\r
181 >      char *opt, *query_string;\r
182 >      int i, ret = 0;\r
183 > -    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
184 > +    int reply_to_all = 1;\r
185 > +    int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, int reply_to_all);\r
186 >      notmuch_show_params_t params;\r
187 >  \r
188 >      reply_format_func = notmuch_reply_format_default;\r
189 > @@ -654,6 +670,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
190 >               g_object_unref (session);\r
191 >               session = NULL;\r
192 >           }\r
193 > +     } else if (STRNCMP_LITERAL (argv[i], "--reply-to=") == 0) {\r
194 > +         opt = argv[i] + sizeof ("--reply-to=") - 1;\r
195 > +         if (strcmp (opt, "sender") == 0) {\r
196 > +              reply_to_all = 0;\r
197 > +         } else if (strcmp (opt, "all") == 0) {\r
198 > +              reply_to_all = 1;\r
199 > +         } else {\r
200 > +              fprintf (stderr, "Invalid value for --reply-to: %s\n", opt);\r
201 > +              return 1;\r
202 > +         }\r
203 >       } else {\r
204 >           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
205 >           return 1;\r
206 > @@ -689,7 +715,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
207 >       return 1;\r
208 >      }\r
209 >  \r
210 > -    if (reply_format_func (ctx, config, query, &params) != 0)\r
211 > +    if (reply_format_func (ctx, config, query, &params, reply_to_all) != 0)\r
212 >       return 1;\r
213 >  \r
214 >      notmuch_query_destroy (query);\r
215 > -- \r
216 > 1.7.2.3\r
217\r