Lazarus Pascal
Lazarus Pascal
Get a MIME Header Field Attribute
See more MIME Examples
Demonstrates the Chilkat Mime.GetHeaderFieldAttribute method, which returns an attribute value parsed from a header field. The first argument is the header field name and the second is the attribute name. Surrounding quotes are removed.
Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.
Background: Many MIME headers pack extra parameters after the main value —
Content-Type: multipart/mixed; boundary="xyz" or Content-Disposition: attachment; filename="report.pdf". This method extracts one of those named attributes directly, saving you from parsing the header string yourself and correctly stripping quotes and handling encoded values.Chilkat Lazarus Pascal 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;
boundary: string;
begin
success := False;
mime := TMime.Create;
success := mime.LoadMimeFile('qa_data/message.eml');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Return an attribute value parsed from a header field. The 1st argument is the header field
// name and the 2nd is the attribute name. For example, the "boundary" attribute of the
// Content-Type header, or the "filename" attribute of Content-Disposition.
boundary := mime.GetHeaderFieldAttribute('Content-Type','boundary');
if (mime.LastMethodSuccess = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Content-Type boundary: ' + boundary);
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.