Skip to content

Commit 6a55c78

Browse files
authored
Merge branch 'v2' into condstore
2 parents e2230b5 + 9d73778 commit 6a55c78

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

capability.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ const (
3434
CapMove Cap = "MOVE" // RFC 6851
3535
CapLiteralMinus Cap = "LITERAL-" // RFC 7888
3636
CapStatusSize Cap = "STATUS=SIZE" // RFC 8438
37+
CapChildren Cap = "CHILDREN" // RFC 3348
3738

3839
CapACL Cap = "ACL" // RFC 4314
3940
CapAppendLimit Cap = "APPENDLIMIT" // RFC 7889
4041
CapBinary Cap = "BINARY" // RFC 3516
4142
CapCatenate Cap = "CATENATE" // RFC 4469
42-
CapChildren Cap = "CHILDREN" // RFC 3348
4343
CapCondStore Cap = "CONDSTORE" // RFC 7162
4444
CapConvert Cap = "CONVERT" // RFC 5259
4545
CapCreateSpecialUse Cap = "CREATE-SPECIAL-USE" // RFC 6154
@@ -92,6 +92,7 @@ var imap4rev2Caps = CapSet{
9292
CapMove: {},
9393
CapLiteralMinus: {},
9494
CapStatusSize: {},
95+
CapChildren: {},
9596
}
9697

9798
// AuthCap returns the capability name for an SASL authentication mechanism.

imapclient/capability.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
"github.com/emersion/go-imap/v2"
7+
"github.com/emersion/go-imap/v2/internal"
78
"github.com/emersion/go-imap/v2/internal/imapwire"
89
)
910

@@ -45,11 +46,11 @@ func readCapabilities(dec *imapwire.Decoder) (imap.CapSet, error) {
4546
for dec.SP() {
4647
}
4748

48-
var name string
49-
if !dec.ExpectAtom(&name) {
50-
return caps, fmt.Errorf("in capability-data: %v", dec.Err())
49+
cap, err := internal.ExpectCap(dec)
50+
if err != nil {
51+
return caps, fmt.Errorf("in capability-data: %w", err)
5152
}
52-
caps[imap.Cap(name)] = struct{}{}
53+
caps[cap] = struct{}{}
5354
}
5455
return caps, nil
5556
}

imapserver/capability.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (c *Conn) availableCaps() []imap.Cap {
8080
imap.CapMove,
8181
imap.CapStatusSize,
8282
imap.CapBinary,
83+
imap.CapChildren,
8384
})
8485
}
8586

imapserver/enable.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package imapserver
22

33
import (
44
"github.com/emersion/go-imap/v2"
5+
"github.com/emersion/go-imap/v2/internal"
56
"github.com/emersion/go-imap/v2/internal/imapwire"
67
)
78

89
func (c *Conn) handleEnable(dec *imapwire.Decoder) error {
910
var requested []imap.Cap
1011
for dec.SP() {
11-
var c string
12-
if !dec.ExpectAtom(&c) {
13-
return dec.Err()
12+
cap, err := internal.ExpectCap(dec)
13+
if err != nil {
14+
return err
1415
}
15-
requested = append(requested, imap.Cap(c))
16+
requested = append(requested, cap)
1617
}
1718
if !dec.ExpectCRLF() {
1819
return dec.Err()

imapserver/imapmemserver/mailbox.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ func (mbox *Mailbox) statusDataLocked(options *imap.StatusOptions) *imap.StatusD
9797
}
9898
if options.HighestModSeq {
9999
data.HighestModSeq = mbox.highestModSeq
100+
}
101+
if options.NumRecent {
102+
num := uint32(0)
103+
data.NumRecent = &num
100104
}
101105
return &data
102106
}

internal/internal.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func ExpectFlagList(dec *imapwire.Decoder) ([]imap.Flag, error) {
6969
return flags, err
7070
}
7171

72+
func ExpectCap(dec *imapwire.Decoder) (imap.Cap, error) {
73+
var name string
74+
if !dec.ExpectAtom(&name) {
75+
return "", dec.Err()
76+
}
77+
return canonicalCap(name), nil
78+
}
79+
7280
func ExpectFlag(dec *imapwire.Decoder) (imap.Flag, error) {
7381
isSystem := dec.Special('\\')
7482
if isSystem && dec.Special('*') {
@@ -168,3 +176,13 @@ func canonicalMailboxAttr(s string) imap.MailboxAttr {
168176
}
169177
return imap.MailboxAttr(s)
170178
}
179+
180+
func canonicalCap(s string) imap.Cap {
181+
// Only two caps are not fully uppercase
182+
for _, cap := range []imap.Cap{imap.CapIMAP4rev1, imap.CapIMAP4rev2} {
183+
if strings.EqualFold(s, string(cap)) {
184+
return cap
185+
}
186+
}
187+
return imap.Cap(strings.ToUpper(s))
188+
}

0 commit comments

Comments
 (0)