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:
parent
19e2750255
commit
748e60e6ca
1 changed files with 25 additions and 0 deletions
|
@ -225,6 +225,31 @@ func (db *DB) MsgTags(key string) ([]string, error) {
|
||||||
return tags, err
|
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,
|
func (db *DB) msgModify(key string,
|
||||||
cb func(*notmuch.Message) error,
|
cb func(*notmuch.Message) error,
|
||||||
) error {
|
) error {
|
||||||
|
|
Loading…
Reference in a new issue