I'm hoping to connect to an Apple engineer here.
Issue description:
In short: iCloud's IMAP servers sometimes produce a malformed response to an IMAP 'UID FETCH' command.
For some fetched messages, the ENVELOPE's message-ID contains unescaped double quotes where those are not allowed according to the RFC (not allowed to link to that here but it's specified in section 9 of the RFC3501).
Like this:
"<"392889836.11.1529401004417.JavaMail.Redacted"@Redacted>"
This causes some IMAP clients to crash or not sync properly (hence not working well or at all with iCloud mail accounts).
Proposed fix
The double quotes iCloud returns in the response should instead be escaped like this:
"<\"392889836.11.1529401004417.JavaMail.Redacted\"@Redacted>"
in order to comply with the RFC.
More details
For more details about how I discovered this issue, please see this.