Skip to content

Commit 75ea6d9

Browse files
committed
Add missing ENABLE command and response
1 parent 08b95f8 commit 75ea6d9

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

commands/enable.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package commands
2+
3+
import (
4+
"github.com/emersion/go-imap"
5+
)
6+
7+
// An ENABLE command, defined in RFC 5161 section 3.1.
8+
type Enable struct {
9+
Caps []string
10+
}
11+
12+
func (cmd *Enable) Command() *imap.Command {
13+
return &imap.Command{
14+
Name: "ENABLE",
15+
Arguments: imap.FormatStringList(cmd.Caps),
16+
}
17+
}
18+
19+
func (cmd *Enable) Parse(fields []interface{}) error {
20+
var err error
21+
cmd.Caps, err = imap.ParseStringList(fields)
22+
return err
23+
}

responses/enabled.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package responses
2+
3+
import (
4+
"github.com/emersion/go-imap"
5+
)
6+
7+
// An ENABLED response, defined in RFC 5161 section 3.2.
8+
type Enabled struct {
9+
Caps []string
10+
}
11+
12+
func (r *Enabled) Handle(resp imap.Resp) error {
13+
name, fields, ok := imap.ParseNamedResp(resp)
14+
if !ok || name != "ENABLED" {
15+
return ErrUnhandled
16+
}
17+
18+
if caps, err := imap.ParseStringList(fields); err != nil {
19+
return err
20+
} else {
21+
r.Caps = append(r.Caps, caps...)
22+
}
23+
24+
return nil
25+
}
26+
27+
func (r *Enabled) WriteTo(w *imap.Writer) error {
28+
fields := []interface{}{imap.RawString("ENABLED")}
29+
for _, cap := range r.Caps {
30+
fields = append(fields, imap.RawString(cap))
31+
}
32+
return imap.NewUntaggedResp(fields).WriteTo(w)
33+
}

0 commit comments

Comments
 (0)