procmail
[Top] [All Lists]

Re: How to use Procmail to remove messages from server after x numberof days

2011-03-01 12:08:46

Quoting PSE-L(_at_)mail(_dot_)professional(_dot_)org:

At 09:50 2011-03-01, Alan Clifford wrote:
I do it. Not on my system mailbox but on the mailboxes for mails such as this mailing list which procmail has put in ~/mail/IN.procmail. Essentially, it deletes stuff that is more than 'n' days old and keeps the younger stuff.

It is rather a monster kludge involving cron, bash script, formail,
procmail and lockfile.

If you just move the messages into dated subdirectories, you don't have to reprocess anything. The downside is that exchanged rarely wrap up within the confines of an arbitrary date cutoff, so you've got exchanges in last months (or weeks) archive, and they continue into the current one. But then, lots of stuff doesn't wrap up in 7-10 days either.

I do it with Maildir on the Spam and Trash folders:
Procmail.rc:
DOMDIR=`/usr/local/vpopmail/bin/vuserinfo -d $EXT@$HOST`
CLEANRESULT=`/usr/local/vpopmail/domains/bin/cleanspamtrash.sh $DOMDIR`

cleanspamtrash.sh:
-----------------------------
#!/bin/sh
#Get current timestamp of file, delete and re-create if older than 1 day
FILE=$1/.spamtrashclean
NOW=`date +%s`
if [ -f "$FILE" ]
then
FILEDATE=`stat -f %m $FILE`
AGE=`expr $NOW - $FILEDATE`
else
AGE=90000
fi

echo "Now is $NOW"
echo "Filedate is $FILEDATE"
echo "Age is $AGE"

if [ $AGE -gt 86400 ]
then
 # Clean Spam and Trash folders
 # 7 days for Spam
 # 14 days for Trash
 if [ -d $1/Maildir/.Trash ]
 then
find $1/Maildir/.Trash/cur/ -maxdepth 1 -type f -mtime +14 -exec rm {} \;
 if [ -f $1/Maildir/.Trash/dovecot.index ]
 then
        rm $1/Maildir/.Trash/dove*
 fi
 fi
 if [ -d $1/Maildir/.Spam ]
 then
 find $1/Maildir/.Spam/cur/ -maxdepth 1 -type f -mtime +7 -exec rm {} \;
 if [ -f $1/Maildir/.Spam/dovecot.index ]
 then
        rm $1/Maildir/.Spam/dove*
 fi
 fi
 #Update/Create timestampfile
 touch $FILE

fi


Rick

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)de
http://mailman.rwth-aachen.de/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>