-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckmail
executable file
·45 lines (43 loc) · 1.06 KB
/
checkmail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
count_file=~/.mail/size
count_mailbox() { grep -c -e '^From:' "$1"; }
count_maildir() { find "$1" -type f | wc -l; }
declare -a boxes=($(
make -C ~/.mail list_mailboxes \
| grep ^/ \
| grep -v -e trash -e byme
))
now=$(date +%s)
last=$(stat -c %Y $count_file)
age=$(( now-last ))
if [[ $age -ge ${MAILCHECK:-60} ]]; then
for i in ${boxes[@]}; do
count=0
if [[ -f $i ]]; then count=$(count_mailbox "$i");
elif [[ -d $i ]]; then count=$(count_maildir "$i");
elif [[ ! -e $i ]]; then count=0
fi
echo $count $i
done
fi > $count_file.new
awk '
{
c=$1;
fn=$2;
paths[fn]++;
if (paths[fn]==2) {
if (c > oc[fn]) {
print "You have ", (c-oc[fn]), "new messages in " fn
}
}
oc[fn]=c;
} ' $count_file $count_file.new > ~/.cache/checkmail
if [[ -s $count_file.new ]]; then
mv $count_file.new $count_file; fi
### in cron:
## */1 * * * * /home/jaroslav/bin/checkmail
##
### in profile:
##
## _checkmail() { [[ -s ~/.cache/checkmail ]] && cat ~/.cache/checkmail && truncate -s0 ~/.cache/checkmail; }
## PS1+="${YELLOW}\$(_checkmail && echo \\n)"