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 awful = require("awful")
17 local util = require("lain.util")
19 local io = { popen = io.popen }
20 local os = { getenv = os.getenv }
22 local string = { len = string.len,
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 ~= nil
44 awful.util.spawn(ext_mail_cmd)
46 -- Find pathes to mailboxes.
47 local p = io.popen("find " .. mailpath ..
48 " -mindepth 1 -maxdepth 2 -type d" ..
55 -- Find all files in the "new" subdirectory. For each
56 -- file, print a single character (no newline). Don't
57 -- match files that begin with a dot.
58 -- Afterwards the length of this string is the number of
59 -- new mails in that box.
60 local mailstring = read_pipe("find " .. line ..
61 "/new -mindepth 1 -type f " ..
62 "-not -name '.*' -printf a")
64 -- Strip off leading mailpath.
65 local box = string.match(line, mailpath .. "/(.*)")
66 local nummails = string.len(mailstring)
77 -- Count the total number of mails irrespective of where it was found
80 for box, number in spairs(boxes)
82 -- Add this box only if it's not to be ignored.
83 if not util.element_in_table(box, ignore_boxes)
85 total = total + number
86 if newmail == "no mail"
88 newmail = box .. "(" .. number .. ")"
90 newmail = newmail .. ", " ..
91 box .. "(" .. number .. ")"
96 widget = maildir.widget
100 newtimer(mailpath, timeout, update, true)
101 return maildir.widget
104 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })