Kyeema;10991297 wrote:
I have to admit I still don't get it really when to add double CRLFs and where not... and I haven't found a good tutorial so far, I'm just experimenting... :eek:
There's not really a need for a tutorial in the matter, just the relevant RFCs. While RFC822, which was the initial RFC defining the MIME structure, has been extended, it should be enough to read it for the purpose of learning how the overall structure of messages should be. Should you need more information, search for MIME on wikipedia and you'll find links to relevant RFCs.
Anyway, a quick look at RFC 822, section 3.2: Header field definitions
field = field-name ":" [ field-body ] CRLF
field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":">
field-body = field-body-contents
[CRLF LWSP-char field-body]
field-body-contents =
<the ASCII characters making up the field-body, as
defined in the following sections, and consisting
of combinations of atom, quoted-string, and
specials tokens, or else consisting of texts>
For the purpose of CRLF, you pretty much only need to read the first line, which reads like this: A header field consists of field name (such as Content-Type) followed by : followed by field body (such as text/plain) followed by CRLF. Not devling deeper into things, that's almost everything you need to know about email headers: Each email header is terminated by one CRLF.
The following lines specify what a field name should look like and what the field body should look like. These lines specify that "folding", CRLF followed by leading whitespace (LWSP), is allowed for the field body. Folding is explaing elsewhere in the RFC, but what it means is that you can break up one header over multiple lines as long as you insert at least one LWSP directly after each such CRLF. It is only a CRLF not followed by LWSP that terminates the header field.
Which means that the following have the exact same meaning
Content-Type: text/plain; charset=utf-8
Content-Type: text/plain;
charset=utf-8
Moving on to section 4: Message syntax
message = fields ( CRLF text ) ; Everything after
; first null line
; is message body
which should be read like this: A message consists of header fields optionally followed by (CRLF optionally followed by text). That is, if there is a message body (the text), there should be a CRLF between the headers and the body. Now, since you allready know that a header is terminated by a CRLF (that is, the CRLF terminating one header field actually belongs to that header field), it follows that there will always be 2 CRLF before the message body: one to terminate the last header field and one preceeding the message body.