Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 97 / 652029daa469b346422b8c23836cc1cbf56476
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 CE43A429E28\r
6         for <notmuch@notmuchmail.org>; Sun,  6 Nov 2011 13:47:24 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id LueDfViMT7bu for <notmuch@notmuchmail.org>;\r
17         Sun,  6 Nov 2011 13:47:23 -0800 (PST)\r
18 Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com\r
19         [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 32E8C429E27\r
22         for <notmuch@notmuchmail.org>; Sun,  6 Nov 2011 13:47:23 -0800 (PST)\r
23 Received: by mail-fx0-f53.google.com with SMTP id n15so1762114faa.26\r
24         for <notmuch@notmuchmail.org>; Sun, 06 Nov 2011 13:47:22 -0800 (PST)\r
25 Received: by 10.223.5.201 with SMTP id 9mr42978295faw.5.1320616042790;\r
26         Sun, 06 Nov 2011 13:47:22 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id e17sm8598363faf.4.2011.11.06.13.47.20\r
30         (version=SSLv3 cipher=OTHER); Sun, 06 Nov 2011 13:47:21 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH v4 1/6] lib: add function to get the number of threads\r
34         matching a search\r
35 Date: Sun,  6 Nov 2011 23:47:10 +0200\r
36 Message-Id:\r
37  <8771bb7ee67586515ff5114747fd680005ccfc5a.1320615322.git.jani@nikula.org>\r
38 X-Mailer: git-send-email 1.7.5.4\r
39 In-Reply-To: <cover.1320615322.git.jani@nikula.org>\r
40 References: <cover.1320615322.git.jani@nikula.org>\r
41 In-Reply-To: <cover.1320615322.git.jani@nikula.org>\r
42 References: <cover.1320615322.git.jani@nikula.org>\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, 06 Nov 2011 21:47:25 -0000\r
56 \r
57 Add function notmuch_query_count_threads() to get the number of threads\r
58 matching a search. This is done by performing a search and figuring out the\r
59 number of unique thread IDs in the matching messages, a significantly\r
60 heavier operation than notmuch_query_count_messages().\r
61 \r
62 Signed-off-by: Jani Nikula <jani@nikula.org>\r
63 ---\r
64  lib/notmuch.h |   14 ++++++++++++++\r
65  lib/query.cc  |   44 ++++++++++++++++++++++++++++++++++++++++++++\r
66  2 files changed, 58 insertions(+), 0 deletions(-)\r
67 \r
68 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
69 index c4330e4..9f23a10 100644\r
70 --- a/lib/notmuch.h\r
71 +++ b/lib/notmuch.h\r
72 @@ -609,6 +609,20 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
73  unsigned\r
74  notmuch_query_count_messages (notmuch_query_t *query);\r
75   \r
76 +/* Return the number of threads matching a search.\r
77 + *\r
78 + * This function performs a search and returns the number of unique thread IDs\r
79 + * in the matching messages. This is the same as number of threads matching a\r
80 + * search.\r
81 + *\r
82 + * Note that this is a significantly heavier operation than\r
83 + * notmuch_query_count_messages().\r
84 + *\r
85 + * If an error occurs, this function may return 0.\r
86 + */\r
87 +unsigned\r
88 +notmuch_query_count_threads (notmuch_query_t *query);\r
89 +\r
90  /* Get the thread ID of 'thread'.\r
91   *\r
92   * The returned string belongs to 'thread' and as such, should not be\r
93 diff --git a/lib/query.cc b/lib/query.cc\r
94 index 6f02b04..b6c0f12 100644\r
95 --- a/lib/query.cc\r
96 +++ b/lib/query.cc\r
97 @@ -457,3 +457,47 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
98  \r
99      return count;\r
100  }\r
101 +\r
102 +unsigned\r
103 +notmuch_query_count_threads (notmuch_query_t *query)\r
104 +{\r
105 +    notmuch_messages_t *messages;\r
106 +    GHashTable *hash;\r
107 +    unsigned int count;\r
108 +    notmuch_sort_t sort;\r
109 +\r
110 +    sort = query->sort;\r
111 +    query->sort = NOTMUCH_SORT_UNSORTED;\r
112 +    messages = notmuch_query_search_messages (query);\r
113 +    query->sort = sort;\r
114 +    if (messages == NULL)\r
115 +       return 0;\r
116 +\r
117 +    hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
118 +    if (hash == NULL) {\r
119 +       talloc_free (messages);\r
120 +       return 0;\r
121 +    }\r
122 +\r
123 +    while (notmuch_messages_valid (messages)) {\r
124 +       notmuch_message_t *message = notmuch_messages_get (messages);\r
125 +       const char *thread_id = notmuch_message_get_thread_id (message);\r
126 +       char *thread_id_copy = talloc_strdup (messages, thread_id);\r
127 +       if (unlikely (thread_id_copy == NULL)) {\r
128 +           notmuch_message_destroy (message);\r
129 +           count = 0;\r
130 +           goto DONE;\r
131 +       }\r
132 +       g_hash_table_insert (hash, thread_id_copy, NULL);\r
133 +       notmuch_message_destroy (message);\r
134 +       notmuch_messages_move_to_next (messages);\r
135 +    }\r
136 +\r
137 +    count = g_hash_table_size (hash);\r
138 +\r
139 +  DONE:\r
140 +    g_hash_table_unref (hash);\r
141 +    talloc_free (messages);\r
142 +\r
143 +    return count;\r
144 +}\r
145 -- \r
146 1.7.5.4\r
147 \r