[PATCH 7/7] go: Bind notmuch_thread_t functions
authorAdrien Bustany <adrien@bustany.org>
Wed, 18 Jul 2012 18:34:35 +0000 (21:34 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:23 +0000 (09:48 -0800)
7b/ba31382bba6ad093dcfb7235278e7f7a48acf6 [new file with mode: 0644]

diff --git a/7b/ba31382bba6ad093dcfb7235278e7f7a48acf6 b/7b/ba31382bba6ad093dcfb7235278e7f7a48acf6
new file mode 100644 (file)
index 0000000..680be69
--- /dev/null
@@ -0,0 +1,337 @@
+Return-Path: <adrien@bustany.org>\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 5683F431FDB\r
+       for <notmuch@notmuchmail.org>; Wed, 18 Jul 2012 11:41:09 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 OV4D8BBF1Od8 for <notmuch@notmuchmail.org>;\r
+       Wed, 18 Jul 2012 11:41:06 -0700 (PDT)\r
+Received: from mail.bustany.org (bustany.org [176.31.244.208])\r
+       by olra.theworths.org (Postfix) with ESMTP id 8063D431FC3\r
+       for <notmuch@notmuchmail.org>; Wed, 18 Jul 2012 11:41:05 -0700 (PDT)\r
+Received: from localhost.localdomain (91-158-2-79.elisa-laajakaista.fi\r
+       [91.158.2.79])\r
+       by mail.bustany.org (Postfix) with ESMTPSA id D26D51400EE\r
+       for <notmuch@notmuchmail.org>; Wed, 18 Jul 2012 20:37:09 +0200 (CEST)\r
+From: Adrien Bustany <adrien@bustany.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 7/7] go: Bind notmuch_thread_t functions\r
+Date: Wed, 18 Jul 2012 21:34:35 +0300\r
+Message-Id: <1342636475-16057-8-git-send-email-adrien@bustany.org>\r
+X-Mailer: git-send-email 1.7.7.6\r
+In-Reply-To: <1342636475-16057-1-git-send-email-adrien@bustany.org>\r
+References: <1342636475-16057-1-git-send-email-adrien@bustany.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 18:41:09 -0000\r
+\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
++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
++ * 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
+-- \r
+1.7.7.6\r
+\r