Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oImap
LOCAL cCapabilities
LOCAL nHasIdle

nSuccess := 0

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

oImap := CreateObject("Chilkat.Imap")

oImap:Ssl := 1
oImap:Port := 993

nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Get the raw capability response.
cCapabilities := oImap:Capability()
IF (oImap:LastMethodSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Test whether the server supports the IDLE extension.
nHasIdle := oImap:HasCapability("IDLE", cCapabilities)
IF (nHasIdle == 1)
    ? "The server supports IDLE."
ELSE
    ? "The server does not support IDLE."
ENDIF

nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

oImap:destroy()