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
11 local read_pipe = require("lain.helpers").read_pipe
12 local spairs = require("lain.helpers").spairs
14 local wibox = require("wibox")
16 local util = require("lain.util")
18 local io = { popen = io.popen }
19 local os = { getenv = os.getenv }
21 local string = { len = string.len,
22 match = string.match }
24 local setmetatable = setmetatable
27 -- lain.widgets.maildir
30 local function worker(args)
31 local args = args or {}
32 local timeout = args.timeout or 60
33 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
34 local ignore_boxes = args.ignore_boxes or {}
35 local settings = args.settings or function() end
37 maildir.widget = wibox.widget.textbox('')
40 -- Find pathes to mailboxes.
41 local p = io.popen("find " .. mailpath ..
42 " -mindepth 1 -maxdepth 1 -type d" ..
49 -- Find all files in the "new" subdirectory. For each
50 -- file, print a single character (no newline). Don't
51 -- match files that begin with a dot.
52 -- Afterwards the length of this string is the number of
53 -- new mails in that box.
54 local mailstring = read_pipe("find " .. line ..
55 "/new -mindepth 1 -type f " ..
56 "-not -name '.*' -printf a")
58 -- Strip off leading mailpath.
59 local box = string.match(line, mailpath .. "/*([^/]+)")
60 local nummails = string.len(mailstring)
71 -- Count the total number of mails irrespective of where it was found
74 for box, number in spairs(boxes)
76 -- Add this box only if it's not to be ignored.
77 if not util.element_in_table(box, ignore_boxes)
79 total = total + number
80 if newmail == "no mail"
82 newmail = box .. "(" .. number .. ")"
84 newmail = newmail .. ", " ..
85 box .. "(" .. number .. ")"
90 widget = maildir.widget
94 newtimer(mailpath, timeout, update, true)
98 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })