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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/usr/local/bin/bash
#
# $Id: xbiff-checkcommand-maildir,v 1.1 2004/06/19 11:50:37 suter Exp $
# Copyright (C) 2004 Mark Suter <suter@humbug.org.au>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# This will allow you to continue using xbiff(1) after you changed from
# mbox to maildir for your email. From the manpage:
#
# checkCommand (class CheckCommand)
# Specifies a shell command to be executed to check for new
# mail rather than examining the size of file. The specified
# string value is used as the argument to a system(3) call and
# may therefore contain i/o redirection. An exit status of 0
# indicates that new mail is waiting, 1 indicates that there has
# been no change in size, and 2 indicates that the mail has been
# cleared. By default, no shell command is provided.
#
# Here's an example usage from my ~/.Xresources:
#
# xbiff*checkCommand: /home/suter/bin/xbiff-checkcommand-maildir /home/suter/mail/In/inbox/
# xbiff*update: 45
#
## Our "die" function (think perl)
die () { echo "$@" 1>&2 ; exit 3 ; }
## Check for our needed binaries
hash test basename cat find wc touch || die $0: required binaries not present
## We expect one arguemnt, the maildir directory
maildir="$1"
test -n "$maildir" || die Usage: $(basename $0) maildir
test -d $maildir || die $0: Thing \"$maildir\" is not a directory.
test -d $maildir/new || die $0: Directory \"$maildir\" does not have a new subdir.
## We need to keep state
count=${TMPDIR:-/tmp}/.xbiff-checkcommand-maildir.count
state=${TMPDIR:-/tmp}/.xbiff-checkcommand-maildir.state
## Read the stored count (zero on error)
old=$(cat $count 2>/dev/null)
test -n "$old" || old=0
## Get current count of emails newer than our state file
if test -e $state ; then
new=$(find $maildir/new/ -type f -newer $state -print | wc -l)
else
new=$(find $maildir/new/ -type f -print | wc -l)
fi
## Write the count for next time
echo $new > $count || die $0: error writing state
## Exit correctly (according the man page above)
test $new -eq 0 -a $old -ne 0 && touch $state && exit 2 # new emails cleared
test $old -ge $new && exit 1 # no new arrivals since last check
test $old -lt $new && exit 0 # more new emails than last check
## Catch fallthough
die $0: should never be reached
|