Sample code for 30+ languages & platforms
Xbase++

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

Xbase++
LOCAL nSuccess
LOCAL oImap
LOCAL oBdCmd
LOCAL oBdResp
LOCAL cRespStr

nSuccess := 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.

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

nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Build the raw command.  Do not include an IMAP tag or a trailing CRLF.
oBdCmd := CreateObject("Chilkat.BinData")
oBdCmd:AppendString("CAPABILITY", "utf-8")

oBdResp := CreateObject("Chilkat.BinData")
nSuccess := oImap:RawCommandBd(oBdCmd, oBdResp)
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    oBdCmd:destroy()
    oBdResp:destroy()
    RETURN
ENDIF

//  Interpret the response bytes as a UTF-8 string.
cRespStr := oBdResp:GetString("utf-8")
? cRespStr

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

oImap:destroy()
oBdCmd:destroy()
oBdResp:destroy()