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 markup = require("lain.util.markup")
11 local run_in_terminal = require("lain.helpers").run_in_terminal
13 local awful = require("awful")
14 local beautiful = require("beautiful")
15 local wibox = require("wibox")
18 local os = { getenv = os.getenv }
20 local string = { len = string.len,
21 match = string.match }
22 local table = { sort = table.sort }
24 local setmetatable = setmetatable
27 -- lain.widgets.maildir
31 local args = args or {}
32 local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
33 local ignore_boxes = args.ignore_boxes or {}
34 local refresh_timeout = args.refresh_timeout or 60
35 local header = args.header or " Mail "
36 local header_color = args.header_color or beautiful.fg_normal or "#FFFFFF"
37 local color_newmail = args.color_newmail or beautiful.fg_focus or "#FFFFFF"
38 local color_nomail = args.color_nomail or beautiful.fg_normal or "#FFFFFF"
39 local app = args.app or "mutt"
40 local shadow = args.shadow or false
42 local mymailcheck = wibox.widget.textbox()
43 local mymailcheckupdate = function()
44 -- Find pathes to mailboxes.
45 local p = io.popen("find " .. mailpath ..
46 " -mindepth 1 -maxdepth 1 -type d" ..
54 -- Find all files in the "new" subdirectory. For each
55 -- file, print a single character (no newline). Don't
56 -- match files that begin with a dot.
57 -- Afterwards the length of this string is the number of
58 -- new mails in that box.
59 local np = io.popen("find " .. line ..
60 "/new -mindepth 1 -type f " ..
61 "-not -name '.*' -printf a")
62 local mailstring = np:read("*all")
64 -- Strip off leading mailpath.
65 local box = string.match(line, mailpath .. "/*([^/]+)")
66 local nummails = string.len(mailstring)
78 for box, number in pairs(boxes)
81 -- Add this box only if it's not to be ignored.
82 if not util.element_in_table(box, ignore_boxes)
86 newmail = box .. "(" .. number .. ")"
88 newmail = newmail .. ", " ..
89 box .. "(" .. number .. ")"
95 -- it will be only executed once
96 for box, number in pairs(boxes)
97 do -- it's useless to show only INBOX(x)
98 if box == "INBOX" then newmail = number end
106 mymailcheck:set_text('')
108 myimapcheck:set_markup(markup(color_nomail, " no mail "))
111 myimapcheck:set_markup(markup(header_color, header) ..
112 markup(color_newmail, newmail) .. " ")
116 local mymailchecktimer = timer({ timeout = refresh_timeout })
117 mymailchecktimer:connect_signal("timeout", mymailcheckupdate)
118 mymailchecktimer:start()
119 mymailcheck:buttons(awful.util.table.join(
129 return setmetatable(maildir, { __call = function(_, ...) return worker(...) end })