diff options
author | Julian Pidancet <julian.pidancet@oracle.com> | 2022-10-26 22:29:09 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-27 21:45:31 +0200 |
commit | 81440e79ada27014de8fc4e84393c796808da93f (patch) | |
tree | d0f72a91e01fce8e8008be660fd103ca8ed3ea5d /worker | |
parent | 135439b83fc5087e7067a040db2fe3ed2da8bb57 (diff) | |
download | aerc-81440e79ada27014de8fc4e84393c796808da93f.tar.gz |
notmuch: add MsgIDFromFilename method to notmuch.DB
Add a method to retrieve the message key associated with a message file
path, if indexed in the database.
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')
-rw-r--r-- | worker/notmuch/lib/database.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 178a2f4f..c3c92b7f 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -120,6 +120,22 @@ func (db *DB) newQuery(ndb *notmuch.DB, query string) (*notmuch.Query, error) { return q, nil } +func (db *DB) MsgIDFromFilename(filename string) (string, error) { + var key string + + err := db.withConnection(false, func(ndb *notmuch.DB) error { + msg, err := ndb.FindMessageByFilename(filename) + if err != nil && !errors.Is(err, notmuch.ErrDuplicateMessageID) { + return err + } + defer msg.Close() + key = msg.ID() + return nil + }) + + return key, err +} + func (db *DB) MsgIDsFromQuery(q string) ([]string, error) { var msgIDs []string err := db.withConnection(false, func(ndb *notmuch.DB) error { |