IMAP + procmail

For increased security and reliability, we no longer allow procmail to run on our mail server directly. However, you can still filter your email using procmail, though it requires a few extra steps. The system described here uses the fetchmail utility to download your mail from our mail server and hand it off to procmail on the local machine for further processing. A periodic cron job can be set up to watch the fetchmail process and restart it if necessary. You may also want to look into using IMAP directly and filtering your mail with sieve.

You must first configure your account to accumulate mail on our IMAP server. This is the default configuration for Computer Science accounts now, but if you have had an account for a long time, you may need to reconfigure. Verify that you can access newly delivered mail by configuring an IMAP client.

Once you are sure that mail sent to your CS account ends up on our IMAP server, you are ready to configure the "client" end of the system (that is, fetchmail and procmail). You can set this system up on any of our Linux machines that you have access to, but note that machines may go down due to hardware failure or for maintenance. We recommend that you use classes.cs.uchicago.edu for this sort of activity, as it is located in a secure machine room, is plugged into a UPS, and goes down less frequently than many other machines. Log on to the machine you have chosen; all further configuration will be done on this machine.

Now, create your procmail configuration. Warning: be sure that any directories referenced in your procmail rules exist, as procmail will not create them for you. If some directories do not exist, procmail may deliver mail to strange locations, such as in the top of your home directory. Start simple and add complicated rules only after you are sure that the entire system works from end to end. Remember, this is your email, and small configuration errors can result in mail being lost.

fetchmail needs your password to be able to retrieve your mail from our IMAP server. You need to create a fetchmailrc file that contains this information. You can run the following commands to do so (you can simply cut and paste the code without modification):

mkdir -p /var/tmp/$LOGNAME
chmod 700 /var/tmp/$LOGNAME
touch /var/tmp/$LOGNAME/.fetchmailrc
chmod 600 /var/tmp/$LOGNAME/.fetchmailrc
cat >>/var/tmp/$LOGNAME/.fetchmailrc <<EOF
poll laime.cs.uchicago.edu protocol IMAP user $LOGNAME password "yourpass"
EOF

Then edit /var/tmp/$LOGNAME/.fetchmailrc and replace the string yourpass with your actual CS Unix password. No files that contain sensitive passwords should exist in your home directory, as your home directory is exported via NFS (and thus passed unencrypted across the CS network). That is why the file is created in /var/tmp. If this file is deleted, fetchmail may not be able to retrieve your mail. The chmod commands restrict read access to this file to yourself.

After you have your procmail configuration and fetchmailrc in place, run /opt/techstaff/bin/imap2procmail. This is a shell script wrapper around fetchmail. Feel free to copy it to your home directory, modify it, and use your modified version. If you use that script without modification, fetchmail will check your mail every five minutes. Please don't configure fetchmail to check more frequently, as our mail server is heavily loaded.

If you want fetchmail to be restarted automatically if it crashes (or the machine is rebooted) you can install a cron job to watch and restart it if necessary. We have crafted such a job for you; run /opt/techstaff/bin/install_watch_imap2procmail to install it. If you decide you don't want to use this service in the future, and you don't know how to disable cron jobs, email techstaff@cs.uchicago.edu and we will disable it for you.

By default, this system leaves mail on the IMAP server as a failsafe in case you make mistakes with procmail. This means that at some point your IMAP store will reach its quota. You will be warned by email before your IMAP account is very full. At that point you can use an IMAP client to log in and delete this redundant mail (email techstaff@cs.uchicago.edu if you need help with this). You can also configure fetchmail to delete messages after they have been fetched (relevant fetchmail options are are --keep and --all), but be careful if you choose to go this route. It is easy to make mistakes and lose mail when using these tools.

This system can be extended to gather mail from any number of POP or IMAP sources and process it with your CS procmail configuration. Consult the fetchmail manual for details.