From 19d16420de3748cdcae2dc9d1a123a1f6fb2425b Mon Sep 17 00:00:00 2001 From: Julian Pidancet Date: Wed, 26 Oct 2022 22:29:01 +0200 Subject: 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 Acked-by: Robin Jarry Acked-by: Tim Culverhouse --- worker/notmuch/lib/database.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'worker/notmuch/lib/database.go') 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 { -- cgit