Delaying Email Delivery Using Procmail and Cron

Because I use Mutt, any mailbox that has new mail tends to get my attention when I check my email. This became particularly annoying because I kept opening my spam mailbox to check a single spam message. Therefore, I decided to come up with a way to delay the delivery of my spam to once per day.

I started by changing my “.procmailrc” to deliver spam messages to a different mailbox that Mutt does not check.

MAIL=`echo $HOME/Mail`
[...]
:H
* ^X-Spam-Status: Yes
$MAIL/delay_spam
[...]

Then I created a new procmailrc file called “spam.procmailrc” that would deliver mail to my checked spam mailbox.

MAIL=`echo $HOME/Mail`

:0
$MAIL/spam

Next, I wrote a short Bash script to use Formail and Procmail to deliver all of the messages in the delayed delivery spam mailbox to the normal spam mailbox.

#! /bin/bash

FORMAIL=/usr/bin/formail
PROCMAIL=/usr/bin/procmail
PROCMAILRC=$HOME/.procmail/spam.procmailrc

MAIL=$HOME/Mail
DELAY=$MAIL/delay_spam
TEMP=$MAIL/.spam
LOCK=$TEMP.lock

# Make sure there is delayed mail and we can get the lock (retry once)
if ( test -s $DELAY && lockfile -r 1 $LOCK 2>/dev/null ); then

    # Add the delayed mail to the temp mailbox and empty the delayed mailbox
    cat $DELAY >> $TEMP && cat /dev/null > $DELAY
    # Process each delayed message
    $FORMAIL -s $PROCMAIL $PROCMAILRC < $TEMP && rm -f $TEMP

    # Delete the lock now that we are done
    rm -f $LOCK
fi

Finally, I set the script to run daily using Cron. Now I am only interrupted by spam when I choose to be instead of every time a new message arrives. I have used the same technique to delay the delivery of emails to unimportant mailing lists so I only read them hourly instead of every time a message arrives.

OWA Sync on Ubuntu

Update: OWA Sync V0.6 (the current version) is not compatible with Exchange 2007. When I set this up, I was connecting to Exchange 2003.

I use OWA Sync to get all of my calendar information onto my Ubuntu desktop. I recently rediscovered the Little Brother’s Database and decided to make my OWA contacts available in Mutt on my Ubuntu desktop, too. (I used lbdb to make my contacts in Apple Address Book available to Mutt when I was still using Mac OS X as my primary operating system.)

The OWA Sync website has a decent explanation of creating a owaSyncrc file. After I created that, I wrote a script that runs as a cron job.

#! /bin/bash

export PATH=$PATH:/usr/local/bin/

/usr/local/bin/owaSync.kit -update

cat $HOME/.owa/Calendar/*.ics > $HOME/.calendar.ics
cat $HOME/.owa/Contacts/*.vcf > $HOME/.contacts.vcf

After a bit of trial and error, I figured out that “/usr/local/bin/” needed to be in the path for the owaSync.kit script to run. After the synchronization is complete, I then concatenate all of the calendar events into a single file and all of the contact cards into a single file. I now have a single calendar file that I can use with PHP iCalendar and a single contacts file that I can use with lbdb. It requires a fairly simple rc file that looks something like this:

METHODS="$METHODS m_vcf m_muttalias"

VCF_FILES="$HOME/.contacts.vcf"
MUTTALIAS_FILES="$HOME/.mutt/aliases"

I add “m_vcf” and “m_muttaliases” to the “METHODS” and then I specify the locations of my OWA contacts and my Mutt aliases. Now when I launch Mutt, I can query for addresses that I downloaded from OWA.

AWStats on Ubuntu Server

Since I am running this blog on my own server, I decided I should probably set up some log parsing. My personal website is hosted by Nearly Free Speech, and they provide AWStats for statistics. Another site I administer is hosted by DreamHost. DreamHost provides Analog web statistics. After playing with both, I decided to use AWStats.

Ubuntu Tutorials has provided a nice tutorial about setting up AWStats on Ubuntu. I configured my sites individually with no default site in the following files:

/etc/awstats/awstats.blog.lundscape.com.conf
/etc/awstats/awstats.claude.zacintosh.com.conf
/etc/awstats/awstats.wiki.lundscape.com.conf

This means that browsing to “http://domain.tld/awstats/awstats.pl” as they suggest won’t work. Instead, I append the site to the end of the string like this: “http://domain.tld/awstats/awstats.pl?config=blog.lundscape.com”.

Also, rather than adding entries to my crontab, I simply added a script to my “/etc/cron.hourly”:

#! /bin/bash

/usr/lib/cgi-bin/awstats.pl -config=blog.lundscape.com \
	-update > /dev/null 2>&1
/usr/lib/cgi-bin/awstats.pl -config=claude.zacintosh.com \
	-update > /dev/null 2>&1
/usr/lib/cgi-bin/awstats.pl -config=wiki.lundscape.com \
	-update > /dev/null 2>&1

This automatically updates my AWStats every hour whether I view my statistics in a web browser or not.