From 3a55b8e6fd51c3dda1ea71c6806f2ee2d71c1065 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 29 Aug 2023 13:15:45 -0500 Subject: notmuch: add notmuch bindings aerc is using an unmaintained fork of a not-well-functioning notmuch binding library. Add custom bindings directly into the aerc repo to make them more maintainable and more customizable to our needs. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/notmuch/thread.go | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 lib/notmuch/thread.go (limited to 'lib/notmuch/thread.go') diff --git a/lib/notmuch/thread.go b/lib/notmuch/thread.go new file mode 100644 index 00000000..1b6eacef --- /dev/null +++ b/lib/notmuch/thread.go @@ -0,0 +1,99 @@ +//go:build notmuch +// +build notmuch + +package notmuch + +/* +#cgo LDFLAGS: -lnotmuch + +#include +#include + +*/ +import "C" +import "time" + +type Thread struct { + thread *C.notmuch_thread_t +} + +// ID returns the thread ID +func (t *Thread) ID() string { + cID := C.notmuch_thread_get_thread_id(t.thread) + return C.GoString(cID) +} + +// TotalMessages returns the total number of messages in the thread +func (t *Thread) TotalMessages() int { + return int(C.notmuch_thread_get_total_messages(t.thread)) +} + +// TotalMessages returns the total number of files in the thread +func (t *Thread) TotalFiles() int { + return int(C.notmuch_thread_get_total_files(t.thread)) +} + +// TopLevelMessages returns an iterator over the top level messages in the +// thread. Messages are sorted oldest-first +func (t *Thread) TopLevelMessages() Messages { + cMessages := C.notmuch_thread_get_toplevel_messages(t.thread) + return Messages{ + messages: cMessages, + } +} + +// Messages returns an iterator over the messages in the thread. Messages are +// sorted oldest-first +func (t *Thread) Messages() Messages { + cMessages := C.notmuch_thread_get_messages(t.thread) + return Messages{ + messages: cMessages, + } +} + +// Matches returns the number of messages in the thread that matched the query +func (t *Thread) Matches() int { + return int(C.notmuch_thread_get_matched_messages(t.thread)) +} + +// Returns a string of authors of the thread +func (t *Thread) Authors() string { + cAuthors := C.notmuch_thread_get_authors(t.thread) + return C.GoString(cAuthors) +} + +// Returns the subject of the thread +func (t *Thread) Subject() string { + cSubject := C.notmuch_thread_get_subject(t.thread) + return C.GoString(cSubject) +} + +// Returns the sent-date of the oldest message in the thread +func (t *Thread) OldestDate() time.Time { + cTime := C.notmuch_thread_get_oldest_date(t.thread) + return time.Unix(int64(cTime), 0) +} + +// Returns the sent-date of the newest message in the thread +func (t *Thread) NewestDate() time.Time { + cTime := C.notmuch_thread_get_newest_date(t.thread) + return time.Unix(int64(cTime), 0) +} + +// Tags returns a slice of all tags in the thread +func (t *Thread) Tags() []string { + cTags := C.notmuch_thread_get_tags(t.thread) + defer C.notmuch_tags_destroy(cTags) + + tags := []string{} + for C.notmuch_tags_valid(cTags) > 0 { + tag := C.notmuch_tags_get(cTags) + tags = append(tags, C.GoString(tag)) + C.notmuch_tags_move_to_next(cTags) + } + return tags +} + +func (t *Thread) Close() { + C.notmuch_thread_destroy(t.thread) +} -- cgit