From 748e60e6caf6b3b5e752020482e2de09f86e883c Mon Sep 17 00:00:00 2001 From: Julian Pidancet Date: Wed, 26 Oct 2022 22:29:00 +0200 Subject: notmuch: add MsgFilenames method to notmuch.DB Multiple files on the filesystem can be referenced under a single key in the notmuch database. MsgFilenames() returns a list of filenames associated with an index key. Signed-off-by: Julian Pidancet Acked-by: Robin Jarry Acked-by: Tim Culverhouse --- worker/notmuch/lib/database.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 1add2770..880ec3f7 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -225,6 +225,31 @@ func (db *DB) MsgTags(key string) ([]string, error) { return tags, err } +func (db *DB) MsgFilenames(key string) ([]string, error) { + var filenames []string + + err := db.withConnection(false, func(ndb *notmuch.DB) error { + msg, err := ndb.FindMessage(key) + if err != nil { + return err + } + defer msg.Close() + + fns := msg.Filenames() + var filename string + for fns.Next(&filename) { + if err != nil && !errors.Is(err, notmuch.ErrDuplicateMessageID) { + return err + } + filenames = append(filenames, filename) + } + + return nil + }) + + return filenames, err +} + func (db *DB) msgModify(key string, cb func(*notmuch.Message) error, ) error { -- cgit