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 newtimer = require("lain.helpers").newtimer
12 local wibox = require("wibox")
15 local os = { getenv = os.getenv }
17 local string = { len = string.len,
18 match = string.match }
19 local table = { sort = table.sort }
21 local setmetatable = setmetatable
24 -- lain.widgets.maildir
28 local args = args or {}
29 local timeout = args.timeout or 60
30 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
31 local ignore_boxes = args.ignore_boxes or {}
32 local settings = args.settings or function() end
34 widget = wibox.widget.textbox('')
37 -- Find pathes to mailboxes.
38 local p = io.popen("find " .. mailpath ..
39 " -mindepth 1 -maxdepth 1 -type d" ..
46 -- Find all files in the "new" subdirectory. For each
47 -- file, print a single character (no newline). Don't
48 -- match files that begin with a dot.
49 -- Afterwards the length of this string is the number of
50 -- new mails in that box.
51 local np = io.popen("find " .. line ..
52 "/new -mindepth 1 -type f " ..
53 "-not -name '.*' -printf a")
54 local mailstring = np:read("*all")
56 -- Strip off leading mailpath.
57 local box = string.match(line, mailpath .. "/*([^/]+)")
58 local nummails = string.len(mailstring)
71 for box, number in pairs(boxes)
74 -- Add this box only if it's not to be ignored.
75 if not util.element_in_table(box, ignore_boxes)
79 newmail = box .. "(" .. number .. ")"
81 newmail = newmail .. ", " ..
82 box .. "(" .. number .. ")"
90 newtimer(mailpath, timeout, update, true)
95 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })