Email archiving command
This commit is contained in:
parent
5af9dfa70c
commit
986eaa0d7a
Binary file not shown.
|
@ -5187,6 +5187,19 @@ function email_archiving {
|
|||
return
|
||||
fi
|
||||
|
||||
# ensure that the mail archive script is up to date
|
||||
if [ -f /usr/local/bin/${PROJECT_NAME}-archive-mail ]; then
|
||||
cp /usr/local/bin/${PROJECT_NAME}-archive-mail /etc/cron.daily/archivemail
|
||||
else
|
||||
if [ -f /usr/bin/${PROJECT_NAME}-archive-mail ]; then
|
||||
cp /usr/bin/${PROJECT_NAME}-archive-mail /etc/cron.daily/archivemail
|
||||
else
|
||||
echo "/usr/bin/${PROJECT_NAME}-archive-email was not found. ${PROJECT_NAME} might not have fully installed."
|
||||
exit 62379
|
||||
fi
|
||||
fi
|
||||
chmod +x /etc/cron.daily/archivemail
|
||||
|
||||
# update to the next commit
|
||||
if [ -d $INSTALL_DIR/cleanup-maildir ]; then
|
||||
if grep -q "cleanup-maildir commit" $COMPLETION_FILE; then
|
||||
|
@ -5222,28 +5235,6 @@ function email_archiving {
|
|||
fi
|
||||
|
||||
cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
|
||||
echo '#!/bin/bash' > /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 'done' >> /etc/cron.daily/archivemail
|
||||
|
||||
echo 'exit 0' >> /etc/cron.daily/archivemail
|
||||
chmod +x /etc/cron.daily/archivemail
|
||||
|
||||
echo 'email_archiving' >> $COMPLETION_FILE
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
#!/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
|
Loading…
Reference in New Issue