File: capability.go

package info (click to toggle)
golang-github-protonmail-gluon 0.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 16,020 kB
  • sloc: sh: 55; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 633 bytes parent folder | download
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
34
35
36
37
package response

import (
	"fmt"

	"github.com/ProtonMail/gluon/imap"
	"golang.org/x/exp/slices"
)

type capability struct {
	caps []imap.Capability
}

func Capability() *capability {
	return &capability{}
}

func (r *capability) WithCapabilities(caps ...imap.Capability) *capability {
	r.caps = append(r.caps, caps...)
	return r
}

func (r *capability) Send(s Session) error {
	return s.WriteResponse(r.String())
}

func (r *capability) String() string {
	var caps []string

	for _, capability := range r.caps {
		caps = append(caps, string(capability))
	}

	slices.Sort(caps)

	return fmt.Sprintf("* CAPABILITY %v", join(caps))
}