aboutsummaryrefslogtreecommitdiffstats
path: root/worker/notmuch
diff options
context:
space:
mode:
authorJulian Pidancet <julian.pidancet@oracle.com>2022-10-26 22:29:01 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-27 21:39:41 +0200
commit19d16420de3748cdcae2dc9d1a123a1f6fb2425b (patch)
tree489f4b31549883da2685672810ff6933ec4bd197 /worker/notmuch
parent748e60e6caf6b3b5e752020482e2de09f86e883c (diff)
downloadaerc-19d16420de3748cdcae2dc9d1a123a1f6fb2425b.tar.gz
notmuch: add IndexFile and DeleteMessage methods to notmuch.DB
The new IndexFile and DeleteMessage allow dynamically inserting and removing files to/from a notmuch database. Signed-off-by: Julian Pidancet <julian.pidancet@oracle.com> Acked-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'worker/notmuch')
-rw-r--r--worker/notmuch/lib/database.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go
index 880ec3f7..67aaaab5 100644
--- a/worker/notmuch/lib/database.go
+++ b/worker/notmuch/lib/database.go
@@ -250,6 +250,35 @@ func (db *DB) MsgFilenames(key string) ([]string, error) {
return filenames, err
}
+func (db *DB) DeleteMessage(filename string) error {
+ return db.withConnection(true, func(ndb *notmuch.DB) error {
+ err := ndb.RemoveMessage(filename)
+ if err != nil && !errors.Is(err, notmuch.ErrDuplicateMessageID) {
+ return err
+ }
+
+ return nil
+ })
+}
+
+func (db *DB) IndexFile(filename string) (string, error) {
+ var key string
+
+ err := db.withConnection(true, func(ndb *notmuch.DB) error {
+ msg, err := ndb.AddMessage(filename)
+ if err != nil && !errors.Is(err, notmuch.ErrDuplicateMessageID) {
+ return err
+ }
+ defer msg.Close()
+ if err := msg.MaildirFlagsToTags(); err != nil {
+ return err
+ }
+ key = msg.ID()
+ return nil
+ })
+ return key, err
+}
+
func (db *DB) msgModify(key string,
cb func(*notmuch.Message) error,
) error {