2010-08-29 01:03:31 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2010, Boris Bolgradov <>
|
|
|
|
--
|
|
|
|
-- This widget type depends on luasocket.
|
|
|
|
--
|
|
|
|
-- Widget arguments are host, port, username and
|
|
|
|
-- password, i.e.:
|
|
|
|
-- {"mail.myhost.com", 110, "John", "132435"}
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local tonumber = tonumber
|
2010-08-29 01:32:24 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local sock_avail, socket = pcall(function()
|
|
|
|
return require("socket")
|
|
|
|
end)
|
2010-08-29 01:03:31 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- POP: provides the count of new messages in a POP3 mailbox
|
2012-06-15 20:48:17 +02:00
|
|
|
-- vicious.contrib.pop
|
2017-01-25 20:12:10 +01:00
|
|
|
local pop_all = {}
|
2010-08-29 01:03:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- {{{ POP3 count widget type
|
|
|
|
local function worker(format, warg)
|
2010-08-29 01:32:24 +02:00
|
|
|
if not sock_avail or (not warg or #warg ~= 4) then
|
2010-08-29 01:03:31 +02:00
|
|
|
return {"N/A"}
|
|
|
|
end
|
|
|
|
|
|
|
|
local host, port = warg[1], tonumber(warg[2])
|
|
|
|
local user, pass = warg[3], warg[4]
|
|
|
|
|
|
|
|
local client = socket.tcp()
|
|
|
|
client:settimeout(3)
|
|
|
|
client:connect(host, port)
|
|
|
|
client:receive("*l")
|
|
|
|
client:send("USER " .. user .. "\r\n")
|
|
|
|
client:receive("*l")
|
|
|
|
client:send("PASS " .. pass .. "\r\n")
|
|
|
|
client:receive("*l")
|
|
|
|
client:send("STAT" .. "\r\n")
|
|
|
|
local response = client:receive("*l")
|
|
|
|
client:close()
|
|
|
|
|
|
|
|
if response:find("%+OK") then
|
|
|
|
response = response:match("%+OK (%d+)")
|
|
|
|
end
|
|
|
|
|
|
|
|
return {response}
|
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2017-01-25 20:12:10 +01:00
|
|
|
return setmetatable(pop_all, { __call = function(_, ...) return worker(...) end })
|