Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Unpack HTML Email to Files
Unpacks an HTML email into an HTML file and related files (images and style sheets). The links within the HTML are updated to point to the files unpacked and saved to disk.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.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
unpackDir: string;
partsSubdir: string;
htmlFilename: string;
begin
success := False;
email := TEmail.Create;
success := email.LoadEml('qa_data/eml/happyHour.eml');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
// Is this an HTML email?
if (email.HasHtmlBody() = True) then
begin
// Unpack the HTML to files. The image and css URLs
// in the HTML are modified to point to the files extracted to disk.
unpackDir := 'qa_output/emails';
partsSubdir := 'images';
htmlFilename := 'happyHour.html';
success := email.UnpackHtml(unpackDir,htmlFilename,partsSubdir);
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('Success.');
end;
email.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.