Skip to content
Snippets Groups Projects
freedombone-rmemail 1.79 KiB
Newer Older
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
Bob Mottram's avatar
Bob Mottram committed
#
# Removes an email address rule from the email configuration
Bob Mottram's avatar
Bob Mottram committed
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2015-2019 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
Bob Mottram's avatar
Bob Mottram committed
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Bob Mottram's avatar
Bob Mottram committed
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
Bob Mottram's avatar
Bob Mottram committed
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Bob Mottram's avatar
Bob Mottram committed
PROJECT_NAME='freedombone'

Bob Mottram's avatar
Bob Mottram committed
export TEXTDOMAIN=${PROJECT_NAME}-rmemail
Bob Mottram's avatar
Bob Mottram committed
export TEXTDOMAINDIR="/usr/share/locale"

MYUSERNAME=$USER

function show_help {
    echo ''
Bob Mottram's avatar
Bob Mottram committed
    echo $"${PROJECT_NAME}-rmemail -u [username] -e [email address]"
Bob Mottram's avatar
Bob Mottram committed
while [ $# -gt 1 ]
do
key="$1"

case $key in
    -h|--help)
    show_help
    ;;
    -u|--user)
    shift
    MYUSERNAME="$1"
    ;;
    -e|--email)
    shift
    EMAILADDRESS="$1"
    ;;
    *)
    # unknown option
    ;;
esac
shift
done

if ! [[ $MYUSERNAME && $EMAILADDRESS ]]; then
    show_help
fi

Bob Mottram's avatar
Bob Mottram committed
MUTTRC="/home/$MYUSERNAME/.muttrc"
PM=/home/$MYUSERNAME/.procmailrc

Bob Mottram's avatar
Bob Mottram committed
if grep -q "Email rule for $EMAILADDRESS ->" "$PM"; then
    sed -i "/# Email rule for $EMAILADDRESS ->.*/,/# End of rule/d" "$PM"