Subject: [apps-discuss] draft-ietf-appsawg-malformed-mail-03 review

From: Timo Sirainen <[email-masked]>
Date: Mon, 13 May 2013 13:04:03 +0300

A quick review from IMAP server developer's point of view:

> 7.  Line Terminaton
> 
>    Thus, handling agents MUST treat naked CRs and LFs as CRLFs when
>    interpreting the message.

Agreed for LFs, but doing this for CRs would often make the code much more complex. A simple strchr(str, '\n') to find a line termination would no longer work. I've also never seen naked CRs intended to be used as CRLFs, but I've seen them sometimes added due to some bug. I think naked CRs are a similar problem as NULs, and maybe should be just deleted or replaced by a space.

> 8.2.  Non-Header Lines
>        From: [email-masked] {1}
>        To: [email-masked] {2}
>        Subject: This is your reminder {3}
>        about the football game tonight {4}
>        Date: Wed, 20 Oct 2010 20:53:35 -0400 {5}

My code currently handles this by treating "about the football game tonight" as header key, which doesn't have a value.

>    The preferred implementation if option 4 above is not employed is to
>    apply the following heuristic when this malformation is detected:
> 

>    1.  Search forward for an empty line.  If one is found, then apply
>        option 3 above to the anomalous line, and continue.
> 
>    2.  Search forward for another line that appears to be a new header
>        field, i.e., a name followed by a colon.  If one is found, then
>        apply option 3 above to the anomalous line, and continue.

Having to search forward is always a pretty annoying way to deal with things. The searched text could even be megabytes after from the current position. My code usually does parsing by only looking up maybe 1 character forward.

> 8.7.  Eight-Bit Data
> 
>    Handling agents MUST reject messages containing null bytes that are
>    not encoded in some standard way, and SHOULD reject other non-ASCII
>    bytes that are similarly not encoded.  If rejection is not done, an
>    ASCII-compatible encoding such as those defined in [MIME] SHOULD be
>    used.

I agree with others that messages shouldn't be rejected because there are NULs or 8bit data in message body. Even in headers hotmail used to send 8bit data directly, but hopefully that's not as common anymore. My code replaces NULs with 0x80 characters (as does UW-IMAP) when sending them to IMAP clients.

> 9.2.  Missing MIME-Version Field

Agreed with Ned that a missing MIME-Version should be allowed (= treated as if it exists with value 1.0). Dovecot used to strictly require it, but after enough complaints from users I changed it so it's no longer required.