I’ve just finshed writing possibly the hackiest(if that’s a word) script I’ve ever written.

I’ve switched to using mutt as my primary mail client and since it’s pretty much a stock mutt setup, it doesn’t particularly like the html emails that the ‘Daily Dilbert’ come as. In order to read the strips with as little effort as possible (always a good thing ;) ), I’ve written this filter. It extracts the url of the image from the email, fetches the image and then replaces the original email with just the image as an attachment (no body).

This is the filter from my .mailfilter (which courier-maildrop uses):

if ( /^Subject: Your Daily Dilbert$/ )
# This increadably hacky script extracts just the picture from the 'daily dibert' email so I can view it through
# my non-html email client (mutt).
# It's in an exception block, so if the hacky script fails the email (hopefully) will still get delivered.
exception {
xfilter "tee $FROMFILE \
| grep 'http://www\.comics\.com/comics/dilbert/archive/images/.*\.gif' \
| sed -e 's#^.*\(http://www\.comics\.com/comics/dilbert/archive/images/.*\.gif\).*$#\1#' > $TEMPFILE \
&& sed -e '/^Subject: Your Daily Dilbert$/d; /^$/Q;' $FROMFILE | tee $FROMFILE > /dev/null \
&& echo 'X-Haxed-For-Piccie-Only: Yes' >> $FROMFILE \
&& curl `cat $TEMPFILE` > /tmp/`cat $TEMPFILE | sed -e 's#^.*/\(.*\.gif\).*$#\1#'` \
&& rm $OUTFILE \
&& mpack -s 'Your Daily Dilbert' -o $OUTFILE /tmp/`cat $TEMPFILE | sed -e 's#^.*/\(.*\.gif\).*$#\1#'` \
&& rm /tmp/`cat $TEMPFILE | sed -e 's#^.*/\(.*\.gif\).*$#\1#'` $TEMPFILE \
to $MAILDIR/.MailingLists/

Note the subject gets deleted, and then re-added when mpack creates the email with attachment. This is because mpack refuses to create mail without a subject, even though I’m adding all the original headers (mainly so I can see spam-assassin’s report) back in later.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>