Archivemail
De wikiGite
Révision datée du 19 septembre 2008 à 15:36 par Frank (discussion | contributions)
#!/bin/bash # Archivemail backup mbox or Maildir to mbox gzipped files. # To read/search a backuped mail, use mutt -f [path_to_archive_file.gz]. # Then forward it with mutt to a valid email address. # The variable BACKUPDIR gives the path of backuped files. MAILDIR=$HOME/Maildir BACKUP=$HOME/archivemails LOG=/opt/systools/log LOGFILE=$BACKUP/archivemail.log BACKUPDIR=$BACKUP/arch$(date +%d%m%y) echo $(date) >> $LOGFILE # $1 is the retention policy. If not set, the default of archimail is 180 days. if [ ! -z $1 ] then RP="-d $1" fi # Archivemail don't work on symbolic links. Retreive real directory path. if [ -h $MAILDIR ] then MAILDIR=$(ls -l /var/www/web7/Maildir | awk 'BEGIN{FS="-> "}{print $2}') fi if [ ! -d $BACKUPDIR ] then mkdir -p $BACKUPDIR if [ $? -ne 0 ] then echo "Creation repertoire $BACKUPDIR impossible !" >> $LOGFILE exit 1 fi fi # "For" doesn't handle directory names with space. Use "while" loop. find $MAILDIR -type d | (while read mfile do if [ "$(echo $mfile | grep -i spam)" != "" -o "$(echo $mfile | grep -i junk)" != "" ] then # If spams, we force delete instead of archive archivemail -d 60 --delete "$mfile" >> $LOGFILE 2>&1 else archivemail $RP -o $BACKUPDIR "$mfile" >> $LOGFILE 2>&1 fi done) echo "Fin de traitement : $(date)">> $LOGFILE