Delphi DLL
Delphi DLL
Test for an IMAP Server Capability
See more IMAP Examples
Demonstrates the Chilkat Imap.HasCapability method, which tests whether a named capability appears in a raw capability response. The second argument is typically the string returned by the Capability method. This example checks whether the server supports the IDLE extension.
Background: Rather than scanning the raw
CAPABILITY text yourself, HasCapability parses it for a specific token. This is the right guard before using any optional feature — for example, only entering an IDLE wait loop, or using the MOVE command, when the server actually advertises it. Fetch the capability string once and test it as many times as needed.Chilkat Delphi DLL Downloads
var
success: Boolean;
imap: HCkImap;
capabilities: PWideChar;
hasIdle: Boolean;
begin
success := False;
// Demonstrates the Imap.HasCapability method, which tests whether a named capability appears
// in a raw capability response. The 2nd argument is typically the string returned by the
// Capability method.
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;
// Get the raw capability response.
capabilities := CkImap__capability(imap);
if (CkImap_getLastMethodSuccess(imap) = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// Test whether the server supports the IDLE extension.
hasIdle := CkImap_HasCapability(imap,'IDLE',capabilities);
if (hasIdle = True) then
begin
Memo1.Lines.Add('The server supports IDLE.');
end
else
begin
Memo1.Lines.Add('The server does not support IDLE.');
end;
success := CkImap_Disconnect(imap);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
CkImap_Dispose(imap);