summaryrefslogtreecommitdiff
path: root/lib/mutt/generate-contacts.sh
blob: ab3cacb3d463c344e375be40f8e4388dd770b1bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env sh
#
# Source: http://wcm1.web.rice.edu/mutt-tips.html

MESSAGE=$(cat)

NEWALIAS=$(echo "${MESSAGE}" | grep ^"From: " | 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/contacts.txt; then
    :
else
    echo "$NEWALIAS" >> $HOME/contacts.txt
fi

echo "${MESSAGE}"