RFC(2)822 - CR LF modes

There is a difference between the conformity of RFC 2822 and best practise.

In RFC 2822 it says that strictly each line has to end up by CR (code 13) followed by LF (code 10). And in addition that the chars CR (code 13) and LF (code 10) should not be used particularly. If looking on Qmails implementation, they will revoke any traffic which is not conform to the above per default.

In real world, it is established, that also a line ending with single LF (code 10) is good practise. So if trying other mail servers like Exim or Exchange or Gmail, you may enter your message either ended by CRLF or single LF.

Also the DATA ending sequence of CRLF.CRLF (CR LF DOT CR LF) may be send as LF.LF (LF DOT LF).

Since version 2.3.0 the component allows to decide by option crlf_mode how to handle the line termination codes. Be aware that CRLF_ENSURE is enabled by default.

# Allow CRLF and LF but always make sure that CRLF is added to message data. _Default_
crlf_mode: CRLF_ENSURE

# Allow CRLF and LF and do not change the incoming data.
crlf_mode: CRLF_LEAVE

# Only allow CRLF otherwise raise an exception
crlf_mode: CRLF_STRICT


Modes

To understand the modes in details:

CRLF_ENSURE

  1. Read input buffer and search for LF (code 10)
  2. Use bytes from buffer start to LF as TEXTLINE
  3. Heal by deleting any occurrence of char CR (code 13) and char LF (code 10) from TEXTLINE
  4. Append cleaned TEXTLINE and RFC conform pair of CRLF to message data buffer

  5. As result you will have a clean RFC 2822 conform message input data

  6. In best case the data is 100% equal to the original input because that already was CRLF conform
  7. Other input data maybe have changed for the linebreaks but the message is conform yet

CRLF_LEAVE

  1. Read input buffer and search for LF (code 10)
  2. Use bytes from buffer start to LF as TEXTLINE
  3. Append TEXTLINE as is to message data buffer

  4. As result you may have a non clean RFC 2822 conform message input data

  5. Other libraries like Mail may have parsing errors

CRLF_STRICT

  1. Read input buffer and search for CRLF (code 13 code 10)
  2. Use bytes from buffer start to CRLF as TEXTLINE
  3. Raise exception if TEXTLINE contains any single CR or LF
  4. Append TEXTLINE as is to message data buffer

  5. As result you will have a clean RFC 2822 conform message input data

  6. The data is 100% equal to the original input because that already was CRLF conform
  7. You maybe drop mails while in real world not all senders are working RFC conform