Re: [PATCH 06/11] lib: store thread recipients in thread structure
[notmuch-archives.git] / 45 / 0874808aba786b3bb5307461fafff876dfec0d
1 Return-Path: <sojkam1@fel.cvut.cz>\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 1EEB2431FBC\r
6         for <notmuch@notmuchmail.org>; Fri, 31 Aug 2012 13:44:40 -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: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 cggC54HXvTK6 for <notmuch@notmuchmail.org>;\r
16         Fri, 31 Aug 2012 13:44:37 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id A9498431FAF\r
19         for <notmuch@notmuchmail.org>; Fri, 31 Aug 2012 13:44:36 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id D5A5119F335E;\r
22         Fri, 31 Aug 2012 22:44:31 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id mOXfFIdsdz32; Fri, 31 Aug 2012 22:44:29 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 9E3E419F32FF;\r
30         Fri, 31 Aug 2012 22:44:29 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (unknown [213.29.198.144])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 70C58660904;\r
34         Fri, 31 Aug 2012 22:44:29 +0200 (CEST)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.80)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1T7Y4q-00021D-1k; Fri, 31 Aug 2012 22:44:28 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: Jameson Graef Rollins <jrollins@finestructure.net>,\r
40         Notmuch Mail <notmuch@notmuchmail.org>\r
41 Subject: Re: [PATCH 06/11] lib: store thread recipients in thread structure\r
42 In-Reply-To: <1345427570-26518-7-git-send-email-jrollins@finestructure.net>\r
43 References: <1345427570-26518-1-git-send-email-jrollins@finestructure.net>\r
44         <1345427570-26518-2-git-send-email-jrollins@finestructure.net>\r
45         <1345427570-26518-3-git-send-email-jrollins@finestructure.net>\r
46         <1345427570-26518-4-git-send-email-jrollins@finestructure.net>\r
47         <1345427570-26518-5-git-send-email-jrollins@finestructure.net>\r
48         <1345427570-26518-6-git-send-email-jrollins@finestructure.net>\r
49         <1345427570-26518-7-git-send-email-jrollins@finestructure.net>\r
50 User-Agent: Notmuch/0.14+3~g608c52f (http://notmuchmail.org) Emacs/24.1.1\r
51         (x86_64-pc-linux-gnu)\r
52 Date: Fri, 31 Aug 2012 22:44:28 +0200\r
53 Message-ID: <87a9xaokpf.fsf@steelpick.2x.cz>\r
54 MIME-Version: 1.0\r
55 Content-Type: text/plain\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Fri, 31 Aug 2012 20:44:40 -0000\r
69 \r
70 On Mon, Aug 20 2012, Jameson Graef Rollins wrote:\r
71 > This utilizes the new thread addresses struct to store thread\r
72 > recipients, again in parallel to authors.\r
73 >\r
74 > Since message recipients are not stored in the database, including\r
75 > recipients in the thread structure exacts a significant overhead as\r
76 > the recipients are retrieved from the original message files.  Because\r
77 > of this, a new boolean argument, include_recipients, is added to the\r
78 > necessary functions (_notmuch_thread_create, _thread_add_message and\r
79 > _thread_add_matched_message) that controls whether the recipients are\r
80 > fetched and included.  If message recipients are ever stored in the\r
81 > database this new argument could probably be removed.\r
82 > ---\r
83 >  lib/notmuch-private.h |    3 +-\r
84 >  lib/notmuch.h         |   14 +++++++++\r
85 >  lib/query.cc          |    3 +-\r
86 >  lib/thread.cc         |   77 +++++++++++++++++++++++++++++++++++++------------\r
87 >  4 files changed, 76 insertions(+), 21 deletions(-)\r
88 >\r
89 > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
90 > index 27a41b6..32d1523 100644\r
91 > --- a/lib/notmuch-private.h\r
92 > +++ b/lib/notmuch-private.h\r
93 > @@ -232,7 +232,8 @@ _notmuch_thread_create (void *ctx,\r
94 >                       unsigned int seed_doc_id,\r
95 >                       notmuch_doc_id_set_t *match_set,\r
96 >                       notmuch_string_list_t *excluded_terms,\r
97 > -                     notmuch_sort_t sort);\r
98 > +                     notmuch_sort_t sort,\r
99 > +                     notmuch_bool_t include_recipients);\r
100 >  \r
101 >  /* message.cc */\r
102 >  \r
103 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
104 > index 6acd38d..f9e71c1 100644\r
105 > --- a/lib/notmuch.h\r
106 > +++ b/lib/notmuch.h\r
107 > @@ -759,6 +759,20 @@ notmuch_thread_get_matched_messages (notmuch_thread_t *thread);\r
108 >  const char *\r
109 >  notmuch_thread_get_authors (notmuch_thread_t *thread);\r
110 >  \r
111 > +/* Get the recipients of 'thread'\r
112 > + *\r
113 > + * The returned string is a comma-separated list of the names of the\r
114 > + * recipients of mail messages in the query results that belong to this\r
115 > + * thread.\r
116 > + *\r
117 > + * The returned string belongs to 'thread' and as such, should not be\r
118 > + * modified by the caller and will only be valid for as long as the\r
119 > + * thread is valid, (which is until notmuch_thread_destroy or until\r
120 > + * the query from which it derived is destroyed).\r
121 > + */\r
122 > +const char *\r
123 > +notmuch_thread_get_recipients (notmuch_thread_t *thread);\r
124 > +\r
125 >  /* Get the subject of 'thread'\r
126 >   *\r
127 >   * The subject is taken from the first message (according to the query\r
128 > diff --git a/lib/query.cc b/lib/query.cc\r
129 > index e9c1a2d..54833a7 100644\r
130 > --- a/lib/query.cc\r
131 > +++ b/lib/query.cc\r
132 > @@ -486,7 +486,8 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
133 >                                  doc_id,\r
134 >                                  &threads->match_set,\r
135 >                                  threads->query->exclude_terms,\r
136 > -                                threads->query->sort);\r
137 > +                                threads->query->sort,\r
138 > +                                FALSE);\r
139 >  }\r
140 >  \r
141 >  void\r
142 > diff --git a/lib/thread.cc b/lib/thread.cc\r
143 > index 757e143..baf07c2 100644\r
144 > --- a/lib/thread.cc\r
145 > +++ b/lib/thread.cc\r
146 > @@ -37,6 +37,7 @@ struct visible _notmuch_thread {\r
147 >      char *thread_id;\r
148 >      char *subject;\r
149 >      notmuch_thread_addresses_t *authors;\r
150 > +    notmuch_thread_addresses_t *recipients;\r
151 >      GHashTable *tags;\r
152 >  \r
153 >      notmuch_message_list_t *message_list;\r
154 > @@ -63,6 +64,7 @@ static int\r
155 >  _notmuch_thread_destructor (notmuch_thread_t *thread)\r
156 >  {\r
157 >      _notmuch_thread_addresses_destructor (thread->authors);\r
158 > +    _notmuch_thread_addresses_destructor (thread->recipients);\r
159 >      g_hash_table_unref (thread->tags);\r
160 >      g_hash_table_unref (thread->message_hash);\r
161 >      return 0;\r
162 > @@ -204,14 +206,17 @@ _thread_cleanup_address (notmuch_thread_t *thread,\r
163 >  static void\r
164 >  _thread_add_message (notmuch_thread_t *thread,\r
165 >                    notmuch_message_t *message,\r
166 > -                  notmuch_string_list_t *exclude_terms)\r
167 > +                  notmuch_string_list_t *exclude_terms,\r
168 > +                  notmuch_bool_t include_recipients)\r
169 >  {\r
170 >      notmuch_tags_t *tags;\r
171 >      const char *tag;\r
172 > -    InternetAddressList *list = NULL;\r
173 > +    InternetAddressList *from_list = NULL;\r
174 > +    InternetAddressList *to_list = NULL;\r
175 >      InternetAddress *address;\r
176 >      const char *from, *author;\r
177 > -    char *clean_author;\r
178 > +    const char *to, *recipient;\r
179 > +    char *clean_address;\r
180 >  \r
181 >      _notmuch_message_list_add_message (thread->message_list,\r
182 >                                      talloc_steal (thread, message));\r
183 > @@ -223,10 +228,9 @@ _thread_add_message (notmuch_thread_t *thread,\r
184 >  \r
185 >      from = notmuch_message_get_header (message, "from");\r
186 >      if (from)\r
187 > -     list = internet_address_list_parse_string (from);\r
188 > -\r
189 > -    if (list) {\r
190 > -     address = internet_address_list_get_address (list, 0);\r
191 > +     from_list = internet_address_list_parse_string (from);\r
192 > +    if (from_list) {\r
193 > +     address = internet_address_list_get_address (from_list, 0);\r
194 >       if (address) {\r
195 >           author = internet_address_get_name (address);\r
196 >           if (author == NULL) {\r
197 > @@ -234,11 +238,32 @@ _thread_add_message (notmuch_thread_t *thread,\r
198 >               mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
199 >               author = internet_address_mailbox_get_addr (mailbox);\r
200 >           }\r
201 > -         clean_author = _thread_cleanup_author (thread, author, from);\r
202 > -         _thread_add_address (thread->authors, clean_author, FALSE);\r
203 > -         notmuch_message_set_author (message, clean_author);\r
204 > +         clean_address = _thread_cleanup_address (thread, author, from);\r
205 > +         _thread_add_address (thread->authors, clean_address, FALSE);\r
206 > +         notmuch_message_set_author (message, clean_address);\r
207 > +     }\r
208 > +     g_object_unref (G_OBJECT (from_list));\r
209 > +    }\r
210 > +\r
211 > +    if (include_recipients) {\r
212 > +    to = notmuch_message_get_header (message, "to");\r
213 \r
214 I think that recipients should be composed from all to, cc and bcc\r
215 headers. I often write emails with only Bcc header. If such an email is\r
216 saved as draft, I might be surprised by not seeing the "recipients".\r
217 \r
218 > +    if (to)\r
219 > +     to_list = internet_address_list_parse_string (to);\r
220 > +    if (to_list) {\r
221 > +     address = internet_address_list_get_address (to_list, 0);\r
222 > +     if (address) {\r
223 > +         recipient = internet_address_get_name (address);\r
224 > +         if (recipient == NULL) {\r
225 > +             InternetAddressMailbox *mailbox;\r
226 > +             mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
227 > +             recipient = internet_address_mailbox_get_addr (mailbox);\r
228 > +         }\r
229 > +         clean_address = _thread_cleanup_address (thread, recipient, to);\r
230 > +         _thread_add_address (thread->recipients, clean_address, FALSE);\r
231 > +         notmuch_message_set_recipients (message, clean_address);\r
232 >       }\r
233 > -     g_object_unref (G_OBJECT (list));\r
234 > +     g_object_unref (G_OBJECT (to_list));\r
235 > +    }\r
236 >      }\r
237 >  \r
238 >      if (! thread->subject) {\r
239 > @@ -301,7 +326,8 @@ _thread_set_subject_from_message (notmuch_thread_t *thread,\r
240 >  static void\r
241 >  _thread_add_matched_message (notmuch_thread_t *thread,\r
242 >                            notmuch_message_t *message,\r
243 > -                          notmuch_sort_t sort)\r
244 > +                          notmuch_sort_t sort,\r
245 > +                          notmuch_bool_t include_recipients)\r
246 >  {\r
247 >      time_t date;\r
248 >      notmuch_message_t *hashed_message;\r
249 > @@ -331,6 +357,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
250 >      }\r
251 >  \r
252 >      _thread_add_address (thread->authors, notmuch_message_get_author (hashed_message), TRUE);\r
253 > +    if (include_recipients)\r
254 > +    _thread_add_address (thread->recipients, notmuch_message_get_recipients (hashed_message), TRUE);\r
255 >  }\r
256 >  \r
257 >  static void\r
258 > @@ -399,10 +427,10 @@ _thread_addresses_init (const void *ctx)\r
259 >   *\r
260 >   * Creating the thread will perform a database search to get all\r
261 >   * messages belonging to the thread and will get the first subject\r
262 > - * line, the total count of messages, and all authors in the thread.\r
263 > - * Each message in the thread is checked against match_set to allow\r
264 > - * for a separate count of matched messages, and to allow a viewer to\r
265 > - * display these messages differently.\r
266 > + * line, the total count of messages, and all authors and recipients\r
267 \r
268 ... all authors (and optionally recipients).\r
269 \r
270 > + * of the thread.  Each message in the thread is checked against\r
271 > + * match_set to allow for a separate count of matched messages, and to\r
272 > + * allow a viewer to display these messages differently.\r
273 >   *\r
274 >   * Here, 'ctx' is talloc context for the resulting thread object.\r
275 >   *\r
276 > @@ -414,7 +442,8 @@ _notmuch_thread_create (void *ctx,\r
277 >                       unsigned int seed_doc_id,\r
278 >                       notmuch_doc_id_set_t *match_set,\r
279 >                       notmuch_string_list_t *exclude_terms,\r
280 > -                     notmuch_sort_t sort)\r
281 > +                     notmuch_sort_t sort,\r
282 > +                     notmuch_bool_t include_recipients)\r
283 >  {\r
284 >      notmuch_thread_t *thread;\r
285 >      notmuch_message_t *seed_message;\r
286 > @@ -453,6 +482,9 @@ _notmuch_thread_create (void *ctx,\r
287 >      thread->authors = _thread_addresses_init (thread);\r
288 >      if (unlikely (thread->authors == NULL))\r
289 >       return NULL;\r
290 > +    thread->recipients = _thread_addresses_init (thread);\r
291 > +    if (unlikely (thread->recipients == NULL))\r
292 > +     return NULL;\r
293 >  \r
294 >      thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,\r
295 >                                         free, NULL);\r
296 > @@ -486,11 +518,11 @@ _notmuch_thread_create (void *ctx,\r
297 >       if (doc_id == seed_doc_id)\r
298 >           message = seed_message;\r
299 >  \r
300 > -     _thread_add_message (thread, message, exclude_terms);\r
301 > +     _thread_add_message (thread, message, exclude_terms, include_recipients);\r
302 >  \r
303 >       if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {\r
304 >           _notmuch_doc_id_set_remove (match_set, doc_id);\r
305 > -         _thread_add_matched_message (thread, message, sort);\r
306 > +         _thread_add_matched_message (thread, message, sort, include_recipients);\r
307 >       }\r
308 >  \r
309 >       _notmuch_message_close (message);\r
310 > @@ -499,6 +531,7 @@ _notmuch_thread_create (void *ctx,\r
311 >      notmuch_query_destroy (thread_id_query);\r
312 >  \r
313 >      _resolve_thread_addresses_string (thread->authors);\r
314 > +    _resolve_thread_addresses_string (thread->recipients);\r
315 >  \r
316 >      _resolve_thread_relationships (thread);\r
317 >  \r
318 > @@ -536,6 +569,12 @@ notmuch_thread_get_authors (notmuch_thread_t *thread)\r
319 >  }\r
320 >  \r
321 >  const char *\r
322 > +notmuch_thread_get_recipients (notmuch_thread_t *thread)\r
323 > +{\r
324 > +    return thread->recipients->string;\r
325 > +}\r
326 > +\r
327 > +const char *\r
328 >  notmuch_thread_get_subject (notmuch_thread_t *thread)\r
329 >  {\r
330 >      return thread->subject;\r
331 > -- \r
332 > 1.7.10.4\r
333 >\r
334 > _______________________________________________\r
335 > notmuch mailing list\r
336 > notmuch@notmuchmail.org\r
337 > http://notmuchmail.org/mailman/listinfo/notmuch\r