-
Notifications
You must be signed in to change notification settings - Fork 2
/
example_test.go
69 lines (57 loc) · 1.54 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package sortthread_test
import (
"log"
"time"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap-sortthread"
"github.com/emersion/go-imap/client"
)
func ExampleSortClient() {
// Assuming c is an IMAP client
var c *client.Client
// Create a new SORT client
sc := sortthread.NewSortClient(c)
// Check the server supports the extension
ok, err := sc.SupportSort()
if err != nil {
log.Fatal(err)
} else if !ok {
log.Fatal("Server doesn't support SORT")
}
// Send a SORT command: search for the first 10 messages, sort them by
// ascending sender and then by descending size
sortCriteria := []sortthread.SortCriterion{
{Field: sortthread.SortFrom},
{Field: sortthread.SortSize, Reverse: true},
}
searchCriteria := imap.NewSearchCriteria()
searchCriteria.SeqNum = new(imap.SeqSet)
searchCriteria.SeqNum.AddRange(1, 10)
uids, err := sc.UidSort(sortCriteria, searchCriteria)
if err != nil {
log.Fatal(err)
}
log.Println(uids)
}
func ExampleThreadClient() {
// Assuming c is an IMAP client
var c *client.Client
// Create a new THREAD client
sc := sortthread.NewThreadClient(c)
// Check the server supports the extension
ok, err := sc.SupportThread()
if err != nil {
log.Fatal(err)
} else if !ok {
log.Fatal("Server doesn't support THREAD")
}
layoutISO := "2006-01-02"
searchCriteria := imap.NewSearchCriteria()
date, _ := time.Parse(layoutISO, "2019-07-05")
searchCriteria.Since = date
threads, err := sc.UidThread(sortthread.References, searchCriteria)
if err != nil {
log.Fatal(err)
}
log.Println(threads)
}