Sample code for 30+ languages & platforms
Lianja

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 Lianja Downloads

Lianja
llSuccess = .F.

//  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.

loImap = createobject("CkImap")

loImap.Ssl = .T.
loImap.Port = 993

llSuccess = loImap.Connect("imap.example.com")
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

//  Get the raw capability response.
lcCapabilities = loImap.Capability()
if (loImap.LastMethodSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif

//  Test whether the server supports the IDLE extension.
llHasIdle = loImap.HasCapability("IDLE",lcCapabilities)
if (llHasIdle = .T.) then
    ? "The server supports IDLE."
else
    ? "The server does not support IDLE."
endif

llSuccess = loImap.Disconnect()
if (llSuccess = .F.) then
    ? loImap.LastErrorText
    release loImap
    return
endif



release loImap