unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / Atom feed
* [PATCH] contrib/go: update the go binding
@ 2021-01-28 22:00 Leandro Dorileo
  0 siblings, 0 replies; only message in thread
From: Leandro Dorileo @ 2021-01-28 22:00 UTC (permalink / raw)
  To: notmuch; +Cc: Leandro Dorileo

From: Leandro Dorileo <leandro@dorileo.org>

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

Signed-off-by: Leandro Dorileo <leandro@dorileo.org>
---
 .../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.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-01-28 22:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 22:00 [PATCH] contrib/go: update the go binding Leandro Dorileo

unofficial mirror of notmuch@notmuchmail.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/notmuch/0 notmuch/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 notmuch notmuch/ https://yhetil.org/notmuch \
		notmuch@notmuchmail.org
	public-inbox-index notmuch

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.notmuch.general
	nntp://news.gmane.io/gmane.mail.notmuch.general


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git