freedombone-archive-mail 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Archives old email
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
  16. #
  17. # This program is free software: you can redistribute it and/or modify
  18. # it under the terms of the GNU Affero General Public License as published by
  19. # the Free Software Foundation, either version 3 of the License, or
  20. # (at your option) any later version.
  21. #
  22. # This program is distributed in the hope that it will be useful,
  23. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. # GNU Affero General Public License for more details.
  26. #
  27. # You should have received a copy of the GNU Affero General Public License
  28. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  29. PROJECT_NAME='freedombone'
  30. export TEXTDOMAIN=${PROJECT_NAME}-archive-mail
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. source /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-validation
  33. for d in /home/*/ ; do
  34. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  35. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  36. # for every user who has a mail directory
  37. if [ -d /home/$USERNAME/Maildir ]; then
  38. MUTTRC=/home/$USERNAME/.muttrc
  39. # update archives
  40. python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
  41. # ensure the user has permissions on the archives
  42. for archive_dir in /home/$USERNAME/Maildir/archive-* ; do
  43. chown -R $USERNAME:$USERNAME $archive_dir
  44. done
  45. # add the archive to .muttrc if needed
  46. if [ -f $MUTTRC ]; then
  47. MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
  48. BACKUP_DIRECTORY=archive-$(date +"%Y")
  49. if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
  50. sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
  51. chown $USERNAME:$USERNAME $MUTTRC
  52. fi
  53. fi
  54. fi
  55. fi
  56. done
  57. exit 0