Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- 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.
local imap = chilkat.Imap.new()
imap.ssl = true
imap.port = 993
local success = imap:connect("imap.example.com")
if not success then
print(imap.last_error_text)
return
end
-- Get the raw capability response.
local capabilities = imap:capability()
if not imap.last_method_success then
print(imap.last_error_text)
return
end
-- Test whether the server supports the IDLE extension.
local hasIdle = imap:has_capability("IDLE", capabilities)
if hasIdle then
print("The server supports IDLE.")
else
print("The server does not support IDLE.")
end
success = imap:disconnect()
if not success then
print(imap.last_error_text)
return
end