50 lines
1.6 KiB
Bash
50 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
add_email() {
|
|
local alias="<${newAlias% *}"
|
|
local emailAddress="<${newAlias##*<}"
|
|
local ignoreList=(
|
|
'amazon.com'
|
|
'billing@'
|
|
'do-not-reply'
|
|
'donotreply'
|
|
'github.com'
|
|
'gitlab.com'
|
|
'mailto'
|
|
'no-reply'
|
|
'noreply'
|
|
'paypal.com'
|
|
'walmart.com'
|
|
)
|
|
# Make the list into a format that works with bash regexp.
|
|
ignoreList="${ignoreList[*]}"
|
|
ignoreList="${ignoreList// /|}"
|
|
# Do not add aliases with no alias-name
|
|
if [[ "$alias" == "UNNAMED" ]]; then
|
|
return
|
|
fi
|
|
# Try to filter out addresses that do not receive replies.
|
|
if [[ "${emailAddress,,}" =~ ${ignoreList} ]]; then
|
|
return
|
|
fi
|
|
# Do not add the same address twice.
|
|
if grep -Fq "$emailAddress" $HOME/.mutt/aliases ; then
|
|
return
|
|
fi
|
|
# Try to not use the same alias-name
|
|
if grep -Fq " $alias " $HOME/.mutt/aliases; then
|
|
alias="${alias}-${emailAddress#*@}"
|
|
alias="${alias%.*}"
|
|
fi
|
|
if grep -Fq "$alias" $HOME/.mutt/aliases; then
|
|
return
|
|
fi
|
|
echo "$newAlias" >> $HOME/.mutt/aliases
|
|
sort -u ~/.mutt/aliases -o ~/.mutt/aliases
|
|
}
|
|
|
|
message=$(cat)
|
|
newAlias=$(echo "${message}" | grep ^"From: " | sed -e s/[\,\"\']//g -e s/'From: '//g | awk -F" " '{if (NF == 1) {print "alias UNNAMED UNNAMED " $0;} else if (NF == 2) {print "alias " $1" " toupper(substr($0,1,1)) tolower(substr($0,2));} else if (NF >= 3) {print "alias ", tolower($1)"-"tolower($(NF-1))" " toupper(substr($0,1,1)) tolower(substr($0,2));}}')
|
|
add_email
|
|
echo "${message}"
|