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") local url = "{iohub.dev:993/imap/ssl/novalidate-cert}" --local url = string.format("{iohub.dev:993/imap/ssl/novalidate-cert/user=dany@iohub.dev;%s}",passwd); local handle, box = imap.open(url,"dany@iohub.dev", passwd, true, true) -- half open and debug on local r,v = false,nil; function dump(obj) if(type(obj) == "table") then print("dump", obj, " size: ", #obj) 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 print(box) if r then print("new box opened", box) else print("reopen failed") end v,r = imap.ping(handle) if r then print("Alive", v) else print("Unable to ping") end local mbdata = imap.check(handle) dump(mbdata) -- 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) -- append message to a mail box --if imap.append(handle, box:gsub("[^}]*$","Drafts"), -- "From: dany@iohub.dev\r\n" -- .. "To: xsang.le@gmail.com\r\n" -- .. "Subject: test\r\n" -- .. "\r\n" -- .. "this is a test message, please ignore\r\n") then -- print("Message appended") --else -- print("Error append message") --end -- get body structure print("########## Get body section 1 structure") local bstruct = imap.get_body_struct(handle, nmail,"1" ) dump(bstruct) print("########## fetch overview messages") local ov = imap.get_overview(handle,string.format("1:%d", nmail), false) dump(ov) print("########## fetch mime") local mime = imap.get_mime(handle,nmail,"1", true) -- peak the message without set it to seen dump(mime) --print("########## get quota") --local quota = imap.get_quota(handle,"user.dany") --dump(quota) --print("########## get quota root") --local quota = imap.get_quotaroot(handle,"INBOX") --dump(quota) --print("########## get ACL") --local acl = imap.get_acl(handle,box) --dump(acl) print("#mail subscriber") local sub = imap.get_subscribed(handle, box:gsub("[^}]*$",""), "*") dump(sub) --print("#mailbox scan") --local sub = imap.scan_mailboxes(handle, box:gsub("[^}]*$",""), "*", "Junk") --dump(sub) print("######### ERROR stack") dump(limap_errors) print("Close handle") imap.close(handle) end