doctora@DoctorA:/usr/share/freepops/lua$ cat abv.lua -- ************************************************************************** -- -- FreePOPs @abv.bg webmail interface -- -- Released under the GNU/GPL license -- Written by Georgi Saev <georgi_saev@abv.bg> -- ************************************************************************** --
-- Globals -- PLUGIN_VERSION = "0.1b" PLUGIN_NAME = "abv.bg" PLUGIN_LICENSE = "GNU/GPL" PLUGIN_DOMAINS = {"@abv.bg","@gyuvetch.bg","@gbg.bg"} -- -------------------------------------------------------------------------- -- foo_globals= {
username="nothing", hostname="nothing", password="nothing", session_id="nothing", browser="nothing", stat_done=false } -- -------------------------------------------------------------------------- -- function init(pstate) freepops.export(pop3server) log.dbg("FreePOPs plugin '".. PLUGIN_NAME.."' version '"..PLUGIN_VERSION.."' started!\n")
-- the serialization module if freepops.dofile("serialize.lua") == nil then return POPSERVER_ERR_UNKNOWN end -- the browser module if freepops.dofile("browser.lua") == nil then return POPSERVER_ERR_UNKNOWN end -- the common module if freepops.dofile("common.lua") == nil then return POPSERVER_ERR_UNKNOWN end -- checks on globals freepops.set_sanity_checks() return POPSERVER_ERR_OK end --
-- -------------------------------------------------------------------------- -- -- Must save the mailbox name
function user(pstate,username1) local at = string.find(username1, "@") local username = string.sub(username1,0,at-1) local hostname = string.sub(username1,at+1) foo_globals.username = username foo_globals.hostname = hostname print("*** the user wants to login as "..foo_globals.username.."@"..foo_globals.hostname.."'") return POPSERVER_ERR_OK end -- -------------------------------------------------------------------------- -- -- Must login
function pass(pstate,password) foo_globals.password = password -- create a new browser local b = browser.new() -- store the browser object in globals foo_globals.browser = b -- create the data to post local post_data = string.format("username=%s&password=%s&hostname=%s",foo_globals.username,foo_globals.password,foo_globals.hostname) -- the uri to post to local post_uri = "http://mail08.abv.bg/app/servlet/bg.abv.mail.Login" -- post it local file,err = nil, nil file,err = b:post_uri(post_uri,post_data) -- search the session ID local _,_,id = string.find(file,"jsessionid=(%w+)") if id == nil then print("*** exiting") return POPSERVER_ERR_AUTH end foo_globals.session_id = id print("*** the user has logged in as "..foo_globals.username.."@"..foo_globals.hostname.."")
return POPSERVER_ERR_OK end
-- -------------------------------------------------------------------------- -- -- Fill the number of messages and their size
function stat(pstate) if foo_globals.stat_done == true then return POPSERVER_ERR_OK end local file,err = nil, nil local b = foo_globals.browser local session_id = foo_globals.session_id file,err = b:get_uri("http://mail08.abv.bg/app/j/box.jsp;jsessionid="..session_id.."?fid=10") local e = ".*<tr>.*<td>.*<input>.*</td>.*<td>.*<img>.*</td>.*<td>[.*]{img}.*</td>.*<td>[.*]{img}.*</td>.*<td>[.*]{img}.*</td>.*<td>.*<a>.*</a>.*</td>.*<td>[.*]{a}[.*]{/a}.*</td>.*<td>.*</td>.*<td>.*</td>.*</tr>" local g = "O<O>O<O>O<X>O<O>O<O>O<O>O<O>O<O>[O]{O}O<O>O<O>[O]{O}O<O>O<O>[O]{O}O<O>O<O>O<O>O<O>O<O>O<O>[O]{O}[O]{O}O<O>O<O>O<O>O<O>X<O>O<O>" local x = mlex.match(file,e,g) --debug print x:print() set_popstate_nummesg(pstate,x:count()) for i=1,x:count() do local _,_,size = string.find(x:get(1,i-1),"(%d+)") local _,_,size_mult_k = string.find(x:get(1,i-1),"([Kk][Bb])") local _,_,size_mult_m = string.find(x:get(1,i-1),"([Mm][Bb])") local _,_,uidl = string.find(x:get(0,i-1),"value=\"(%d+)\"") if size_mult_k ~= nil then size = size * 1024 end if size_mult_m ~= nil then size = size * 1024 * 1024 end set_mailmessage_size(pstate,i,size) set_mailmessage_uidl(pstate,i,uidl) end foo_globals.stat_done = true 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 --------------------------------------------------------------------------------
-- The callback factory for retr -- function retr_cb(data) local a = stringhack.new() return function(s,len) s = a:dothack(s).."\0" popserver_callback(s,data) return len,nil end end -- -------------------------------------------------------------------------- -- -- Get message msg, must call -- popserver_callback to send the data function retr(pstate,msg,pdata) local data=pdata -- we need the stat local st = stat(pstate) if st ~= POPSERVER_ERR_OK then return st end -- the callback local cb = retr_cb(data) -- some local stuff local session_id = foo_globals.session_id local b = foo_globals.browser local uri ="http://mail08.abv.bg/app/servlet/bg.abv.mail.GetData;jsessionid="..session_id.."?fid=10&mid="..get_mailmessage_uidl(pstate,msg).."&nid=0&eid=-1&charset=Cp1251&ac=d" -- tell the browser to pipe the uri using cb local f,rc = b:pipe_uri(uri,cb) if not f then log.error_print("Asking for "..uri.."\n") log.error_print(rc.."\n") return POPSERVER_ERR_NETWORK end return POPSERVER_ERR_OK end
-- -------------------------------------------------------------------------- -- -- Must quit without updating
function quit(pstate) return POPSERVER_ERR_OK end
|