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")
11 local naughty = require("naughty")
12 local wibox = require("wibox")
14 local string = { format = string.format,
16 local tonumber = tonumber
18 local setmetatable = setmetatable
23 local function worker(args)
25 local args = args or {}
27 local server = args.server
28 local mail = args.mail
29 local password = args.password
31 local port = args.port or 993
32 local timeout = args.timeout or 60
33 local is_plain = args.is_plain or false
34 local followtag = args.followtag or false
35 local settings = args.settings or function() end
37 local head_command = "curl --connect-timeout 3 -fsm 3"
38 local request = "-X 'SEARCH (UNSEEN)'"
40 helpers.set_map(mail, 0)
43 password = helpers.read_pipe(password):gsub("\n", "")
46 imap.widget = wibox.widget.textbox('')
49 mail_notification_preset = {
50 icon = helpers.icons_dir .. "mail.png",
55 mail_notification_preset.screen = awful.screen.focused()
58 curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
59 head_command, server, port, mail, password, request)
61 helpers.async(curl, function(f)
62 _, mailcount = string.gsub(f, "%d+", "")
67 if mailcount >= 1 and mailcount > helpers.get_map(mail) then
68 if mailcount == 1 then
69 nt = mail .. " has one new message"
71 nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
73 naughty.notify({ preset = mail_notification_preset, text = nt })
76 helpers.set_map(mail, mailcount)
81 helpers.newtimer(mail, timeout, update, true)
83 return setmetatable(imap, { __index = imap.widget })
86 return setmetatable({}, { __call = function(_, ...) return worker(...) end })