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 <julian.pidancet@oracle.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Julian Pidancet 2022-10-26 22:29:00 +02:00 committed by Robin Jarry
parent 19e2750255
commit 748e60e6ca

View file

@ -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 {