@Dave_Evers
You should start with studying the specification of Email message format.
Refer to RFC-2822
Internet Message Format
Messages are divided into lines of characters. A line is a series of characters that is delimited with the two characters carriage-return and line-feed; that is, the carriage return (CR) character (ASCII value 13) followed immediately by the line feed (LF) character (ASCII value 10). (The carriage-return/line-feed pair is usually written in this document as “CRLF”.)
Here the doc mentions CRLF (0x0D 0x0A in hex) should be used as line separator in Email messages on the fly.
In the networking domain, a “new line” must be represented by a fixed byte sequence (0x0D 0x0A). Protocol defines it regardless which type of OS/application is generating/consuming messages across network. The RFC-2822 requires CR LF.
However, a “new line” in files is OS-dependent due to a historical reason. Here is a pitfall.
Mac wants a new line to be a single LF (0x0A). Therefore any text editors on Mac translate 0x0D 0x0A into 0x0a.
Linux want the same as Mac.
Windows wants (perhaps) a new line to be 2 bytes of CRLF. Text editors translates 0x0A into 0x0D 0x0A.
Also, Git has an optional feature that, on Windows, it translates all CR LF (new line in Windows style) in files into LF (Unix style) when you commit changes into git repository.
I found an interesting article about the history of CR+LF vs LF:
There is a twist in Java also. The following code:
System.out.println("\n");
This line writes a 0x0A on Mac, but it will (though I haven’t tested it) writes “0x0D 0x0A” on Windows. Java checks the type of OS where it is currently working on, and switches the binary representation of “\n”.
If you save a new line in Email message into a file, it will have either of 0x0D 0x0A or 0x0A depending on which OS, on with which application you saved the message into the file. Therefore the content of the file may not be valid as a Email message as RFC-2822 specifies.
Short advice to @Dave_Evers
You shouldn’t make *.eml files at all.
You should not serialzie raw bytes of an Email message into a local file to consume later.
You should use some proven software (such as Java Mail API) to parse Email messages on the fly into informational pieces. Your application queries the message body, save it into file, and just use it. Your application should not try to parse the Email message (=headers + CRLF + body).
You should not try to create/edit Email messages as file using text editors.