All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
9 local helpers = require("lain.helpers")
10 local shell = require("awful.util").shell
11 local naughty = require("naughty")
12 local wibox = require("wibox")
13 local string = { format = string.format,
15 local tonumber = tonumber
16 local setmetatable = setmetatable
21 local function worker(args )
22 local imap = helpers.make_widget_textbox()
23 local args = args or {}
24 local server = args.server
25 local mail = args.mail
26 local password = args.password
27 local port = args.port or 993
28 local timeout = args.timeout or 60
29 local is_plain = args.is_plain or false
30 local followtag = args.followtag or false
31 local settings = args.settings or function() end
33 local head_command = "curl --connect-timeout 3 -fsm 3"
34 local request = "-X 'SEARCH (UNSEEN)'"
36 helpers.set_map(mail, 0)
39 helpers.async(string.format("%s -s '%s'", shell, password), function(f)
40 password = f:gsub("\n", "")
45 mail_notification_preset = {
46 icon = helpers.icons_dir .. "mail.png",
51 mail_notification_preset.screen = awful.screen.focused()
54 curl = string.format("%s -c '%s --url imaps://%s:%s/INBOX -u %s:%q %s -k'",
55 shell, head_command, server, port, mail, password, request)
57 helpers.async(curl, function(f)
58 _, mailcount = string.gsub(f, "%d+", "")
64 if mailcount >= 1 and mailcount > helpers.get_map(mail) then
65 if mailcount == 1 then
66 nt = mail .. " has one new message"
68 nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
70 naughty.notify({ preset = mail_notification_preset, text = nt })
73 helpers.set_map(mail, mailcount)
78 helpers.newtimer(mail, timeout, update)
80 return setmetatable(imap, { __index = imap.widget })
83 return setmetatable({}, { __call = function(_, ...) return worker(...) end })