Delphi DLL
Delphi DLL
Fetch 1st N Headers of Search Results
Calls Search to get a message set, then downloads the 1st N messages in the message set. There are two equivalent ways of doing it: (1) iterate from 0 to N-1 and download each message individually, or (2) create a new message set that contains the 1st N messages and pass it to FetchHeaders. Both are demonstrated here.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Imap, Email, MessageSet;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
imap: HCkImap;
fetchUids: Boolean;
messageSet: HCkMessageSet;
numFound: Integer;
upperBound: Integer;
i: Integer;
bUid: Boolean;
headerOnly: Boolean;
email: HCkEmail;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
imap := CkImap_Create();
// Connect to an IMAP server.
// Use TLS
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;
// Login
success := CkImap_Login(imap,'****','****');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Select an IMAP mailbox
success := CkImap_SelectMailbox(imap,'Inbox');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Get the message IDs of all the emails in the mailbox
// We can choose to fetch UIDs or sequence numbers.
fetchUids := True;
messageSet := CkMessageSet_Create();
success := CkImap_QueryMbx(imap,'ALL',fetchUids,messageSet);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
numFound := CkMessageSet_getCount(messageSet);
if (numFound = 0) then
begin
Memo1.Lines.Add('No messages found.');
Exit;
end;
// Get the 1st 10 messages in messageSet.
upperBound := 10;
if (numFound < upperBound) then
begin
upperBound := numFound;
end;
i := 0;
bUid := CkMessageSet_getHasUids(messageSet);
headerOnly := True;
email := CkEmail_Create();
while i < upperBound do
begin
success := CkImap_FetchEmail(imap,headerOnly,CkMessageSet_GetId(messageSet,i),bUid,email);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
Memo1.Lines.Add(IntToStr(i) + ': ' + CkEmail__subject(email));
i := i + 1;
end;
// Disconnect from the IMAP server.
success := CkImap_Disconnect(imap);
CkImap_Dispose(imap);
CkMessageSet_Dispose(messageSet);
CkEmail_Dispose(email);
end;