Re: [PATCH 7/7] go: Bind notmuch_thread_t functions
authorAustin Clements <amdragon@MIT.EDU>
Wed, 18 Jul 2012 20:50:28 +0000 (16:50 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:23 +0000 (09:48 -0800)
85/223f70d2eecaaf6bd289fca50710dffe4df12b [new file with mode: 0644]

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