Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Repair MIME Formatting Problems in an Email
See more Email Object Examples
Demonstrates the Chilkat Email.ApplyFixups method, which repairs selected MIME-formatting problems commonly found in email produced by other software. The argument is a comma-separated list of fixup keywords. The currently defined keyword is FixRelated, which relocates HTML-related items (such as embedded images) into the appropriate MIME structure so they are not incorrectly presented as ordinary attachments. This example loads an email and applies that fixup.
Background: Not every mail program builds strictly correct MIME. A common defect is placing an inline image as a loose attachment instead of nesting it in a
multipart/related enclosure, which makes it show up as a downloadable file rather than displaying in the HTML. ApplyFixups corrects such structural issues so the message renders as intended.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;
begin
success := False;
// Demonstrates the ApplyFixups method, which repairs selected MIME-formatting problems
// commonly found in email produced by other software. The argument is a comma-separated
// list of fixup keywords.
email := TEmail.Create;
success := email.LoadEml('qa_data/eml/message.eml');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
// Apply the "FixRelated" fixup, which relocates HTML-related items (such as embedded
// images) into the proper MIME structure so they are not shown as ordinary attachments.
success := email.ApplyFixups('FixRelated');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('Applied MIME fixups.');
// Note: The path "qa_data/..." is a relative local filesystem path,
// relative to the current working directory of the running application.
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.