aboutsummaryrefslogtreecommitdiffstats
path: root/lib/notmuch/directory.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/directory.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/directory.go')
-rw-r--r--lib/notmuch/directory.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/notmuch/directory.go b/lib/notmuch/directory.go
new file mode 100644
index 00000000..796c66ef
--- /dev/null
+++ b/lib/notmuch/directory.go
@@ -0,0 +1,64 @@
+//go:build notmuch
+// +build notmuch
+
+package notmuch
+
+/*
+#cgo LDFLAGS: -lnotmuch
+
+#include <notmuch.h>
+
+*/
+import "C"
+import "time"
+
+type Directory struct {
+ dir *C.notmuch_directory_t
+}
+
+func (dir *Directory) SetModifiedTime(t time.Time) error {
+ cTime := C.time_t(t.Unix())
+ return errorWrap(C.notmuch_directory_set_mtime(dir.dir, cTime))
+}
+
+func (dir *Directory) ModifiedTime() time.Time {
+ cTime := C.notmuch_directory_get_mtime(dir.dir)
+ return time.Unix(int64(cTime), 0)
+}
+
+func (dir *Directory) Filenames() []string {
+ cFilenames := C.notmuch_directory_get_child_files(dir.dir)
+ defer C.notmuch_filenames_destroy(cFilenames)
+
+ filenames := []string{}
+ for C.notmuch_filenames_valid(cFilenames) > 0 {
+ filename := C.notmuch_filenames_get(cFilenames)
+ filenames = append(filenames, C.GoString(filename))
+ C.notmuch_filenames_move_to_next(cFilenames)
+ }
+ return filenames
+}
+
+func (dir *Directory) Directories() []string {
+ cFilenames := C.notmuch_directory_get_child_directories(dir.dir)
+ defer C.notmuch_filenames_destroy(cFilenames)
+
+ filenames := []string{}
+ for C.notmuch_filenames_valid(cFilenames) > 0 {
+ filename := C.notmuch_filenames_get(cFilenames)
+ filenames = append(filenames, C.GoString(filename))
+ C.notmuch_filenames_move_to_next(cFilenames)
+ }
+ return filenames
+}
+
+// Delete deletes a directory document from the database and destroys
+// the underlying object. Any child directories and files must have been
+// deleted firs the caller
+func (dir *Directory) Delete() error {
+ return errorWrap(C.notmuch_directory_delete(dir.dir))
+}
+
+func (dir *Directory) Close() {
+ C.notmuch_directory_destroy(dir.dir)
+}