[UP] use ion3-plus haha.
[arrow.git] / archlinux_conf / etc / ion3 / old / statusd_maildir.lua
blobdef4f16c096c1f878ff7291c9a56a35d15ecdf77
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>
3 --
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.
8 --
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.
13 --
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
30 statusd_maildir={
31 interval=9000,
32 maildirs = {INBOX="~/Maildir/"},
34 end
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')
40 local count = 0
41 local line = f:read()
42 if line then
43 repeat
44 count = count + 1
45 line = f:read()
46 until not line
47 end
48 f:close()
49 return count
50 end
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
56 end
58 local maildir_timer
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))
66 if new>0 then
67 statusd.inform("maildir_"..key.."_hint", "important")
68 statusd.inform("maildir_"..key.."_new_hint", "important")
69 statusd.inform("maildir_"..key.."_total_hint", "important")
70 else
71 statusd.inform("maildir_"..key.."_hint", "normal")
72 statusd.inform("maildir_"..key.."_new_hint", "normal")
73 statusd.inform("maildir_"..key.."_total_hint", "normal")
74 end
75 end
76 maildir_timer:set(settings.interval, update_maildir)
77 end
79 maildir_timer = statusd.create_timer()
80 update_maildir()