Re: [PATCH v3] emacs: postpone/resume support
[notmuch-archives.git] / fb / e61833b7312afc3fb7c1e1b44fba84c570b438
1 Return-Path: <jan@ryngle.com>\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 56815431FAE\r
6         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 19:30:32 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id CI8+1m7tLGIW for <notmuch@notmuchmail.org>;\r
11         Tue, 24 Nov 2009 19:30:31 -0800 (PST)\r
12 Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com\r
13         [209.85.218.224])\r
14         by olra.theworths.org (Postfix) with ESMTP id 5E988431FBC\r
15         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 19:30:31 -0800 (PST)\r
16 Received: by bwz24 with SMTP id 24so5548849bwz.30\r
17         for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 19:30:30 -0800 (PST)\r
18 Received: by 10.204.153.220 with SMTP id l28mr6968577bkw.86.1259119829994;\r
19         Tue, 24 Nov 2009 19:30:29 -0800 (PST)\r
20 Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34])\r
21         by mx.google.com with ESMTPS id 15sm1599936bwz.4.2009.11.24.19.30.29\r
22         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
23         Tue, 24 Nov 2009 19:30:29 -0800 (PST)\r
24 Received: by x61s.janakj (Postfix, from userid 1000)\r
25         id C86CF440651; Wed, 25 Nov 2009 04:30:22 +0100 (CET)\r
26 From: Jan Janak <jan@ryngle.com>\r
27 To: notmuch@notmuchmail.org\r
28 Date: Wed, 25 Nov 2009 04:30:21 +0100\r
29 Message-Id: <1259119822-22593-1-git-send-email-jan@ryngle.com>\r
30 X-Mailer: git-send-email 1.6.3.3\r
31 In-Reply-To: <1258935056-9746-2-git-send-email-jan@ryngle.com>\r
32 References: <1258935056-9746-2-git-send-email-jan@ryngle.com>\r
33 Subject: [notmuch] [PATCH 1/2] lib: New function to collect tags from a list\r
34         of messages.\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.12\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Wed, 25 Nov 2009 03:30:32 -0000\r
48 \r
49 This patch adds a new function that can be used to collect a list of\r
50 unique tags from a list of messages. 'notmuch search-tags' uses the\r
51 function to get a list of tags from messages matching a search-term,\r
52 but it has the potential to be used elsewhere so we put it in the lib.\r
53 \r
54 Signed-off-by: Jan Janak <jan@ryngle.com>\r
55 ---\r
56  lib/messages.c |   40 ++++++++++++++++++++++++++++++++++++++++\r
57  lib/notmuch.h  |   15 +++++++++++++++\r
58  2 files changed, 55 insertions(+), 0 deletions(-)\r
59 \r
60 diff --git a/lib/messages.c b/lib/messages.c\r
61 index 54c0ab0..aa92535 100644\r
62 --- a/lib/messages.c\r
63 +++ b/lib/messages.c\r
64 @@ -20,6 +20,8 @@\r
65  \r
66  #include "notmuch-private.h"\r
67  \r
68 +#include <glib.h>\r
69 +\r
70  /* Create a new notmuch_message_list_t object, with 'ctx' as its\r
71   * talloc owner.\r
72   *\r
73 @@ -140,3 +142,41 @@ notmuch_messages_destroy (notmuch_messages_t *messages)\r
74  {\r
75      talloc_free (messages);\r
76  }\r
77 +\r
78 +\r
79 +notmuch_tags_t *\r
80 +notmuch_messages_collect_tags (notmuch_messages_t *messages)\r
81 +{\r
82 +    notmuch_tags_t *tags, *msg_tags;\r
83 +    notmuch_message_t *msg;\r
84 +    GHashTable *htable;\r
85 +    GList *keys, *l;\r
86 +    const char *tag;\r
87 +\r
88 +    tags = _notmuch_tags_create (messages);\r
89 +    if (tags == NULL) return NULL;\r
90 +\r
91 +    htable = g_hash_table_new_full (g_str_hash, g_str_equal, free, NULL);\r
92 +\r
93 +    while ((msg = notmuch_messages_get (messages))) {\r
94 +       msg_tags = notmuch_message_get_tags (msg);\r
95 +       while ((tag = notmuch_tags_get (msg_tags))) {\r
96 +           g_hash_table_insert (htable, xstrdup (tag), NULL);\r
97 +           notmuch_tags_advance (msg_tags);\r
98 +       }\r
99 +       notmuch_tags_destroy (msg_tags);\r
100 +       notmuch_message_destroy (msg);\r
101 +       notmuch_messages_advance (messages);\r
102 +    }\r
103 +\r
104 +    keys = g_hash_table_get_keys (htable);\r
105 +    for (l = keys; l; l = l->next) {\r
106 +       _notmuch_tags_add_tag (tags, (char *)l->data);\r
107 +    }\r
108 +\r
109 +    g_list_free (keys);\r
110 +    g_hash_table_destroy (htable);\r
111 +\r
112 +    _notmuch_tags_prepare_iterator (tags);\r
113 +    return tags;\r
114 +}\r
115 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
116 index c05e802..9fa2770 100644\r
117 --- a/lib/notmuch.h\r
118 +++ b/lib/notmuch.h\r
119 @@ -635,6 +635,21 @@ notmuch_messages_advance (notmuch_messages_t *messages);\r
120  void\r
121  notmuch_messages_destroy (notmuch_messages_t *messages);\r
122  \r
123 +/* Return a list of tags from all messages.\r
124 + *\r
125 + * The resulting list is guaranteed not to contain duplicated tags.\r
126 + *\r
127 + * WARNING: You can no longer iterate over messages after calling this\r
128 + * function, because the iterator will point at the end of the list.\r
129 + * We do not have a function to reset the iterator yet and the only\r
130 + * way how you can iterate over the list again is to recreate the\r
131 + * message list.\r
132 + *\r
133 + * The function returns NULL on error.\r
134 + */\r
135 +notmuch_tags_t *\r
136 +notmuch_messages_collect_tags (notmuch_messages_t *messages);\r
137 +\r
138  /* Get the message ID of 'message'.\r
139   *\r
140   * The returned string belongs to 'message' and as such, should not be\r
141 -- \r
142 1.6.3.3\r
143 \r