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
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\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
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
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
47 bindings/go/src/notmuch/notmuch.go | 253 +++++++++++++++++++++++++++++++++++-
\r
48 1 files changed, 252 insertions(+), 1 deletions(-)
\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
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
67 -// TODO: wrap threads and thread
\r
68 +/* Return the number of threads matching a search.
\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
74 + * Note that this is a significantly heavier operation than
\r
75 + * notmuch_query_count_messages().
\r
77 + * If an error occurs, this function may return 0.
\r
79 +func (self *Query) CountThreads() uint {
\r
80 + return uint(C.notmuch_query_count_threads(self.query))
\r
83 /* Is the given 'threads' iterator pointing at a valid thread.
\r
85 @@ -722,6 +737,45 @@ func (self *Threads) Valid() bool {
\r
89 +/* Get the current thread from 'threads' as a notmuch_thread_t.
\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
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
97 + * If an out-of-memory situation occurs, this function will return
\r
100 +func (self *Threads) Get() *Thread {
\r
101 + if self.threads == nil {
\r
104 + thread := C.notmuch_threads_get(self.threads)
\r
105 + if thread == nil {
\r
108 + return createThread(thread, self)
\r
111 +/* Move the 'threads' iterator to the next thread.
\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
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
121 +func (self *Threads) MoveToNext() {
\r
122 + if self.threads == nil {
\r
125 + C.notmuch_threads_move_to_next(self.threads)
\r
128 /* Destroy a notmuch_threads_t object.
\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
135 +/* Get the thread ID of 'thread'.
\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
142 +func (self *Thread) GetThreadId() string {
\r
143 + if self.thread == nil {
\r
146 + id := C.notmuch_thread_get_thread_id(self.thread)
\r
152 + return C.GoString(id)
\r
155 +/* Get the total number of messages in 'thread'.
\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
160 +func (self *Thread) GetTotalMessages() int {
\r
161 + if self.thread == nil {
\r
164 + return int(C.notmuch_thread_get_total_messages(self.thread))
\r
167 +/* Get a notmuch_messages_t iterator for the top-level messages in
\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
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
179 +func (self *Thread) GetToplevelMessages() *Messages {
\r
180 + if self.thread == nil {
\r
183 + msgs := C.notmuch_thread_get_toplevel_messages(self.thread)
\r
187 + return createMessages(msgs, self)
\r
190 +/* Get a notmuch_messages_t iterator for the top-level messages in
\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
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
202 +func (self *Thread) GetMatchedMessages() int {
\r
203 + if self.thread == nil {
\r
206 + return int(C.notmuch_thread_get_matched_messages(self.thread))
\r
209 +/* Get a notmuch_messages_t iterator for the top-level messages in
\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
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
221 +func (self *Thread) GetAuthors() []string {
\r
222 + if self.thread == nil {
\r
223 + return make([]string, 0)
\r
225 + authors_str := C.notmuch_thread_get_authors(self.thread)
\r
227 + if authors_str == nil {
\r
228 + return make([]string, 0)
\r
231 + return strings.Split(C.GoString(authors_str), ", ")
\r
234 +/* Get the subject of 'thread'
\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
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
245 +func (self *Thread) GetSubject() string {
\r
246 + if self.thread == nil {
\r
249 + subject := C.notmuch_thread_get_subject(self.thread)
\r
251 + if subject == nil {
\r
255 + return C.GoString(subject)
\r
258 +/* Get the date of the oldest message in 'thread' as a time_t value.
\r
260 +func (self *Thread) GetOldestDate() time.Time {
\r
261 + if self.thread == nil {
\r
262 + return time.Unix(0, 0)
\r
264 + return time.Unix(int64(C.notmuch_thread_get_oldest_date(self.thread)), 0)
\r
267 +/* Get the date of the newest message in 'thread' as a time_t value.
\r
269 +func (self *Thread) GetNewestDate() time.Time {
\r
270 + if self.thread == nil {
\r
271 + return time.Unix(0, 0)
\r
273 + return time.Unix(int64(C.notmuch_thread_get_oldest_date(self.thread)), 0)
\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
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
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
289 + * Typical usage might be:
\r
291 + * notmuch_thread_t *thread;
\r
292 + * notmuch_tags_t *tags;
\r
293 + * const char *tag;
\r
295 + * thread = notmuch_threads_get (threads);
\r
297 + * for (tags = notmuch_thread_get_tags (thread);
\r
298 + * notmuch_tags_valid (tags);
\r
299 + * notmuch_result_move_to_next (tags))
\r
301 + * tag = notmuch_tags_get (tags);
\r
305 + * notmuch_thread_destroy (thread);
\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
312 +func (self *Thread) GetTags() *Tags {
\r
313 + if self.thread == nil {
\r
316 + tags := C.notmuch_thread_get_tags(self.thread)
\r
320 + return createTags(tags, self)
\r
323 +/* Destroy a notmuch_thread_t object. */
\r
324 +func (self *Thread) Destroy() {
\r
325 + if self.thread == nil {
\r
328 + C.notmuch_thread_destroy(self.thread)
\r
329 + self.thread = nil
\r
332 /* Is the given 'messages' iterator pointing at a valid message.
\r
334 * When this function returns TRUE, notmuch_messages_get will return a
\r