@@ -61,7 +61,11 @@ func (info *MailboxInfo) Parse(fields []interface{}) error {
6161
6262 var ok bool
6363 if info .Delimiter , ok = fields [1 ].(string ); ! ok {
64- return errors .New ("Mailbox delimiter must be a string" )
64+ // The delimiter may be specified as NIL, which gets converted to a nil interface.
65+ if fields [1 ] != nil {
66+ return errors .New ("Mailbox delimiter must be a string" )
67+ }
68+ info .Delimiter = ""
6569 }
6670
6771 if name , err := ParseString (fields [2 ]); err != nil {
@@ -82,8 +86,17 @@ func (info *MailboxInfo) Format() []interface{} {
8286 for i , attr := range info .Attributes {
8387 attrs [i ] = RawString (attr )
8488 }
89+
90+ // If the delimiter is NIL, we need to treat it specially by inserting
91+ // a nil field (so that it's later converted to an unquoted NIL atom).
92+ var del interface {}
93+
94+ if info .Delimiter != "" {
95+ del = info .Delimiter
96+ }
97+
8598 // Thunderbird doesn't understand delimiters if not quoted
86- return []interface {}{attrs , info . Delimiter , FormatMailboxName (name )}
99+ return []interface {}{attrs , del , FormatMailboxName (name )}
87100}
88101
89102// TODO: optimize this
@@ -123,12 +136,12 @@ func (info *MailboxInfo) match(name, pattern string) bool {
123136func (info * MailboxInfo ) Match (reference , pattern string ) bool {
124137 name := info .Name
125138
126- if strings .HasPrefix (pattern , info .Delimiter ) {
139+ if info . Delimiter != "" && strings .HasPrefix (pattern , info .Delimiter ) {
127140 reference = ""
128141 pattern = strings .TrimPrefix (pattern , info .Delimiter )
129142 }
130143 if reference != "" {
131- if ! strings .HasSuffix (reference , info .Delimiter ) {
144+ if info . Delimiter != "" && ! strings .HasSuffix (reference , info .Delimiter ) {
132145 reference += info .Delimiter
133146 }
134147 if ! strings .HasPrefix (name , reference ) {
0 commit comments