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

MIME Content Part Descriptor Properties

See more MIME Examples

Demonstrates the properties that describe an individual MIME content part: Charset (the charset parameter of Content-Type), Encoding (the Content-Transfer-Encoding), Disposition (the Content-Disposition value), Filename (the filename parameter of Content-Disposition), and Name (the name parameter of Content-Type). Each is set and then read back, and the effect is visible in the serialized MIME header.

Background. These properties operate on the current MIME entity's header fields. Filename and Name are receiver-facing labels, not local filesystem paths, and Charset is meaningful for text parts.

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.Mime;

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

procedure RunDemo;
var
  success: Boolean;
  mime: TMime;
  mimeStr: string;

begin
  success := False;

  mime := TMime.Create;
  success := mime.SetBodyFromPlainText('The quick brown fox.');
  if (success = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;

  //  Charset is the charset parameter of the Content-Type header field (meaningful for text parts).
  mime.Charset := 'utf-8';

  //  Encoding is the Content-Transfer-Encoding for this part.
  mime.Encoding := 'quoted-printable';

  //  Disposition, Filename, and Name describe how a receiver should present the part.
  //  Filename is the filename parameter of Content-Disposition; Name is the name parameter of
  //  Content-Type.  Both are receiver-facing names, not local filesystem paths.
  mime.Disposition := 'attachment';
  mime.Filename := 'note.txt';
  mime.Name := 'note.txt';

  //  Read the descriptors back.
  WriteLn('Charset = ' + mime.Charset);
  WriteLn('Encoding = ' + mime.Encoding);
  WriteLn('Disposition = ' + mime.Disposition);
  WriteLn('Filename = ' + mime.Filename);
  WriteLn('Name = ' + mime.Name);

  //  The descriptors appear in the serialized MIME header.
  mimeStr := mime.GetMime();
  if (mime.LastMethodSuccess = False) then
    begin
      WriteLn(mime.LastErrorText);
      Exit;
    end;
  WriteLn(mimeStr);


  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.