[PATCH] Omit User-Agent: header by default
[notmuch-archives.git] / 7b / ba31382bba6ad093dcfb7235278e7f7a48acf6
1 Return-Path: <adrien@bustany.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 5683F431FDB\r
6         for <notmuch@notmuchmail.org>; Wed, 18 Jul 2012 11:41:09 -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: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 OV4D8BBF1Od8 for <notmuch@notmuchmail.org>;\r
16         Wed, 18 Jul 2012 11:41:06 -0700 (PDT)\r
17 Received: from mail.bustany.org (bustany.org [176.31.244.208])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8063D431FC3\r
19         for <notmuch@notmuchmail.org>; Wed, 18 Jul 2012 11:41:05 -0700 (PDT)\r
20 Received: from localhost.localdomain (91-158-2-79.elisa-laajakaista.fi\r
21         [91.158.2.79])\r
22         by mail.bustany.org (Postfix) with ESMTPSA id D26D51400EE\r
23         for <notmuch@notmuchmail.org>; Wed, 18 Jul 2012 20:37:09 +0200 (CEST)\r
24 From: Adrien Bustany <adrien@bustany.org>\r
25 To: notmuch@notmuchmail.org\r
26 Subject: [PATCH 7/7] go: Bind notmuch_thread_t functions\r
27 Date: Wed, 18 Jul 2012 21:34:35 +0300\r
28 Message-Id: <1342636475-16057-8-git-send-email-adrien@bustany.org>\r
29 X-Mailer: git-send-email 1.7.7.6\r
30 In-Reply-To: <1342636475-16057-1-git-send-email-adrien@bustany.org>\r
31 References: <1342636475-16057-1-git-send-email-adrien@bustany.org>\r
32 X-BeenThere: notmuch@notmuchmail.org\r
33 X-Mailman-Version: 2.1.13\r
34 Precedence: list\r
35 List-Id: "Use and development of the notmuch mail system."\r
36         <notmuch.notmuchmail.org>\r
37 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
38         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
39 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
40 List-Post: <mailto:notmuch@notmuchmail.org>\r
41 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
42 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
44 X-List-Received-Date: Wed, 18 Jul 2012 18:41:09 -0000\r
45 \r
46 ---\r
47  bindings/go/src/notmuch/notmuch.go |  253 +++++++++++++++++++++++++++++++++++-\r
48  1 files changed, 252 insertions(+), 1 deletions(-)\r
49 \r
50 diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go\r
51 index be4cb8c..f667dbb 100644\r
52 --- a/bindings/go/src/notmuch/notmuch.go\r
53 +++ b/bindings/go/src/notmuch/notmuch.go\r
54 @@ -12,6 +12,8 @@ package notmuch\r
55  */\r
56  import "C"\r
57  import "runtime"\r
58 +import "strings"\r
59 +import "time"\r
60  import "unsafe"\r
61  \r
62  // Status codes used for the return values of most functions\r
63 @@ -700,7 +702,20 @@ func (self *Query) CountMessages() uint {\r
64         return uint(C.notmuch_query_count_messages(self.query))\r
65  }\r
66  \r
67 -// TODO: wrap threads and thread\r
68 +/* Return the number of threads matching a search.\r
69 + *\r
70 + * This function performs a search and returns the number of unique thread IDs\r
71 + * in the matching messages. This is the same as number of threads matching a\r
72 + * search.\r
73 + *\r
74 + * Note that this is a significantly heavier operation than\r
75 + * notmuch_query_count_messages().\r
76 + *\r
77 + * If an error occurs, this function may return 0.\r
78 + */\r
79 +func (self *Query) CountThreads() uint {\r
80 +       return uint(C.notmuch_query_count_threads(self.query))\r
81 +}\r
82  \r
83  /* Is the given 'threads' iterator pointing at a valid thread.\r
84   *\r
85 @@ -722,6 +737,45 @@ func (self *Threads) Valid() bool {\r
86         return true\r
87  }\r
88  \r
89 +/* Get the current thread from 'threads' as a notmuch_thread_t.\r
90 + *\r
91 + * Note: The returned thread belongs to 'threads' and has a lifetime\r
92 + * identical to it (and the query to which it belongs).\r
93 + *\r
94 + * See the documentation of notmuch_query_search_threads for example\r
95 + * code showing how to iterate over a notmuch_threads_t object.\r
96 + *\r
97 + * If an out-of-memory situation occurs, this function will return\r
98 + * NULL.\r
99 + */\r
100 +func (self *Threads) Get() *Thread {\r
101 +       if self.threads == nil {\r
102 +               return nil\r
103 +       }\r
104 +       thread := C.notmuch_threads_get(self.threads)\r
105 +       if thread == nil {\r
106 +               return nil\r
107 +       }\r
108 +       return createThread(thread, self)\r
109 +}\r
110 +\r
111 +/* Move the 'threads' iterator to the next thread.\r
112 + *\r
113 + * If 'threads' is already pointing at the last thread then the\r
114 + * iterator will be moved to a point just beyond that last thread,\r
115 + * (where notmuch_threads_valid will return FALSE and\r
116 + * notmuch_threads_get will return NULL).\r
117 + *\r
118 + * See the documentation of notmuch_query_search_threads for example\r
119 + * code showing how to iterate over a notmuch_threads_t object.\r
120 + */\r
121 +func (self *Threads) MoveToNext() {\r
122 +       if self.threads == nil {\r
123 +               return\r
124 +       }\r
125 +       C.notmuch_threads_move_to_next(self.threads)\r
126 +}\r
127 +\r
128  /* Destroy a notmuch_threads_t object.\r
129   *\r
130   * It's not strictly necessary to call this function. All memory from\r
131 @@ -735,6 +789,203 @@ func (self *Threads) Destroy() {\r
132         }\r
133  }\r
134  \r
135 +/* Get the thread ID of 'thread'.\r
136 + *\r
137 + * The returned string belongs to 'thread' and as such, should not be\r
138 + * modified by the caller and will only be valid for as long as the\r
139 + * thread is valid, (which is until notmuch_thread_destroy or until\r
140 + * the query from which it derived is destroyed).\r
141 + */\r
142 +func (self *Thread) GetThreadId() string {\r
143 +       if self.thread == nil {\r
144 +               return ""\r
145 +       }\r
146 +       id := C.notmuch_thread_get_thread_id(self.thread)\r
147 +\r
148 +       if id == nil {\r
149 +               return ""\r
150 +       }\r
151 +\r
152 +       return C.GoString(id)\r
153 +}\r
154 +\r
155 +/* Get the total number of messages in 'thread'.\r
156 + *\r
157 + * This count consists of all messages in the database belonging to\r
158 + * this thread. Contrast with notmuch_thread_get_matched_messages() .\r
159 + */\r
160 +func (self *Thread) GetTotalMessages() int {\r
161 +       if self.thread == nil {\r
162 +               return 0\r
163 +       }\r
164 +       return int(C.notmuch_thread_get_total_messages(self.thread))\r
165 +}\r
166 +\r
167 +/* Get a notmuch_messages_t iterator for the top-level messages in\r
168 + * 'thread'.\r
169 + *\r
170 + * This iterator will not necessarily iterate over all of the messages\r
171 + * in the thread. It will only iterate over the messages in the thread\r
172 + * which are not replies to other messages in the thread.\r
173 + *\r
174 + * To iterate over all messages in the thread, the caller will need to\r
175 + * iterate over the result of notmuch_message_get_replies for each\r
176 + * top-level message (and do that recursively for the resulting\r
177 + * messages, etc.).\r
178 + */\r
179 +func (self *Thread) GetToplevelMessages() *Messages {\r
180 +       if self.thread == nil {\r
181 +               return nil\r
182 +       }\r
183 +       msgs := C.notmuch_thread_get_toplevel_messages(self.thread)\r
184 +       if msgs == nil {\r
185 +               return nil\r
186 +       }\r
187 +       return createMessages(msgs, self)\r
188 +}\r
189 +\r
190 +/* Get a notmuch_messages_t iterator for the top-level messages in\r
191 + * 'thread'.\r
192 + *\r
193 + * This iterator will not necessarily iterate over all of the messages\r
194 + * in the thread. It will only iterate over the messages in the thread\r
195 + * which are not replies to other messages in the thread.\r
196 + *\r
197 + * To iterate over all messages in the thread, the caller will need to\r
198 + * iterate over the result of notmuch_message_get_replies for each\r
199 + * top-level message (and do that recursively for the resulting\r
200 + * messages, etc.).\r
201 + */\r
202 +func (self *Thread) GetMatchedMessages() int {\r
203 +       if self.thread == nil {\r
204 +               return 0\r
205 +       }\r
206 +       return int(C.notmuch_thread_get_matched_messages(self.thread))\r
207 +}\r
208 +\r
209 +/* Get a notmuch_messages_t iterator for the top-level messages in\r
210 + * 'thread'.\r
211 + *\r
212 + * This iterator will not necessarily iterate over all of the messages\r
213 + * in the thread. It will only iterate over the messages in the thread\r
214 + * which are not replies to other messages in the thread.\r
215 + *\r
216 + * To iterate over all messages in the thread, the caller will need to\r
217 + * iterate over the result of notmuch_message_get_replies for each\r
218 + * top-level message (and do that recursively for the resulting\r
219 + * messages, etc.).\r
220 + */\r
221 +func (self *Thread) GetAuthors() []string {\r
222 +       if self.thread == nil {\r
223 +               return make([]string, 0)\r
224 +       }\r
225 +       authors_str := C.notmuch_thread_get_authors(self.thread)\r
226 +\r
227 +       if authors_str == nil {\r
228 +               return make([]string, 0)\r
229 +       }\r
230 +\r
231 +       return strings.Split(C.GoString(authors_str), ", ")\r
232 +}\r
233 +\r
234 +/* Get the subject of 'thread'\r
235 + *\r
236 + * The subject is taken from the first message (according to the query\r
237 + * order---see notmuch_query_set_sort) in the query results that\r
238 + * belongs to this thread.\r
239 + *\r
240 + * The returned string belongs to 'thread' and as such, should not be\r
241 + * modified by the caller and will only be valid for as long as the\r
242 + * thread is valid, (which is until notmuch_thread_destroy or until\r
243 + * the query from which it derived is destroyed).\r
244 + */\r
245 +func (self *Thread) GetSubject() string {\r
246 +       if self.thread == nil {\r
247 +               return ""\r
248 +       }\r
249 +       subject := C.notmuch_thread_get_subject(self.thread)\r
250 +\r
251 +       if subject == nil {\r
252 +               return ""\r
253 +       }\r
254 +\r
255 +       return C.GoString(subject)\r
256 +}\r
257 +\r
258 +/* Get the date of the oldest message in 'thread' as a time_t value.\r
259 + */\r
260 +func (self *Thread) GetOldestDate() time.Time {\r
261 +       if self.thread == nil {\r
262 +               return time.Unix(0, 0)\r
263 +       }\r
264 +       return time.Unix(int64(C.notmuch_thread_get_oldest_date(self.thread)), 0)\r
265 +}\r
266 +\r
267 +/* Get the date of the newest message in 'thread' as a time_t value.\r
268 + */\r
269 +func (self *Thread) GetNewestDate() time.Time {\r
270 +       if self.thread == nil {\r
271 +               return time.Unix(0, 0)\r
272 +       }\r
273 +       return time.Unix(int64(C.notmuch_thread_get_oldest_date(self.thread)), 0)\r
274 +}\r
275 +\r
276 +/* Get the tags for 'thread', returning a notmuch_tags_t object which\r
277 + * can be used to iterate over all tags.\r
278 + *\r
279 + * Note: In the Notmuch database, tags are stored on individual\r
280 + * messages, not on threads. So the tags returned here will be all\r
281 + * tags of the messages which matched the search and which belong to\r
282 + * this thread.\r
283 + *\r
284 + * The tags object is owned by the thread and as such, will only be\r
285 + * valid for as long as the thread is valid, (for example, until\r
286 + * notmuch_thread_destroy or until the query from which it derived is\r
287 + * destroyed).\r
288 + *\r
289 + * Typical usage might be:\r
290 + *\r
291 + *     notmuch_thread_t *thread;\r
292 + *     notmuch_tags_t *tags;\r
293 + *     const char *tag;\r
294 + *\r
295 + *     thread = notmuch_threads_get (threads);\r
296 + *\r
297 + *     for (tags = notmuch_thread_get_tags (thread);\r
298 + *          notmuch_tags_valid (tags);\r
299 + *          notmuch_result_move_to_next (tags))\r
300 + *     {\r
301 + *         tag = notmuch_tags_get (tags);\r
302 + *         ....\r
303 + *     }\r
304 + *\r
305 + *     notmuch_thread_destroy (thread);\r
306 + *\r
307 + * Note that there's no explicit destructor needed for the\r
308 + * notmuch_tags_t object. (For consistency, we do provide a\r
309 + * notmuch_tags_destroy function, but there's no good reason to call\r
310 + * it if the message is about to be destroyed).\r
311 + */\r
312 +func (self *Thread) GetTags() *Tags {\r
313 +       if self.thread == nil {\r
314 +               return nil\r
315 +       }\r
316 +       tags := C.notmuch_thread_get_tags(self.thread)\r
317 +       if tags == nil {\r
318 +               return nil\r
319 +       }\r
320 +       return createTags(tags, self)\r
321 +}\r
322 +\r
323 +/* Destroy a notmuch_thread_t object. */\r
324 +func (self *Thread) Destroy() {\r
325 +       if self.thread == nil {\r
326 +               return\r
327 +       }\r
328 +       C.notmuch_thread_destroy(self.thread)\r
329 +       self.thread = nil\r
330 +}\r
331 +\r
332  /* Is the given 'messages' iterator pointing at a valid message.\r
333   *\r
334   * When this function returns TRUE, notmuch_messages_get will return a\r
335 -- \r
336 1.7.7.6\r
337 \r