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)
47 -- Find pathes to mailboxes.
48 local p = io.popen("find " .. mailpath ..
49 " -mindepth 1 -maxdepth 2 -type d" ..
56 -- Find all files in the "new" subdirectory. For each
57 -- file, print a single character (no newline). Don't
58 -- match files that begin with a dot.
59 -- Afterwards the length of this string is the number of
60 -- new mails in that box.
61 local mailstring = read_pipe("find " .. line ..
62 "/new -mindepth 1 -type f " ..
63 "-not -name '.*' -printf a")
65 -- Strip off leading mailpath.
66 local box = string.match(line, mailpath .. "/(.*)")
67 local nummails = string.len(mailstring)
78 -- Count the total number of mails irrespective of where it was found
81 for box, number in spairs(boxes)
83 -- Add this box only if it's not to be ignored.
84 if not util.element_in_table(box, ignore_boxes)
86 total = total + number
87 if newmail == "no mail"
89 newmail = box .. "(" .. number .. ")"
91 newmail = newmail .. ", " ..
92 box .. "(" .. number .. ")"
97 widget = maildir.widget
101 newtimer(mailpath, timeout, update, true)
102 return maildir.widget
105 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })