rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

commit bd118aa26edbe65e09ff6e1518c8771ebce1edd8
parent da6e1c0dd1c5491da2bafffeb033389605efce70
Author: parazyd <parazyd@dyne.org>
Date:   Sun,  4 Mar 2018 00:57:16 +0100

Ditch abook and use our own csv-based addressbook.

Diffstat:
Mbin/rpabook | 17++++++++++++-----
Msieve.c | 2+-
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/bin/rpabook b/bin/rpabook @@ -6,7 +6,7 @@ profile="${RPPROFILE:-$HOME/.rp/default}" ab="$profile/whitelist.abook" usage() { - printf " * usage: $(basename $0) [-a] [-c]\n" + printf " * usage: $(basename $0) [-a < email] [-c pattern]\n" printf "\t-a: add to abook\n" printf "\t-c: completion (used from mutt)\n" exit 1 @@ -16,16 +16,23 @@ for i in $@; do case "$i" in -a) email="$(cat)" - addr="$(echo $email | rpheaders From | cut -d'<' -f2 | tr -d '<>')" + 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" && { echo " * address already in abook" exit 0 } - echo "$email" | abook --datafile "$ab" --add-email-quiet + + if [ "$addr" = "$name" ]; then + name="$(echo "$name" | cut -d '@' -f1)" + fi + + echo "email=$addr,$name" >> "$ab" exit $? ;; -c) - abook --datafile "$ab" --mutt-query "$2" + grep "^email=$2" "$ab" | sed -e 's/email=//' -e 's/,/\t/' exit $? ;; *) @@ -34,4 +41,4 @@ for i in $@; do esac done -abook --datafile "$profile/whitelist.abook" +usage diff --git a/sieve.c b/sieve.c @@ -61,7 +61,7 @@ int genabook(char *line) { char *email; strtok(line, "="); - email = strtok(NULL, "="); + email = strtok(NULL, ","); if (!email) return 1; printf("if header :contains \"From\" \"%s\"", email);