Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Delete a Set of POP3 Messages by UIDL
See more POP3 Examples
Demonstrates the Chilkat MailMan.DeleteUidlSet method, which marks the POP3 messages whose UIDLs are listed in a StringTable for deletion. Chilkat processes the UIDL set and sends a DELE command for each located message. This example deletes two messages by UIDL.
Background: When you already know exactly which messages to remove — by their stable UIDLs —
DeleteUidlSet deletes them all in one call without first downloading them. It is the efficient counterpart to fetching-then-deleting: for example, after processing messages elsewhere, hand back just their UIDLs to clear them. The deletions are committed when the POP3 session ends (unless ImmediateDelete is set).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.MailMan,
Chilkat.StringTable;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
uidls: TStringTable;
begin
success := False;
// Demonstrates the MailMan.DeleteUidlSet method, which marks the POP3 messages whose UIDLs
// are listed in a StringTable for deletion. Chilkat sends DELE for each located message.
mailman := TMailMan.Create;
// Configure the POP3 server connection.
mailman.MailHost := 'pop.example.com';
mailman.MailPort := 995;
mailman.PopSsl := True;
mailman.PopUsername := 'user@example.com';
mailman.PopPassword := 'myPassword';
// Build the set of UIDLs to delete.
uidls := TStringTable.Create;
uidls.Append('0000000123abcdef');
uidls.Append('0000000124abcdef');
// Mark the messages for deletion.
success := mailman.DeleteUidlSet(uidls);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
// Unless the ImmediateDelete property is set to True, the messages are only marked for
// deletion. End the POP3 session (which sends the QUIT command) to commit the deletions.
success := mailman.Pop3EndSession();
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
WriteLn('Deleted the UIDL set from the POP3 server.');
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
mailman.Free;
uidls.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.