3 Licensed under GNU General Public License v2
4 * (c) 2014, Samir Benmendil
5 * (c) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
11 local os = { getenv = os.getenv }
13 local string = { len = string.len,
15 format = string.format,
19 -- lain.widgets.maildir
24 local updates=tonumber(conky_parse('${updates}'))
25 if newmail and updates % 30 ~= 0 then
28 local mailpath = os.getenv("HOME") .. "/mail"
30 -- Find pathes to mailboxes.
31 local dirs = io.popen("find " .. mailpath .. " -type d -name new -or -name cur -prune")
33 for line in dirs:lines() do
34 -- Strip off leading mailpath.
35 local acc = string.match(line, mailpath.."/*([^/]+)")
36 local box = string.match(line, mailpath..'/'..acc.."/*([^/]+)")
37 if boxes[acc] == nil then
40 if boxes[acc][box] == nil then
44 -- Find all files in the "new" subdirectory. For each
45 -- file, print a single character (no newline). Don't
46 -- match files that begin with a dot.
47 -- Afterwards the length of this string is the number of
48 -- new mails in that box.
49 if line:sub(-3) == 'new' then
50 local new = io.popen("find " .. line .. " -type f -not -name '.*' -printf a")
51 cnt_new = string.len(new:read("*all"))
54 boxes[acc][box]['cnt_new'] = string.format("${color e6db74}%5d${color}", cnt_new)
56 boxes[acc][box]['cnt_new'] = string.format("%5d", cnt_new)
58 elseif line:sub(-3) == 'cur' then
59 local old = io.popen("find " .. line .. " -type f -not -name '*:2,*S*' -printf a")
60 cnt_old = string.len(old:read("*all"))
63 boxes[acc][box]['cnt_old'] = string.format("${color fd971f}%2d${color}", cnt_old)
65 boxes[acc][box]['cnt_old'] = string.format("%2d", cnt_old)
72 local accounts = {"gmail"}
73 local mailboxes = { {"inbox", "chakra"},
74 {"youtube", "unimaas"}}
75 for a, acc in pairs(accounts) do
76 for b, box in ipairs(mailboxes) do
77 local boxl = boxes[acc][box[1]]
78 local boxr = boxes[acc][box[2]]
79 newmail = newmail .. string.format("%10s:%s/%s", box[1], boxl['cnt_new'], boxl['cnt_old'])
80 newmail = newmail .. string.format("%11s:%s/%s\n", box[2], boxr['cnt_new'], boxr['cnt_old'])
83 newmail = string.sub(newmail, 1 , #newmail - 1)