freedombone-ignore 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Adds an email ignore rule for either an email address
  12. # or text in the subject line
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. PROJECT_NAME='freedombone'
  31. export TEXTDOMAIN=${PROJECT_NAME}-ignore
  32. export TEXTDOMAINDIR="/usr/share/locale"
  33. MYUSERNAME=$USER
  34. EMAIL_ADDRESS=
  35. SUBJECT_TEXT=
  36. function show_help {
  37. echo ''
  38. echo $"${PROJECT_NAME}-ignore -u [username] -e [mail address] -t [text in subject line]"
  39. echo ''
  40. exit 0
  41. }
  42. while [[ $# > 1 ]]
  43. do
  44. key="$1"
  45. case $key in
  46. -h|--help)
  47. show_help
  48. ;;
  49. -u|--user)
  50. shift
  51. MYUSERNAME="$1"
  52. ;;
  53. -e|--email)
  54. shift
  55. EMAIL_ADDRESS="$1"
  56. ;;
  57. -t|--text)
  58. shift
  59. SUBJECT_TEXT="$1"
  60. ;;
  61. *)
  62. # unknown option
  63. ;;
  64. esac
  65. shift
  66. done
  67. if ! [[ $MYUSERNAME && $EMAIL_ADDRESS ]]; then
  68. if ! [[ $MYUSERNAME && $SUBJECT_TEXT ]]; then
  69. show_help
  70. fi
  71. fi
  72. MUTTRC=/home/$MYUSERNAME/.muttrc
  73. PM=/home/$MYUSERNAME/.procmailrc
  74. # Ignore if subject line contains text
  75. if [ "$SUBJECT_TEXT" ]; then
  76. if ! grep -q "Ignore rule for $SUBJECT_TEXT" $PM; then
  77. echo "# Ignore rule for $SUBJECT_TEXT" >> $PM
  78. echo ":0" >> $PM
  79. echo " * ^Subject:.*$SUBJECT_TEXT" >> $PM
  80. echo "/dev/null" >> $PM
  81. echo "# End of ignore rule" >> $PM
  82. chown $MYUSERNAME:$MYUSERNAME $PM
  83. fi
  84. fi
  85. # ignore an email address
  86. if [ $EMAIL_ADDRESS ]; then
  87. if ! grep -q "Ignore rule for $EMAIL_ADDRESS" $PM; then
  88. echo "# Ignore rule for $EMAIL_ADDRESS" >> $PM
  89. echo ":0" >> $PM
  90. echo " * ^From:.*$EMAIL_ADDRESS" >> $PM
  91. echo "/dev/null" >> $PM
  92. echo "# End of ignore rule" >> $PM
  93. chown $MYUSERNAME:$MYUSERNAME $PM
  94. fi
  95. fi
  96. PROCMAILLOG=/home/$MYUSERNAME/log
  97. if [ ! -d $PROCMAILLOG ]; then
  98. mkdir $PROCMAILLOG
  99. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  100. fi
  101. exit 0