aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/emersion/go-imap/commands/list.go
diff options
context:
space:
mode:
authorJordan <me@jordan.im>2023-02-04 23:54:03 -0700
committerJordan <me@jordan.im>2023-02-04 23:54:03 -0700
commitc4159d895ac399ca55326f7b4ff8bfbf8402e654 (patch)
tree45340ca429c16f683b375695d01e03d65ebf22b0 /vendor/github.com/emersion/go-imap/commands/list.go
downloadpigeon-c4159d895ac399ca55326f7b4ff8bfbf8402e654.tar.gz
pigeon-c4159d895ac399ca55326f7b4ff8bfbf8402e654.zip
initial commit
Diffstat (limited to 'vendor/github.com/emersion/go-imap/commands/list.go')
-rw-r--r--vendor/github.com/emersion/go-imap/commands/list.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/github.com/emersion/go-imap/commands/list.go b/vendor/github.com/emersion/go-imap/commands/list.go
new file mode 100644
index 0000000..52686e9
--- /dev/null
+++ b/vendor/github.com/emersion/go-imap/commands/list.go
@@ -0,0 +1,60 @@
+package commands
+
+import (
+ "errors"
+
+ "github.com/emersion/go-imap"
+ "github.com/emersion/go-imap/utf7"
+)
+
+// List is a LIST command, as defined in RFC 3501 section 6.3.8. If Subscribed
+// is set to true, LSUB will be used instead.
+type List struct {
+ Reference string
+ Mailbox string
+
+ Subscribed bool
+}
+
+func (cmd *List) Command() *imap.Command {
+ name := "LIST"
+ if cmd.Subscribed {
+ name = "LSUB"
+ }
+
+ enc := utf7.Encoding.NewEncoder()
+ ref, _ := enc.String(cmd.Reference)
+ mailbox, _ := enc.String(cmd.Mailbox)
+
+ return &imap.Command{
+ Name: name,
+ Arguments: []interface{}{ref, mailbox},
+ }
+}
+
+func (cmd *List) Parse(fields []interface{}) error {
+ if len(fields) < 2 {
+ return errors.New("No enough arguments")
+ }
+
+ dec := utf7.Encoding.NewDecoder()
+
+ if mailbox, err := imap.ParseString(fields[0]); err != nil {
+ return err
+ } else if mailbox, err := dec.String(mailbox); err != nil {
+ return err
+ } else {
+ // TODO: canonical mailbox path
+ cmd.Reference = imap.CanonicalMailboxName(mailbox)
+ }
+
+ if mailbox, err := imap.ParseString(fields[1]); err != nil {
+ return err
+ } else if mailbox, err := dec.String(mailbox); err != nil {
+ return err
+ } else {
+ cmd.Mailbox = imap.CanonicalMailboxName(mailbox)
+ }
+
+ return nil
+}