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.
3 Licensed under GNU General Public License v2
8 local helpers = require("lain.helpers")
9 local naughty = require("naughty")
10 local wibox = require("wibox")
11 local awful = require("awful")
14 local tonumber = tonumber
19 local function factory(args)
20 local imap = { widget = wibox.widget.textbox() }
21 local args = args or {}
22 local server = args.server
23 local mail = args.mail
24 local password = args.password
25 local port = args.port or 993
26 local timeout = args.timeout or 60
27 local pwdtimeout = args.pwdtimeout or 10
28 local is_plain = args.is_plain or false
29 local followtag = args.followtag or false
30 local notify = args.notify or "on"
31 local settings = args.settings or function() end
33 local head_command = "curl --connect-timeout 3 -fsm 3"
34 local request = "-X 'STATUS INBOX (MESSAGES RECENT UNSEEN)'"
36 if not server or not mail or not password then return end
38 mail_notification_preset = {
39 icon = helpers.icons_dir .. "mail.png",
43 helpers.set_map(mail, 0)
46 if type(password) == "string" or type(password) == "table" then
47 helpers.async(password, function(f) password = f:gsub("\n", "") end)
48 elseif type(password) == "function" then
49 imap.pwdtimer = helpers.newtimer(mail .. "-password", pwdtimeout, function()
50 local retrieved_password, try_again = password()
52 imap.pwdtimer:stop() -- stop trying to retrieve
53 password = retrieved_password or "" -- failsafe
59 function imap.update()
60 -- do not update if the password has not been retrieved yet
61 if type(password) ~= "string" then return end
63 local curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:'%s' %s -k",
64 head_command, server, port, mail, password, request)
66 helpers.async(curl, function(f)
67 imap_now = { ["MESSAGES"] = 0, ["RECENT"] = 0, ["UNSEEN"] = 0 }
69 for s,d in f:gmatch("(%w+)%s+(%d+)") do imap_now[s] = tonumber(d) end
70 mailcount = imap_now["UNSEEN"] -- backwards compatibility
75 if notify == "on" and mailcount and mailcount >= 1 and mailcount > helpers.get_map(mail) then
76 if followtag then mail_notification_preset.screen = awful.screen.focused() end
78 preset = mail_notification_preset,
79 text = string.format("%s has <b>%d</b> new message%s", mail, mailcount, mailcount == 1 and "" or "s")
83 helpers.set_map(mail, imap_now["UNSEEN"])
88 imap.timer = helpers.newtimer(mail, timeout, imap.update, true, true)