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
6 * (c) 2010-2012, Peter Hofmann
10 local awful = require("awful")
11 local wibox = require("wibox")
12 local helpers = require("lain.helpers")
13 local io = { popen = io.popen }
14 local os = { getenv = os.getenv }
15 local string = { format = string.format,
16 match = string.match }
17 local setmetatable = setmetatable
19 -- Maildir check (synchronous)
20 -- lain.widgets.maildir
23 local function worker(args)
24 local args = args or {}
25 local timeout = args.timeout or 60
26 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
27 local ignore_boxes = args.ignore_boxes or {}
28 local settings = args.settings or function() end
31 maildir.widget = wibox.widget.textbox()
33 function maildir.update()
34 if cmd then helpers.async({ awful.util.shell, "-c", cmd }, function() end) end
36 -- Find pathes to mailboxes.
37 local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath))
42 -- Find all files in the "new" subdirectory. For each
43 -- file, print a single character (no newline). Don't
44 -- match files that begin with a dot.
45 -- Afterwards the length of this string is the number of
46 -- new mails in that box.
47 local mailstring = helpers.read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line))
49 -- Strip off leading mailpath.
50 local box = string.match(line, mailpath .. "/(.*)")
51 local nummails = #mailstring
60 local newmail = "no mail"
63 for box, number in helpers.spairs(boxes) do
64 -- Add this box only if it's not to be ignored.
65 if not helpers.element_in_table(box, ignore_boxes) then
66 total = total + number
67 if newmail == "no mail" then
68 newmail = string.format("%s(%s)", box, number)
70 newmail = string.format("%s, %s(%s)", newmail, box, number)
75 widget = maildir.widget
79 maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true)
84 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })