rp

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

commit da75dab0f51f6ce1c3781dec7f8e5cb384370425
parent aeda40ca26a0390f913f3478b48e1c46def8dfdf
Author: parazyd <parazyd@dyne.org>
Date:   Wed, 28 Feb 2018 20:58:58 +0100

Parse the abook in sieve.c as well.

Diffstat:
Mbin/rpsieve | 33++++++++++-----------------------
Msieve.c | 20++++++++++++++++++--
2 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/bin/rpsieve b/bin/rpsieve @@ -1,7 +1,7 @@ #!/bin/sh profile="${RPPROFILE:-$HOME/.rp/default}" -. "$HOME"/.rp/rplib/common.sh +. "$profile"/../rplib/common.sh usage() { einfo "usage: $(basename $0) [-e] [-u]" @@ -26,11 +26,12 @@ done ft="$profile/filters.txt" fs="$profile/filters.sieve" +ab="$profile/whitelist.abook" -[ -n "$edit" ] && { vim "$ft" || edie "$(basename $0) canceled" } +[ -n "$edit" ] && { vim "$ft" || edie "$(basename $0) canceled"; } [ -f "$ft" ] || edie "no filters.txt file" +[ -f "$ab" ] || edie "no whitelist.abook file" -einfo "adding skel" cat <<EOF > "$fs" # mailbox supports fileinto :create require ["fileinto","mailbox","variables"]; @@ -45,33 +46,19 @@ if header :contains "Sender" "mailman-bounce" { EOF rohrpost rpsieve < "$ft" >> "$fs" +rohrpost rpsieve < "$ab" >> "$fs" -einfo "adding rpabook whitelist" -cat <<EOF >> "$profile/fs" - -# INBOX -if header :contains "From" [ -EOF - -grep '^email' "$profile/whitelist.abook" | \ - sed -e 's/^email=/"/' -e 's/$/",/' | \ - head -c -2 >> "$fs" - - -einfo "finalizing" -cat <<EOF >> "$profile/fs" - -] -{ fileinto :create "INBOX"; stop; } - +cat <<EOF >> "$fs" # spam if header :is "X-Spam-Flag" "YES" { fileinto :create "zz.spam"; stop; } +# everything else fileinto :create "unsorted"; EOF if [ -n "$upload" ]; then einfo "uploading filters.sieve" - scp "$fs" \ - tupac3.dyne.org:/var/vmail/sieve-scripts/"$(readlink $profile)" + host=t3.dyne.org + path=/var/vmail/sieve-scripts/"$(readlink $profile)" + scp "$fs" "$host:$path" || edie "upload failed" fi diff --git a/sieve.c b/sieve.c @@ -58,12 +58,25 @@ int genfrom(char *line) { return 0; } +int genabook(char *line) { + char *email; + + strtok(line, "="); + email = strtok(NULL, "="); + if (!email) return 1; + + printf("if header :contains \"From\" \"%s\"", email); + printf(" { fileinto: create \"INBOX\"; stop; }\n"); + + einfo("from: %s -> INBOX\n", email); + + return 0; +} + int sievemain(int argc, char *argv[]) { int c = 0; char l[MAXLINESIZE]; - einfo("regenerating filters.sieve\n"); - while (fgets(l, sizeof(l), stdin)) { c++; strtok(l, "\n"); @@ -75,6 +88,9 @@ int sievemain(int argc, char *argv[]) { if (genfrom(l)) ewarn("invalid line: %d\n", c); } + else if (!strncmp("email=", l, 6)) { + genabook(l); + } } printf("\n");