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.
3 Licensed under GNU General Public License v2
4 * (c) 2013, Luke Bonham
5 * (c) 2010-2012, Peter Hofmann
9 local newtimer = require("lain.helpers").newtimer
11 local wibox = require("wibox")
14 local os = { getenv = os.getenv }
16 local string = { len = string.len,
17 match = string.match }
18 local table = { sort = table.sort }
20 local setmetatable = setmetatable
23 -- lain.widgets.maildir
26 local function worker(args)
27 local args = args or {}
28 local timeout = args.timeout or 60
29 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
30 local ignore_boxes = args.ignore_boxes or {}
31 local settings = args.settings or function() end
33 maildir.widget = wibox.widget.textbox('')
36 -- Find pathes to mailboxes.
37 local p = io.popen("find " .. mailpath ..
38 " -mindepth 1 -maxdepth 1 -type d" ..
45 -- Find all files in the "new" subdirectory. For each
46 -- file, print a single character (no newline). Don't
47 -- match files that begin with a dot.
48 -- Afterwards the length of this string is the number of
49 -- new mails in that box.
50 local np = io.popen("find " .. line ..
51 "/new -mindepth 1 -type f " ..
52 "-not -name '.*' -printf a")
53 local mailstring = np:read("*all")
55 -- Strip off leading mailpath.
56 local box = string.match(line, mailpath .. "/*([^/]+)")
57 local nummails = string.len(mailstring)
70 for box, number in pairs(boxes)
73 -- Add this box only if it's not to be ignored.
74 if not util.element_in_table(box, ignore_boxes)
78 newmail = box .. "(" .. number .. ")"
80 newmail = newmail .. ", " ..
81 box .. "(" .. number .. ")"
86 widget = maildir.widget
90 newtimer(mailpath, timeout, update, true)
94 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })