File: lsub.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 (48 lines) | stat: -rw-r--r-- 932 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
38
39
40
41
42
43
44
45
46
47
48
package command

import (
	"fmt"

	"github.com/ProtonMail/gluon/rfcparser"
)

type LSub struct {
	Mailbox     string
	LSubMailbox string
}

func (l LSub) String() string {
	return fmt.Sprintf("LSUB '%v' '%v'", l.Mailbox, l.LSubMailbox)
}

func (l LSub) SanitizedString() string {
	return l.String()
}

type LSubCommandParser struct{}

func (LSubCommandParser) FromParser(p *rfcparser.Parser) (Payload, error) {
	// lsub            = "LSUB" SP mailbox SP list-mailbox
	if err := p.Consume(rfcparser.TokenTypeSP, "expected space after command"); err != nil {
		return nil, err
	}

	mailbox, err := ParseMailbox(p)
	if err != nil {
		return nil, err
	}

	if err := p.Consume(rfcparser.TokenTypeSP, "expected space after mailbox"); err != nil {
		return nil, err
	}

	listMailbox, err := parseListMailbox(p)
	if err != nil {
		return nil, err
	}

	return &LSub{
		Mailbox:     mailbox.Value,
		LSubMailbox: listMailbox.Value,
	}, nil
}