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 spawn = require("awful").spawn
11 local wibox = require("wibox")
13 local element_in_table = require("lain.helpers").element_in_table
14 local newtimer = require("lain.helpers").newtimer
15 local read_pipe = require("lain.helpers").read_pipe
16 local spairs = require("lain.helpers").spairs
18 local io = { popen = io.popen }
19 local os = { getenv = os.getenv }
21 local string = { format = string.format,
23 match = string.match }
25 local setmetatable = setmetatable
28 -- lain.widgets.maildir
31 local function worker(args)
32 local args = args or {}
33 local timeout = args.timeout or 60
34 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
35 local ignore_boxes = args.ignore_boxes or {}
36 local settings = args.settings or function() end
37 local ext_mail_cmd = args.external_mail_cmd
39 maildir.widget = wibox.widget.textbox('')
42 if ext_mail_cmd then awful.spawn(ext_mail_cmd) end
44 -- Find pathes to mailboxes.
45 local p = io.popen(string.format("find %s -mindepth 1 -maxdepth 2 -type d -not -name .git", mailpath))
50 -- Find all files in the "new" subdirectory. For each
51 -- file, print a single character (no newline). Don't
52 -- match files that begin with a dot.
53 -- Afterwards the length of this string is the number of
54 -- new mails in that box.
55 local mailstring = read_pipe(string.format("find %s /new -mindepth 1 -type f -not -name '.*' -printf a", line))
57 -- Strip off leading mailpath.
58 local box = string.match(line, mailpath .. "/(.*)")
59 local nummails = string.len(mailstring)
68 local newmail = "no mail"
71 for box, number in spairs(boxes) do
72 -- Add this box only if it's not to be ignored.
73 if not util.element_in_table(box, ignore_boxes) then
74 total = total + number
75 if newmail == "no mail" then
76 newmail = string.format("%s(%s)", box, number)
78 newmail = string.format("%s, %s(%s)", newmail, box, number)
83 widget = maildir.widget
88 newtimer(mailpath, timeout, update, true)
90 return setmetatable(maildir, { __index = maildir.widget })
93 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })