Sample code for 30+ languages & platforms
Lua

Get an IMAP Mailbox Quota

See more IMAP Examples

Demonstrates the Chilkat Imap.GetQuota method, which sends the IMAP GETQUOTA command for a quota root and returns the server response as JSON. The server must advertise the IMAP QUOTA extension. This example queries the default quota root.

Tip: JSON parsing code for this result can be generated at Chilkat Tools.

Background: Mail servers often cap how much storage an account may use. The IMAP QUOTA extension reports the current usage and limit for a quota root — a scope that may cover one mailbox or a whole account. Reading it lets an application warn a user who is nearing their limit, or refuse to append large messages that would exceed it. Check HasCapability for QUOTA first, since not all servers support it.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the Imap.GetQuota method, which sends the IMAP GETQUOTA command for a quota
-- root and returns the server response as JSON.  The server must advertise the IMAP QUOTA
-- extension.

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

success = imap:login("user@example.com", "myPassword")
if not success then
    print(imap.last_error_text)
    return
end

-- Get the quota for a quota root (an empty string queries the default quota root).
local quotaJson = imap:get_quota("")
if not imap.last_method_success then
    print(imap.last_error_text)
    return
end

print(quotaJson)

-- JSON parsing code for this result can be generated at Chilkat's online tool:
-- https://tools.chilkat.io/jsonParse

success = imap:disconnect()
if not success then
    print(imap.last_error_text)
    return
end