freedomboneeee/src/freedombone-archive-mail

62 lines
2.2 KiB
Plaintext
Raw Normal View History

2015-12-21 11:53:42 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Archives old email
# License
# =======
#
# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
export TEXTDOMAINDIR="/usr/share/locale"
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USERNAME != "git" ]]; then
# 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