The RFC-2822 standard specifies a syntax for text messages that are sent between computer users, within the framework of “electronic mail” messages. The RFC-2822 specifies lines should be no longer than 78 characters, and the MIME spec RFC-2045, says:
The encoded output stream must be represented in lines of no more than 76 characters each. All line breaks or other characters not found in Table 1- The Base64 Alphabet must be ignored by decoding software.
procedure TForm55.Button1Click(Sender: TObject); var S: string; begin S := ‘jfdlksjflkasjdlfow7r89fpsduf87s8fy4387rhfofldsajfhasddlsihjsldhjlsdhlfhjsdafhjsadh’; Memo1.Text := TNetEncoding.Base64.EncodeBytesToString(TEncoding.GetEncoding(‘ISO-8859-1’).GetBytes(S)); end;
You will notice that this produces a #13#10 in the middle.
Delphi and/or C++ Builder is automatically wrapping at 76 characters per line (TBase64Encoding.kCharsPerLine.) You can override this in one of the constructors and pass 0: TBase64Encoding.Create(0) where 0 means don’t wrap lines.
Delphi and C++ Builder does this because it’s a net encoding and base64 is used for representing binary in, eg, email; Recalling that the RFC-2822 specifies lines should be no longer than 78 characters and the MIME spec RFC-2045, and it says: “The encoded output stream must be represented in lines of no more than 76 characters each. All line breaks or other characters not found in Table 1- The Base64 Alphabet must be ignored by decoding software.”
We see that Delphi and C++ Builder matches the spec accurately!
This is completely valid. RAD Studio (Delphi and/or C++ Builder) creates 100% valid MIME base64 encoded text!
Compared to this corresponding .NET code, which (unlike Delphi or C++ Builder) does not put anything in the middle:
Embarcadero’s users understand the scalability and stability of C++ and Delphi, and depend on the decades of innovation those languages bring to development. Ninety of the Fortune 100 and an active community of more than three million users worldwide have relied on Embarcadero’s award-winning products over the past 30 years. Icons by Icons8.com.