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>
This commit is contained in:
Julian Pidancet 2022-10-26 22:29:09 +02:00 committed by Robin Jarry
parent 135439b83f
commit 81440e79ad

View file

@ -120,6 +120,22 @@ func (db *DB) newQuery(ndb *notmuch.DB, query string) (*notmuch.Query, error) {
return q, nil 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) { func (db *DB) MsgIDsFromQuery(q string) ([]string, error) {
var msgIDs []string var msgIDs []string
err := db.withConnection(false, func(ndb *notmuch.DB) error { err := db.withConnection(false, func(ndb *notmuch.DB) error {