From 81440e79ada27014de8fc4e84393c796808da93f Mon Sep 17 00:00:00 2001 From: Julian Pidancet Date: Wed, 26 Oct 2022 22:29:09 +0200 Subject: [PATCH] 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 Acked-by: Robin Jarry Acked-by: Tim Culverhouse --- worker/notmuch/lib/database.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 178a2f4..c3c92b7 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 {