redeliver-mail: new script to redeliver all mail in /var/mail
[clinton/scripts.git] / redeliver-mail
diff --git a/redeliver-mail b/redeliver-mail
new file mode 100755 (executable)
index 0000000..0d68870
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Redeliver any messages that may have accidentally been sent to
+# /var/mail/$USER, due to temporary AFS glitches.
+#
+# This should be called as root on deleuze.
+
+for MBOX in /var/mail/*; do
+
+    USER=$(basename $MBOX)
+    TMPMBOX=/tmp/exim4/$USER.mbox.tmp
+
+    # Sanity check: file exists and has nonzero size
+    if ! test -s $MBOX; then
+        continue
+    fi
+
+    # Deliver mail.  If the message still can't be written to
+    # $USER/Maildir, Exim will place it in /var/mail/$USER again.
+    mv /var/mail/$USER $TMPMBOX
+    formail -s /etc/exim4/deliver-once $USER < $TMPMBOX
+    rm -f $TMPMBOX
+done