forked from jordwest/imap-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
command_list.go
46 lines (40 loc) · 1.31 KB
/
command_list.go
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
package conn
import (
"regexp"
"strings"
)
const listArgSelector int = 1
func cmdList(args commandArgs, c *Conn) {
if !c.assertAuthenticated(args.ID()) {
return
}
reference := args.Arg(0)
mailboxname := args.Arg(1)
if mailboxname == "" {
// Blank mailboxname means request directory separator
c.writeResponse("", "LIST (\\Noselect) \"/\" \"\"")
} else {
re, error := regexp.Compile(strings.Replace(strings.Replace("^" + reference + mailboxname + "$", "*", ".*", -1), "%", "[^/]*", -1))
if error != nil { return }
for _, mailbox := range c.User.Mailboxes() {
if re.MatchString(mailbox.Name()) {
c.writeResponse("", "LIST () \"/\" \""+mailbox.Name()+"\"")
}
}
}
//~ if args.Arg(listArgSelector) == "" {
//~ // Blank selector means request directory separator
//~ c.writeResponse("", "LIST (\\Noselect) \"/\" \"\"")
//~ } else if args.Arg(listArgSelector) == "*" {
//~ // List all mailboxes requested
//~ for _, mailbox := range c.User.Mailboxes() {
//~ c.writeResponse("", "LIST () \"/\" \""+mailbox.Name()+"\"")
//~ }
//~ } else if args.Arg(listArgSelector) == "%" {
//~ // List all mailboxes requested
//~ for _, mailbox := range c.User.Mailboxes() {
//~ c.writeResponse("", "LIST () \"/\" \""+mailbox.Name()+"\"")
//~ }
//~ }
c.writeResponse(args.ID(), "OK LIST completed")
}