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