PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkBinData.pb"
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 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.
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckLogin(imap,"user@example.com","myPassword")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Build the raw command. Do not include an IMAP tag or a trailing CRLF.
bdCmd.i = CkBinData::ckCreate()
If bdCmd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkBinData::ckAppendString(bdCmd,"CAPABILITY","utf-8")
bdResp.i = CkBinData::ckCreate()
If bdResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkImap::ckRawCommandBd(imap,bdCmd,bdResp)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkBinData::ckDispose(bdCmd)
CkBinData::ckDispose(bdResp)
ProcedureReturn
EndIf
; Interpret the response bytes as a UTF-8 string.
respStr.s = CkBinData::ckGetString(bdResp,"utf-8")
Debug respStr
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkBinData::ckDispose(bdCmd)
CkBinData::ckDispose(bdResp)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
CkBinData::ckDispose(bdCmd)
CkBinData::ckDispose(bdResp)
ProcedureReturn
EndProcedure