Sample code for 30+ languages & platforms
Tcl

Send a Raw IMAP Command (Binary)

See more IMAP Examples

Demonstrates the Chilkat Imap.RawCommandBd method, which sends raw IMAP command bytes and receives the raw response bytes. The first argument is a BinData holding the command — without an IMAP tag or trailing CRLF, which Chilkat supplies — and the second is a BinData that receives the response.

Background: This is an escape hatch for rare server extensions the API does not otherwise expose. It is intended for commands with a single-line response that do not change Imap object state such as the selected mailbox or message count. For everyday operations, use the dedicated methods, which parse responses and maintain object state for you.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Imap.RawCommandBd method, which sends raw IMAP command bytes and receives
#  the raw response bytes.  The 1st argument is a BinData containing the command (without a tag
#  or trailing CRLF -- Chilkat supplies both), and the 2nd is a BinData that receives the
#  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
}

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

#  Build the raw command.  Do not include an IMAP tag or a trailing CRLF.
set bdCmd [new_CkBinData]

CkBinData_AppendString $bdCmd "CAPABILITY" "utf-8"

set bdResp [new_CkBinData]

set success [CkImap_RawCommandBd $imap $bdCmd $bdResp]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    delete_CkBinData $bdCmd
    delete_CkBinData $bdResp
    exit
}

#  Interpret the response bytes as a UTF-8 string.
set respStr [CkBinData_getString $bdResp "utf-8"]
puts "$respStr"

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


delete_CkImap $imap
delete_CkBinData $bdCmd
delete_CkBinData $bdResp