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:
parent
135439b83f
commit
81440e79ad
1 changed files with 16 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue