Email rule based on subject text
This commit is contained in:
parent
cc22c0473c
commit
4ade1a6f91
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"${PROJECT_NAME}-addemail -u [username] -e [email address] -g [group name] --public [yes|no]": ""
|
||||
"${PROJECT_NAME}-addemail -u [username] -e [email address] -s [subject text] -g [group name] --public [yes|no]": ""
|
||||
}
|
|
@ -25,6 +25,9 @@
|
|||
"No email address was given": "",
|
||||
"No folder name was given": "",
|
||||
"Email rule for $RULE_EMAIL was added": "",
|
||||
"When email arrives with subject containing:": "",
|
||||
"No subject text was given": "",
|
||||
"Email rule for subject '$RULE_SUBJECT' was added": "",
|
||||
"Block or unblock emails from a given address": "",
|
||||
"Block it:": "",
|
||||
"Block an email": "",
|
||||
|
@ -35,7 +38,8 @@
|
|||
"Change Email Filtering Rules": "",
|
||||
"Choose an operation:": "",
|
||||
"Add yourself to a mailing list": "",
|
||||
"Add an email rule": "",
|
||||
"Add an email rule for an address": "",
|
||||
"Add an email rule for a subject": "",
|
||||
"Block or unblock an email address": "",
|
||||
"Block or unblock email with subject text": "",
|
||||
"Back to main menu": "",
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"${PROJECT_NAME}-addemail -u [username] -e [email address] -g [group name] --public [yes|no]": ""
|
||||
"${PROJECT_NAME}-addemail -u [username] -e [email address] -s [subject text] -g [group name] --public [yes|no]": ""
|
||||
}
|
|
@ -25,6 +25,9 @@
|
|||
"No email address was given": "",
|
||||
"No folder name was given": "",
|
||||
"Email rule for $RULE_EMAIL was added": "",
|
||||
"When email arrives with subject containing:": "",
|
||||
"No subject text was given": "",
|
||||
"Email rule for subject '$RULE_SUBJECT' was added": "",
|
||||
"Block or unblock emails from a given address": "",
|
||||
"Block it:": "",
|
||||
"Block an email": "",
|
||||
|
@ -35,7 +38,8 @@
|
|||
"Change Email Filtering Rules": "",
|
||||
"Choose an operation:": "",
|
||||
"Add yourself to a mailing list": "",
|
||||
"Add an email rule": "",
|
||||
"Add an email rule for an address": "",
|
||||
"Add an email rule for a subject": "",
|
||||
"Block or unblock an email address": "",
|
||||
"Block or unblock email with subject text": "",
|
||||
"Back to main menu": "",
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"${PROJECT_NAME}-addemail -u [username] -e [email address] -g [group name] --public [yes|no]": ""
|
||||
"${PROJECT_NAME}-addemail -u [username] -e [email address] -s [subject text] -g [group name] --public [yes|no]": ""
|
||||
}
|
|
@ -25,6 +25,9 @@
|
|||
"No email address was given": "",
|
||||
"No folder name was given": "",
|
||||
"Email rule for $RULE_EMAIL was added": "",
|
||||
"When email arrives with subject containing:": "",
|
||||
"No subject text was given": "",
|
||||
"Email rule for subject '$RULE_SUBJECT' was added": "",
|
||||
"Block or unblock emails from a given address": "",
|
||||
"Block it:": "",
|
||||
"Block an email": "",
|
||||
|
@ -35,7 +38,8 @@
|
|||
"Change Email Filtering Rules": "",
|
||||
"Choose an operation:": "",
|
||||
"Add yourself to a mailing list": "",
|
||||
"Add an email rule": "",
|
||||
"Add an email rule for an address": "",
|
||||
"Add an email rule for a subject": "",
|
||||
"Block or unblock an email address": "",
|
||||
"Block or unblock email with subject text": "",
|
||||
"Back to main menu": "",
|
||||
|
|
Binary file not shown.
|
@ -36,12 +36,13 @@ export TEXTDOMAINDIR="/usr/share/locale"
|
|||
|
||||
MYUSERNAME=$USER
|
||||
EMAILADDRESS=
|
||||
SUBJECT_TEXT=
|
||||
GROUP_NAME=
|
||||
PUBLIC='no'
|
||||
|
||||
function show_help {
|
||||
echo ''
|
||||
echo $"${PROJECT_NAME}-addemail -u [username] -e [email address] -g [group name] --public [yes|no]"
|
||||
echo $"${PROJECT_NAME}-addemail -u [username] -e [email address] -s [subject text] -g [group name] --public [yes|no]"
|
||||
echo ''
|
||||
exit 0
|
||||
}
|
||||
|
@ -62,6 +63,10 @@ case $key in
|
|||
shift
|
||||
EMAILADDRESS="$1"
|
||||
;;
|
||||
-s|--subject)
|
||||
shift
|
||||
SUBJECT_TEXT="$1"
|
||||
;;
|
||||
-g|--group)
|
||||
shift
|
||||
GROUP_NAME="$1"
|
||||
|
@ -77,14 +82,27 @@ esac
|
|||
shift
|
||||
done
|
||||
|
||||
if ! [[ $MYUSERNAME && $EMAILADDRESS && $GROUP_NAME ]]; then
|
||||
if ! [[ $MYUSERNAME && $GROUP_NAME ]]; then
|
||||
show_help
|
||||
fi
|
||||
|
||||
if [ ${#EMAILADDRESS} -lt 2 ]; then
|
||||
if [ ${#SUBJECT_TEXT} -lt 2 ]; then
|
||||
show_help
|
||||
fi
|
||||
fi
|
||||
|
||||
MUTTRC=/home/$MYUSERNAME/.muttrc
|
||||
PM=/home/$MYUSERNAME/.procmailrc
|
||||
LISTDIR=/home/$MYUSERNAME/Maildir/$GROUP_NAME
|
||||
|
||||
proc_rule=" * ^From:.*$EMAILADDRESS"
|
||||
proc_comment="# Email rule for $EMAILADDRESS -> $GROUP_NAME"
|
||||
if [ ${#SUBJECT_TEXT} -gt 0 ]; then
|
||||
proc_rule=" * ^From:.*$EMAILADDRESS"
|
||||
proc_comment="# Email rule for '$SUBJECT_TEXT' -> $GROUP_NAME"
|
||||
fi
|
||||
|
||||
if [ ! -d "$LISTDIR" ]; then
|
||||
mkdir -m 700 $LISTDIR
|
||||
mkdir -m 700 $LISTDIR/tmp
|
||||
|
@ -92,40 +110,43 @@ if [ ! -d "$LISTDIR" ]; then
|
|||
mkdir -m 700 $LISTDIR/cur
|
||||
fi
|
||||
chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
|
||||
if ! grep -q "Email rule for $EMAILADDRESS -> $GROUP_NAME" $PM; then
|
||||
if ! grep -q "$proc_comment" $PM; then
|
||||
if [[ $PUBLIC != "yes" ]]; then
|
||||
# private emails go after the encryption stage
|
||||
echo '' >> $PM
|
||||
echo "# Email rule for $EMAILADDRESS -> $GROUP_NAME" >> $PM
|
||||
echo "$proc_comment" >> $PM
|
||||
echo ":0" >> $PM
|
||||
echo " * ^From:.*$EMAILADDRESS" >> $PM
|
||||
echo "$proc_rule" >> $PM
|
||||
echo "$LISTDIR/new" >> $PM
|
||||
echo "# End of rule" >> $PM
|
||||
else
|
||||
# public emails are copied before hte encryption stage
|
||||
# public emails are copied before the encryption stage
|
||||
if ! grep -q '# encrypt' $PM; then
|
||||
echo '' >> $PM
|
||||
echo "# Email rule for $EMAILADDRESS -> $GROUP_NAME" >> $PM
|
||||
echo "$proc_comment" >> $PM
|
||||
echo ":0" >> $PM
|
||||
echo " * ^From:.*$EMAILADDRESS" >> $PM
|
||||
echo "$proc_rule" >> $PM
|
||||
echo "$LISTDIR/new" >> $PM
|
||||
echo "# End of rule" >> $PM
|
||||
else
|
||||
filter=$(echo "# Email rule for $EMAILADDRESS -> $GROUP_NAME\n:0\n * ^From:.*$EMAILADDRESS\n$LISTDIR/new\n# End of rule\n")
|
||||
filter=$(echo "$proc_comment\n:0\n${proc_rule}\n$LISTDIR/new\n# End of rule\n")
|
||||
sed -i "/# encrypt/i ${filter}" $PM
|
||||
fi
|
||||
fi
|
||||
chown $MYUSERNAME:$MYUSERNAME $PM
|
||||
fi
|
||||
|
||||
if [ ! -f "$MUTTRC" ]; then
|
||||
cp /etc/Muttrc $MUTTRC
|
||||
chown $MYUSERNAME:$MYUSERNAME $MUTTRC
|
||||
fi
|
||||
|
||||
PROCMAILLOG=/home/$MYUSERNAME/log
|
||||
if [ ! -d $PROCMAILLOG ]; then
|
||||
mkdir $PROCMAILLOG
|
||||
chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
|
||||
fi
|
||||
|
||||
MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)
|
||||
if [[ $MUTT_MAILBOXES != *$GROUP_NAME* ]]; then
|
||||
if ! grep -q "=$GROUP_NAME" $MUTTRC; then
|
||||
|
|
|
@ -180,7 +180,7 @@ function add_to_mailing_list {
|
|||
--msgbox $"$LIST_NAME list was added" 6 40
|
||||
}
|
||||
|
||||
function email_rule {
|
||||
function email_rule_address {
|
||||
data=$(tempfile 2>/dev/null)
|
||||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --backtitle $"Freedombone User Control Panel" \
|
||||
|
@ -229,6 +229,50 @@ function email_rule {
|
|||
--msgbox $"Email rule for $RULE_EMAIL was added" 6 40
|
||||
}
|
||||
|
||||
function email_rule_subject {
|
||||
data=$(tempfile 2>/dev/null)
|
||||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --backtitle $"Freedombone User Control Panel" \
|
||||
--title $"Create an email rule" \
|
||||
--form "\n" 9 65 4 \
|
||||
$"When email arrives with subject containing:" 1 1 "" 1 35 24 28 \
|
||||
$"Move to folder:" 2 1 "" 2 35 24 28 \
|
||||
$"Public:" 3 1 $"no" 3 35 4 25 \
|
||||
2> $data
|
||||
sel=$?
|
||||
case $sel in
|
||||
1) return;;
|
||||
255) return;;
|
||||
esac
|
||||
RULE_SUBJECT=$(cat $data | sed -n 1p)
|
||||
RULE_FOLDER=$(cat $data | sed -n 2p)
|
||||
RULE_PUBLIC=$(cat $data | sed -n 3p)
|
||||
|
||||
if [ ${#RULE_PUBLIC} -lt 1 ]; then
|
||||
RULE_PUBLIC='no'
|
||||
fi
|
||||
if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
|
||||
RULE_PUBLIC='yes'
|
||||
else
|
||||
RULE_PUBLIC='no'
|
||||
fi
|
||||
if [ ${#RULE_SUBJECT} -lt 2 ]; then
|
||||
dialog --title $"Create an email rule" \
|
||||
--msgbox $"No subject text was given" 6 40
|
||||
return
|
||||
fi
|
||||
if [ ${#RULE_FOLDER} -lt 2 ]; then
|
||||
dialog --title $"Create an email rule" \
|
||||
--msgbox $"No folder name was given" 6 40
|
||||
return
|
||||
fi
|
||||
|
||||
${PROJECT_NAME}-addemail -u $USER -s "$RULE_SUBJECT" \
|
||||
-g "$RULE_FOLDER" --public $RULE_PUBLIC
|
||||
dialog --title $"Create an email rule" \
|
||||
--msgbox $"Email rule for subject '$RULE_SUBJECT' was added" 6 40
|
||||
}
|
||||
|
||||
function block_unblock_email {
|
||||
blockstr=$"Block or unblock emails from a given address"
|
||||
data=$(tempfile 2>/dev/null)
|
||||
|
@ -307,13 +351,14 @@ function menu_email {
|
|||
trap "rm -f $data" 0 1 2 5 15
|
||||
dialog --backtitle $"Freedombone User Control Panel" \
|
||||
--title $"Change Email Filtering Rules" \
|
||||
--radiolist $"Choose an operation:" 13 70 6 \
|
||||
--radiolist $"Choose an operation:" 14 70 7 \
|
||||
1 $"Add yourself to a mailing list" off \
|
||||
2 $"Remove yourself from a mailing list" off \
|
||||
3 $"Add an email rule" off \
|
||||
4 $"Block or unblock an email address" off \
|
||||
5 $"Block or unblock email with subject text" off \
|
||||
6 $"Back to main menu" on 2> $data
|
||||
3 $"Add an email rule for an address" off \
|
||||
4 $"Add an email rule for a subject" off \
|
||||
5 $"Block or unblock an email address" off \
|
||||
6 $"Block or unblock email with subject text" off \
|
||||
7 $"Back to main menu" on 2> $data
|
||||
sel=$?
|
||||
case $sel in
|
||||
1) break;;
|
||||
|
@ -322,10 +367,11 @@ function menu_email {
|
|||
case $(cat $data) in
|
||||
1) add_to_mailing_list;;
|
||||
2) remove_user_from_mailing_list;;
|
||||
3) email_rule;;
|
||||
4) block_unblock_email;;
|
||||
5) block_unblock_subject;;
|
||||
6) break;;
|
||||
3) email_rule_address;;
|
||||
4) email_rule_subject;;
|
||||
5) block_unblock_email;;
|
||||
6) block_unblock_subject;;
|
||||
7) break;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue