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 io = { popen = io.popen }
15 local tonumber = tonumber
16 local string = { len = string.len,
17 format = string.format }
19 local setmetatable = setmetatable
25 local function worker(args)
26 local args = args or {}
28 local server = args.server
29 local mail = args.mail
30 local password = args.password
32 local port = args.port or "993"
33 local timeout = args.timeout or 60
34 local encoding = args.encoding or nil
35 local maxlen = args.maxlen or 200
36 local is_plain = args.is_plain or false
37 local settings = args.settings or function() end
39 local checkmail = helpers.scripts_dir .. "checkmail"
41 helpers.set_map(mail, true)
42 helpers.set_map(mail .. " count", "0")
48 local f = io.popen(password)
49 password = f:read("*all"):gsub("\n", ""):gsub("\r", "")
51 imap.stored = password
53 password = imap.stored
57 imap.widget = wibox.widget.textbox('')
59 notification_preset = {
60 icon = helpers.icons_dir .. "mail.png",
65 function imap.update()
66 to_execute = string.format("%s -s %s -u %s -p %s --port %s",
67 checkmail, server, mail, password, port)
71 to_execute = string.format("%s --encoding %s",
75 f = io.popen(to_execute)
81 if ws:find("No new messages") ~= nil
83 helpers.set_map(mail, true)
84 elseif ws:find("CheckMailError: invalid credentials") ~= nil
86 helpers.set_map(mail, true)
87 mailcount = "invalid credentials"
89 mailcount = ws:match("%d") or "0"
90 if helpers.get_map(mail .. " count") ~= mailcount and mailcount ~= "0"
92 helpers.set_map(mail, true)
93 helpers.set_map(mail .. " count", mailcount)
100 if helpers.get_map(mail) and tonumber(mailcount) >= 1
102 notify_title = ws:match(mail .. " has %d new message.?")
103 ws = ws:gsub(notify_title, "", 1):gsub("\n", "", 2)
105 -- trying to remove useless infos
106 ws = ws:gsub("--Content.%S+.-\n", "")
107 ws = ws:gsub("--%d+.-\n", "")
109 if string.len(ws) > maxlen
111 ws = ws:sub(1, maxlen) .. "[...]"
114 notify_title = notify_title:gsub("\n", "")
117 preset = notification_preset,
118 title = notify_title,
122 helpers.set_map(mail, false)
126 helpers.newtimer(mail, timeout, imap.update, true)
131 return setmetatable(imap, { __call = function(_, ...) return worker(...) end })