-- ************************************************************************** -- -- FreePOPs @mail2world.com webmail interface -- -- Released under the GNU/GPL license -- Written by Russell Schwager -- ************************************************************************** -- -- Globals -- PLUGIN_VERSION = "0.0.2b" PLUGIN_NAME = "mail2world.com" PLUGIN_REQUIRE_VERSION = "0.0.97" PLUGIN_LICENSE = "GNU/GPL" PLUGIN_URL = "http://freepops.sourceforge.net/download.php?file=mail2world.lua" PLUGIN_HOMEPAGE = "http://freepops.sourceforge.net/" PLUGIN_AUTHORS_NAMES = {"Russell Schwager"} PLUGIN_AUTHORS_CONTACTS = {"russells (at) despammed (.) com"} --PLUGIN_DOMAINS = {"@mail2world.com", "@mail2.*%.com"} PLUGIN_REGEXES = {"@mail2.*%.com"} PLUGIN_PARAMETERS = { {name="folder", description={ it=[[La cartella che vuoi ispezionare.]], en=[[The folder you want to interact with. Default is Inbox.]]} }, {name = "nossl", description = { en = [[ Parameter is used to force the plugin to not use ssl in its session. Set the value to 1 to enable this feature.]] } }, } PLUGIN_DESCRIPTIONS = { it=[[ Per usare questo plugin dovrete usare il vostro indirizzo email completo come nome utente e la vostra vera password come password.]], en=[[ To use this plugin you have to use your full email address as the username and your real password as the password. For support, please post a question to the forum instead of emailing the author(s).]] } -- ************************************************************************** -- -- Global Strings -- ************************************************************************** -- local globals = { -- Server URL -- strLoginUrl = "://www.mail2world.com/default.asp", -- Login strings -- strLoginPostData = "username=%s&domain=%s&password=%s&rememberme=&faction=login&securebutt=on&submitbut.x=19&submitbut.y=14", strLoginFailed = "Login Failed - Invalid User name and/or password", -- Expressions to pull out of returned HTML from mail2world corresponding to a problem -- strRetGoodLogin = '(
0 and dcnt < 5 then log.dbg("Sending Delete URL: " .. cmdUrl .. "\n") local body, err = browser:post_uri(cmdUrl, post) if not body or err then log.error_print("Unable to delete messages.\n") end end -- Save and then Free up the session -- session.save(hash(), serialize_state(), session.OVERWRITE) session.unlock(hash()) log.dbg("Session saved - Account: " .. internalState.strUser .. "@" .. internalState.strDomain .. "\n") return POPSERVER_ERR_OK end -- Stat command - Get the number of messages and their size -- function stat(pstate) -- Have we done this already? If so, we've saved the results -- if internalState.bStatDone then return POPSERVER_ERR_OK end -- Local variables -- local browser = internalState.browser local nPage = 1 local nMsgs = 0 local nTotPages = 0; local cmdUrl = string.format(globals.strCmdMsgList, internalState.strMailServer, internalState.strGUID, internalState.strMBox); local baseUrl = cmdUrl -- Debug Message -- log.dbg("Stat URL: " .. cmdUrl .. "\n"); -- Initialize our state -- set_popstate_nummesg(pstate, nMsgs) -- Local function to process the list of messages, getting id's and sizes -- local function funcProcess(body) -- Cycle through the items and store the msg id and size. --- for uidl, size in string.gfind(body, globals.strMsgLinePattern) do if not uidl or not size then log.say("Mail2World Module needs to fix it's individual message list pattern matching.\n") return nil, "Unable to parse the size and uidl from the html" end -- Convert the size from it's string (4KB or 2MB) to bytes -- First figure out the unit (KB or just B) -- local _, _, kbUnit = string.find(size, "([Kk])") _, _, size = string.find(size, "([%d]+)[KkMm]") if not kbUnit then size = math.max(tonumber(size), 0) * 1024 * 1024 else size = math.max(tonumber(size), 0) * 1024 end -- Save the information -- nMsgs = nMsgs + 1 log.dbg("Processed STAT - Msg: " .. nMsgs .. ", UIDL: " .. uidl .. ", Size: " .. size) set_popstate_nummesg(pstate, nMsgs) set_mailmessage_size(pstate, nMsgs, size) set_mailmessage_uidl(pstate, nMsgs, uidl) end return true, nil end -- Local Function to check for more pages of messages. If found, the -- change the command url -- local function funcCheckForMorePages(body) -- See if there are messages remaining -- if nPage < nTotPages then nPage = nPage + 1 cmdUrl = baseUrl .. string.format(globals.strCmdMsgListNextPage, nPage) return false end return true end -- Local Function to get the list of messages -- local function funcGetPage() -- Debug Message -- log.dbg("Debug - Getting page: ".. cmdUrl) -- Get the page and check to see if we got results -- local body, err = browser:get_uri(cmdUrl) if body == nil then return body, err end -- Is the session expired -- local _, _, strSessExpr = string.find(body, globals.strRetLoginSessionExpired) if strSessExpr == nil then -- Invalidate the session -- internalState.bLoginDone = nil session.remove(hash()) -- Try Logging back in -- local status = login() if status ~= POPSERVER_ERR_OK then return nil, "Session expired. Unable to recover" end -- Reset the local variables -- browser = internalState.browser cmdUrl = string.format(globals.strCmdMsgList, internalState.strMailServer, internalState.strGUID, internalState.strMBox); if nPage > 1 then cmdUrl = cmdUrl .. string.format(globals.strCmdMsgListNextPage, nPage) end -- Retry to load the page -- return browser:get_uri(cmdUrl) end -- Get the total number of messages -- if nTotPages == 0 then local _, _, strTotPages = string.find(body, globals.strNumPagesPat) if strTotPages ~= nil then nTotPages = tonumber(strTotPages) else nTotPages = 1 end log.dbg("Total Pages in message list: " .. nTotPages) end return body, err end -- Run through the pages and pull out all the message pieces from -- all the message lists -- if not support.do_until(funcGetPage, funcCheckForMorePages, funcProcess) then log.error_print("STAT Failed.\n") session.remove(hash()) return POPSERVER_ERR_NETWORK end -- Update our state -- internalState.bStatDone = true -- Check to see that we completed successfully. If not, return a network -- error. This is the safest way to let the email client now that there is -- a problem but that it shouldn't drop the list of known uidls. if (nPage < nTotPages) then return POPSERVER_ERR_NETWORK end -- Return that we succeeded -- return POPSERVER_ERR_OK end -- Fill msg uidl field -- function uidl(pstate,msg) return common.uidl(pstate, msg) end -- Fill all messages uidl field -- function uidl_all(pstate) return common.uidl_all(pstate) end -- Fill msg size -- function list(pstate,msg) return common.list(pstate, msg) end -- Fill all messages size -- function list_all(pstate) return common.list_all(pstate) end -- Unflag each message marked for deletion -- function rset(pstate) return common.rset(pstate) end -- Mark msg for deletion -- function dele(pstate,msg) return common.dele(pstate, msg) end -- Do nothing -- function noop(pstate) return common.noop(pstate) end -- Retrieve the message -- function retr(pstate, msg, data) downloadMsg(pstate, msg, -2, data) return POPSERVER_ERR_OK end -- Top Command (like retr) -- function top(pstate, msg, nLines, data) downloadMsg(pstate, msg, nLines, data) return POPSERVER_ERR_OK end -- Plugin Initialization - Pretty standard stuff. Copied from the manual -- function init(pstate) -- Let the log know that we have been found -- log.dbg(PLUGIN_NAME .. "(" .. PLUGIN_VERSION ..") found!\n") -- Import the freepops name space allowing for us to use the status messages -- freepops.export(pop3server) -- Load dependencies -- -- Serialization -- require("serial") -- Browser -- require("browser") -- MIME Parser/Generator -- require("mimer") -- Common module -- require("common") -- Run a sanity check -- freepops.set_sanity_checks() -- Let the log know that we have initialized ok -- log.dbg(PLUGIN_NAME .. "(" .. PLUGIN_VERSION ..") initialized!\n") -- Everything loaded ok -- return POPSERVER_ERR_OK end -- EOF -- ************************************************************************** --