File tree Expand file tree Collapse file tree 5 files changed +36
-3
lines changed Expand file tree Collapse file tree 5 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -64,11 +64,11 @@ func (c *Conn) availableCaps() []imap.Cap {
64
64
imap .CapEnable ,
65
65
imap .CapIdle ,
66
66
}... )
67
- // TODO: implement imap.CapSearchRes
68
67
addAvailableCaps (& caps , available , []imap.Cap {
69
68
imap .CapNamespace ,
70
69
imap .CapUIDPlus ,
71
70
imap .CapESearch ,
71
+ imap .CapSearchRes ,
72
72
imap .CapListExtended ,
73
73
imap .CapListStatus ,
74
74
imap .CapMove ,
Original file line number Diff line number Diff line change @@ -461,6 +461,11 @@ func (dec *Decoder) ExpectMailbox(ptr *string) bool {
461
461
}
462
462
463
463
func (dec * Decoder ) ExpectSeqSet (ptr * imap.SeqSet ) bool {
464
+ if dec .Special ('$' ) {
465
+ * ptr = imap .SearchRes ()
466
+ return true
467
+ }
468
+
464
469
var s string
465
470
if ! dec .Expect (dec .Func (& s , isSeqSetChar ), "sequence-set" ) {
466
471
return false
Original file line number Diff line number Diff line change @@ -159,11 +159,12 @@ func (enc *Encoder) Mailbox(name string) *Encoder {
159
159
}
160
160
161
161
func (enc * Encoder ) SeqSet (seqSet imap.SeqSet ) * Encoder {
162
- if len (seqSet ) == 0 {
162
+ s := seqSet .String ()
163
+ if s == "" {
163
164
enc .setErr (fmt .Errorf ("imapwire: cannot encode empty sequence set" ))
164
165
return enc
165
166
}
166
- return enc .writeString (seqSet . String () )
167
+ return enc .writeString (s )
167
168
}
168
169
169
170
func (enc * Encoder ) Flag (flag imap.Flag ) * Encoder {
Original file line number Diff line number Diff line change 1
1
package imap
2
2
3
3
import (
4
+ "reflect"
4
5
"time"
5
6
)
6
7
@@ -11,6 +12,8 @@ type SearchOptions struct {
11
12
ReturnMax bool
12
13
ReturnAll bool
13
14
ReturnCount bool
15
+ // Requires IMAP4rev2 or SEARCHRES
16
+ ReturnSave bool
14
17
}
15
18
16
19
// SearchCriteria is a criteria for the SEARCH command.
@@ -116,3 +119,24 @@ func (data *SearchData) AllNums() []uint32 {
116
119
nums , _ := data .All .Nums ()
117
120
return nums
118
121
}
122
+
123
+ // searchRes is a special empty SeqSet which can be used as a marker. It has
124
+ // a non-zero cap so that its data pointer is non-nil and can be compared.
125
+ var (
126
+ searchRes = make (SeqSet , 0 , 1 )
127
+ searchResAddr = reflect .ValueOf (searchRes ).Pointer ()
128
+ )
129
+
130
+ // SearchRes returns a special marker which can be used instead of a SeqSet to
131
+ // reference the last SEARCH result. On the wire, it's encoded as '$'.
132
+ //
133
+ // It requires IMAP4rev2 or the SEARCHRES extension.
134
+ func SearchRes () SeqSet {
135
+ return searchRes
136
+ }
137
+
138
+ // IsSearchRes checks whether a sequence set is a reference to the last SEARCH
139
+ // result. See SearchRes.
140
+ func IsSearchRes (seqSet SeqSet ) bool {
141
+ return reflect .ValueOf (seqSet ).Pointer () == searchResAddr
142
+ }
Original file line number Diff line number Diff line change @@ -214,6 +214,9 @@ func (s SeqSet) Nums() (nums []uint32, ok bool) {
214
214
215
215
// String returns a sorted representation of all contained sequence values.
216
216
func (s SeqSet ) String () string {
217
+ if IsSearchRes (s ) {
218
+ return "$"
219
+ }
217
220
if len (s ) == 0 {
218
221
return ""
219
222
}
You can’t perform that action at this time.
0 commit comments