Автор Тема: Pop3 и Web Mail  (Прочетена 19498 пъти)

DoctorA

  • Напреднали
  • *****
  • Публикации: 106
    • Профил
Pop3 и Web Mail
« Отговор #45 -: Sep 20, 2005, 15:39 »
ето я и новата версия
има само bug fixes
Примерен код

-- ************************************************************************** --
-- FreePOPs @abv.bg webmail interface
--
-- Released under the GNU/GPL license
-- Written by Georgi Saev <georgi_saev@abv.bg>
-- ************************************************************************** --

-- Globals
--
PLUGIN_VERSION = "0.1.3"
PLUGIN_NAME = "abv.bg"
PLUGIN_LICENSE = "GNU/GPL"
PLUGIN_DOMAINS = {"@abv.bg","@gyuvetch.bg","@gbg.bg"}
-- -------------------------------------------------------------------------- --
foo_globals= {  
 debug_level = 0,
 username="nothing",
 hostname="nothing",
 password="nothing",
 session_id="nothing",
 browser="nothing",
 stat_done=false,
 stat_fixed_id="nothing"
}
-- -------------------------------------------------------------------------- --
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
   if foo_globals.debug_level == 1 then
      print("*** the user wants to login as "..foo_globals.username.."@"..foo_globals.hostname.."'");
   end


 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://mail05.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              
              if foo_globals.debug_level == 1 then
             print("*** exiting")
         end
              return POPSERVER_ERR_AUTH
       end
       foo_globals.session_id = id
          if foo_globals.debug_level == 1 then
        print("*** the user has logged in as "..foo_globals.username.."@"..foo_globals.hostname.."")
          end
       return POPSERVER_ERR_OK
end

-- -------------------------------------------------------------------------- --
-- Fill the number of messages and their size
function fix_no_sessid(pstate,add_page_var)
       if foo_globals.debug_level == 1 then
         print("*** WARNING: stat can't get sessid fixing")
         print("*** re-loging in")
       end
   pass(nil,foo_globals.password)
      if foo_globals.debug_level == 1 then
         print("*** is it ok ?")
      end
   local file,err = nil, nil
     local b = foo_globals.browser
     local session_id = foo_globals.session_id
     if foo_globals.debug_level == 1 then
        print("***  foo_globals.session_id= "..foo_globals.session_id.."")
     end
     file,err = b:get_uri("http://mail05.abv.bg/app/j/box.jsp;jsessionid="..session_id.."?fid=10"..add_page_var.."")
     local _,_,id = string.find(file,"jsessionid=(%w+)")
     if id == nil then
        if foo_globals.debug_level == 1 then
       print("*** this is err :")
            print(err)
--     print("*** this is file :")
--     print(file)
            print("*** it's not ok ?")
   end
      return fix_no_sessid()
    else
          if foo_globals.debug_level == 1 then
             print("*** fixed")
          end
     return id,file
 end
end
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
     local j=0
     file,err = b:get_uri("http://mail05.abv.bg/app/j/box.jsp;jsessionid="..session_id.."?fid=10")
     local _,_,id = string.find(file,"jsessionid=(%w+)")
     if id == nil then
             id,file =fix_no_sessid()
     end
     local _,_,num_pages = string.find(file,"Стр. 1 от (%w+)")
     if num_pages == nil then
         num_pages=1
     end
           

     local nummesg = 0
     for tmp = 1,num_pages do
          file,err = b:get_uri("http://mail05.abv.bg/app/j/box.jsp;jsessionid="..session_id.."?fid=10&pid="..tmp.."")
          local _,_,id = string.find(file,"jsessionid=(%w+)")
          if id == nil then
                id,file =fix_no_sessid(pstate,"&pid="..tmp.."")
          end
          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()
          nummesg = nummesg + x:count()

     end
        if foo_globals.debug_level == 1 then
           print("*** "..nummesg.." pisma ob6to r1")
   end
     set_popstate_nummesg(pstate,nummesg)




   for tmp = 1,num_pages do
          file,err = b:get_uri("http://mail05.abv.bg/app/j/box.jsp;jsessionid="..session_id.."?fid=10&pid="..tmp.."")
          local _,_,id = string.find(file,"jsessionid=(%w+)")
          if id == nil then
                id,file =fix_no_sessid()
          end
          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()
          if foo_globals.debug_level == 1 then
              print("*** Getting page "..tmp.." out of "..num_pages.."")
     end

 
      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            
             j=j+1
             set_mailmessage_size(pstate,j,size)
             set_mailmessage_uidl(pstate,j,uidl)
        if foo_globals.debug_level == 1 then   
                print("*** "..i.." pisma so far")
        end
      end
   end


      if foo_globals.debug_level == 1 then
          print("*** "..j.." pisma")
      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://mail05.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
-- --------------------------------------------------------------------------------
--                             END OF FILE
-- --------------------------------------------------------------------------------
Активен

Meesa find yousa's lackin' in faith disturbin'

DoctorA

  • Напреднали
  • *****
  • Публикации: 106
    • Профил
Pop3 и Web Mail
« Отговор #46 -: Sep 21, 2005, 14:34 »
и pls пишете ако има bugs щото аз не го тест-вам тоя plugin
и май само alabal го ползва ( или поне само той ми пише че има bugs )
колкото до предложението на Agent_SMITH
Цитат
Темата съдържа много полезни неща (и много празни приказки, ама нейсе).

Ако автора на темата е съгласен, бих искал да я преместя в секция ПРОГРАМИРАНЕ. Грехота е полезни неща да стоят в "... всякакви други глупости"

не съм автора на темата ама според мен няма да има смисал , щтото сега имам 4 дена почивка и като свърша с домашни и "всякакви други глупости" май ще ми остане време да кача plugin-а и малко инфо за него на някое free и като го кача ще го сложа в раздел MADE IN BG на сайта
Активен

Meesa find yousa's lackin' in faith disturbin'

DoctorA

  • Напреднали
  • *****
  • Публикации: 106
    • Профил
Pop3 и Web Mail
« Отговор #47 -: Sep 25, 2005, 23:14 »
http://openfmi.net/projects/abv-lua/
Активен

Meesa find yousa's lackin' in faith disturbin'

Подобни теми
Заглавие Започната от Отговора Прегледи Последна публикация
POP3 problemi
Настройка на програми
pepino 1 1482 Последна публикация Jul 30, 2004, 18:41
от Agent_SMITH
problem s POP3
Настройка на програми
pepino 2 1118 Последна публикация Aug 11, 2004, 13:09
от vladou
Windows Mail => Linux Mail
Настройка на програми
Shadowfox 2 5746 Последна публикация Feb 08, 2005, 08:58
от
Pop3 проблем
Хардуерни и софтуерни проблеми
west 2 2381 Последна публикация Mar 19, 2006, 19:19
от west
Pop3 поща
Настройка на програми
colomager 8 3806 Последна публикация Apr 09, 2006, 16:47
от Ivv