Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 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.

set imap [new_CkImap]

CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993

set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

#  Get the raw capability response.
set capabilities [CkImap_capability $imap]
if {[CkImap_get_LastMethodSuccess $imap] == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

#  Test whether the server supports the IDLE extension.
set hasIdle [CkImap_HasCapability $imap "IDLE" $capabilities]
if {$hasIdle == 1} then {
    puts "The server supports IDLE."
} else {
    puts "The server does not support IDLE."
}

set success [CkImap_Disconnect $imap]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}


delete_CkImap $imap