Sample code for 30+ languages & platforms
VB.NET

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 VB.NET Downloads

VB.NET
Dim success As Boolean = False

'  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.

Dim imap As New Chilkat.Imap

imap.Ssl = True
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = False) Then
    Debug.WriteLine(imap.LastErrorText)
    Exit Sub
End If


'  Get the raw capability response.
Dim capabilities As String = imap.Capability()
If (imap.LastMethodSuccess = False) Then
    Debug.WriteLine(imap.LastErrorText)
    Exit Sub
End If


'  Test whether the server supports the IDLE extension.
Dim hasIdle As Boolean = imap.HasCapability("IDLE",capabilities)
If (hasIdle = True) Then
    Debug.WriteLine("The server supports IDLE.")
Else
    Debug.WriteLine("The server does not support IDLE.")
End If


success = imap.Disconnect()
If (success = False) Then
    Debug.WriteLine(imap.LastErrorText)
    Exit Sub
End If