Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
imap: HCkImap;
numMessages: Integer;
count: Integer;
failedSet: HCkMessageSet;
fetchedSet: HCkMessageSet;
bundle: HCkEmailBundle;
begin
success := False;
// 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.
imap := CkImap_Create();
CkImap_putSsl(imap,True);
CkImap_putPort(imap,993);
success := CkImap_Connect(imap,'imap.example.com');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
success := CkImap_Login(imap,'user@example.com','myPassword');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
numMessages := CkImap_SelectMailbox(imap,'Inbox');
if (numMessages < 0) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Fetch messages 1..25 (or fewer if the mailbox is smaller).
count := 25;
if (count > numMessages) then
begin
count := numMessages;
end;
failedSet := CkMessageSet_Create();
fetchedSet := CkMessageSet_Create();
bundle := CkEmailBundle_Create();
success := CkImap_FetchChunk2(imap,1,count,failedSet,fetchedSet,bundle);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
Memo1.Lines.Add('Fetched: ' + IntToStr(CkMessageSet_getCount(fetchedSet)));
Memo1.Lines.Add('Failed: ' + IntToStr(CkMessageSet_getCount(failedSet)));
success := CkImap_Disconnect(imap);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
CkImap_Dispose(imap);
CkMessageSet_Dispose(failedSet);
CkMessageSet_Dispose(fetchedSet);
CkEmailBundle_Dispose(bundle);