diff options
author | Julian Pidancet <julian.pidancet@oracle.com> | 2022-10-26 22:29:00 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-27 21:39:41 +0200 |
commit | 748e60e6caf6b3b5e752020482e2de09f86e883c (patch) | |
tree | 3438994e78267a8597a31b4176438ee897b3151c /worker/notmuch/lib | |
parent | 19e275025538a92bae92b152c4e39bdd22ad7e7f (diff) | |
download | aerc-748e60e6caf6b3b5e752020482e2de09f86e883c.tar.gz |
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>
Diffstat (limited to 'worker/notmuch/lib')
-rw-r--r-- | worker/notmuch/lib/database.go | 25 |
1 files changed, 25 insertions, 0 deletions
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 { |