From 0b9c448b659f2d545bac3e439cfcf22944397c11 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 19 Jul 2012 16:50:28 +2000 Subject: [PATCH] Re: [PATCH 7/7] go: Bind notmuch_thread_t functions --- 85/223f70d2eecaaf6bd289fca50710dffe4df12b | 375 ++++++++++++++++++++++ 1 file changed, 375 insertions(+) create mode 100644 85/223f70d2eecaaf6bd289fca50710dffe4df12b diff --git a/85/223f70d2eecaaf6bd289fca50710dffe4df12b b/85/223f70d2eecaaf6bd289fca50710dffe4df12b new file mode 100644 index 000000000..72299a8e6 --- /dev/null +++ b/85/223f70d2eecaaf6bd289fca50710dffe4df12b @@ -0,0 +1,375 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id CD78A431FAF + for ; Wed, 18 Jul 2012 13:50:32 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id YylisYt207DJ for ; + Wed, 18 Jul 2012 13:50:31 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU + [18.7.68.37]) + by olra.theworths.org (Postfix) with ESMTP id 9BB9E431FAE + for ; Wed, 18 Jul 2012 13:50:31 -0700 (PDT) +X-AuditID: 12074425-b7f9b6d0000008c4-55-500721978e0e +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id 80.47.02244.79127005; Wed, 18 Jul 2012 16:50:31 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6IKoUbe025232; + Wed, 18 Jul 2012 16:50:30 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6IKoTwC007340 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Wed, 18 Jul 2012 16:50:30 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SrbCX-0001EO-1E; Wed, 18 Jul 2012 16:50:29 -0400 +Date: Wed, 18 Jul 2012 16:50:28 -0400 +From: Austin Clements +To: Adrien Bustany +Subject: Re: [PATCH 7/7] go: Bind notmuch_thread_t functions +Message-ID: <20120718205028.GV31670@mit.edu> +References: <1342636475-16057-1-git-send-email-adrien@bustany.org> + <1342636475-16057-8-git-send-email-adrien@bustany.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <1342636475-16057-8-git-send-email-adrien@bustany.org> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hTV1p2uyB5gsOcSj8X6O2vZLK7fnMns + wOTx8cA9Jo9nq24xBzBFcdmkpOZklqUW6dslcGUseBFbcM+3ouPnTKYGxt/WXYycHBICJhIb + d/5mhrDFJC7cW8/WxcjFISSwj1Hi+bp1rBDOBkaJ1ee7WSCck0wSH5p7oJwljBLbH71gAeln + EVCVeH37KRuIzSagIbFt/3JGEFtEQF1iR2c7mM0sIC3x7XczE4gtLGAj8fHJBLB6XgEdiSez + ZrCD2EIC1RLfP6xggYgLSpyc+YQFoldL4sa/l0C9HGBzlv/jAAlzCjhLXP++gxXEFhVQkZhy + chvbBEahWUi6ZyHpnoXQvYCReRWjbEpulW5uYmZOcWqybnFyYl5eapGuhV5uZoleakrpJkZQ + WLO7qO5gnHBI6RCjAAejEg/vg12sAUKsiWXFlbmHGCU5mJREeT8JsQcI8SXlp1RmJBZnxBeV + 5qQWH2KU4GBWEuF9IAiU401JrKxKLcqHSUlzsCiJ895IuekvJJCeWJKanZpakFoEk5Xh4FCS + 4L2uANQoWJSanlqRlplTgpBm4uAEGc4DNJxbEWR4cUFibnFmOkT+FKOilDjvepBmAZBERmke + XC8s7bxiFAd6RZj3EkgVDzBlwXW/AhrMBDK4mA1kcEkiQkqqgbHueRjn28kB6u3F//mt1h1R + FFmk1nWgcw1T/aPCjhL3usqUg8K71BJkVN+WOLw4q8efv+CI6T7/q488/2zy5GbbtDDLv1sg + 88/VB5NiSj/nrZkXbeFbdjDNQ+7Hye6fjMafDjy49Ckn9Gt7p5355sApT/evvGd0ovpGcu9W + HsEdEvxzCqbZr1ViKc5INNRiLipOBADBrsVfFgMAAA== +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Wed, 18 Jul 2012 20:50:32 -0000 + +Quoth Adrien Bustany on Jul 18 at 9:34 pm: +> --- +> bindings/go/src/notmuch/notmuch.go | 253 +++++++++++++++++++++++++++++++++++- +> 1 files changed, 252 insertions(+), 1 deletions(-) +> +> diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go +> index be4cb8c..f667dbb 100644 +> --- a/bindings/go/src/notmuch/notmuch.go +> +++ b/bindings/go/src/notmuch/notmuch.go +> @@ -12,6 +12,8 @@ package notmuch +> */ +> import "C" +> import "runtime" +> +import "strings" +> +import "time" +> import "unsafe" +> +> // Status codes used for the return values of most functions +> @@ -700,7 +702,20 @@ func (self *Query) CountMessages() uint { +> return uint(C.notmuch_query_count_messages(self.query)) +> } +> +> -// TODO: wrap threads and thread +> +/* Return the number of threads matching a search. +> + * +> + * This function performs a search and returns the number of unique thread IDs +> + * in the matching messages. This is the same as number of threads matching a +> + * search. +> + * +> + * Note that this is a significantly heavier operation than +> + * notmuch_query_count_messages(). +> + * +> + * If an error occurs, this function may return 0. +> + */ +> +func (self *Query) CountThreads() uint { +> + return uint(C.notmuch_query_count_threads(self.query)) +> +} +> +> /* Is the given 'threads' iterator pointing at a valid thread. +> * +> @@ -722,6 +737,45 @@ func (self *Threads) Valid() bool { +> return true +> } +> +> +/* Get the current thread from 'threads' as a notmuch_thread_t. +> + * +> + * Note: The returned thread belongs to 'threads' and has a lifetime +> + * identical to it (and the query to which it belongs). +> + * +> + * See the documentation of notmuch_query_search_threads for example +> + * code showing how to iterate over a notmuch_threads_t object. +> + * +> + * If an out-of-memory situation occurs, this function will return +> + * NULL. +> + */ +> +func (self *Threads) Get() *Thread { +> + if self.threads == nil { +> + return nil +> + } +> + thread := C.notmuch_threads_get(self.threads) +> + if thread == nil { +> + return nil +> + } +> + return createThread(thread, self) +> +} +> + +> +/* Move the 'threads' iterator to the next thread. +> + * +> + * If 'threads' is already pointing at the last thread then the +> + * iterator will be moved to a point just beyond that last thread, +> + * (where notmuch_threads_valid will return FALSE and +> + * notmuch_threads_get will return NULL). +> + * +> + * See the documentation of notmuch_query_search_threads for example +> + * code showing how to iterate over a notmuch_threads_t object. +> + */ +> +func (self *Threads) MoveToNext() { +> + if self.threads == nil { +> + return +> + } +> + C.notmuch_threads_move_to_next(self.threads) +> +} +> + +> /* Destroy a notmuch_threads_t object. +> * +> * It's not strictly necessary to call this function. All memory from +> @@ -735,6 +789,203 @@ func (self *Threads) Destroy() { +> } +> } +> +> +/* Get the thread ID of 'thread'. +> + * +> + * The returned string belongs to 'thread' and as such, should not be +> + * modified by the caller and will only be valid for as long as the +> + * thread is valid, (which is until notmuch_thread_destroy or until +> + * the query from which it derived is destroyed). +> + */ +> +func (self *Thread) GetThreadId() string { +> + if self.thread == nil { +> + return "" +> + } +> + id := C.notmuch_thread_get_thread_id(self.thread) +> + +> + if id == nil { +> + return "" +> + } +> + +> + return C.GoString(id) +> +} +> + +> +/* Get the total number of messages in 'thread'. +> + * +> + * This count consists of all messages in the database belonging to +> + * this thread. Contrast with notmuch_thread_get_matched_messages() . +> + */ +> +func (self *Thread) GetTotalMessages() int { +> + if self.thread == nil { +> + return 0 +> + } +> + return int(C.notmuch_thread_get_total_messages(self.thread)) +> +} +> + +> +/* Get a notmuch_messages_t iterator for the top-level messages in +> + * 'thread'. +> + * +> + * This iterator will not necessarily iterate over all of the messages +> + * in the thread. It will only iterate over the messages in the thread +> + * which are not replies to other messages in the thread. +> + * +> + * To iterate over all messages in the thread, the caller will need to +> + * iterate over the result of notmuch_message_get_replies for each +> + * top-level message (and do that recursively for the resulting +> + * messages, etc.). +> + */ +> +func (self *Thread) GetToplevelMessages() *Messages { +> + if self.thread == nil { +> + return nil +> + } +> + msgs := C.notmuch_thread_get_toplevel_messages(self.thread) +> + if msgs == nil { +> + return nil +> + } +> + return createMessages(msgs, self) +> +} +> + +> +/* Get a notmuch_messages_t iterator for the top-level messages in +> + * 'thread'. +> + * +> + * This iterator will not necessarily iterate over all of the messages +> + * in the thread. It will only iterate over the messages in the thread +> + * which are not replies to other messages in the thread. +> + * +> + * To iterate over all messages in the thread, the caller will need to +> + * iterate over the result of notmuch_message_get_replies for each +> + * top-level message (and do that recursively for the resulting +> + * messages, etc.). +> + */ + +Wrong comment. (Same for the next two methods.) + +> +func (self *Thread) GetMatchedMessages() int { +> + if self.thread == nil { +> + return 0 +> + } +> + return int(C.notmuch_thread_get_matched_messages(self.thread)) +> +} +> + +> +/* Get a notmuch_messages_t iterator for the top-level messages in +> + * 'thread'. +> + * +> + * This iterator will not necessarily iterate over all of the messages +> + * in the thread. It will only iterate over the messages in the thread +> + * which are not replies to other messages in the thread. +> + * +> + * To iterate over all messages in the thread, the caller will need to +> + * iterate over the result of notmuch_message_get_replies for each +> + * top-level message (and do that recursively for the resulting +> + * messages, etc.). +> + */ +> +func (self *Thread) GetAuthors() []string { +> + if self.thread == nil { +> + return make([]string, 0) +> + } +> + authors_str := C.notmuch_thread_get_authors(self.thread) +> + +> + if authors_str == nil { +> + return make([]string, 0) +> + } +> + +> + return strings.Split(C.GoString(authors_str), ", ") +> +} +> + +> +/* Get the subject of 'thread' +> + * +> + * The subject is taken from the first message (according to the query +> + * order---see notmuch_query_set_sort) in the query results that +> + * belongs to this thread. +> + * +> + * The returned string belongs to 'thread' and as such, should not be +> + * modified by the caller and will only be valid for as long as the +> + * thread is valid, (which is until notmuch_thread_destroy or until +> + * the query from which it derived is destroyed). +> + */ +> +func (self *Thread) GetSubject() string { +> + if self.thread == nil { +> + return "" +> + } +> + subject := C.notmuch_thread_get_subject(self.thread) +> + +> + if subject == nil { +> + return "" +> + } +> + +> + return C.GoString(subject) +> +} +> + +> +/* Get the date of the oldest message in 'thread' as a time_t value. +> + */ +> +func (self *Thread) GetOldestDate() time.Time { +> + if self.thread == nil { +> + return time.Unix(0, 0) +> + } +> + return time.Unix(int64(C.notmuch_thread_get_oldest_date(self.thread)), 0) +> +} +> + +> +/* Get the date of the newest message in 'thread' as a time_t value. +> + */ +> +func (self *Thread) GetNewestDate() time.Time { +> + if self.thread == nil { +> + return time.Unix(0, 0) +> + } +> + return time.Unix(int64(C.notmuch_thread_get_oldest_date(self.thread)), 0) +> +} +> + +> +/* Get the tags for 'thread', returning a notmuch_tags_t object which +> + * can be used to iterate over all tags. +> + * +> + * Note: In the Notmuch database, tags are stored on individual +> + * messages, not on threads. So the tags returned here will be all +> + * tags of the messages which matched the search and which belong to +> + * this thread. +> + * +> + * The tags object is owned by the thread and as such, will only be +> + * valid for as long as the thread is valid, (for example, until +> + * notmuch_thread_destroy or until the query from which it derived is +> + * destroyed). +> + * +> + * Typical usage might be: +> + * +> + * notmuch_thread_t *thread; +> + * notmuch_tags_t *tags; +> + * const char *tag; +> + * +> + * thread = notmuch_threads_get (threads); +> + * +> + * for (tags = notmuch_thread_get_tags (thread); +> + * notmuch_tags_valid (tags); +> + * notmuch_result_move_to_next (tags)) +> + * { +> + * tag = notmuch_tags_get (tags); +> + * .... +> + * } +> + * +> + * notmuch_thread_destroy (thread); + +I wonder if this example should be updated for Go? OTOH, all of the +comments seem to be copied verbatim, to the point of referring to C +function names and status symbols. + +> + * +> + * Note that there's no explicit destructor needed for the +> + * notmuch_tags_t object. (For consistency, we do provide a +> + * notmuch_tags_destroy function, but there's no good reason to call +> + * it if the message is about to be destroyed). +> + */ +> +func (self *Thread) GetTags() *Tags { +> + if self.thread == nil { +> + return nil +> + } +> + tags := C.notmuch_thread_get_tags(self.thread) +> + if tags == nil { +> + return nil +> + } +> + return createTags(tags, self) +> +} +> + +> +/* Destroy a notmuch_thread_t object. */ +> +func (self *Thread) Destroy() { +> + if self.thread == nil { +> + return +> + } +> + C.notmuch_thread_destroy(self.thread) +> + self.thread = nil +> +} +> + +> /* Is the given 'messages' iterator pointing at a valid message. +> * +> * When this function returns TRUE, notmuch_messages_get will return a -- 2.26.2