2022-08-26 19:40:12 +02:00
|
|
|
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")
|
2023-01-10 00:34:20 +01:00
|
|
|
local passwd = os.getenv("IMAP_PWD") or "!x$@n9ph"
|
2022-08-26 19:40:12 +02:00
|
|
|
local url = string.format("{iohub.dev:143/imap/tls-sslv23/novalidate-cert/user=mrsang;%s}",passwd);
|
2023-01-10 00:34:20 +01:00
|
|
|
local handle, box = imap.open(url,true, true) -- half open and debug on
|
2022-08-26 19:40:12 +02:00
|
|
|
|
|
|
|
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
|
2023-01-10 00:34:20 +01:00
|
|
|
r, box = imap.reopen(handle,box:gsub("[^}]*$","INBOX"), false, true) -- half open off, debug on
|
2022-08-26 19:40:12 +02:00
|
|
|
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("===============================")
|
2023-01-10 00:34:20 +01:00
|
|
|
local header = imap.get_header(handle, nmail)
|
2022-08-26 19:40:12 +02:00
|
|
|
dump(header)
|
|
|
|
print("===============================")
|
2023-01-10 00:34:20 +01:00
|
|
|
--local raw_body = imap.get_raw_body(handle, nmail, true) -- peak the message without set it to seen
|
|
|
|
--print(raw_body)
|
2022-08-26 19:40:12 +02:00
|
|
|
print("===============================")
|
2023-01-10 00:34:20 +01:00
|
|
|
local structure = imap.get_structure(handle, nmail)
|
2022-08-26 19:40:12 +02:00
|
|
|
dump(structure)
|
|
|
|
|
|
|
|
imap.close(handle)
|
|
|
|
end
|