Forked the emersion/go-imap v1 project.
This commit is contained in:
61
imapclient/search_test.go
Normal file
61
imapclient/search_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package imapclient_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/emersion/go-imap/v2"
|
||||
)
|
||||
|
||||
func TestSearch(t *testing.T) {
|
||||
client, server := newClientServerPair(t, imap.ConnStateSelected)
|
||||
defer client.Close()
|
||||
defer server.Close()
|
||||
|
||||
criteria := imap.SearchCriteria{
|
||||
Header: []imap.SearchCriteriaHeaderField{{
|
||||
Key: "Message-Id",
|
||||
Value: "<191101702316132@example.com>",
|
||||
}},
|
||||
}
|
||||
data, err := client.Search(&criteria, nil).Wait()
|
||||
if err != nil {
|
||||
t.Fatalf("Search().Wait() = %v", err)
|
||||
}
|
||||
seqSet, ok := data.All.(imap.SeqSet)
|
||||
if !ok {
|
||||
t.Fatalf("SearchData.All = %T, want SeqSet", data.All)
|
||||
}
|
||||
nums, _ := seqSet.Nums()
|
||||
want := []uint32{1}
|
||||
if !reflect.DeepEqual(nums, want) {
|
||||
t.Errorf("SearchData.All.Nums() = %v, want %v", nums, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestESearch(t *testing.T) {
|
||||
client, server := newClientServerPair(t, imap.ConnStateSelected)
|
||||
defer client.Close()
|
||||
defer server.Close()
|
||||
|
||||
if !client.Caps().Has(imap.CapESearch) {
|
||||
t.Skip("server doesn't support ESEARCH")
|
||||
}
|
||||
|
||||
criteria := imap.SearchCriteria{
|
||||
Header: []imap.SearchCriteriaHeaderField{{
|
||||
Key: "Message-Id",
|
||||
Value: "<191101702316132@example.com>",
|
||||
}},
|
||||
}
|
||||
options := imap.SearchOptions{
|
||||
ReturnCount: true,
|
||||
}
|
||||
data, err := client.Search(&criteria, &options).Wait()
|
||||
if err != nil {
|
||||
t.Fatalf("Search().Wait() = %v", err)
|
||||
}
|
||||
if want := uint32(1); data.Count != want {
|
||||
t.Errorf("Count = %v, want %v", data.Count, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user