notmuch: add IndexFile and DeleteMessage methods to notmuch.DB
The new IndexFile and DeleteMessage allow dynamically inserting and removing files to/from a notmuch 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
748e60e6ca
commit
19d16420de
1 changed files with 29 additions and 0 deletions
|
@ -250,6 +250,35 @@ func (db *DB) MsgFilenames(key string) ([]string, error) {
|
|||
return filenames, err
|
||||
}
|
||||
|
||||
func (db *DB) DeleteMessage(filename string) error {
|
||||
return db.withConnection(true, func(ndb *notmuch.DB) error {
|
||||
err := ndb.RemoveMessage(filename)
|
||||
if err != nil && !errors.Is(err, notmuch.ErrDuplicateMessageID) {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (db *DB) IndexFile(filename string) (string, error) {
|
||||
var key string
|
||||
|
||||
err := db.withConnection(true, func(ndb *notmuch.DB) error {
|
||||
msg, err := ndb.AddMessage(filename)
|
||||
if err != nil && !errors.Is(err, notmuch.ErrDuplicateMessageID) {
|
||||
return err
|
||||
}
|
||||
defer msg.Close()
|
||||
if err := msg.MaildirFlagsToTags(); err != nil {
|
||||
return err
|
||||
}
|
||||
key = msg.ID()
|
||||
return nil
|
||||
})
|
||||
return key, err
|
||||
}
|
||||
|
||||
func (db *DB) msgModify(key string,
|
||||
cb func(*notmuch.Message) error,
|
||||
) error {
|
||||
|
|
Loading…
Reference in a new issue