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 is_plain = args.is_plain or false
28 local followtag = args.followtag or false
29 local notify = args.notify or "on"
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 if type(password) == "string" or type(password) == "table" then
41 helpers.async(password, function(f) password = f:gsub("\n", "") end)
42 elseif type(password) == "function" then
48 mail_notification_preset = {
49 icon = helpers.icons_dir .. "mail.png",
54 mail_notification_preset.screen = awful.screen.focused()
57 curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
58 head_command, server, port, mail, password, request)
60 helpers.async(curl, function(f)
61 mailcount = tonumber(f:match("UNSEEN (%d+)"))
65 if notify == "on" and mailcount >= 1 and mailcount > helpers.get_map(mail) then
66 if mailcount == 1 then
67 nt = mail .. " has one new message"
69 nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
71 naughty.notify { preset = mail_notification_preset, text = nt }
74 helpers.set_map(mail, mailcount)
79 imap.timer = helpers.newtimer(mail, timeout, update, true, true)