Re: [PATCH] bug in notmuch-fcc-header-setup
[notmuch-archives.git] / 7b / ad574a6262e973f8cb9238bfc60484c3401247
1 Return-Path: <meskio@sindominio.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 882A5417340\r
6         for <notmuch@notmuchmail.org>; Sat, 20 Mar 2010 03:21:42 -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: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\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 zQ5iSnDOmwm7 for <notmuch@notmuchmail.org>;\r
16         Sat, 20 Mar 2010 03:21:40 -0700 (PDT)\r
17 Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26])\r
18         by olra.theworths.org (Postfix) with ESMTP id DEB23431FC1\r
19         for <notmuch@notmuchmail.org>; Sat, 20 Mar 2010 03:21:39 -0700 (PDT)\r
20 Received: from localhost (localhost.localdomain [127.0.0.1])\r
21         by flatline.sindominio.net (Postfix) with ESMTP id C66F2262E3E;\r
22         Sat, 20 Mar 2010 11:21:38 +0100 (CET)\r
23 X-Virus-Scanned: Debian amavisd-new at sindominio.net\r
24 Received: from flatline.sindominio.net ([127.0.0.1])\r
25         by localhost (flatline.sindominio.net [127.0.0.1]) (amavisd-new,\r
26         port 10024)\r
27         with ESMTP id Yiiim5dMf4NV; Sat, 20 Mar 2010 11:21:35 +0100 (CET)\r
28 Received: from blackspot (heal.cauterized.net [89.140.131.167])\r
29         by flatline.sindominio.net (Postfix) with ESMTPA id 6EA72262E3B;\r
30         Sat, 20 Mar 2010 11:21:28 +0100 (CET)\r
31 Received: by blackspot (Postfix, from userid 1000)\r
32         id 0FF728BDFC; Sat, 20 Mar 2010 11:24:51 +0100 (CET)\r
33 From: Ruben Pollan <meskio@sindominio.net>\r
34 To: notmuch@notmuchmail.org\r
35 Date: Sat, 20 Mar 2010 11:23:22 +0100\r
36 Message-Id: <1269080605-5617-3-git-send-email-meskio@sindominio.net>\r
37 X-Mailer: git-send-email 1.7.0\r
38 In-Reply-To: <873a09jt2t.fsf@yoom.home.cworth.org>\r
39 References: <873a09jt2t.fsf@yoom.home.cworth.org>\r
40 Subject: [notmuch] [PATCH 2/5] Added backwards iterator to messages\r
41 X-BeenThere: notmuch@notmuchmail.org\r
42 X-Mailman-Version: 2.1.13\r
43 Precedence: list\r
44 List-Id: "Use and development of the notmuch mail system."\r
45         <notmuch.notmuchmail.org>\r
46 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
48 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
49 List-Post: <mailto:notmuch@notmuchmail.org>\r
50 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
51 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
53 X-List-Received-Date: Sat, 20 Mar 2010 10:21:42 -0000\r
54 \r
55 Added the functions notmuch_messages_move_to_prevoius,\r
56 notmuch_messages_move_to_last and  notmuch_messages_move_to_first to\r
57 notmuch library. With them is possible to iterate backwards on messages.\r
58 \r
59 * notmuch_messages_move_to_prevoius do the opposite than\r
60   notmuch_messages_move_to_next, getting the messages iterator one\r
61   position backwards.\r
62 \r
63 * notmuch_messages_move_to_last move the iterator to the first last\r
64   message.\r
65 \r
66 * notmuch_messages_move_to_first move the iterator to the first valid\r
67   message.\r
68 ---\r
69  lib/messages.c        |   31 +++++++++++++++++++++++++++++\r
70  lib/notmuch-private.h |   10 +++++++++\r
71  lib/notmuch.h         |   28 ++++++++++++++++++++++++++\r
72  lib/query.cc          |   52 +++++++++++++++++++++++++++++++++++++++++++++++++\r
73  4 files changed, 121 insertions(+), 0 deletions(-)\r
74 \r
75 diff --git a/lib/messages.c b/lib/messages.c\r
76 index 2a85774..975e4b1 100644\r
77 --- a/lib/messages.c\r
78 +++ b/lib/messages.c\r
79 @@ -90,6 +90,7 @@ _notmuch_messages_create (notmuch_message_list_t *list)\r
80  \r
81      messages->is_of_list_type = TRUE;\r
82      messages->iterator = list->head;\r
83 +    messages->list = list;\r
84  \r
85      return messages;\r
86  }\r
87 @@ -134,6 +135,15 @@ notmuch_messages_get (notmuch_messages_t *messages)\r
88  }\r
89  \r
90  void\r
91 +notmuch_messages_move_to_first (notmuch_messages_t *messages)\r
92 +{\r
93 +    if (! messages->is_of_list_type)\r
94 +       return _notmuch_mset_messages_move_to_first (messages);\r
95 +\r
96 +    messages->iterator = messages->list->head;\r
97 +}\r
98 +\r
99 +void\r
100  notmuch_messages_move_to_next (notmuch_messages_t *messages)\r
101  {\r
102      if (! messages->is_of_list_type)\r
103 @@ -146,6 +156,27 @@ notmuch_messages_move_to_next (notmuch_messages_t *messages)\r
104  }\r
105  \r
106  void\r
107 +notmuch_messages_move_to_last (notmuch_messages_t *messages)\r
108 +{\r
109 +    if (! messages->is_of_list_type)\r
110 +       return _notmuch_mset_messages_move_to_last (messages);\r
111 +\r
112 +    messages->iterator = messages->list->tail;\r
113 +}\r
114 +\r
115 +void\r
116 +notmuch_messages_move_to_previous (notmuch_messages_t *messages)\r
117 +{\r
118 +    if (! messages->is_of_list_type)\r
119 +       return _notmuch_mset_messages_move_to_previous (messages);\r
120 +\r
121 +    if (messages->iterator == NULL)\r
122 +       return;\r
123 +\r
124 +    messages->iterator = messages->iterator->prev;\r
125 +}\r
126 +\r
127 +void\r
128  notmuch_messages_destroy (notmuch_messages_t *messages)\r
129  {\r
130      talloc_free (messages);\r
131 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
132 index 3b3f0eb..2269d2b 100644\r
133 --- a/lib/notmuch-private.h\r
134 +++ b/lib/notmuch-private.h\r
135 @@ -364,6 +364,7 @@ typedef struct _notmuch_message_list {\r
136  struct _notmuch_messages {\r
137      notmuch_bool_t is_of_list_type;\r
138      notmuch_message_node_t *iterator;\r
139 +    notmuch_message_list_t *list;\r
140  };\r
141  \r
142  notmuch_message_list_t *\r
143 @@ -389,8 +390,17 @@ notmuch_message_t *\r
144  _notmuch_mset_messages_get (notmuch_messages_t *messages);\r
145  \r
146  void\r
147 +_notmuch_mset_messages_move_to_first (notmuch_messages_t *messages);\r
148 +\r
149 +void\r
150  _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages);\r
151  \r
152 +void\r
153 +_notmuch_mset_messages_move_to_last (notmuch_messages_t *messages);\r
154 +\r
155 +void\r
156 +_notmuch_mset_messages_move_to_previous (notmuch_messages_t *messages);\r
157 +\r
158  /* message.cc */\r
159  \r
160  void\r
161 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
162 index 0d9cb0f..753f3bb 100644\r
163 --- a/lib/notmuch.h\r
164 +++ b/lib/notmuch.h\r
165 @@ -645,6 +645,15 @@ notmuch_messages_valid (notmuch_messages_t *messages);\r
166  notmuch_message_t *\r
167  notmuch_messages_get (notmuch_messages_t *messages);\r
168  \r
169 +/* Move the 'messages' iterator to the first message.\r
170 + *\r
171 + * After that the 'messages' iterator will be set to the first valid \r
172 + * message, so it can be use to iterate with \r
173 + * notmuch_messages_move_to_next.\r
174 + */\r
175 +void\r
176 +notmuch_messages_move_to_first (notmuch_messages_t *messages);\r
177 +\r
178  /* Move the 'messages' iterator to the next message.\r
179   *\r
180   * If 'messages' is already pointing at the last message then the\r
181 @@ -658,6 +667,25 @@ notmuch_messages_get (notmuch_messages_t *messages);\r
182  void\r
183  notmuch_messages_move_to_next (notmuch_messages_t *messages);\r
184  \r
185 +/* Move the 'messages' iterator to the last message.\r
186 + *\r
187 + * After that the 'messages' iterator will be set to the last valid \r
188 + * message, so it can be use to iterate with \r
189 + * notmuch_messages_move_to_previous.\r
190 + */\r
191 +void\r
192 +notmuch_messages_move_to_last (notmuch_messages_t *messages);\r
193 +\r
194 +/* Move the 'messages' iterator to the previous message.\r
195 + *\r
196 + * If 'messages' is already pointing at the first message then the\r
197 + * iterator will be moved to a point just beyond that first message,\r
198 + * (where notmuch_messages_valid will return FALSE and\r
199 + * notmuch_messages_get will return NULL).\r
200 + */\r
201 +void\r
202 +notmuch_messages_move_to_previous (notmuch_messages_t *messages);\r
203 +\r
204  /* Destroy a notmuch_messages_t object.\r
205   *\r
206   * It's not strictly necessary to call this function. All memory from\r
207 diff --git a/lib/query.cc b/lib/query.cc\r
208 index 9266d35..970c35a 100644\r
209 --- a/lib/query.cc\r
210 +++ b/lib/query.cc\r
211 @@ -35,6 +35,7 @@ typedef struct _notmuch_mset_messages {\r
212      notmuch_messages_t base;\r
213      notmuch_database_t *notmuch;\r
214      Xapian::MSetIterator iterator;\r
215 +    Xapian::MSetIterator iterator_begin;\r
216      Xapian::MSetIterator iterator_end;\r
217  } notmuch_mset_messages_t;\r
218  \r
219 @@ -86,6 +87,7 @@ static int\r
220  _notmuch_messages_destructor (notmuch_mset_messages_t *messages)\r
221  {\r
222      messages->iterator.~MSetIterator ();\r
223 +    messages->iterator_begin.~MSetIterator ();\r
224      messages->iterator_end.~MSetIterator ();\r
225  \r
226      return 0;\r
227 @@ -108,6 +110,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
228         messages->base.iterator = NULL;\r
229         messages->notmuch = notmuch;\r
230         new (&messages->iterator) Xapian::MSetIterator ();\r
231 +       new (&messages->iterator_begin) Xapian::MSetIterator ();\r
232         new (&messages->iterator_end) Xapian::MSetIterator ();\r
233  \r
234         talloc_set_destructor (messages, _notmuch_messages_destructor);\r
235 @@ -157,6 +160,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
236         mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
237  \r
238         messages->iterator = mset.begin ();\r
239 +       messages->iterator_begin = mset.begin ();\r
240         messages->iterator_end = mset.end ();\r
241  \r
242      } catch (const Xapian::Error &error) {\r
243 @@ -208,6 +212,16 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
244  }\r
245  \r
246  void\r
247 +_notmuch_mset_messages_move_to_first (notmuch_messages_t *messages)\r
248 +{\r
249 +    notmuch_mset_messages_t *mset_messages;\r
250 +\r
251 +    mset_messages = (notmuch_mset_messages_t *) messages;\r
252 +\r
253 +    mset_messages->iterator = mset_messages->iterator_begin;\r
254 +}\r
255 +\r
256 +void\r
257  _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages)\r
258  {\r
259      notmuch_mset_messages_t *mset_messages;\r
260 @@ -217,6 +231,44 @@ _notmuch_mset_messages_move_to_next (notmuch_messages_t *messages)\r
261      mset_messages->iterator++;\r
262  }\r
263  \r
264 +void\r
265 +_notmuch_mset_messages_move_to_last (notmuch_messages_t *messages)\r
266 +{\r
267 +    notmuch_mset_messages_t *mset_messages;\r
268 +\r
269 +    mset_messages = (notmuch_mset_messages_t *) messages;\r
270 +\r
271 +    mset_messages->iterator = mset_messages->iterator_end;\r
272 +    mset_messages->iterator--;\r
273 +}\r
274 +\r
275 +void\r
276 +_notmuch_mset_messages_move_to_previous (notmuch_messages_t *messages)\r
277 +{\r
278 +    notmuch_mset_messages_t *mset_messages;\r
279 +\r
280 +    mset_messages = (notmuch_mset_messages_t *) messages;\r
281 +\r
282 +    if (mset_messages->iterator == mset_messages->iterator_begin)\r
283 +    {\r
284 +        /*\r
285 +         * Xapian iterators can not be beyond the first element, so we\r
286 +         * assign the iterator_end to mark the iterator as invalid in case\r
287 +         * of move_to_previous with the iterator at the beginning\r
288 +         */\r
289 +        mset_messages->iterator = mset_messages->iterator_end;\r
290 +    }\r
291 +    else if (_notmuch_mset_messages_valid (messages))\r
292 +    {\r
293 +        /*\r
294 +         * If is valid move the iterator. To emulate the same behavior \r
295 +         * than notmuch_messages_t the iterator won't be updated if is \r
296 +         * not valid\r
297 +         */\r
298 +        mset_messages->iterator--;\r
299 +    }\r
300 +}\r
301 +\r
302  /* Glib objects force use to use a talloc destructor as well, (but not\r
303   * nearly as ugly as the for messages due to C++ objects). At\r
304   * this point, I'd really like to have some talloc-friendly\r
305 -- \r
306 1.7.0\r
307 \r