3 # Redeliver any messages that may have accidentally been sent to
4 # /var/mail/$USER, due to temporary AFS glitches.
6 # This should be called as root on deleuze.
8 # USAGE: redeliver-mail [USER]
10 # If USER is specified, redeliver their mail, regardless of whether
11 # mail redelivery is stopped for all users.
13 BLOCKFILE
=/tmp
/exim
4/inhibit-redelivery
15 # Function to deliver mail for $USER. If the message still can't be
16 # written to $USER/Maildir, Exim will place it in /var/mail/$USER
18 function deliver_mail
() {
22 mv /var
/mail
/$USER $TMPMBOX
23 formail
-s /etc
/exim
4/deliver-once
$USER < $TMPMBOX
29 echo "Incorrect number of arguments"
31 elif [ -n "$1" ]; then
32 # Do redelivery for just one person
35 TMPMBOX
=/tmp
/exim
4/$USER.mbox.tmp
37 if test -f $TMPMBOX; then
38 echo "The temporary file $TMPMBOX still exists."
39 echo "Please wait an hour for it to go away before running this" \
44 if ! test -s $MBOX ||
! test -f $MBOX; then
49 deliver_mail
$USER $TMPMBOX
50 echo Done delivering
mail for $USER
54 # Make sure we didn't get into trouble with an earlier run of this
55 # script. A separate daily cron job should run to check for the
56 # existence of this file.
57 if test -f $BLOCKFILE; then
61 # Run redelivery for everyone
62 for MBOX
in /var
/mail
/*; do
64 USER
=$
(basename $MBOX)
65 TMPMBOX
=/tmp
/exim
4/$USER.mbox.tmp
67 # Sanity check: file exists and has nonzero size
68 if ! test -s $MBOX; then
72 # Sanity check: If TMPMBOX exists and is 20 minutes old or less,
73 # there is some serious trouble, and we should (1) email
74 # postmaster about it and (2) block future processing of /var/mail
75 # until someone removes BLOCKFILE.
77 # If TMPMBOX exists and is older than 20 minutes, it's probably
78 # stale, so blow it away. Note that we will never get to this
79 # point if BLOCKFILE exists, so there is no need to refine the
81 if test -f $TMPMBOX; then
82 if test $
(stat
--format=%Y
$TMPMBOX) -le \
83 $
(date --date='-20 min' +%s
); then
86 echo -e "/var/mail/$USER contains too much email." \
87 "\nBlocking email redelivery script until this is resolved." \
88 "\n\nTo indicate that this is resolved, do the following" \
90 "\n (1) Wait for $TMPMBOX to go away (should take an hour)" \
91 "\n (2) Run '$0 $USER'" \
92 "\n (3) Remove $BLOCKFILE" | \
93 mail -s "[redeliver-mail] Mail backlog too large on deleuze" \
94 -e -a "From: root@deleuze.hcoop.net" \
95 postmaster@deleuze.hcoop.net
102 # Deliver mail. If the message still can't be written to
103 # $USER/Maildir, Exim will place it in /var/mail/$USER again.
104 deliver_mail
$USER $TMPMBOX