Skip to content

Commit

Permalink
Query.AddTagExclude
Browse files Browse the repository at this point in the history
  • Loading branch information
brunnre8 committed Jul 22, 2019
1 parent d2f9206 commit de61b90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,15 @@ func (q *Query) SetExcludeScheme(mode ExcludeMode) {
cmode := C.notmuch_exclude_t(mode)
C.notmuch_query_set_omit_excluded(q.toC(), cmode)
}

// AddTagExclude adds a tag that will be excluded from the query results by default.
// This exclusion will be ignored if this tag appears explicitly in the query.
func (q *Query) AddTagExclude(tag string) error {
ctag := C.CString(tag)
defer C.free(unsafe.Pointer(ctag))
status := C.notmuch_query_add_tag_exclude(q.toC(), ctag)
if status != C.NOTMUCH_STATUS_IGNORED {
return statusErr(status)
}
return nil
}
14 changes: 14 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,17 @@ func TestSetExcludeScheme(t *testing.T) {
q.SetExcludeScheme(mode)
}
}

func TestAddTagExclude(t *testing.T) {
db, err := Open(dbPath, DBReadOnly)
if err != nil {
t.Fatal(err)
}
defer db.Close()

q := db.NewQuery("subject:\"Introducing myself\"")
err = q.AddTagExclude("spam")
if err != nil {
t.Errorf("q.AddTagExclude(\"spam\"): unexpected error: %v", err)
}
}

0 comments on commit de61b90

Please sign in to comment.