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

Rick Romero <[email protected]>
Newsgroups gmane.mail.procmail
Message-ID <[email protected]>
Quoting [email protected]:

> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.