go-imap
go-imap copied to clipboard
fetch: ensure field names are Atoms
This PR makes sure the fields in FETCH/SEARCH are atoms.
The spec says it is allowed to have strings (ie with double quotes) here, but I'm on an IMAP server that doesn't totally respect that:
> A004 SEARCH HEADER Message-Id <[email protected]>
< * SEARCH 1
< A004 OK SEARCH done
> A004 FETCH 1 (BODY[HEADER.FIELDS (Message-ID)])
< * 1 FETCH (BODY[HEADER.FIELDS (MESSAGE-ID)] {65}
< Message-ID: <[email protected]>
<
< )
< A004 OK FETCH done
> A004 FETCH 1 (BODY[HEADER.FIELDS ("Message-ID")])
< * 1 FETCH (BODY[HEADER.FIELDS ("MESSAGE-ID")] {2}
<
< )
< A004 OK FETCH done
The server in question is provided by mailo.com. I know this deviates from standard, but I can only guess if we send something stricter than expected then it's ok ?
Unfortunately this approach breaks the case where values contain invalid atom characters, such as spaces for instance.
Oh well. I suppose we could have Encoder.AString
which uses an atom if the value doesn't contain special characters?
Wait, there are header field names with spaces ? This change is only for field names, not values (which should always be a string as you say)
-- Matthieu Rakotojaona
Wait, there are header field names with spaces ?
Technically yes. The only character a header field can't contain is a colon. See ftext
in RFC 5322 section 3.6.8.
Regardless, the string comes from the user of the library, which means that it can potentially be anything. We shouldn't produce invalid IMAP syntax even if the user provides an invalid header field name.
Out of curiosity, a literal also doesn't work with mailo
-- Matthieu Rakotojaona