limap/test.lua

72 lines
2.1 KiB
Lua

local OP_DEBUG = 0x1
local OP_READONLY = 0x2
local OP_ANONYMOUS = 0x4 --/* anonymous open of newsgroup */
local OP_SHORTCACHE = 0x8 --/* short (elt-only) caching */
local OP_SILENT = 0x10 --/* don't pass up events (internal use) */
local OP_PROTOTYPE = 0x20 --/* return driver prototype */
local OP_HALFOPEN = 0x40 --/* half-open (IMAP connect but no select) */
local OP_EXPUNGE= 0x80 --/* silently expunge recycle stream */
local imap = require("limap")
local passwd = os.getenv("IMAP_PWD") or ""
local url = string.format("{iohub.dev:143/imap/tls-sslv23/novalidate-cert/user=mrsang;%s}",passwd);
local handle, box = imap.open(url,OP_HALFOPEN|OP_DEBUG)
local r,v = false,nil;
function dump(obj)
if(type(obj) == "table") then
for k,v in pairs(obj) do
print(k)
dump(v)
end
else
print("[",obj,"]")
end
end
if(handle) then
print("mailbox openned")
local boxes = imap.get_mail_boxes(handle, box:gsub("[^}]*$",""),"*")
for k, v in ipairs(boxes) do
print("=================")
for k1, v1 in pairs(v) do
print(k1,v1)
end
end
r, box = imap.reopen(handle,box:gsub("[^}]*$","INBOX"), OP_DEBUG)
if r then
print("new box opened", box)
else
print("reopen failed")
end
r,v = imap.ping(handle)
if r then
print("Alive", v)
else
print("Unable to ping")
end
imap.check(handle);
-- get nmail
local nmail = imap.get_nmail(handle);
print("umber of mail", nmail);
if nmail > 0 then
local headers = imap.get_headers(handle)
dump(headers)
end
print("===============================")
local header = imap.get_header(handle, nmail-3)
dump(header)
print("===============================")
local raw_body = imap.get_raw_body(handle, nmail-3, true) -- peak the message without set it to seen
print(raw_body)
print("===============================")
local structure = imap.get_structure(handle, nmail-3)
dump(structure)
imap.close(handle)
end