File: enabled.go

package info (click to toggle)
golang-github-emersion-go-imap 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 840 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (2)
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
package responses

import (
	"github.com/emersion/go-imap"
)

// An ENABLED response, defined in RFC 5161 section 3.2.
type Enabled struct {
	Caps []string
}

func (r *Enabled) Handle(resp imap.Resp) error {
	name, fields, ok := imap.ParseNamedResp(resp)
	if !ok || name != "ENABLED" {
		return ErrUnhandled
	}

	if caps, err := imap.ParseStringList(fields); err != nil {
		return err
	} else {
		r.Caps = append(r.Caps, caps...)
	}

	return nil
}

func (r *Enabled) WriteTo(w *imap.Writer) error {
	fields := []interface{}{imap.RawString("ENABLED")}
	for _, cap := range r.Caps {
		fields = append(fields, imap.RawString(cap))
	}
	return imap.NewUntaggedResp(fields).WriteTo(w)
}