aboutsummaryrefslogtreecommitdiff
path: root/bin/mutt-autoalias
blob: a9725d5af2ea3234e7b1d5d80c630e46a716b0f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh

MESSAGE=$(cat)

EXCLUDE="\(.*@bugs.\(debian.org|launchpad.net\)|.*@.*.launchpad.net|noreply|.*facebook.*|.*gmail.com.*Behalf Of\)"
NEWALIAS=$(echo "${MESSAGE}" | grep ^"From: " | egrep -v "${EXCLUDE}" | sed s/[\,\"\']//g | awk '{$1=""; if (NF == 3) {print "alias" $0;} else if (NF == 2) {print "alias" $0 $0;} else if (NF > 3) {print "alias", tolower($(NF-1))"."tolower($2) $0;}}')

if grep -Fxq "$NEWALIAS" $HOME/.mutt/alias.rc; then
    :
elif [ "x${NEWALIAS}" = "x" ]; then
    :
else
    echo "$NEWALIAS" >> $HOME/.mutt/alias.rc
fi

echo "${MESSAGE}"