aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-08-29 01:03:31 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-08-29 01:03:31 +0200
commitf8a8696389d93104532396a26ce178bfbfa894ad (patch)
tree15d11e81ab07f5e24efc50dc7ac3dbbc05c8ec03 /contrib
parent1a443cda66be20ac176bd70ade7f14be7bec41b4 (diff)
downloadvicious-legacy-f8a8696389d93104532396a26ce178bfbfa894ad.tar.xz
contrib: imported POP3 widget from Boris
Diffstat (limited to 'contrib')
-rw-r--r--contrib/init.lua1
-rw-r--r--contrib/pop.lua52
2 files changed, 53 insertions, 0 deletions
diff --git a/contrib/init.lua b/contrib/init.lua
index 8df46b5..e0f681a 100644
--- a/contrib/init.lua
+++ b/contrib/init.lua
@@ -13,6 +13,7 @@ require("vicious.contrib.mpc")
require("vicious.contrib.netcfg")
require("vicious.contrib.net")
require("vicious.contrib.ossvol")
+require("vicious.contrib.pop")
require("vicious.contrib.pulse")
require("vicious.contrib.rss")
require("vicious.contrib.sensors")
diff --git a/contrib/pop.lua b/contrib/pop.lua
new file mode 100644
index 0000000..7b87eab
--- /dev/null
+++ b/contrib/pop.lua
@@ -0,0 +1,52 @@
+---------------------------------------------------
+-- 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 setmetatable = setmetatable
+local socket = require("socket")
+local tonumber = tonumber
+-- }}}
+
+
+-- POP: provides the count of new messages in a POP3 mailbox
+module("vicious.contrib.pop")
+
+
+-- {{{ POP3 count widget type
+local function worker(format, warg)
+ if not warg or #warg ~= 4 then
+ 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
+-- }}}
+
+setmetatable(_M, { __call = function(_, ...) return worker(...) end })