Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / ab / fe9007f70870451f24061a2d10185430979706
1 Return-Path: <jrollins@finestructure.net>\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 D7801431FBD\r
6         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:14 -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 1prNKKMgMWAR for <notmuch@notmuchmail.org>;\r
16         Sun, 19 Aug 2012 18:53:12 -0700 (PDT)\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
18         [131.215.239.19])\r
19         by olra.theworths.org (Postfix) with ESMTP id 87E6E431FC2\r
20         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:08 -0700 (PDT)\r
21 Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by fire-doxen-postvirus (Postfix) with ESMTP id C92ED2E50D7B\r
23         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:07 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
25 Received: from finestructure.net (unknown [76.89.192.57])\r
26         (Authenticated sender: jrollins)\r
27         by fire-doxen-submit (Postfix) with ESMTP id 9ED252E50D80\r
28         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:05 -0700 (PDT)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id D6FE893E; Sun, 19 Aug 2012 18:53:03 -0700 (PDT)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>\r
33 Subject: [PATCH 06/11] lib: store thread recipients in thread structure\r
34 Date: Sun, 19 Aug 2012 18:52:45 -0700\r
35 Message-Id: <1345427570-26518-7-git-send-email-jrollins@finestructure.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1345427570-26518-6-git-send-email-jrollins@finestructure.net>\r
38 References: <1345427570-26518-1-git-send-email-jrollins@finestructure.net>\r
39         <1345427570-26518-2-git-send-email-jrollins@finestructure.net>\r
40         <1345427570-26518-3-git-send-email-jrollins@finestructure.net>\r
41         <1345427570-26518-4-git-send-email-jrollins@finestructure.net>\r
42         <1345427570-26518-5-git-send-email-jrollins@finestructure.net>\r
43         <1345427570-26518-6-git-send-email-jrollins@finestructure.net>\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: Mon, 20 Aug 2012 01:53:15 -0000\r
57 \r
58 This utilizes the new thread addresses struct to store thread\r
59 recipients, again in parallel to authors.\r
60 \r
61 Since message recipients are not stored in the database, including\r
62 recipients in the thread structure exacts a significant overhead as\r
63 the recipients are retrieved from the original message files.  Because\r
64 of this, a new boolean argument, include_recipients, is added to the\r
65 necessary functions (_notmuch_thread_create, _thread_add_message and\r
66 _thread_add_matched_message) that controls whether the recipients are\r
67 fetched and included.  If message recipients are ever stored in the\r
68 database this new argument could probably be removed.\r
69 ---\r
70  lib/notmuch-private.h |    3 +-\r
71  lib/notmuch.h         |   14 +++++++++\r
72  lib/query.cc          |    3 +-\r
73  lib/thread.cc         |   77 +++++++++++++++++++++++++++++++++++++------------\r
74  4 files changed, 76 insertions(+), 21 deletions(-)\r
75 \r
76 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
77 index 27a41b6..32d1523 100644\r
78 --- a/lib/notmuch-private.h\r
79 +++ b/lib/notmuch-private.h\r
80 @@ -232,7 +232,8 @@ _notmuch_thread_create (void *ctx,\r
81                         unsigned int seed_doc_id,\r
82                         notmuch_doc_id_set_t *match_set,\r
83                         notmuch_string_list_t *excluded_terms,\r
84 -                       notmuch_sort_t sort);\r
85 +                       notmuch_sort_t sort,\r
86 +                       notmuch_bool_t include_recipients);\r
87  \r
88  /* message.cc */\r
89  \r
90 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
91 index 6acd38d..f9e71c1 100644\r
92 --- a/lib/notmuch.h\r
93 +++ b/lib/notmuch.h\r
94 @@ -759,6 +759,20 @@ notmuch_thread_get_matched_messages (notmuch_thread_t *thread);\r
95  const char *\r
96  notmuch_thread_get_authors (notmuch_thread_t *thread);\r
97  \r
98 +/* Get the recipients of 'thread'\r
99 + *\r
100 + * The returned string is a comma-separated list of the names of the\r
101 + * recipients of mail messages in the query results that belong to this\r
102 + * thread.\r
103 + *\r
104 + * The returned string belongs to 'thread' and as such, should not be\r
105 + * modified by the caller and will only be valid for as long as the\r
106 + * thread is valid, (which is until notmuch_thread_destroy or until\r
107 + * the query from which it derived is destroyed).\r
108 + */\r
109 +const char *\r
110 +notmuch_thread_get_recipients (notmuch_thread_t *thread);\r
111 +\r
112  /* Get the subject of 'thread'\r
113   *\r
114   * The subject is taken from the first message (according to the query\r
115 diff --git a/lib/query.cc b/lib/query.cc\r
116 index e9c1a2d..54833a7 100644\r
117 --- a/lib/query.cc\r
118 +++ b/lib/query.cc\r
119 @@ -486,7 +486,8 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
120                                    doc_id,\r
121                                    &threads->match_set,\r
122                                    threads->query->exclude_terms,\r
123 -                                  threads->query->sort);\r
124 +                                  threads->query->sort,\r
125 +                                  FALSE);\r
126  }\r
127  \r
128  void\r
129 diff --git a/lib/thread.cc b/lib/thread.cc\r
130 index 757e143..baf07c2 100644\r
131 --- a/lib/thread.cc\r
132 +++ b/lib/thread.cc\r
133 @@ -37,6 +37,7 @@ struct visible _notmuch_thread {\r
134      char *thread_id;\r
135      char *subject;\r
136      notmuch_thread_addresses_t *authors;\r
137 +    notmuch_thread_addresses_t *recipients;\r
138      GHashTable *tags;\r
139  \r
140      notmuch_message_list_t *message_list;\r
141 @@ -63,6 +64,7 @@ static int\r
142  _notmuch_thread_destructor (notmuch_thread_t *thread)\r
143  {\r
144      _notmuch_thread_addresses_destructor (thread->authors);\r
145 +    _notmuch_thread_addresses_destructor (thread->recipients);\r
146      g_hash_table_unref (thread->tags);\r
147      g_hash_table_unref (thread->message_hash);\r
148      return 0;\r
149 @@ -204,14 +206,17 @@ _thread_cleanup_address (notmuch_thread_t *thread,\r
150  static void\r
151  _thread_add_message (notmuch_thread_t *thread,\r
152                      notmuch_message_t *message,\r
153 -                    notmuch_string_list_t *exclude_terms)\r
154 +                    notmuch_string_list_t *exclude_terms,\r
155 +                    notmuch_bool_t include_recipients)\r
156  {\r
157      notmuch_tags_t *tags;\r
158      const char *tag;\r
159 -    InternetAddressList *list = NULL;\r
160 +    InternetAddressList *from_list = NULL;\r
161 +    InternetAddressList *to_list = NULL;\r
162      InternetAddress *address;\r
163      const char *from, *author;\r
164 -    char *clean_author;\r
165 +    const char *to, *recipient;\r
166 +    char *clean_address;\r
167  \r
168      _notmuch_message_list_add_message (thread->message_list,\r
169                                        talloc_steal (thread, message));\r
170 @@ -223,10 +228,9 @@ _thread_add_message (notmuch_thread_t *thread,\r
171  \r
172      from = notmuch_message_get_header (message, "from");\r
173      if (from)\r
174 -       list = internet_address_list_parse_string (from);\r
175 -\r
176 -    if (list) {\r
177 -       address = internet_address_list_get_address (list, 0);\r
178 +       from_list = internet_address_list_parse_string (from);\r
179 +    if (from_list) {\r
180 +       address = internet_address_list_get_address (from_list, 0);\r
181         if (address) {\r
182             author = internet_address_get_name (address);\r
183             if (author == NULL) {\r
184 @@ -234,11 +238,32 @@ _thread_add_message (notmuch_thread_t *thread,\r
185                 mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
186                 author = internet_address_mailbox_get_addr (mailbox);\r
187             }\r
188 -           clean_author = _thread_cleanup_author (thread, author, from);\r
189 -           _thread_add_address (thread->authors, clean_author, FALSE);\r
190 -           notmuch_message_set_author (message, clean_author);\r
191 +           clean_address = _thread_cleanup_address (thread, author, from);\r
192 +           _thread_add_address (thread->authors, clean_address, FALSE);\r
193 +           notmuch_message_set_author (message, clean_address);\r
194 +       }\r
195 +       g_object_unref (G_OBJECT (from_list));\r
196 +    }\r
197 +\r
198 +    if (include_recipients) {\r
199 +    to = notmuch_message_get_header (message, "to");\r
200 +    if (to)\r
201 +       to_list = internet_address_list_parse_string (to);\r
202 +    if (to_list) {\r
203 +       address = internet_address_list_get_address (to_list, 0);\r
204 +       if (address) {\r
205 +           recipient = internet_address_get_name (address);\r
206 +           if (recipient == NULL) {\r
207 +               InternetAddressMailbox *mailbox;\r
208 +               mailbox = INTERNET_ADDRESS_MAILBOX (address);\r
209 +               recipient = internet_address_mailbox_get_addr (mailbox);\r
210 +           }\r
211 +           clean_address = _thread_cleanup_address (thread, recipient, to);\r
212 +           _thread_add_address (thread->recipients, clean_address, FALSE);\r
213 +           notmuch_message_set_recipients (message, clean_address);\r
214         }\r
215 -       g_object_unref (G_OBJECT (list));\r
216 +       g_object_unref (G_OBJECT (to_list));\r
217 +    }\r
218      }\r
219  \r
220      if (! thread->subject) {\r
221 @@ -301,7 +326,8 @@ _thread_set_subject_from_message (notmuch_thread_t *thread,\r
222  static void\r
223  _thread_add_matched_message (notmuch_thread_t *thread,\r
224                              notmuch_message_t *message,\r
225 -                            notmuch_sort_t sort)\r
226 +                            notmuch_sort_t sort,\r
227 +                            notmuch_bool_t include_recipients)\r
228  {\r
229      time_t date;\r
230      notmuch_message_t *hashed_message;\r
231 @@ -331,6 +357,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
232      }\r
233  \r
234      _thread_add_address (thread->authors, notmuch_message_get_author (hashed_message), TRUE);\r
235 +    if (include_recipients)\r
236 +    _thread_add_address (thread->recipients, notmuch_message_get_recipients (hashed_message), TRUE);\r
237  }\r
238  \r
239  static void\r
240 @@ -399,10 +427,10 @@ _thread_addresses_init (const void *ctx)\r
241   *\r
242   * Creating the thread will perform a database search to get all\r
243   * messages belonging to the thread and will get the first subject\r
244 - * line, the total count of messages, and all authors in the thread.\r
245 - * Each message in the thread is checked against match_set to allow\r
246 - * for a separate count of matched messages, and to allow a viewer to\r
247 - * display these messages differently.\r
248 + * line, the total count of messages, and all authors and recipients\r
249 + * of the thread.  Each message in the thread is checked against\r
250 + * match_set to allow for a separate count of matched messages, and to\r
251 + * allow a viewer to display these messages differently.\r
252   *\r
253   * Here, 'ctx' is talloc context for the resulting thread object.\r
254   *\r
255 @@ -414,7 +442,8 @@ _notmuch_thread_create (void *ctx,\r
256                         unsigned int seed_doc_id,\r
257                         notmuch_doc_id_set_t *match_set,\r
258                         notmuch_string_list_t *exclude_terms,\r
259 -                       notmuch_sort_t sort)\r
260 +                       notmuch_sort_t sort,\r
261 +                       notmuch_bool_t include_recipients)\r
262  {\r
263      notmuch_thread_t *thread;\r
264      notmuch_message_t *seed_message;\r
265 @@ -453,6 +482,9 @@ _notmuch_thread_create (void *ctx,\r
266      thread->authors = _thread_addresses_init (thread);\r
267      if (unlikely (thread->authors == NULL))\r
268         return NULL;\r
269 +    thread->recipients = _thread_addresses_init (thread);\r
270 +    if (unlikely (thread->recipients == NULL))\r
271 +       return NULL;\r
272  \r
273      thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,\r
274                                           free, NULL);\r
275 @@ -486,11 +518,11 @@ _notmuch_thread_create (void *ctx,\r
276         if (doc_id == seed_doc_id)\r
277             message = seed_message;\r
278  \r
279 -       _thread_add_message (thread, message, exclude_terms);\r
280 +       _thread_add_message (thread, message, exclude_terms, include_recipients);\r
281  \r
282         if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {\r
283             _notmuch_doc_id_set_remove (match_set, doc_id);\r
284 -           _thread_add_matched_message (thread, message, sort);\r
285 +           _thread_add_matched_message (thread, message, sort, include_recipients);\r
286         }\r
287  \r
288         _notmuch_message_close (message);\r
289 @@ -499,6 +531,7 @@ _notmuch_thread_create (void *ctx,\r
290      notmuch_query_destroy (thread_id_query);\r
291  \r
292      _resolve_thread_addresses_string (thread->authors);\r
293 +    _resolve_thread_addresses_string (thread->recipients);\r
294  \r
295      _resolve_thread_relationships (thread);\r
296  \r
297 @@ -536,6 +569,12 @@ notmuch_thread_get_authors (notmuch_thread_t *thread)\r
298  }\r
299  \r
300  const char *\r
301 +notmuch_thread_get_recipients (notmuch_thread_t *thread)\r
302 +{\r
303 +    return thread->recipients->string;\r
304 +}\r
305 +\r
306 +const char *\r
307  notmuch_thread_get_subject (notmuch_thread_t *thread)\r
308  {\r
309      return thread->subject;\r
310 -- \r
311 1.7.10.4\r
312 \r