tags:

views:

212

answers:

4

From http://www.faqs.org/rfcs/rfc2822.html:

CR and LF MUST only occur together as CRLF; they MUST NOT appear independently in the body.

We have a web service that sends out confirmation emails, but one of our users pointed out that this does not adhere to the rfc2822 standard. So my question is, why is it important for CR and LF to appear together in email messages?

+11  A: 

Because it's in the accepted RFC?

Implementations are derived from RFCs. If that was not the case, then there would be no guarantee of interoperability between different implementations. There may or may not be tangible, technical reasons of requiring them to appear together, but in this case those reasons are irrelevant. It's a simple matter of "because they said so."

Sean Bright
I don't think your first sentence needs to be a question. It can just be a statement. (sorry for the nit)
Scott W
@Scott W: I think the interrogative form is ironic...
PhiLho
Thanks for the answer - but I think that was implied in my asking this question in the first place. I was looking for a more technical reason.
+6  A: 

Think in term of an old teletype. CR returns the write head to the beginning of the line, LF rolls the paper one line forward. You need both steps to begin a new line. If you use CR without LF, you will overwrite the same text, which is of course illegal.

Anyway, this is the historial reason to define CR+LF as the ASCII-code for a new line. Of course in the end it is just arbitrary codes. Some systems use only CR to indicate a new line, some systems use only LF, some use a different character entirely. RFC2822 had to chose one, and decided to allow only the sequence CRLF.

Since the RFC decided to use CRLF, it makes sense to disallow CR or LF seperately, since this would be pretty useless and problematic to handle anyway.

JacquesB
I think based on the question asked, this is the most correct answer. It attempts to justify the arbitrary decision by the authors of the RFC to require CRLF with a technically sound argument (that of the teletype). I'd +10 you if I could!
Sean Bright
A: 

If not you end up with a CR, which puts you on the same line, then whatever you write would be on top of the chars at the left on the same line, then comes the LF and you are in some column towards the middle and start writing again. Messy.

Otávio Décio
+5  A: 

Because in email CRLF is the line separator. If you only use CR or only use LF you will have all sorts of unexpected problems with various clients, SMTP server combination. Some servers will reject your emails, some will "fix" your emails. Fixed emails are some of the most fun to deal with.

Darryl Braaten
That makes sense. My concern was that some users might be parsing the confirmation emails, so I was reluctant to change it without a good reason. Thank you.
"Because in email CRLF is the line separator." - What is the technical reason for that?
Sean Bright
The technical reason is that it is in the RFC ;)
Scott W
Ding ding ding! :P
Sean Bright
Since he already had a link to the rfc I decided to explain the problems that will happen if you don't follow it. Saying RTFM doesn't help someone who has already done that. :)
Darryl Braaten