Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.58+

IMAP Get Quota Root

Sends the GETQUOTAROOT command to the IMAP server to get the quota root for a given mailbox. This also provides quota information for the given mailbox.

The GetQuotaRoot method is only available for IMAP servers that support the QUOTA extension.

The information is returned in JSON format. This example demonstrates how to parse the JSON to get the desired information.

Typically, the quota root for the Inbox is the empty string.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local imap = chilkat.Imap.new()

-- Use TLS
imap.ssl = true
imap.port = 993
local success = imap:connect("MY-IMAP-DOMAIN")
if not success then
    print(imap.last_error_text)
    return
end

-- Authenticate
success = imap:login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD")
if not success then
    print(imap.last_error_text)
    return
end

-- First check to see if the IMAP server supports the QUOTA extension.
local caps = imap:capability()
if not imap.last_method_success then
    print(imap.last_error_text)
    return
end

if not imap:has_capability("QUOTA", caps) then
    print("IMAP server does not support the QUOTA extension.")
    return
end

local jsonStr = imap:get_quota_root("Inbox")
if not imap.last_method_success then
    print(imap.last_error_text)
    return
end

-- The JSON string will look something like this:
-- {"QUOTAROOT":{"mailbox":"Inbox","root":""},"QUOTA":{"root":"","resource":"STORAGE","used":22216,"max":15728640}}
print(jsonStr)

-- This is easy to parse...
local json = chilkat.JsonObject.new()
json:load(jsonStr)

-- Get the quota root for Inbox, which is an empty string in the case above.
local quotaRoot = json:string_of("QUOTAROOT.root")
print("Quota Root for Inbox: [" .. quotaRoot .. "]")

-- Now get the resource name (which can be STORAGE or MESSAGE) and the used/max values.
-- Most servers have STORAGE quotas, which are for total capacity.  For example, GMail's
-- STORAGE quota is 15GB (at the time of writing this example).
-- A MESSAGE quota sets a limit on the number of messages.
local resourceName = json:string_of("QUOTA.resource")
local quotaUsed = json:int_of("QUOTA.used")
local quotaMax = json:int_of("QUOTA.max")

print("Resource: " .. resourceName)
print("Quota Used (in KB): " .. quotaUsed)
print("Quota Max (in KB): " .. quotaMax)

-- Disconnect from the IMAP server.
success = imap:disconnect()