[H-GEN] procmail fun (was archiving old e-mail)

Sean Burford slide at tellurian.com.au
Mon Jan 17 23:26:36 EST 2000


[ Humbug *General* list - semi-serious discussions about Humbug and ]
[ Unix-related topics.  Please observe the list's charter.          ]

> I recently got the idea of sorting out and archiving my collection of old
> e-mail accumulated over the last 3 years, and this weekend, I took it on,
> and came up with a solution using formail, procmail and hypermail, and
> gave me nice indexed HTML mail archives.

I love procmail, my procmailrc is rather large :)  A tip (or two):

I have an NT box on my desk, but I know when I get mail because of the 
following rule.  It uses smbclient to send me a winpopup if I receive 
mail that doesn't fall into other catagories:
  # General mail
  :0 Hc:sorted/mbox.lock
  sorted/mbox
  :0 A
  | ( echo "New mail on Slide" ; echo ; /usr/bin/formail -X date -X from -X 
  subject ) | /usr/local/samba/bin/smbclient -N -U "Slide:MBox" -W tellurian 
  -M hilarious

I found a utility on freshmeat called 'grepmail' which greps mailbox 
files.  I use it to archive old messages using the following script.  It 
is run from cron on the 10th of the month, and archives all mail from 
before the first of the month:

#!/bin/sh

export archdir="/home/admin/slide/mail/sorted/archived";
export maildir="/home/admin/slide/mail/sorted";
export filename="`date +%Y%m`";
export basedate="1 `date +%b\ %Y`";

if [ ! -d $archdir ]
then
  echo Creating $archdir;
  install -d --mode=0700 $archdir ;
fi

cd $maildir
for x in *
do
  touch $x.lock
  if [ -f $x ]
  then
    if [ -f $archdir/$x.$filename -o -f $archdir/$x.current ]
    then
      echo Refusing to process $x, it appears to already have been processed
    else
      /usr/local/bin/grepmail -d "before $basedate" $x | gzip > \
         $archdir/$x.$filename.gz;
      /usr/local/bin/grepmail -d "after  $basedate" $x > $archdir/$x.current;
      cat $x >> $archdir/$x.presort
      mv $archdir/$x.current $x
    fi
  fi
  rm $x.lock
done

Sean

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.



More information about the General mailing list