Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id A394B6DE17A6 for ; Sun, 31 May 2015 05:07:56 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.56 X-Spam-Level: X-Spam-Status: No, score=-0.56 tagged_above=-999 required=5 tests=[AWL=-0.009, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DQlLnaLJSnh1 for ; Sun, 31 May 2015 05:07:55 -0700 (PDT) Received: from mout.web.de (mout.web.de [212.227.15.14]) by arlo.cworth.org (Postfix) with ESMTPS id 95E5A6DE17A3 for ; Sun, 31 May 2015 05:07:54 -0700 (PDT) Received: from localhost ([92.204.48.23]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0Mb8xf-1Yeslp1e2t-00KdaH; Sun, 31 May 2015 14:02:46 +0200 From: laochailan To: notmuch@notmuchmail.org Subject: [PATCH 1/5] Added thread bindings to go bindings Date: Sun, 31 May 2015 14:02:11 +0200 Message-Id: <1433073735-7721-2-git-send-email-laochailan@web.de> X-Mailer: git-send-email 2.4.2 In-Reply-To: <1433073735-7721-1-git-send-email-laochailan@web.de> References: <1433073735-7721-1-git-send-email-laochailan@web.de> X-Provags-ID: V03:K0:/SkHwgRIL0//GXbrPm63u13OxF7Yjy40Gr7BKF2NcqG+c0fxEmS ygJUSBFjra7gGvnguM6fp2xsUDS5ktTrObAgO9CYJYr1CIZD/KigHdP4RITGgvurL7j5XVM zL/VViuqbip/rHWaHXfmONFqd72xecvjDRLY/7XF17oGddY/UxSJlUExwkeYTlnACY5hOtW 5Pnv6CGGkNeuI7gOhR5rw== X-UI-Out-Filterresults: notjunk:1;V01:K0:5LczhKmpEF4=:3G4PJMjbl2h7wvS4oICFKV xwJ7yqaQsV2aenUG80g7UkcdfUscerr9CZBShkUpX6BAy1Jf3E/rcQBHu4DMGjNjfFqyQgMfF Z1e54KUcv9p7NjA2Whb9PzFNy3nx4euOGrjN0VSe86fgqCeIQOl3vXSDO/t9qtkIeYsAJl/RD L6a7zoD3b5Fz0S2WkVZCrcnrgb6NCARJi2qX7Ft7D48QSM8/rjQIV81qZZ+6K23ijqbtZA6Pd UScnlh+lpHuORyVwyWcfEkhv16xbjDwZhP64GWjGkmiCNmY/+PosSOLYF9yipuY2FeX1sSyx+ /XJXpJ7c+SraqZXuWaFsfDLCZmMQZ4p0gFL/KTStgnvk1uDTvn7bbS7lVLazfXl41y+r3xbjq XdjqEVQzTm971xGN3kNSQ90UnkqGXpSlVVvEUA3OZo2RGbgmkHLhWdEMbwOqq3QW6YWGlrSiP OPMvNr1M72NAxSGmUBAUrOgaBEeQw9cpa6B6TXTIKEs99g3n/D28NxOspLLCUkvAtguRqPBsK HvjG2U2ghS+/cdeNa3Kjduohq0LOQc8fer0AcGI2o/olEcSeJetjUQh16tj8r1qpTF5U8JoV3 7x6yO4CNGD3GSEEsCV9zFiBZG7GSyushOQ1Hq2TbAKPf7nyx9ipz7R7vGv38zc8PIaBLM9GFQ mr/mbV9TJYjhQVYr+wC/KSaQx7xYPTGVEJ3a4L1CRwt/IDg== X-Mailman-Approved-At: Mon, 01 Jun 2015 09:14:43 -0700 Cc: laochailan X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 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: Sun, 31 May 2015 12:07:56 -0000 --- bindings/go/src/notmuch/notmuch.go | 262 ++++++++++++++++++++++++++++++++++++- 1 file changed, 260 insertions(+), 2 deletions(-) diff --git a/bindings/go/src/notmuch/notmuch.go b/bindings/go/src/notmuch/notmuch.go index 0fff1ab..a0b901f 100644 --- a/bindings/go/src/notmuch/notmuch.go +++ b/bindings/go/src/notmuch/notmuch.go @@ -534,8 +534,6 @@ func (self *Query) CountMessages() uint { return uint(C.notmuch_query_count_messages(self.query)) } -// TODO: wrap threads and thread - /* Is the given 'threads' iterator pointing at a valid thread. * * When this function returns TRUE, notmuch_threads_get will return a @@ -556,6 +554,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 &Thread{thread} +} + +/* 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 @@ -568,6 +605,227 @@ 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' in oldest-first order. + * + * 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. + * + * The returned list will be destroyed when the thread is destroyed. + */ +func (self *Thread) GetToplevelMessages() (*Messages, Status) { + if self.thread == nil { + return nil, STATUS_NULL_POINTER + } + + msgs := C.notmuch_thread_get_toplevel_messages(self.thread) + if msgs == nil { + return nil, STATUS_NULL_POINTER + } + return &Messages{msgs}, STATUS_SUCCESS +} + +/** + * Get a notmuch_thread_t iterator for all messages in 'thread' in + * oldest-first order. + * + * The returned list will be destroyed when the thread is destroyed. + */ +func (self *Thread) GetMessages() (*Messages, Status) { + if self.thread == nil { + return nil, STATUS_NULL_POINTER + } + + msgs := C.notmuch_thread_get_messages(self.thread) + if msgs == nil { + return nil, STATUS_NULL_POINTER + } + return &Messages{msgs}, STATUS_SUCCESS +} + +/** + * Get the number of messages in 'thread' that matched the search. + * + * This count includes only the messages in this thread that were + * matched by the search from which the thread was created and were + * not excluded by any exclude tags passed in with the query (see + * notmuch_query_add_tag_exclude). Contrast with + * notmuch_thread_get_total_messages() . + */ +func (self *Thread) GetMatchedMessages() int { + if self.thread == nil { + return 0 + } + return int(C.notmuch_thread_get_matched_messages(self.thread)) +} + +/** + * Get the authors of 'thread' as a UTF-8 string. + * + * The returned string is a comma-separated list of the names of the + * authors of mail messages in the query results that belong to this + * thread. + * + * The string contains authors of messages matching the query first, then + * non-matched authors (with the two groups separated by '|'). Within + * each group, authors are ordered by date. + * + * 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) GetAuthors() string { + if self.thread == nil { + return "" + } + str := C.notmuch_thread_get_authors(self.thread) + if str == nil { + return "" + } + return C.GoString(str) +} + +/** + * Get the subject of 'thread' as a UTF-8 string. + * + * 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 "" + } + str := C.notmuch_thread_get_subject(self.thread) + if str == nil { + return "" + } + return C.GoString(str) +} + +/** + * Get the date of the oldest message in 'thread' as a time_t value. + */ +func (self *Thread) GetOldestDate() int64 { + if self.thread == nil { + return 0 + } + date := C.notmuch_thread_get_oldest_date(self.thread) + + return int64(date) +} + +/** + * Get the date of the newest message in 'thread' as a time_t value. + */ +func (self *Thread) GetNewestDate() int64 { + if self.thread == nil { + return 0 + } + date := C.notmuch_thread_get_newest_date(self.thread) + + return int64(date) +} + +/** + * 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_tags_move_to_next (tags)) + * { + * tag = notmuch_tags_get (tags); + * .... + * } + * + * notmuch_thread_destroy (thread); + * + * 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 &Tags{tags} +} + +/** + * Destroy a notmuch_thread_t object. + */ +func (self *Thread) Destroy() { + if self.thread != nil { + C.notmuch_thread_destroy(self.thread) + } +} + /* Is the given 'messages' iterator pointing at a valid message. * * When this function returns TRUE, notmuch_messages_get will return a -- 2.4.2