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
13 local read_pipe = require("lain.helpers").read_pipe
14 >>>>>>> upstream/master
16 local wibox = require("wibox")
18 local util = require("lain.util")
20 local io = { popen = io.popen }
21 local os = { getenv = os.getenv }
23 local string = { len = string.len,
24 match = string.match }
25 local table = { sort = table.sort }
27 local setmetatable = setmetatable
30 -- lain.widgets.maildir
33 local function worker(args)
34 local args = args or {}
35 local timeout = args.timeout or 60
36 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
37 local ignore_boxes = args.ignore_boxes or {}
38 local settings = args.settings or function() end
40 maildir.widget = wibox.widget.textbox('')
43 -- Find pathes to mailboxes.
44 local p = io.popen("find " .. mailpath ..
45 " -mindepth 1 -maxdepth 1 -type d" ..
52 -- Find all files in the "new" subdirectory. For each
53 -- file, print a single character (no newline). Don't
54 -- match files that begin with a dot.
55 -- Afterwards the length of this string is the number of
56 -- new mails in that box.
58 local np = io.popen("find " .. line ..
59 "/new -mindepth 1 -type f " ..
60 "-not -name '.*' -printf a")
61 local mailstring = np:read("*a")
63 local mailstring = read_pipe("find " .. line ..
64 "/new -mindepth 1 -type f " ..
65 "-not -name '.*' -printf a")
66 >>>>>>> upstream/master
68 -- Strip off leading mailpath.
69 local box = string.match(line, mailpath .. "/*([^/]+)")
70 local nummails = string.len(mailstring)
82 --Count the total number of mails irrespective of where it was found
88 -- Count the total number of mails irrespective of where it was found
89 >>>>>>> upstream/master
92 for box, number in pairs(boxes)
94 -- Add this box only if it's not to be ignored.
95 if not util.element_in_table(box, ignore_boxes)
97 total = total + number
98 if newmail == "no mail"
100 newmail = box .. "(" .. number .. ")"
102 newmail = newmail .. ", " ..
103 box .. "(" .. number .. ")"
108 widget = maildir.widget
112 newtimer(mailpath, timeout, update, true)
113 return maildir.widget
116 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })