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 naughty = require("naughty")
11 local wibox = require("wibox")
12 local string = { format = string.format,
14 local tonumber = tonumber
15 local setmetatable = setmetatable
20 local function worker(args)
21 local imap = helpers.make_widget_textbox()
22 local args = args or {}
23 local server = args.server
24 local mail = args.mail
25 local password = args.password
26 local port = args.port or 993
27 local timeout = args.timeout or 60
28 local is_plain = args.is_plain or false
29 local followtag = args.followtag or false
30 local settings = args.settings or function() end
32 local head_command = "curl --connect-timeout 3 -fsm 3"
33 local request = "-X 'SEARCH (UNSEEN)'"
35 if not server or not mail or not password then return end
37 helpers.set_map(mail, 0)
40 helpers.async(password, function(f) password = f:gsub("\n", "") end)
44 mail_notification_preset = {
45 icon = helpers.icons_dir .. "mail.png",
50 mail_notification_preset.screen = awful.screen.focused()
53 curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
54 head_command, server, port, mail, password, request)
56 helpers.async(curl, function(f)
57 _, mailcount = string.gsub(f, "%d+", "")
63 if mailcount >= 1 and mailcount > helpers.get_map(mail) then
64 if mailcount == 1 then
65 nt = mail .. " has one new message"
67 nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
69 naughty.notify({ preset = mail_notification_preset, text = nt })
72 helpers.set_map(mail, mailcount)
77 imap.timer = helpers.newtimer(mail, timeout, update, true, true)
82 return setmetatable({}, { __call = function(_, ...) return worker(...) end })