Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Convert 8-bit MIME Parts to Base64
See more MIME Examples
Demonstrates the Chilkat Mime.Convert8Bit method, which recursively converts every part whose Content-Transfer-Encoding is 8bit or binary to base64. It takes no arguments and is a void method.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: The original SMTP standard only guaranteed 7-bit transport, and some legacy servers still reject or mangle raw 8-bit and binary content. Converting those parts to base64 — a 7-bit-safe encoding — makes the whole message safe to relay through such systems without loss. It walks the entire tree, so a multipart message with several offending parts is fixed in one call.
Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Mime;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mime: TMime;
mimeText: string;
begin
success := False;
mime := TMime.Create;
success := mime.LoadMimeFile('qa_data/message.eml');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Recursively convert every part whose Content-Transfer-Encoding is 8bit or binary to base64.
// This makes the MIME safe to transmit over channels that only support 7-bit text (such as some
// legacy SMTP servers).
mime.Convert8Bit();
WriteLn('8bit/binary parts converted to base64.');
mimeText := mime.GetMime();
if (mime.LastMethodSuccess = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn(mimeText);
mime.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.