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.

Allowing RSS Access on a Private MediaWiki

I run two Private MediaWiki which do not allow unauthenticated users to create accounts, edit pages, or read pages. I have whitelisted a few special pages including the login page. An example configuration is displayed below.

$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['*']['read'] = false;
$wgGroupPermissions['*']['edit'] = false;
$wgWhitelistRead = array (
    "Special:Userlogin",
    "MediaWiki:Common.css",
    "MediaWiki:Common.js",
    "MediaWiki:Monobook.css",
    "MediaWiki:Monobook.js",
    "-"
    );

The problem with this is that I want to be able to monitor these private wikis in my RSS client. Therefore, I added another two lines to the configuration to allow my desktop unauthenticated access to the recent changes RSS feed on my wikis. This could be changed to make it easy to punch a hole for multiple clients. The additions are shown below.

if ($_SERVER['REMOTE_ADDR'] == "192.168.1.42")
    $wgWhitelistRead[] = "Special:RecentChanges";

Now I can monitor both of my private wikis from my RSS client on my desktop computer. However, all other machines will still require authentication to get to the wiki.

(Even More) Advanced Bash Completion

In my previous post, I described how to set up tab completion for many common commands using these Bash completion files. This works well for established commands, but it doesn’t work so well for commands that I have written myself.

I use a command called “hc12-console” to connect to 68HC12 microcontrollers over a serial port. The command takes two arguments: the name of a microcontroller to connect to and a file to load. I only have two microcontrollers called “dragon1” and “dragon2”. Therefore, I want to be able to tab complete the first argument to one of those values only. The second argument should be the name of a file that ends in “.load”.

I do this with a function that checks the argument number and then completes it based on a specified list or by limiting the types of files that will be listed.

_hc12console ()
{
	local cur

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}

	# First argument completes with either dragon1 or dragon2
	if [[ $COMP_CWORD -eq 1 ]] ; then
		COMPREPLY=( $( compgen -W "dragon1 dragon2" -- $cur ) )
		return 0
	fi

	# Second argument completes with only files matching *.load
	if [[ $COMP_CWORD -eq 2 ]] ; then
		COMPREPLY=( $( compgen -f -X '!*.load' -- $cur ) )
		return 0
	fi

	# All other arguments will not auto-complete
	return 0
}
complete -F _hc12console hc12-console

I added the script above to a file that my bashrc sources. It associates the function with the shell command, and then instead of manually typing out:

hc12-console dragon1 file.load <enter>

I can type:

hc12<tab> <tab>1 <tab> <enter>

Run a Shell Command in a Makefile

I had a directory of BMP image files that I wanted to convert to EPS (Encapsulated PostScript). Since I was planning on adding files to the directory, I did not want to hard code the names of the files into the makefile that would do the conversion. Therefore, the trick was to run a shell command inside of the makefile. The first line lists all of the BMP files and assigns it to “BMP_FILES”. The next line replaces the “bmp” extension with “eps”. The complete makefile is below.

BMP_FILES = $(shell ls *.bmp)
EPS_FILES = ${BMP_FILES:%.bmp=%.eps}

all: ${EPS_FILES}

%.eps : %.bmp
	convert $*.bmp $*.eps

All that is left is to type “make” in the directory, and all of the BMP files will be converted to EPS.

ZigVersion

I prefer to do all of my Subversion work from the command line, but I realize that not all people are like me. Clarissa and I have been using a wiki to keep track of most of our shared information (including our wedding preparations), but our wiki does not work well for content like spreadsheets. Therefore, I decided to try out a Subversion repository. After some initial searching for graphical clients, I found ZigVersion. It is a simple graphical Subversion client for Mac OS X. It took a little bit to explain how it worked and how to use it to Clarissa, but now we have been sharing and editing non-wiki-friendly files for a few weeks.

Extract Email Attachments With Procmail and Munpack

I regularly use the Marquette University PrintWise Canon copiers to scan paper documents into PDF files. These files are delivered to me via email where I manually save each PDF attachment, rename it, and move it to the appropriate directory. Using Procmail and Munpack, I was able to eliminate some of the tedium of this problem.

I inserted the following block of code into my .procmailrc file. It looks for emails that were sent from me and to me by a Canon copier. When it finds one, it copes the email and pipes it to Munpack which extracts the attachments into my attachments directory.

ATTACH=`echo $HOME/attachments`
:0 c
* ^To:.*[email protected]
* ^From:.*[email protected]
* ^X-Mailer: Canon imageRUNNER
| munpack -q -C $ATTACH

After the attachment has been extracted, I can rename it and move it to the appropriate directory, and I still receive the email in my inbox so I know I have attachments to deal with.

iTunes Web Application Search Results

My iTunes Web Application project shows up on the first page of results for most relevant search. More than 60 people clicked on search results for it on Google in September 2009. I would say this is a good thing. However, I doubt it is what most people are actually looking for. I really do recommend Subsonic or even Sockso over my own project. Unless someone is looking to continue work on my project. I would recommend that, too.

PDF to PNG Conversion on Mac OS X

I had a several page scanned document stored in PDF format that I needed to convert to PNG so I could upload it to a PayPal account to resolve a limited access problem. I found several solutions for Linux that produced inadequate image files. When I switched to my Mac OS X laptop, I opened the PDF in Preview. I selected “Save As…” from the File menu, selected “PNG” from the drop down menu and set the resolution to 300 pixels per inch. I hit the Save button, and the newly created PNG opened up. The quality was adequate, and the problem was solved.

Time Warner Internet in my Studio Apartment

I moved into my apartment just over a week ago. Time Warner came out and set up my Internet in my studio apartment this morning. The process was pretty smooth. However, it would appear that my unit had the only unmarked line in the box in the basement. The cable disaster made finding the line quite the challenge.

Time Warner Cable Box

Once the technician found the correct line, the rest was easy, and the speeds are what I expected.

Time Warner Speakeasy Speet Test

Time Warner Speedtest.net

Since I just need Internet for one more semester, hopefully, I won’t have any problems.

eBooks on BlackBerry

Up until recently, I have read most of my novels and books on a Palm TX handheld using TextDrive. I used PorDiBle to convert text files into PDB files that TextDrive could read.

This method worked much better when I always carried my Palm handheld with me and used it as my primary calendar and contact management device. The appeal of electronic books is that I always have it with me. Once I started using my BlackBerry to maintain everything, my Palm fell into disuse, and I no longer carried it with me. I started reading less. I needed a new solution.

I have started using Mobipocket on my BlackBerry and Stanza to convert texts. Mobipocket has a whole online store for purchasing texts, but the reader itself is free and can read non-purchased texts that I already have. Stanza can convert between plain text and the Mobipocket format. Unfortunately, Stanza is only available for Mac OS X and Windows. There are other options, but Stanza worked best.

Now I once again always carry the device with my current novel, and I can spend my free time reading instead of playing games on my BlackBerry.