Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkEmailBundle.pb"
IncludeFile "CkMailMan.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  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.i = CkMailMan::ckCreate()
    If mailman.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Configure the POP3 server connection.
    CkMailMan::setCkMailHost(mailman, "pop.example.com")
    CkMailMan::setCkMailPort(mailman, 995)
    CkMailMan::setCkPopSsl(mailman, 1)
    CkMailMan::setCkPopUsername(mailman, "user@example.com")
    CkMailMan::setCkPopPassword(mailman, "myPassword")

    ;  Fetch all messages (headers are enough; each carries an X-UIDL header).
    bundle.i = CkEmailBundle::ckCreate()
    If bundle.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkMailMan::ckFetchAll(mailman,1,1,0,bundle)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        CkEmailBundle::ckDispose(bundle)
        ProcedureReturn
    EndIf

    ;  Delete every message in the bundle.
    success = CkMailMan::ckDeleteBundle(mailman,bundle)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        CkEmailBundle::ckDispose(bundle)
        ProcedureReturn
    EndIf

    ;  Unless the ImmediateDelete property is set to 1, the messages are only marked for
    ;  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletions.
    success = CkMailMan::ckPop3EndSession(mailman)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        CkEmailBundle::ckDispose(bundle)
        ProcedureReturn
    EndIf

    Debug "Deleted " + Str(CkEmailBundle::ckMessageCount(bundle)) + " 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.


    CkMailMan::ckDispose(mailman)
    CkEmailBundle::ckDispose(bundle)


    ProcedureReturn
EndProcedure