1 -- Authors: Brett Parker <iDunno@sommitrealweird.co.uk>
2 -- License: GPL, version 2 or later
5 -- statusd_maildir.lua - Gets new and total counts of mails in a Maildir structure
6 -- Copyright (c) 2005 Brett Parker <iDunno@sommitrealweird.co.uk>
8 -- This program is free software; you can redistribute it and/or modify
9 -- it under the terms of the GNU General Public License as published by
10 -- the Free Software Foundation; either version 2 of the License, or
11 -- (at your option) any later version.
13 -- This program is distributed in the hope that it will be useful,
14 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
15 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 -- GNU General Public License for more details.
18 -- You should have received a copy of the GNU General Public License
19 -- along with this program; if not, write to the Free Software
20 -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 -- This exports the variables %maildir_MAILDIRNAME, %maildir_MAILDIRNAME_new
23 -- and %maildir_MAILDIRNAME_total to the status bar where MAILDIRNAME is
24 -- the key in the maildirs setting.
26 -- The 2 settings available in the cfg_statusbar.lua are:
27 -- interval - this is the number of milliseconds between each check
28 -- maildirs - this is a key value list of Maildirs, the key is used
29 -- for MAILDIRNAME above.
31 -- The defaults update every 10 seconds with a maildir of ~/Maildir/
33 if not statusd_maildir
then
36 maildirs
= {INBOX
="~/Maildir/"},
40 local settings
= table.join (statusd
.get_config("maildir"), statusd_maildir
)
42 local function get_num_files(directory
)
43 local f
= io
.popen('/bin/ls -U1 '..directory
, 'r')
56 local function get_maildir_counts(maildir
)
57 local newcount
= get_num_files(maildir
..'/new/')
58 local curcount
= get_num_files(maildir
..'/cur/')
59 return newcount
, newcount
+ curcount
64 local function update_maildir()
65 for key
, maildir
in pairs(settings
.maildirs
) do
66 local new
, total
= get_maildir_counts(maildir
)
67 statusd
.inform("maildir_"..key
, new
.."/"..total
)
68 statusd
.inform("maildir_"..key
.."_new", tostring(new
))
69 statusd
.inform("maildir_"..key
.."_total", tostring(total
))
71 statusd
.inform("maildir_"..key
.."_hint", "important")
72 statusd
.inform("maildir_"..key
.."_new_hint", "important")
73 statusd
.inform("maildir_"..key
.."_total_hint", "important")
75 statusd
.inform("maildir_"..key
.."_hint", "normal")
76 statusd
.inform("maildir_"..key
.."_new_hint", "normal")
77 statusd
.inform("maildir_"..key
.."_total_hint", "normal")
80 maildir_timer
:set(settings
.interval
, update_maildir
)
83 maildir_timer
= statusd
.create_timer()