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

Compare Two Emails by UIDL

See more Email Object Examples

Demonstrates the Chilkat Email.UidlEquals method, which returns true if this email's UIDL equals the UIDL of the email passed as the argument. The comparison is meaningful for messages obtained through POP3. This example gives two emails the same UIDL and compares them.

Background: A POP3 UIDL is a stable, unique identifier a server assigns to each message in a mailbox. Comparing UIDLs is how a client decides whether two message references point to the same server message — the basis for "leave messages on server" logic, where an app downloads a message once and skips it on later checks by remembering its UIDL.

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

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

procedure RunDemo;
var
  email1: TEmail;
  email2: TEmail;
  eq: Boolean;

begin
  //  Demonstrates the UidlEquals method, which returns true if this email's UIDL equals the
  //  UIDL of the email passed as the argument.  UIDLs are POP3 message identifiers.

  email1 := TEmail.Create;
  email1.AddHeaderField('X-UIDL','0000000123abcdef');

  email2 := TEmail.Create;
  email2.AddHeaderField('X-UIDL','0000000123abcdef');

  //  Compare the two emails' UIDLs.
  eq := email1.UidlEquals(email2);

  if (eq = True) then
    begin
      WriteLn('The two emails have the same UIDL.');
    end
  else
    begin
      WriteLn('The two emails have different UIDLs.');
    end;


  email1.Free;
  email2.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.