I realized today I had several bugs related to NILs. I?ll add these to imaptest, but thought I?d mention here also in case others have similar issues:
1. My understanding from RFC 3501 is that NILs are case-insensitive, because of:
Note: [ABNF] rules MUST be followed strictly; in
particular:
(1) Except as noted otherwise, all alphabetic characters
are case-insensitive. The use of upper or lower case
characters to define token strings is for editorial clarity
only. Implementations MUST accept these strings in a
case-insensitive fashion.
I was checking only for uppercase NILs. Then again there weren't actually any IMAP command parameters where NIL was allowed before I implemented SETMETADATA today.
2. NIL is a valid atom in astrings, and must be treated the same as ?NIL?:
Note: NIL is never used for any data item which takes the
form of an atom. For example, a mailbox name of "NIL" is a
mailbox named NIL as opposed to a non-existent mailbox
name. This is because mailbox uses "astring" syntax which
is an atom or a string.
And of course this needs to work case-sensitively when used in mailbox names, so NIL != nil.
3. When sending NIL (case-insensitive) astring to clients, it?s better to send it quoted. Clients are much less likely to implement 2 correctly, and I?m sure in some cases my code is calling write_astring() when it?s really nstring in ABNF.