unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH resend] contrib/go: update the go binding
@ 2021-02-19  0:05 Leandro Dorileo
  2021-05-02 10:44 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: Leandro Dorileo @ 2021-02-19  0:05 UTC (permalink / raw)
  To: notmuch; +Cc: Leandro Dorileo

Make sure to update the go binding to reflect the recent changes to
notmuch api.
---
 .../go/src/notmuch-addrlookup/addrlookup.go   | 22 ++++++++++--
 contrib/go/src/notmuch/notmuch.go             | 34 +++++++++++--------
 2 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/contrib/go/src/notmuch-addrlookup/addrlookup.go b/contrib/go/src/notmuch-addrlookup/addrlookup.go
index 916e5bb2..b1023f24 100644
--- a/contrib/go/src/notmuch-addrlookup/addrlookup.go
+++ b/contrib/go/src/notmuch-addrlookup/addrlookup.go
@@ -130,7 +130,12 @@ func search_address_passes(queries [3]*notmuch.Query, name string) []string {
 			//println("**warning: idx [",idx,"] contains a nil query")
 			continue
 		}
-		msgs := query.SearchMessages()
+
+		msgs, status := query.SearchMessages()
+		if status != notmuch.STATUS_SUCCESS {
+			continue
+		}
+
 		ht := addresses_by_frequency(msgs, name, pass, &addr_to_realname)
 		for addr, count := range *ht {
 			freq, ok := addr_freq[addr]
@@ -231,8 +236,21 @@ func (self *address_matcher) run(name string) {
 	}
 	queries[1] = self.db.CreateQuery(query)
 
+	cnt1, cnt2 := uint(0), uint(0)
+	status := notmuch.STATUS_SUCCESS
+
 	// if that leads only to a few hits, we check every from too
-	if queries[0].CountMessages()+queries[1].CountMessages() < 10 {
+	cnt1, status = queries[0].CountMessages()
+	if status != notmuch.STATUS_SUCCESS {
+		log.Fatalf("Failed to count messages: %v.", status)
+	}
+
+	cnt2, status = queries[1].CountMessages()
+	if status != notmuch.STATUS_SUCCESS {
+		log.Fatalf("Failed to count messages: %v.", status)
+	}
+
+	if cnt1+cnt2 < 10 {
 		query = ""
 		if name != "" {
 			query = "from:" + name + "*"
diff --git a/contrib/go/src/notmuch/notmuch.go b/contrib/go/src/notmuch/notmuch.go
index 5496198a..c04c4c5a 100644
--- a/contrib/go/src/notmuch/notmuch.go
+++ b/contrib/go/src/notmuch/notmuch.go
@@ -255,10 +255,10 @@ func (self *Database) AddMessage(fname string) (*Message, Status) {
 		return nil, STATUS_OUT_OF_MEMORY
 	}
 
-	var c_msg *C.notmuch_message_t = new(C.notmuch_message_t)
-	st := Status(C.notmuch_database_add_message(self.db, c_fname, &c_msg))
+	msg := &Message{message: nil}
+	st := Status(C.notmuch_database_add_message(self.db, c_fname, &msg.message))
 
-	return &Message{message: c_msg}, st
+	return msg, st
 }
 
 /* Remove a message from the given notmuch database.
@@ -454,12 +454,13 @@ func (self *Query) GetSort() Sort {
  *
  * If a Xapian exception occurs this function will return NULL.
  */
-func (self *Query) SearchThreads() *Threads {
-	threads := C.notmuch_query_search_threads(self.query)
-	if threads == nil {
-		return nil
+func (self *Query) SearchThreads() (*Threads, Status) {
+	threads := &Threads{threads: nil}
+	st := Status(C.notmuch_query_search_threads(self.query, &threads.threads))
+	if st != STATUS_SUCCESS {
+		return nil, st
 	}
-	return &Threads{threads: threads}
+	return threads, st
 }
 
 /* Execute a query for messages, returning a notmuch_messages_t object
@@ -500,12 +501,13 @@ func (self *Query) SearchThreads() *Threads {
  *
  * If a Xapian exception occurs this function will return NULL.
  */
-func (self *Query) SearchMessages() *Messages {
-	msgs := C.notmuch_query_search_messages(self.query)
-	if msgs == nil {
-		return nil
+func (self *Query) SearchMessages() (*Messages, Status) {
+	msgs := &Messages{messages: nil}
+	st := Status(C.notmuch_query_search_messages(self.query, &msgs.messages))
+	if st != STATUS_SUCCESS {
+		return nil, st
 	}
-	return &Messages{messages: msgs}
+	return msgs, st
 }
 
 /* Destroy a notmuch_query_t along with any associated resources.
@@ -530,8 +532,10 @@ func (self *Query) Destroy() {
  * If a Xapian exception occurs, this function may return 0 (after
  * printing a message).
  */
-func (self *Query) CountMessages() uint {
-	return uint(C.notmuch_query_count_messages(self.query))
+func (self *Query) CountMessages() (uint, Status) {
+	var cnt C.uint
+	st := Status(C.notmuch_query_count_messages(self.query, &cnt))
+	return uint(cnt), st
 }
 
 /* Is the given 'threads' iterator pointing at a valid thread.
-- 
2.30.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH resend] contrib/go: update the go binding
  2021-02-19  0:05 [PATCH resend] contrib/go: update the go binding Leandro Dorileo
@ 2021-05-02 10:44 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2021-05-02 10:44 UTC (permalink / raw)
  To: Leandro Dorileo, notmuch

Leandro Dorileo <l@dorileo.org> writes:

> Make sure to update the go binding to reflect the recent changes to
> notmuch api.
> ---

Hi Leandro;

Thanks for the patch. I don't speak golang, so I'm waiting (and
waiting) for feedback from other users of the go bindings.

d

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-02 10:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-19  0:05 [PATCH resend] contrib/go: update the go binding Leandro Dorileo
2021-05-02 10:44 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).