freedombone-archive-mail 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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@robotics.uk.to>
  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. for d in /home/*/ ; do
  33. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  34. if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
  35. # for every user who has a mail directory
  36. if [ -d /home/$USERNAME/Maildir ]; then
  37. MUTTRC=/home/$USERNAME/.muttrc
  38. # update archives
  39. python /usr/bin/cleanup-maildir --archive-folder="archive" --maildir-root="/home/$USERNAME/Maildir" archive ""
  40. # ensure the user has permissions on the archives
  41. for archive_dir in /home/$USERNAME/Maildir/archive-* ; do
  42. chown -R $USERNAME:$USERNAME $archive_dir
  43. done
  44. # add the archive to .muttrc if needed
  45. if [ -f $MUTTRC ]; then
  46. MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
  47. BACKUP_DIRECTORY=archive-$(date +"%Y")
  48. if [[ $MUTT_MAILBOXES != *$BACKUP_DIRECTORY* ]]; then
  49. sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$BACKUP_DIRECTORY|g" $MUTTRC
  50. chown $USERNAME:$USERNAME $MUTTRC
  51. fi
  52. fi
  53. fi
  54. fi
  55. done
  56. exit 0