freedombone-ignore 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU 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 General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. MYUSERNAME=$USER
  31. EMAIL_ADDRESS=
  32. SUBJECT_TEXT=
  33. function show_help {
  34. echo ''
  35. echo 'freedombone-ignore -u [username] -e [mail address] -t [text in subject line]'
  36. echo ''
  37. exit 0
  38. }
  39. while [[ $# > 1 ]]
  40. do
  41. key="$1"
  42. case $key in
  43. -h|--help)
  44. show_help
  45. ;;
  46. -u|--user)
  47. shift
  48. MYUSERNAME="$1"
  49. ;;
  50. -e|--email)
  51. shift
  52. EMAIL_ADDRESS="$1"
  53. ;;
  54. -t|--text)
  55. shift
  56. SUBJECT_TEXT="$1"
  57. ;;
  58. *)
  59. # unknown option
  60. ;;
  61. esac
  62. shift
  63. done
  64. if ! [[ $MYUSERNAME && $EMAIL_ADDRESS ]]; then
  65. if ! [[ $MYUSERNAME && $SUBJECT_TEXT ]]; then
  66. show_help
  67. fi
  68. fi
  69. MUTTRC=/home/$MYUSERNAME/.muttrc
  70. PM=/home/$MYUSERNAME/.procmailrc
  71. # Ignore if subject line contains text
  72. if [ "$SUBJECT_TEXT" ]; then
  73. if ! grep -q "Ignore rule for $SUBJECT_TEXT" $PM; then
  74. echo "# Ignore rule for $SUBJECT_TEXT" >> $PM
  75. echo ":0" >> $PM
  76. echo " * ^Subject:.*$SUBJECT_TEXT" >> $PM
  77. echo "/dev/null" >> $PM
  78. echo "# End of ignore rule" >> $PM
  79. chown $MYUSERNAME:$MYUSERNAME $PM
  80. fi
  81. fi
  82. # ignore an email address
  83. if [ $EMAIL_ADDRESS ]; then
  84. if ! grep -q "Ignore rule for $EMAIL_ADDRESS" $PM; then
  85. echo "# Ignore rule for $EMAIL_ADDRESS" >> $PM
  86. echo ":0" >> $PM
  87. echo " * ^From:.*$EMAIL_ADDRESS" >> $PM
  88. echo "/dev/null" >> $PM
  89. echo "# End of ignore rule" >> $PM
  90. chown $MYUSERNAME:$MYUSERNAME $PM
  91. fi
  92. fi
  93. PROCMAILLOG=/home/$MYUSERNAME/log
  94. if [ ! -d $PROCMAILLOG ]; then
  95. mkdir $PROCMAILLOG
  96. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  97. fi
  98. exit 0