Skip to content

Commit

Permalink
fix(GODT-2550): Announce IMAP ID Capability
Browse files Browse the repository at this point in the history
Feature was built in but never announced to the clients.
  • Loading branch information
LBeernaertProton committed Apr 13, 2023
1 parent 81e7559 commit 3e8cc8b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion imap/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const (
UNSELECT Capability = `UNSELECT`
UIDPLUS Capability = `UIDPLUS`
MOVE Capability = `MOVE`
ID Capability = `ID`
)

func IsCapabilityAvailableBeforeAuth(c Capability) bool {
switch c {
case IMAP4rev1, StartTLS, IDLE:
case IMAP4rev1, StartTLS, IDLE, ID:
return true
case UNSELECT, UIDPLUS, MOVE:
return false
Expand Down
2 changes: 1 addition & 1 deletion internal/session/handle_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (s *Session) getCaps() []imap.Capability {
return s.caps
}

caps := []imap.Capability{}
var caps []imap.Capability
for _, c := range s.caps {
if imap.IsCapabilityAvailableBeforeAuth(c) {
caps = append(caps, c)
Expand Down
2 changes: 1 addition & 1 deletion internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func New(
inputCollector: inputCollector,
scanner: scanner,
backend: backend,
caps: []imap.Capability{imap.IMAP4rev1, imap.IDLE, imap.UNSELECT, imap.UIDPLUS, imap.MOVE},
caps: []imap.Capability{imap.IMAP4rev1, imap.IDLE, imap.UNSELECT, imap.UIDPLUS, imap.MOVE, imap.ID},
sessionID: sessionID,
eventCh: eventCh,
idleBulkTime: idleBulkTime,
Expand Down
6 changes: 3 additions & 3 deletions tests/capability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
func TestCapability(t *testing.T) {
runOneToOneTest(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
c.C("A001 Capability")
c.S(`* CAPABILITY IDLE IMAP4rev1 STARTTLS`)
c.S(`* CAPABILITY ID IDLE IMAP4rev1 STARTTLS`)
c.S("A001 OK CAPABILITY")

c.C(`A002 login "user" "pass"`)
c.S(`A002 OK [CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT] Logged in`)
c.S(`A002 OK [CAPABILITY ID IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT] Logged in`)

c.C("A003 Capability")
c.S(`* CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT`)
c.S(`* CAPABILITY ID IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT`)
c.S("A003 OK CAPABILITY")
})
}
2 changes: 1 addition & 1 deletion tests/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestLoginLiteralFailure(t *testing.T) {
func TestLoginCapabilities(t *testing.T) {
runOneToOneTest(t, defaultServerOptions(t), func(c *testConnection, _ *testSession) {
c.C("A001 login user pass")
c.S(`A001 OK [CAPABILITY IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT] Logged in`)
c.S(`A001 OK [CAPABILITY ID IDLE IMAP4rev1 MOVE STARTTLS UIDPLUS UNSELECT] Logged in`)
})
}

Expand Down

0 comments on commit 3e8cc8b

Please sign in to comment.