mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 17:04:39 +03:00
imapserver: allow creating mailboxes with characters &#*%, and encode mailbox names in imap with imaputf7 when needed
the imapserver started with imap4rev2-only and utf8=only. to prevent potential issues with imaputf7, which makes "&" special, we refused any mailbox with an "&" in the name. we already tried decoding utf7, falling back to using a mailbox name verbatim. that behaviour wasn't great. we now treat the enabled extensions IMAP4rev2 and/or UTF8=ACCEPT as indication whether mailbox names are in imaputf7. if they are, the encoding must be correct. we now also send mailbox names in imaputf7 when imap4rev2/utf8=accept isn't enabled. and we now allow "*" and "%" (wildcard characters for matching) in mailbox names. not ideal for IMAP LIST with patterns, but not enough reason to refuse them in mailbox names. people that migrate may run into this, possibly as blocker. we also allow "#" in mailbox names, but not as first character, to prevent potential clashes with IMAP namespaces in the future. based on report from Damian Poddebniak using https://github.com/duesee/imap-flow and issue #110, thanks for reporting!
This commit is contained in:
@ -2599,12 +2599,18 @@ func CheckMailboxName(name string, allowInbox bool) (normalizedName string, isIn
|
||||
if strings.HasPrefix(name, "/") || strings.HasSuffix(name, "/") || strings.Contains(name, "//") {
|
||||
return "", false, errors.New("bad slashes in mailbox name")
|
||||
}
|
||||
|
||||
// "%" and "*" are difficult to use with the IMAP LIST command, but we allow mostly
|
||||
// allow them. ../rfc/3501:1002 ../rfc/9051:983
|
||||
if strings.HasPrefix(name, "#") {
|
||||
return "", false, errors.New("mailbox name cannot start with hash due to conflict with imap namespaces")
|
||||
}
|
||||
|
||||
// "#" and "&" are special in IMAP mailbox names. "#" for namespaces, "&" for
|
||||
// IMAP-UTF-7 encoding. We do allow them. ../rfc/3501:1018 ../rfc/9051:991
|
||||
|
||||
for _, c := range name {
|
||||
switch c {
|
||||
case '%', '*', '#', '&':
|
||||
return "", false, fmt.Errorf("character %c not allowed in mailbox name", c)
|
||||
}
|
||||
// ../rfc/6855:192
|
||||
// ../rfc/3501:999 ../rfc/6855:192 ../rfc/9051:979
|
||||
if c <= 0x1f || c >= 0x7f && c <= 0x9f || c == 0x2028 || c == 0x2029 {
|
||||
return "", false, errors.New("control characters not allowed in mailbox name")
|
||||
}
|
||||
|
Reference in New Issue
Block a user