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 = args.color or beautiful.fg_focus or "#FFFFFF"
39 local mail_encoding = args.mail_encoding or nil
40 local maxlen = args.maxlen or 200
41 local app = args.app or "mutt"
42 local is_plain = args.is_plain or false
43 local shadow = args.shadow or false
45 helpers.set_map(mail, true)
46 helpers.set_map(mail .. " count", "0")
48 local checkmail = helpers.scripts_dir .. "checkmail"
52 local f = io.popen(password)
53 password = f:read("*all"):gsub("\n", ""):gsub("\r", "")
57 local myimapcheck = wibox.widget.textbox()
59 local myimapcheckupdate = function()
63 myimapcheck:set_text('')
65 myimapcheck:set_markup(markup(color, " no mail "))
69 conn = io.popen("ip link show")
70 check_conn = conn:read("*all")
73 if not check_conn:find("state UP") then
78 to_execute = checkmail .. ' -s ' .. server ..
79 ' -u ' .. mail .. ' -p ' .. password
82 if mail_encoding ~= nil
84 to_execute = to_execute .. ' --encoding '
88 f = io.popen(to_execute)
92 if ws:find("No new messages") ~= nil
94 helpers.set_map(mail, true)
96 elseif ws:find("CheckMailError: invalid credentials") ~= nil
98 helpers.set_map(mail, true)
99 myimapcheck:set_markup(" " .. markup(header_color, header) ..
100 markup(color, "invalid credentials "))
102 mailcount = ws:match("%d") or "?"
104 if helpers.get_map(mail .. " count") ~= mailcount and mailcount ~= "?"
106 helpers.set_map(mail, true)
107 helpers.set_map(mail .. " count", mailcount)
110 myimapcheck:set_markup(" " .. markup(header_color, header) ..
111 markup(color, mailcount) .. " ")
113 if helpers.get_map(mail)
116 -- May happens sometimes using keyrings or other password fetchers.
117 -- Since this should be automatically fixed in short times, we threat
118 -- this exception delaying the update to the next timeout.
122 elseif tonumber(mailcount) >= 1
124 notify_title = ws:match(mail .. " has %d new message.?")
125 ws = ws:gsub(notify_title, "", 1):gsub("\n", "", 2)
127 ws = ws:gsub("--Content.%S+.-\n", "")
128 ws = ws:gsub("--%d+.-\n", "")
130 if string.len(ws) > maxlen
132 ws = ws:sub(1, maxlen) .. "[...]"
135 notify_title = notify_title:gsub("\n", "")
138 naughty.notify({ title = notify_title,
141 icon = beautiful.lain_mail_notify or
142 helpers.icons_dir .. "mail.png",
144 position = "top_left" })
146 helpers.set_map(mail, false)
151 local myimapchecktimer = timer({ timeout = refresh_timeout })
152 myimapchecktimer:connect_signal("timeout", myimapcheckupdate)
153 myimapchecktimer:start()
154 myimapcheck:buttons(awful.util.table.join(
158 helpers.run_in_terminal(app)
165 return setmetatable(imap, { __call = function(_, ...) return worker(...) end })