Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / 94 / 68b4501028f3a9312f3761444a86bd8c86a9ad
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 4A69E431FC0\r
6         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:12 -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 XVHEU2ZXjptE for <notmuch@notmuchmail.org>;\r
16         Sun, 19 Aug 2012 18:53:10 -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 F34D2431FBD\r
20         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:07 -0700 (PDT)\r
21 Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by earth-doxen-postvirus (Postfix) with ESMTP id BBF3366E00DF\r
23         for <notmuch@notmuchmail.org>; Sun, 19 Aug 2012 18:53:07 -0700 (PDT)\r
24 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
25 Received: from finestructure.net (unknown [76.89.192.57])\r
26         (Authenticated sender: jrollins)\r
27         by earth-doxen-submit (Postfix) with ESMTP id A2A7966E00DE\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 DE5B1CD7; 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 08/11] cli: add thread recipients to search output\r
34 Date: Sun, 19 Aug 2012 18:52:47 -0700\r
35 Message-Id: <1345427570-26518-9-git-send-email-jrollins@finestructure.net>\r
36 X-Mailer: git-send-email 1.7.10.4\r
37 In-Reply-To: <1345427570-26518-8-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         <1345427570-26518-7-git-send-email-jrollins@finestructure.net>\r
45         <1345427570-26518-8-git-send-email-jrollins@finestructure.net>\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: Mon, 20 Aug 2012 01:53:12 -0000\r
59 \r
60 This adds a "--include-recipients" option to notmuch search.  With\r
61 structured output formats (e.g. json), a new recipients field will be\r
62 included that holds recipients of the thread.  Matched and non-matched\r
63 recipients are delineated as with authors.\r
64 \r
65 As mentioned in the previous patch for the underlying lib functions,\r
66 the need for the option is because message recipients are not stored\r
67 in the database and therefore retrieving them adds a significant\r
68 overhead.  If they were included, this option would not be necessary.\r
69 ---\r
70  lib/notmuch.h    |    6 +++++-\r
71  lib/query.cc     |    5 +++--\r
72  notmuch-search.c |   14 +++++++++++---\r
73  notmuch-show.c   |    2 +-\r
74  test/json        |    1 -\r
75  5 files changed, 20 insertions(+), 8 deletions(-)\r
76 \r
77 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
78 index f9e71c1..8eb455e 100644\r
79 --- a/lib/notmuch.h\r
80 +++ b/lib/notmuch.h\r
81 @@ -642,6 +642,9 @@ notmuch_threads_valid (notmuch_threads_t *threads);\r
82  \r
83  /* Get the current thread from 'threads' as a notmuch_thread_t.\r
84   *\r
85 + * If the include_recipients flag is TRUE, thread recipients will be\r
86 + * included in the returned thread object.\r
87 + *\r
88   * Note: The returned thread belongs to 'threads' and has a lifetime\r
89   * identical to it (and the query to which it belongs).\r
90   *\r
91 @@ -652,7 +655,8 @@ notmuch_threads_valid (notmuch_threads_t *threads);\r
92   * NULL.\r
93   */\r
94  notmuch_thread_t *\r
95 -notmuch_threads_get (notmuch_threads_t *threads);\r
96 +notmuch_threads_get (notmuch_threads_t *threads,\r
97 +                    notmuch_bool_t include_recipients);\r
98  \r
99  /* Move the 'threads' iterator to the next thread.\r
100   *\r
101 diff --git a/lib/query.cc b/lib/query.cc\r
102 index 54833a7..0a4f058 100644\r
103 --- a/lib/query.cc\r
104 +++ b/lib/query.cc\r
105 @@ -472,7 +472,8 @@ notmuch_threads_valid (notmuch_threads_t *threads)\r
106  }\r
107  \r
108  notmuch_thread_t *\r
109 -notmuch_threads_get (notmuch_threads_t *threads)\r
110 +notmuch_threads_get (notmuch_threads_t *threads,\r
111 +                    notmuch_bool_t include_recipients)\r
112  {\r
113      unsigned int doc_id;\r
114  \r
115 @@ -487,7 +488,7 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
116                                    &threads->match_set,\r
117                                    threads->query->exclude_terms,\r
118                                    threads->query->sort,\r
119 -                                  FALSE);\r
120 +                                  include_recipients);\r
121  }\r
122  \r
123  void\r
124 diff --git a/notmuch-search.c b/notmuch-search.c\r
125 index 830c4e4..f610a84 100644\r
126 --- a/notmuch-search.c\r
127 +++ b/notmuch-search.c\r
128 @@ -52,7 +52,8 @@ do_search_threads (sprinter_t *format,\r
129                    notmuch_sort_t sort,\r
130                    output_t output,\r
131                    int offset,\r
132 -                  int limit)\r
133 +                  int limit,\r
134 +                  notmuch_bool_t include_recipients)\r
135  {\r
136      notmuch_thread_t *thread;\r
137      notmuch_threads_t *threads;\r
138 @@ -76,7 +77,7 @@ do_search_threads (sprinter_t *format,\r
139          notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);\r
140          notmuch_threads_move_to_next (threads), i++)\r
141      {\r
142 -       thread = notmuch_threads_get (threads);\r
143 +       thread = notmuch_threads_get (threads, include_recipients);\r
144  \r
145         if (i < offset) {\r
146             notmuch_thread_destroy (thread);\r
147 @@ -91,6 +92,7 @@ do_search_threads (sprinter_t *format,\r
148         } else { /* output == OUTPUT_SUMMARY */\r
149             void *ctx_quote = talloc_new (thread);\r
150             const char *authors = notmuch_thread_get_authors (thread);\r
151 +           const char *recipients = notmuch_thread_get_recipients (thread);\r
152             const char *subject = notmuch_thread_get_subject (thread);\r
153             const char *thread_id = notmuch_thread_get_thread_id (thread);\r
154             int matched = notmuch_thread_get_matched_messages (thread);\r
155 @@ -129,6 +131,10 @@ do_search_threads (sprinter_t *format,\r
156                 format->integer (format, total);\r
157                 format->map_key (format, "authors");\r
158                 format->string (format, authors);\r
159 +               if (include_recipients) {\r
160 +                   format->map_key (format, "recipients");\r
161 +                   format->string (format, recipients);\r
162 +               }\r
163                 format->map_key (format, "subject");\r
164                 format->string (format, subject);\r
165             }\r
166 @@ -303,6 +309,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
167      int offset = 0;\r
168      int limit = -1; /* unlimited */\r
169      int exclude = EXCLUDE_TRUE;\r
170 +    notmuch_bool_t include_recipients = FALSE;\r
171      unsigned int i;\r
172  \r
173      enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }\r
174 @@ -331,6 +338,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
175                                    { 0, 0 } } },\r
176         { NOTMUCH_OPT_INT, &offset, "offset", 'O', 0 },\r
177         { NOTMUCH_OPT_INT, &limit, "limit", 'L', 0  },\r
178 +       { NOTMUCH_OPT_BOOLEAN, &include_recipients, "include-recipients", 'r', 0 },\r
179         { 0, 0, 0, 0, 0 }\r
180      };\r
181  \r
182 @@ -402,7 +410,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
183      default:\r
184      case OUTPUT_SUMMARY:\r
185      case OUTPUT_THREADS:\r
186 -       ret = do_search_threads (format, query, sort, output, offset, limit);\r
187 +       ret = do_search_threads (format, query, sort, output, offset, limit, include_recipients);\r
188         break;\r
189      case OUTPUT_MESSAGES:\r
190      case OUTPUT_FILES:\r
191 diff --git a/notmuch-show.c b/notmuch-show.c\r
192 index 3556293..cc4b428 100644\r
193 --- a/notmuch-show.c\r
194 +++ b/notmuch-show.c\r
195 @@ -965,7 +965,7 @@ do_show (void *ctx,\r
196          notmuch_threads_valid (threads);\r
197          notmuch_threads_move_to_next (threads))\r
198      {\r
199 -       thread = notmuch_threads_get (threads);\r
200 +       thread = notmuch_threads_get (threads, FALSE);\r
201  \r
202         messages = notmuch_thread_get_toplevel_messages (thread);\r
203  \r
204 diff --git a/test/json b/test/json\r
205 index ac423a8..f441b59 100755\r
206 --- a/test/json\r
207 +++ b/test/json\r
208 @@ -61,7 +61,6 @@ test_expect_equal_json "$output" "[{\"thread\": \"XXX\",\r
209   \"unread\"]}]"\r
210  \r
211  test_begin_subtest "Search message: include recipients"\r
212 -test_subtest_known_broken\r
213  output=$(notmuch search --format=json --include-recipients "json-search-message" | notmuch_search_sanitize)\r
214  test_expect_equal_json "$output" "[{\"thread\": \"XXX\",\r
215   \"timestamp\": 946728000,\r
216 -- \r
217 1.7.10.4\r
218 \r