[PATCH] convert bitmap to unsigned char
[notmuch-archives.git] / c0 / cd8669f37dd7b45bae8bbc405e4837b8f66eff
1 Return-Path: <jan@iptel.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 3966C431FBF\r
6         for <notmuch@notmuchmail.org>; Thu, 19 Nov 2009 03:35:07 -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 r5UMGTB+G9l7 for <notmuch@notmuchmail.org>;\r
11         Thu, 19 Nov 2009 03:35:06 -0800 (PST)\r
12 Received: from mail.iptel.org (smtp.iptel.org [213.192.59.67])\r
13         by olra.theworths.org (Postfix) with ESMTP id DEAC8431FAE\r
14         for <notmuch@notmuchmail.org>; Thu, 19 Nov 2009 03:35:05 -0800 (PST)\r
15 Received: by mail.iptel.org (Postfix, from userid 103)\r
16         id B27F2370667; Thu, 19 Nov 2009 12:34:42 +0100 (CET)\r
17 Received: from x61s.janakj (nat.sip-server.net [213.192.30.130])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (Client did not present a certificate)\r
20         by mail.iptel.org (Postfix) with ESMTPSA id B9041370659\r
21         for <notmuch@notmuchmail.org>; Thu, 19 Nov 2009 12:34:41 +0100 (CET)\r
22 Received: by x61s.janakj (Postfix, from userid 1000)\r
23         id 89305440651; Thu, 19 Nov 2009 12:34:41 +0100 (CET)\r
24 From: Jan Janak <jan@ryngle.com>\r
25 To: notmuch@notmuchmail.org\r
26 Date: Thu, 19 Nov 2009 12:34:40 +0100\r
27 Message-Id: <1258630481-5133-1-git-send-email-jan@ryngle.com>\r
28 X-Mailer: git-send-email 1.6.3.3\r
29 Subject: [notmuch] [PATCH 1/2] notmuch: Support for notmuch_database_get_tags\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.12\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Thu, 19 Nov 2009 11:35:07 -0000\r
43 \r
44 This patch adds a new function called notmuch_database_get_tags which\r
45 can be used to obtain a list of all tags defined in the database (that\r
46 is, the list all tags from all messages). The function produces an\r
47 alphabetically sorted list.\r
48 \r
49 To add support for the new function, we rip the guts off of\r
50 notmuch_message_get_tags and put them in a new generic function\r
51 called _notmuch_convert_tags. The generic function takes a TermIterator\r
52 as argument and produces a notmuch_tags_t list of tags.\r
53 \r
54 Function notmuch_message_get_tags is then reimplemented to call the\r
55 generic function with message->doc.termlist_begin() as argument.\r
56 \r
57 Similarly, we implement notmuch_message_database_tags, the function\r
58 calls the generic function with db->xapian_db->allterms_begin() as\r
59 argument.\r
60 \r
61 Finally, notmuch_database_get_tags is exported through lib/notmuch.h\r
62 \r
63 Signed-off-by: Jan Janak <jan@ryngle.com>\r
64 ---\r
65  lib/database.cc |   48 ++++++++++++++++++++++++++++++++++++++++++++++++\r
66  lib/message.cc  |   38 ++++++--------------------------------\r
67  lib/notmuch.h   |    4 ++++\r
68  3 files changed, 58 insertions(+), 32 deletions(-)\r
69 \r
70 diff --git a/lib/database.cc b/lib/database.cc\r
71 index 4998fc9..b1c15c3 100644\r
72 --- a/lib/database.cc\r
73 +++ b/lib/database.cc\r
74 @@ -983,3 +983,51 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
75  \r
76      return ret;\r
77  }\r
78 +\r
79 +notmuch_tags_t *\r
80 +_notmuch_convert_tags (void* ctx, Xapian::TermIterator i);\r
81 +\r
82 +/* Converts tags from the format used in Xapian to a list in\r
83 +   notmuch_tags_t. */\r
84 +notmuch_tags_t *\r
85 +_notmuch_convert_tags (void* ctx, Xapian::TermIterator i)\r
86 +{\r
87 +    const char *prefix = _find_prefix ("tag");\r
88 +    notmuch_tags_t *tags;\r
89 +    std::string tag;\r
90 +\r
91 +    /* Currently this iteration is written with the assumption that\r
92 +     * "tag" has a single-character prefix. */\r
93 +    assert (strlen (prefix) == 1);\r
94 +\r
95 +    tags = _notmuch_tags_create (ctx);\r
96 +    if (unlikely (tags == NULL))\r
97 +       return NULL;\r
98 +\r
99 +    i.skip_to (prefix);\r
100 +\r
101 +    while (1) {\r
102 +       tag = *i;\r
103 +\r
104 +       if (tag.empty () || tag[0] != *prefix)\r
105 +           break;\r
106 +\r
107 +       _notmuch_tags_add_tag (tags, tag.c_str () + 1);\r
108 +\r
109 +       i++;\r
110 +    }\r
111 +\r
112 +    _notmuch_tags_prepare_iterator (tags);\r
113 +\r
114 +    return tags;\r
115 +}\r
116 +\r
117 +/*\r
118 + * Returns a list of all tags defined in a notmuch database. The resulting\r
119 + * list is sorted alphabetically.\r
120 + */\r
121 +notmuch_tags_t *\r
122 +notmuch_database_get_tags (notmuch_database_t *db)\r
123 +{\r
124 +       return _notmuch_convert_tags(db, db->xapian_db->allterms_begin());\r
125 +}\r
126 diff --git a/lib/message.cc b/lib/message.cc\r
127 index 9488fb6..af23bb2 100644\r
128 --- a/lib/message.cc\r
129 +++ b/lib/message.cc\r
130 @@ -41,6 +41,9 @@ struct _notmuch_message {\r
131      Xapian::Document doc;\r
132  };\r
133  \r
134 +extern notmuch_tags_t *\r
135 +_notmuch_convert_tags (void* ctx, Xapian::TermIterator i);\r
136 +\r
137  /* "128 bits of thread-id ought to be enough for anybody" */\r
138  #define NOTMUCH_THREAD_ID_BITS  128\r
139  #define NOTMUCH_THREAD_ID_DIGITS (NOTMUCH_THREAD_ID_BITS / 4)\r
140 @@ -445,43 +448,14 @@ notmuch_message_get_date (notmuch_message_t *message)\r
141      return Xapian::sortable_unserialise (value);\r
142  }\r
143  \r
144 +\r
145  notmuch_tags_t *\r
146  notmuch_message_get_tags (notmuch_message_t *message)\r
147  {\r
148 -    const char *prefix = _find_prefix ("tag");\r
149 -    Xapian::TermIterator i, end;\r
150 -    notmuch_tags_t *tags;\r
151 -    std::string tag;\r
152 -\r
153 -    /* Currently this iteration is written with the assumption that\r
154 -     * "tag" has a single-character prefix. */\r
155 -    assert (strlen (prefix) == 1);\r
156 -\r
157 -    tags = _notmuch_tags_create (message);\r
158 -    if (unlikely (tags == NULL))\r
159 -       return NULL;\r
160 -\r
161 -    i = message->doc.termlist_begin ();\r
162 -    end = message->doc.termlist_end ();\r
163 -\r
164 -    i.skip_to (prefix);\r
165 -\r
166 -    while (1) {\r
167 -       tag = *i;\r
168 -\r
169 -       if (tag.empty () || tag[0] != *prefix)\r
170 -           break;\r
171 -\r
172 -       _notmuch_tags_add_tag (tags, tag.c_str () + 1);\r
173 -\r
174 -       i++;\r
175 -    }\r
176 -\r
177 -    _notmuch_tags_prepare_iterator (tags);\r
178 -\r
179 -    return tags;\r
180 +       return _notmuch_convert_tags(message, message->doc.termlist_begin());\r
181  }\r
182  \r
183 +\r
184  void\r
185  _notmuch_message_set_date (notmuch_message_t *message,\r
186                            const char *date)\r
187 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
188 index cc713a3..1edcfd6 100644\r
189 --- a/lib/notmuch.h\r
190 +++ b/lib/notmuch.h\r
191 @@ -271,6 +271,10 @@ notmuch_message_t *\r
192  notmuch_database_find_message (notmuch_database_t *database,\r
193                                const char *message_id);\r
194  \r
195 +notmuch_tags_t *\r
196 +notmuch_database_get_tags (notmuch_database_t *database);\r
197 +\r
198 +\r
199  /* Create a new query for 'database'.\r
200   *\r
201   * Here, 'database' should be an open database, (see\r
202 -- \r
203 1.6.3.3\r
204 \r