commit 4264e1a756e3fc3dda1e433649554bc89afc4019
parent 85e612430fe7a24f11d00b41e53e8c1849d2d7e8
Author: parazyd <parazyd@dyne.org>
Date: Mon, 4 Mar 2019 11:02:40 +0100
rpabook formatting.
Diffstat:
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/bin/rpabook b/bin/rpabook
@@ -11,8 +11,8 @@ ab="$profile/whitelist.abook"
usage() {
cat <<EOF
* Usage: $(basename $0) [-a < email] [-c pattern]
- -a: add to abook
- -c: completion (used with mutt)
+ -a: add to abook
+ -c: completion (used with mutt)
EOF
exit 1
}
@@ -23,8 +23,8 @@ while getopts "ach" opt; do
email="$(cat)"
addr="$(echo "$email" | rpheaders From | cut -d'<' -f2 | tr -d '<>')"
name="$(echo "$email" | rpheaders From | cut -d'<' -f1 | sed 's/ $//')"
- echo "$addr"
- grep -q "^email=$addr" "$ab" && {
+ printf "%s <%s>\n" "$name" "$addr"
+ grep -q "^email=\"$addr\"" "$ab" && {
echo "* Address already in abook"
exit 0
}
@@ -33,12 +33,24 @@ while getopts "ach" opt; do
name="$(echo "$name" | cut -d '@' -f1)"
fi
- echo "email=$addr,$name" >> "$ab"
- exit $?
+ printf "email=\"%s\",%s" "$addr" "$name" >> "$ab"
+ exit 0
;;
c)
- grep -i "$2" "$ab" | sed -e 's/^email=//' -e 's/,/\t/'
- exit $?
+ contact="$(grep -i "$2" "$ab")"
+ ret="$?"
+ if [ -t 1 ]; then
+ echo "$contact" | while read line; do
+ [ -n "$line" ] || break
+ email="$(echo "$line" | cut -d',' -f1 | cut -c 8- | sed 's/"$//')"
+ name="$(echo "$line" | cut -d',' -f2-)"
+ printf "%s <%s>\n" "$name" "$email"
+ done
+ else
+ echo "$contact" | sed -e 's/^email=//' -e 's/,/\t/' \
+ -e 's/"//' -e 's/"//'
+ fi
+ exit 0
;;
*)
usage