PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 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.
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
; Get the raw capability response.
capabilities.s = CkImap::ckCapability(imap)
If CkImap::ckLastMethodSuccess(imap) = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Test whether the server supports the IDLE extension.
hasIdle.i = CkImap::ckHasCapability(imap,"IDLE",capabilities)
If hasIdle = 1
Debug "The server supports IDLE."
Else
Debug "The server does not support IDLE."
EndIf
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
ProcedureReturn
EndProcedure