Sample code for 30+ languages & platforms
Tcl

Get the IMAP Server Capabilities

See more IMAP Examples

Demonstrates the Chilkat Imap.Capability method, which sends the IMAP CAPABILITY command and returns the server's raw capability response. This example connects and prints the capability list. Use HasCapability to test for a specific one.

Background: Not all IMAP servers support the same features. The CAPABILITY response is the server's advertised menu — a space-separated list of extensions such as IDLE (push notifications of new mail), MOVE, UIDPLUS, QUOTA, and the supported AUTH= mechanisms. A well-behaved client checks capabilities before relying on an optional feature, falling back gracefully when it is absent.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Imap.Capability method, which sends the IMAP CAPABILITY command and
#  returns the server's raw capability response.

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
}

#  Ask the server for its capability list.
set capabilities [CkImap_capability $imap]
if {[CkImap_get_LastMethodSuccess $imap] == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

puts "Server capabilities: $capabilities"

#  Sample output:
#  
#    Server capabilities: * CAPABILITY IMAP4rev1 LOGIN-REFERRALS ID ENABLE IDLE SASL-IR LITERAL+ AUTH=PLAIN AUTH=LOGIN
#    aaab OK Pre-login capabilities listed, post-login capabilities have more.

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


delete_CkImap $imap