2015-12-21 11:53:42 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Archives old email
|
|
|
|
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
2016-01-02 22:58:27 +01:00
|
|
|
# Copyright (C) 2015-2016 Bob Mottram <bob@robotics.uk.to>
|
2015-12-21 11:53:42 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2016-02-13 23:09:27 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2015-12-21 11:53:42 +01:00
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2016-02-13 23:09:27 +01:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
2015-12-21 11:53:42 +01:00
|
|
|
#
|
2016-02-13 23:09:27 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-12-21 11:53:42 +01:00
|
|
|
|
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
|
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
2016-10-01 11:39:23 +02:00
|
|
|
source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-validation
|
|
|
|
|
2015-12-21 11:53:42 +01:00
|
|
|
for d in /home/*/ ; do
|
|
|
|
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
|
2016-10-01 11:39:23 +02:00
|
|
|
if [[ $(is_valid_user $USERNAME) == "1" ]]; then
|
2015-12-21 11:53:42 +01:00
|
|
|
# for every user who has a mail directory
|
|
|
|
if [ -d /home/$USERNAME/Maildir ]; then
|
|
|
|
MUTTRC=/home/$USERNAME/.muttrc
|
|
|
|
# update archives
|
|
|
|
python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
|
|
|
|
# ensure the user has permissions on the archives
|
|
|
|
for archive_dir in /home/$USERNAME/Maildir/archive-* ; do
|
|
|
|
chown -R $USERNAME:$USERNAME $archive_dir
|
|
|
|
done
|
|
|
|
# add the archive to .muttrc if needed
|
|
|
|
if [ -f $MUTTRC ]; then
|
|
|
|
MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
|
|
|
|
BACKUP_DIRECTORY=archive-$(date +"%Y")
|
|
|
|
if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
|
|
|
|
sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
|
|
|
|
chown $USERNAME:$USERNAME $MUTTRC
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|