Lazarus Pascal
Lazarus Pascal
Delete a Bundle of POP3 Messages
See more POP3 Examples
Demonstrates the Chilkat MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs stored in the X-UIDL headers of the Email objects in an EmailBundle. An email without an X-UIDL header is skipped. This example fetches all messages and deletes them.
Background:
DeleteBundle is the batch version of DeleteEmail: it marks every message in a downloaded bundle for deletion in one call. A typical "download and clear the mailbox" workflow is to fetch all messages, process them, then delete the whole bundle. Because a bundle can be filtered or built selectively, you can also delete just the subset you no longer need. The deletions commit when the POP3 session ends.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.MailMan,
Chilkat.EmailBundle;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
bundle: TEmailBundle;
begin
success := False;
// Demonstrates the MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs
// stored in the X-UIDL headers of the Email objects in an EmailBundle. An email without an
// X-UIDL header is skipped.
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';
// Fetch all messages (headers are enough; each carries an X-UIDL header).
bundle := TEmailBundle.Create;
success := mailman.FetchAll(True,True,0,bundle);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
// Delete every message in the bundle.
success := mailman.DeleteBundle(bundle);
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 ' + bundle.MessageCount + ' messages 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;
bundle.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.