1 --------------------------------------------------------------------------------------------
4 -- Flexible Maildir monitor with configurable alarms and optional launcher for external
5 -- commands. The name "nmaild" stands for "aNy-mail-directories".
7 --------------------------------------------------------------------------------------------
8 --> Meters: %nmaild_new, %nmaild_read, %nmaild_allnew and %nmaild_allread <--
9 --------------------------------------------------------------------------------------------
11 -- If you do not customize default settings, this script detects the environment
12 -- variable "$MAILDIR". If that variable is not set, then ~/Maildir will be used as
13 -- default path. Otherwise, %nmaild_new and %nmaild_read are counters for new and
14 -- read emails into the first maildir found in settings. %nmaild_allnew and
15 -- %nmaild_allread are counters of new and read emails into the other mail directories
18 -- (Example: ~/Maildir/home, ~/Maildir/work, ~/Maildir/forum_lists, ~/Mail/FSCK,
19 -- spam, etc. where ~Maild/home is the main directory, others are counted as all*)
22 -- * If the directory ~/.ion3 does not exist create it and copy cfg_statusbar.lua
23 -- (the file is located somewhere in your /usr/share/ion3 or /usr/local/share/ion3
24 -- or /etc/X11/ion3 depending on ion3 installation). We need that file located on
25 -- our $HOME to edit and override Ion3 system configurations.
27 -- ** The file should look like this:
28 -- template = "[Mail %nmaild_new:%nmaild_all|%nmaild_allnew%nmaild_allread]"
30 -- After you restart ion3 (killall -USR1 ion3) or (session/restart on Ion menu),
31 -- the statusbar will look like this:
33 -- [Mail: 1:1|4:23] where |1:1| is meaning one mail new and one mail read in first dir.
35 -- You can change this script behavior by writting something like this in
38 -----> CONFIGURATION EXAMPLE: ------------------------------------------------------------
40 -- nmaild = { Values not in config will be assumed from defaults
41 -- update_interval = 15*1000, --> Miliseconds (default is 15 seconds)
42 -- check = { --> Put here the list of maildirs to 'check' for.
43 -- "~/Maildir", Please, pay attention to the logical structure.
45 -- "~/Maildir/copies",
48 -- "/xmail/office/susan",
52 -- new = {"critical", 1}, --> Alarms: For new, read, allnew and allread.
53 -- read = {"important", 5}, --------------------------
54 -- allnew = {"critical", 5}, Syntax: mailfilter = {"hint", value},
55 -- allread = {"important", 10},
56 -- exec_on_new = "play ~/mew_wmail.mp3" --> Execute something on new email arrival.
57 -- If you want to deactivate exec_on_new,
58 -- just erase it from settings.
59 -- If you need to specify very complex commands
60 -- the best way is to replace the quotes for
61 -- [[ at start and ]] at the end.
63 -- }, --> Take care, write correct config endings.
66 -- --------------------------
67 -- "hint" means the color of alarm: If you are
68 -- daredevil, edit the file lookcommon_XXX.lua
69 -- (You must have a copy into ~/.ion3 directory)
70 -- to change colors or to add more (xcolors).
71 -- If 'value' reaches (is >= than) the number
72 -- you put here, alarms will be displayed !!.
74 -------------------------------------------------------------------------------------------
76 -- Internal cycles are provided by string.gsub() so, hopefully, we avoid unnecesary
77 -- use of lines and variables. This script will do only four (4) callings, no matters
78 -- the number of maildirs specified in cfg_statusbar.
83 -- Added "exec_on_new" function. You don't need to use it, but it does more fancy the
84 -- script. Now, it can do audio advices, launch your email client or show [g-k-x]message
85 -- when new emails are detected.
88 -- To show the amounts of disk used. If someone finds interesting that addition...
91 -- GPL2 Copyright (C) 2006 Mario GarcĂa H.
92 -- See http://www.gnu.org/licenses/gpl.html to read complete licence)
94 -- T.STAMP: sat nov 18 01:03:50 COT 2006
97 -- <drosophila (at) Nmental (dot) com>
99 ------ DEFAULT CONFIGURATION : -----------------------------------------------------------
102 local last_count
= { new
= 0, allnew
= 0 }
104 update_interval
= 9000,
105 check
= { os
.getenv("MAILDIR") or "~/Maildir" },
106 exec_on_new
= false, --> Use this to play sounds , to execute an
107 new
= { "critical", 1 }, -- email client, etc. on new email arrival.
108 read = { "important", 5 },
109 allnew
= { "critical", 5 },
110 allread
= {"important", 20 }
112 local settings
= table.join(statusd
.get_config("nmaild"), defaults
)
114 ------ SCRIPT : --------------------------------------------------------------------------
116 local function exec_on_new()
117 if settings
.exec_on_new
then
118 os
.execute(settings
.exec_on_new
.." 2>/dev/null &")
123 local get_count
= function(nmaild
, label
)
124 local read_dirs
= io
.popen("du -a " ..nmaild
.. " 2>/dev/null", "r")
125 local count
= read_dirs
:read("*a"); read_dirs
:close()
126 _
, count
= string.gsub(count
, "%d+%.%C+%.%C+", "") --> Simple filter.
128 local hint
= count
>= settings
[label
][2] and settings
[label
][1] or "normal"
129 statusd
.inform("nmaild_" ..label
, tostring(count
))
130 statusd
.inform("nmaild_" ..label
.. "_hint", hint
)
132 if (label
== "new" or label
== "allnew") and (count
> last_count
[label
]) then
133 last_count
[label
] = count
137 if count
== 0 and (label
== "new" or label
== "allnew") then
138 last_count
[label
] = 0
143 local function plan_count()
144 get_count(settings
.check
[1] .."/new", "new"); coroutine
.yield()
145 get_count(settings
.check
[1] .."/cur", "read"); coroutine
.yield()
146 get_count(table.concat(settings
.check
, "/new ", 2) .."/new", "allnew"); coroutine
.yield()
147 get_count(table.concat(settings
.check
, "/cur ", 2) .."/cur", "allread")
151 local function update_nmaild()
152 local threads
= coroutine
.create(plan_count
) --> Trying to avoid read bottlenecks ,>
153 while coroutine
.resume(threads
) do end --> Without threads the timer will die :(
154 nmaild_timer
:set(settings
.update_interval
, update_nmaild
)
157 nmaild_timer
= statusd
.create_timer()