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 markup = require("lain.util.markup")
10 local helpers = require("lain.helpers")
12 local awful = require("awful")
13 local beautiful = require("beautiful")
14 local naughty = require("naughty")
15 local wibox = require("wibox")
18 local tonumber = tonumber
21 local setmetatable = setmetatable
28 local args = args or {}
30 local server = args.server
31 local mail = args.mail
32 local password = args.password
34 local port = args.port or "993"
35 local refresh_timeout = args.refresh_timeout or 60
36 local header = args.header or " Mail "
37 local header_color = args.header_color or beautiful.fg_normal or "#FFFFFF"
38 local color_newmail = args.color_newmail or beautiful.fg_focus or "#FFFFFF"
39 local color_nomail = args.color_nomail or beautiful.fg_normal or "#FFFFFF"
40 local mail_encoding = args.mail_encoding or nil
41 local maxlen = args.maxlen or 200
42 local app = args.app or "mutt"
43 local is_plain = args.is_plain or false
44 local shadow = args.shadow or false
46 helpers.set_map(mail, true)
47 helpers.set_map(mail .. " count", "0")
49 local checkmail = helpers.scripts_dir .. "checkmail"
53 local f = io.popen(password)
54 password = f:read("*all"):gsub("\n", ""):gsub("\r", "")
58 local myimapcheck = wibox.widget.textbox()
60 local myimapcheckupdate = function()
64 myimapcheck:set_text('')
66 myimapcheck:set_markup(markup(color_nomail, " no mail "))
70 conn = io.popen("ip link show")
71 check_conn = conn:read("*all")
74 if not check_conn:find("state UP") then
79 to_execute = checkmail .. ' -s ' .. server ..
80 ' -u ' .. mail .. ' -p ' .. password
83 if mail_encoding ~= nil
85 to_execute = to_execute .. ' --encoding '
89 f = io.popen(to_execute)
93 if ws:find("No new messages") ~= nil
95 helpers.set_map(mail, true)
97 elseif ws:find("CheckMailError: invalid credentials") ~= nil
99 helpers.set_map(mail, true)
100 myimapcheck.set_markup(markup(header_color, header) ..
101 markup(color_newmail, "invalid credentials "))
103 mailcount = ws:match("%d") or "?"
105 if helpers.get_map(mail .. " count") ~= mailcount and mailcount ~= "?"
107 helpers.set_map(mail, true)
108 helpers.set_map(mail .. " count", mailcount)
111 myimapcheck:set_markup(markup(header_color, header) ..
112 markup(color_newmail, mailcount) .. " ")
114 if helpers.get_map(mail)
117 -- May happens sometimes using keyrings or other password fetchers.
118 -- Since this should be automatically fixed in short times, we threat
119 -- this exception delaying the update to the next timeout.
123 elseif tonumber(mailcount) >= 1
125 notify_title = ws:match(mail .. " has %d new message.?")
126 ws = ws:gsub(notify_title, "", 1):gsub("\n", "", 2)
128 ws = ws:gsub("--Content.%S+.-\n", "")
129 ws = ws:gsub("--%d+.-\n", "")
131 if string.len(ws) > maxlen
133 ws = ws:sub(1, maxlen) .. "[...]"
136 notify_title = notify_title:gsub("\n", "")
139 naughty.notify({ title = notify_title,
142 icon = beautiful.lain_mail_notify or
143 helpers.icons_dir .. "mail.png",
145 position = "top_left" })
147 helpers.set_map(mail, false)
152 local myimapchecktimer = timer({ timeout = refresh_timeout })
153 myimapchecktimer:connect_signal("timeout", myimapcheckupdate)
154 myimapchecktimer:start()
155 myimapcheck:buttons(awful.util.table.join(
159 helpers.run_in_terminal(app)
166 return setmetatable(imap, { __call = function(_, ...) return worker(...) end })