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
21 local maildir = helpers.make_widget_textbox()
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 function maildir.update()
32 if cmd then helpers.async({ awful.util.shell, "-c", cmd }, function() end) end
34 -- Find pathes to mailboxes.
35 local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath))
40 -- Find all files in the "new" subdirectory. For each
41 -- file, print a single character (no newline). Don't
42 -- match files that begin with a dot.
43 -- Afterwards the length of this string is the number of
44 -- new mails in that box.
45 local mailstring = helpers.read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line))
47 -- Strip off leading mailpath.
48 local box = string.match(line, mailpath .. "/(.*)")
49 local nummails = #mailstring
58 local newmail = "no mail"
61 for box, number in helpers.spairs(boxes) do
62 -- Add this box only if it's not to be ignored.
63 if not helpers.element_in_table(box, ignore_boxes) then
64 total = total + number
65 if newmail == "no mail" then
66 newmail = string.format("%s(%s)", box, number)
68 newmail = string.format("%s, %s(%s)", newmail, box, number)
73 widget = maildir.widget
77 maildir.timer = helpers.newtimer(mailpath, timeout, maildir.update, true, true)
82 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })