Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Process Large POP3 MailboxDemonstrates how to read email from a mailbox that may contain a large number of emails.
IncludeFile "CkMailMan.pb" IncludeFile "CkEmailBundle.pb" IncludeFile "CkStringArray.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. mailman.i = CkMailMan::ckCreate() If mailman.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkMailMan::setCkMailHost(mailman, "pop.example.com") CkMailMan::setCkPopUsername(mailman, "myLogin") CkMailMan::setCkPopPassword(mailman, "myPassword") CkMailMan::setCkMailPort(mailman, 995) CkMailMan::setCkPopSsl(mailman, 1) ; Get the list of UIDLs for all emails in the mailbox. sa.i = CkMailMan::ckGetUidls(mailman) If CkMailMan::ckLastMethodSuccess(mailman) = 0 Debug CkMailMan::ckLastErrorText(mailman) CkMailMan::ckDispose(mailman) ProcedureReturn EndIf i.i numEmails.i = CkStringArray::ckCount(sa) If numEmails = 0 Debug "Mailbox is empty" CkMailMan::ckDispose(mailman) ProcedureReturn EndIf chunkSize.i = 6 ; Download the emails in chunks of 6 emails each. chunkBeginIdx.i = 0 chunkEndIdx.i = chunkSize - 1 If chunkEndIdx >= numEmails chunkEndIdx = numEmails - 1 EndIf saChunk.i = CkStringArray::ckCreate() If saChunk.i = 0 Debug "Failed to create object." ProcedureReturn EndIf While (chunkBeginIdx < numEmails) Debug Str(chunkBeginIdx) + " to " + Str(chunkEndIdx) ; Build a chunk of UIDLs. CkStringArray::ckClear(saChunk) For i = chunkBeginIdx To chunkEndIdx CkStringArray::ckAppend(saChunk,CkStringArray::ckGetString(sa,i)) Next ; Log the UIDLs in this chunk... chunkStr.s = CkStringArray::ckSaveToText(saChunk) Debug chunkStr ; Download this chunk of email from the POP3 server. bundle.i = CkMailMan::ckFetchMultiple(mailman,saChunk) If CkMailMan::ckLastMethodSuccess(mailman) = 0 Debug CkMailMan::ckLastErrorText(mailman) CkMailMan::ckDispose(mailman) CkStringArray::ckDispose(saChunk) ProcedureReturn EndIf Debug "Downloaded " + Str(CkEmailBundle::ckMessageCount(bundle)) + " emails." Debug "----" ; Process the bundle... ; (your application's processing code goes here...) CkEmailBundle::ckDispose(bundle) ; Get the next chunk... chunkBeginIdx = chunkBeginIdx + chunkSize chunkEndIdx = chunkEndIdx + chunkSize If chunkEndIdx >= numEmails chunkEndIdx = numEmails - 1 EndIf Wend CkStringArray::ckDispose(sa) CkMailMan::ckDispose(mailman) CkStringArray::ckDispose(saChunk) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.