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