aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
authorJulian Pidancet <julian.pidancet@oracle.com>2022-10-26 22:29:09 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-27 21:45:31 +0200
commit81440e79ada27014de8fc4e84393c796808da93f (patch)
treed0f72a91e01fce8e8008be660fd103ca8ed3ea5d /worker
parent135439b83fc5087e7067a040db2fe3ed2da8bb57 (diff)
downloadaerc-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.go16
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 {