Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Load MIME from BinData

See more MIME Examples

Demonstrates the Chilkat Mime.LoadMimeBd method, which parses complete MIME bytes from a BinData and replaces the current MIME. The only argument is the BinData.

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: This is the safest loader because it works on raw bytes: MIME can carry 8-bit content and even embedded NUL bytes that a text string would mangle, so loading from a BinData preserves the message exactly. Prefer it whenever the input is binary or of uncertain encoding — a downloaded message, a file read as bytes — over the string-based loaders.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.BinData,
  Chilkat.Mime;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  bd: TBinData;
  mime: TMime;

begin
  success := False;

  //  Demonstrates the Mime.LoadMimeBd method, which parses complete MIME bytes from a BinData and
  //  replaces the current MIME.  The only argument is the BinData.  This is the preferred loader
  //  when the MIME may contain arbitrary 8-bit or embedded NUL bytes.

  bd := TBinData.Create;
  success := bd.LoadFile('qa_data/message.eml');
  if (success = False) then
    begin
      WriteLn(bd.LastErrorText);
      Exit;
    end;

  mime := TMime.Create;
  success := mime.LoadMimeBd(bd);
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  WriteLn('Content-Type: ' + mime.ContentType);


  bd.Free;
  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.