Some of you may have heard that there is a problem with locking when receiving mails at the WSI. My admins told me, if I don't receive mail on a Sun machine, I risk losing mail or a corrupted mailbox once a year.
If you don't want to risk losing mails, here's a short HOW TO receive mails safely at the WSI.
Create the file ~/.procmailrc with the following
content:
DEFAULT=/afs/informatik.uni-tuebingen.de/home/LOGINNAME/mailspool/Maildir/
Replace LOGINNAME with your login name. Note the trailing slash, it's the important part.
Create the file ~/.forward with the following content:
"|exec /usr/procmail/bin/procmail" Now all your mail goes into single files in
~/mailspool/Maildir/new . No locking problems anymore, as you
can access every mail by opening a single file. The proper locking is
done via AFS.
If you don't delete your emails regularly, or if you don't have a good
email client that can understand the Maildir format of your new
mailbox, than you need to move the mails out of the
~/mailspool/Maildir/new/ folder into some other folder.
I use a script that does this for me. It looks like this:
#!/bin/sh
maildir=$HOME/mailspool/Maildir # where my mails initially arrives
lockfile=${maildir}.lock # lock file for $maildir
procmail_local=$HOME/.procmailrc-local # local procmail script
logfile=$HOME/.Maildir/movemail.log # log file, just in case
shopt -s nullglob # allow null patterns
if [ ! -w $maildir ] ; then
echo "Maildir $maildir not writable. Aborting"
exit 2
fi
trap "rm -f -- ${lockfile}" 1 2 3 13 15 # remove lock if bailing out
lockfile -l 100 ${maildir}.lock
for mail in $maildir/{new,cur}/* ; do
# move mails to my final mail folder (in a save way)
if procmail -m $procmail_local < $mail ; then
rm -f -- $mail
else
if [ ! -e "$logfile" ] ; then
touch $logfile
fi
trap "rm -f -- ${logfile}.lock" 1 2 3 13 15
lockfile -l 100 ${logfile}.lock
echo "movemail: `date +'%F %R'`: Could not deliver $mail." >> movemail.log
rm -f -- ${logfile}.lock
fi
done
rm -f -- ${maildir}.lock
The script uses (yet another) local procmail file called
.procmailrc-local . It looks like this:
MAILDIR=/afs/informatik.uni-tuebingen.de/home/LOGINNAME/.Maildir/incoming/
Again, replace LOGINNAME with your login name and note the trailing slash. If your email client does not understand mailboxes in Maildir format (like Thunderbird), remove the trailing slash.
If you call the script, your mail arrives at ~/.Maildir/incoming without any locking problems.
Calling the script regularly by hand is boring. Thus, I use a crontab entry. Say
crontab -e
on the command line and enter the following line (using vi? Press 'I' to enter something, if finished, press ESC, then ':wq' and return. Don't know why people love this editor):
*/10 * * * * /home/LOGINNAME/PATH-TO-SCRIPT
Replace LOGINNAME with your login name and PATH-TO-SCRIPT with the path to the script printed above.
The crontab entry only works when you are logged in. Otherwise, your
mail will remain in your initial incoming folder in mailspool
. For this, I use a local script that checks if I am logged in
before actually moving my mail:
#!/bin/sh
movemail=/home/LOGINNAME/PATH-TO-SCRIPT
# Maybe call movemail, if LOGINNAME is logged in.
if who | grep LOGINNAME 2>&1 > /dev/null && test -x $movemail ; then
$movemail
fi
My crontab entry actually calls this local script, which in turn calls the script printed above. Again, replace LOGINNAME with your login name and PATH-TO-SCRIPT with the path to the script.
That's it. Too difficult? Tell your administrator to change the default mailbox format from mailbox to Maildir and give you more mail space. And use a mail client that understands Maildir (I use mutt).
Cheers,
Andreas.
This file has been created with Markdown.