aboutsummaryrefslogtreecommitdiffstats
path: root/lib/notmuch/messages.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-08-29 13:15:45 -0500
committerRobin Jarry <robin@jarry.cc>2023-08-30 22:10:20 +0200
commit3a55b8e6fd51c3dda1ea71c6806f2ee2d71c1065 (patch)
tree93a83c576c8c4cad8164d6b7ef65dbb185aa8390 /lib/notmuch/messages.go
parentab7d32c1fe5182a7a7631bb4dc35bed49af752c0 (diff)
downloadaerc-3a55b8e6fd51c3dda1ea71c6806f2ee2d71c1065.tar.gz
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 <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/notmuch/messages.go')
-rw-r--r--lib/notmuch/messages.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/notmuch/messages.go b/lib/notmuch/messages.go
new file mode 100644
index 00000000..22cc0094
--- /dev/null
+++ b/lib/notmuch/messages.go
@@ -0,0 +1,58 @@
+//go:build notmuch
+// +build notmuch
+
+package notmuch
+
+/*
+#cgo LDFLAGS: -lnotmuch
+
+#include <notmuch.h>
+
+*/
+import "C"
+
+type Messages struct {
+ message *C.notmuch_message_t
+ messages *C.notmuch_messages_t
+}
+
+// Next advances the Messages iterator to the next message. Next returns false if
+// no more messages are available
+func (m *Messages) Next() bool {
+ if C.notmuch_messages_valid(m.messages) == 0 {
+ return false
+ }
+ m.message = C.notmuch_messages_get(m.messages)
+ C.notmuch_messages_move_to_next(m.messages)
+ return true
+}
+
+// Message returns the current message in the iterator
+func (m *Messages) Message() Message {
+ return Message{
+ message: m.message,
+ }
+}
+
+// Close frees memory associated with a Messages iterator. This method is not
+// strictly necessary to call, as the resources will be freed when the Query
+// associated with the Messages object is freed.
+func (m *Messages) Close() {
+ C.notmuch_messages_destroy(m.messages)
+}
+
+// Tags returns a slice of all tags in the message list. WARNING: After calling
+// tags, the message list can no longer be iterated; a new list must be created
+// to iterate after calling Tags
+func (m *Messages) Tags() []string {
+ cTags := C.notmuch_messages_collect_tags(m.messages)
+ 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
+}