freedombone-unignore 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Removes an 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-unignore -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. # unignore if subject line contains text
  72. if [ $SUBJECT_TEXT ]; then
  73. if grep -q "Ignore rule for $SUBJECT_TEXT" $PM; then
  74. sed -i "/# Ignore rule for $SUBJECT_TEXT/,/# End of ignore rule/d" $PM
  75. fi
  76. fi
  77. # unignore an email address
  78. if [ $EMAIL_ADDRESS ]; then
  79. if grep -q "Ignore rule for $EMAIL_ADDRESS" $PM; then
  80. sed -i "/# Ignore rule for $EMAIL_ADDRESS/,/# End of ignore rule/d" $PM
  81. fi
  82. fi
  83. exit 0