freedombone-ignore 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Adds an email ignore rule for either an email address
  10. # or text in the subject line
  11. #
  12. # License
  13. # =======
  14. #
  15. # Copyright (C) 2015-2018 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}-ignore
  31. export TEXTDOMAINDIR="/usr/share/locale"
  32. MYUSERNAME=$USER
  33. EMAIL_ADDRESS=
  34. SUBJECT_TEXT=
  35. function show_help {
  36. echo ''
  37. echo $"${PROJECT_NAME}-ignore -u [username] -e [mail address] -t [text in subject line]"
  38. echo ''
  39. exit 0
  40. }
  41. while [ $# -gt 1 ]
  42. do
  43. key="$1"
  44. case $key in
  45. -h|--help)
  46. show_help
  47. ;;
  48. -u|--user)
  49. shift
  50. MYUSERNAME="$1"
  51. ;;
  52. -e|--email)
  53. shift
  54. EMAIL_ADDRESS="$1"
  55. ;;
  56. -t|--text)
  57. shift
  58. SUBJECT_TEXT="$1"
  59. ;;
  60. *)
  61. # unknown option
  62. ;;
  63. esac
  64. shift
  65. done
  66. if ! [[ $MYUSERNAME && $EMAIL_ADDRESS ]]; then
  67. if ! [[ $MYUSERNAME && $SUBJECT_TEXT ]]; then
  68. show_help
  69. fi
  70. fi
  71. MUTTRC="/home/$MYUSERNAME/.muttrc"
  72. PM="/home/$MYUSERNAME/.procmailrc"
  73. # Ignore if subject line contains text
  74. if [ "$SUBJECT_TEXT" ]; then
  75. if ! grep -q "Ignore rule for $SUBJECT_TEXT" "$PM"; then
  76. { echo "# Ignore rule for $SUBJECT_TEXT";
  77. echo ":0";
  78. echo " * ^Subject:.*$SUBJECT_TEXT";
  79. echo "/dev/null";
  80. echo "# End of ignore rule"; } >> "$PM"
  81. chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
  82. fi
  83. fi
  84. # ignore an email address
  85. if [ "$EMAIL_ADDRESS" ]; then
  86. if ! grep -q "Ignore rule for $EMAIL_ADDRESS" "$PM"; then
  87. { echo "# Ignore rule for $EMAIL_ADDRESS";
  88. echo ":0";
  89. echo " * ^From:.*$EMAIL_ADDRESS";
  90. echo "/dev/null";
  91. echo "# End of ignore rule"; } >> "$PM"
  92. chown "$MYUSERNAME":"$MYUSERNAME" "$PM"
  93. fi
  94. fi
  95. PROCMAILLOG=/home/$MYUSERNAME/log
  96. if [ ! -d "$PROCMAILLOG" ]; then
  97. mkdir "$PROCMAILLOG"
  98. chown -R "$MYUSERNAME":"$MYUSERNAME" "$PROCMAILLOG"
  99. fi
  100. exit 0