PowerBuilder
PowerBuilder
Fetch a Chunk of Messages, Tracking Failures
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchChunk2 method, which downloads a run of messages by sequence number and reports which succeeded and which failed. The arguments are the starting sequence number, the count, a MessageSet that receives the failed IDs, a MessageSet that receives the successfully-fetched IDs, and the EmailBundle. This example fetches the first chunk of messages and reports the success and failure counts.
Background: When bulk-downloading a large mailbox, individual messages can occasionally fail to fetch (a corrupt message on the server, a transient error) without failing the whole operation.
FetchChunk2 is designed for that reality: it returns a partial EmailBundle plus two MessageSet objects so your code can log or retry exactly the messages that did not come through, rather than aborting the entire sync.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
integer li_NumMessages
integer li_Count
oleobject loo_FailedSet
oleobject loo_FetchedSet
oleobject loo_Bundle
li_Success = 0
// Demonstrates the Imap.FetchChunk2 method, which downloads a run of messages by sequence
// number and reports which succeeded and which failed. The 1st argument is the starting
// sequence number, the 2nd is the count, the 3rd receives the failed IDs, the 4th receives
// the successfully-fetched IDs, and the 5th is the EmailBundle.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_NumMessages = loo_Imap.SelectMailbox("Inbox")
if li_NumMessages < 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Fetch messages 1..25 (or fewer if the mailbox is smaller).
li_Count = 25
if li_Count > li_NumMessages then
li_Count = li_NumMessages
end if
loo_FailedSet = create oleobject
li_rc = loo_FailedSet.ConnectToNewObject("Chilkat.MessageSet")
loo_FetchedSet = create oleobject
li_rc = loo_FetchedSet.ConnectToNewObject("Chilkat.MessageSet")
loo_Bundle = create oleobject
li_rc = loo_Bundle.ConnectToNewObject("Chilkat.EmailBundle")
li_Success = loo_Imap.FetchChunk2(1,li_Count,loo_FailedSet,loo_FetchedSet,loo_Bundle)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_FailedSet
destroy loo_FetchedSet
destroy loo_Bundle
return
end if
Write-Debug "Fetched: " + string(loo_FetchedSet.Count)
Write-Debug "Failed: " + string(loo_FailedSet.Count)
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_FailedSet
destroy loo_FetchedSet
destroy loo_Bundle
return
end if
destroy loo_Imap
destroy loo_FailedSet
destroy loo_FetchedSet
destroy loo_Bundle