Email archiving for multiple users

This commit is contained in:
Bob Mottram 2015-10-28 08:12:38 +00:00
parent 4be9baabc5
commit 1076e9d2ad
1 changed files with 19 additions and 11 deletions

View File

@ -6829,7 +6829,7 @@ function configure_imap {
if [ -f /var/lib/dovecot/ssl-parameters.dat ]; then
rm /var/lib/dovecot/ssl-parameters.dat
fi
service dovecot restart
echo 'configure_imap' >> $COMPLETION_FILE
}
@ -7486,17 +7486,25 @@ function email_archiving {
git clone https://github.com/bashrc/cleanup-maildir
cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
echo '#!/bin/bash' > /etc/cron.daily/archivemail
echo "MUTTRC=/home/$MY_USERNAME/.muttrc" >> /etc/cron.daily/archivemail
echo "python /usr/bin/cleanup-maildir --archive-folder='archive' --maildir-root='/home/$MY_USERNAME/Maildir' archive ''" >> /etc/cron.daily/archivemail
echo "chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir/archive-*" >> /etc/cron.daily/archivemail
echo 'if [ -f $MUTTRC ]; then' >> /etc/cron.daily/archivemail
echo ' MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)' >> /etc/cron.daily/archivemail
echo ' BACKUP_DIRECTORY=archive-$(date +"%Y")' >> /etc/cron.daily/archivemail
echo ' if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then' >> /etc/cron.daily/archivemail
echo ' sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC' >> /etc/cron.daily/archivemail
echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /etc/cron.daily/archivemail
echo 'for d in /home/*/ ; do' >> /etc/cron.daily/archivemail
echo ' USERNAME=$(echo "$d" | awk -F '"'"'/'"'"' '"'"'{print $3}'"'"')' >> /etc/cron.daily/archivemail
echo ' if [[ $USERNAME != "git" ]]; then' >> /etc/cron.daily/archivemail
echo ' if [ -d /home/$USERNAME/Maildir ]; then' >> /etc/cron.daily/archivemail
echo ' MUTTRC=/home/$USERNAME/.muttrc' >> /etc/cron.daily/archivemail
echo ' python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""' >> /etc/cron.daily/archivemail
echo ' chown -R $USERNAME:$USERNAME /home/$USERNAME/Maildir/archive-*' >> /etc/cron.daily/archivemail
echo ' if [ -f $MUTTRC ]; then' >> /etc/cron.daily/archivemail
echo ' MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)' >> /etc/cron.daily/archivemail
echo ' BACKUP_DIRECTORY=archive-$(date +"%Y")' >> /etc/cron.daily/archivemail
echo ' if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then' >> /etc/cron.daily/archivemail
echo ' sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC' >> /etc/cron.daily/archivemail
echo ' chown $USERNAME:$USERNAME $MUTTRC' >> /etc/cron.daily/archivemail
echo ' fi' >> /etc/cron.daily/archivemail
echo ' fi' >> /etc/cron.daily/archivemail
echo ' fi' >> /etc/cron.daily/archivemail
echo ' fi' >> /etc/cron.daily/archivemail
echo 'fi' >> /etc/cron.daily/archivemail
echo 'done' >> /etc/cron.daily/archivemail
echo 'exit 0' >> /etc/cron.daily/archivemail
chmod +x /etc/cron.daily/archivemail