limap/test.lua
2023-01-10 00:34:20 +01:00

72 lines
2.2 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 "!x$@n9ph"
local url = string.format("{iohub.dev:143/imap/tls-sslv23/novalidate-cert/user=mrsang;%s}",passwd);
local handle, box = imap.open(url,true, true) -- half open and debug on
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"), false, true) -- half open off, debug on
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)
dump(header)
print("===============================")
--local raw_body = imap.get_raw_body(handle, nmail, true) -- peak the message without set it to seen
--print(raw_body)
print("===============================")
local structure = imap.get_structure(handle, nmail)
dump(structure)
imap.close(handle)
end