rp

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

commit b5ad207a6a8154d480c106b806b0c30b45bfad83
parent 3f114cd8cb6f27aea493842ac778c526fcaaa704
Author: parazyd <parazyd@dyne.org>
Date:   Wed, 28 Feb 2018 20:20:20 +0100

Add rohrpost rpsieve.

Diffstat:
MMakefile | 11++++++++---
Mmisc/filters.txt | 19+++++++++++--------
Mrohrpost.c | 21+++++++++++++++++++--
Asieve.c | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asieve.h | 11+++++++++++
5 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,9 +5,14 @@ include config.mk BIN = $(NAME) -OBJ = $(BIN:=.o) headers.o ind.o +OBJ = $(BIN:=.o) headers.o ind.o sieve.o all: $(BIN) + cp -f $(NAME) bin + cd bin; \ + for i in `../$(NAME) -i`; do \ + ln -fs $(NAME) $$i; \ + done $(OBJ): config.mk @@ -30,8 +35,8 @@ install: all chmod 755 $(DESTDIR)$(PREFIX)/bin/$$i; \ done; \ for i in `../$(NAME) -i`; do \ - ln -s $(NAME) $$i; \ - done + cp -a $$i $(DESTDIR)$(PREFIX)/bin; \ + done; cp $(NAME) $(DESTDIR)$(PREFIX)/bin chmod 755 $(DESTDIR)$(PREFIX)/bin/$(NAME) sed "s,SHAREPREFIX,$(SHAREPREFIX),g" < bin/rpinit > $(DESTDIR)$(PREFIX)/bin/rpinit diff --git a/misc/filters.txt b/misc/filters.txt @@ -1,14 +1,17 @@ # filter configuration for rp # this file is parsed by rpsieve and generates filters.sieve +# due to laziness, make sure the first declarations are "to", and then "from" -from twitter.com save zz.social -from facebookmail.com save zz.social -from feedback@slack.com save zz.spam +# mailinglists +to,heads@lists.dyne.org,save,dyne.heads +to,unsystem@lists.dyne.org,save,dyne.unsystem +to,gopher-project@other.debian.org,save,debian.gopher-project -# mailinglists -to heads@lists.dyne.org save dyne.heads -to unsystem@lists.dyne.org save dyne.unsystem -from gerrit@coreboot.org save coreboot.gerrit -to gopher-project@other.debian.org save debian.gopher-project +# random + +from,twitter.com,save,zz.social +from,facebookmail.com,save,zz.social +from,feedback@slack.com,save,zz.spam +from,gerrit@coreboot.org,save,coreboot.gerrit diff --git a/rohrpost.c b/rohrpost.c @@ -10,6 +10,7 @@ #include "arg.h" #include "headers.h" #include "ind.h" +#include "sieve.h" char *argv0; @@ -31,16 +32,32 @@ enum { }; struct command cmds[] = { - {"rpheaders", DOINSTALL, headersmain}, + {"rpheaders", DOINSTALL, headersmain}, + {"rpsieve", DONTINSTALL, sievemain}, }; int main(int argc, char *argv[]) { int i; + char *lsl; + + for (i = 0; i < nelem(cmds); i++) { + lsl = strrchr(argv[0], '/'); + if (lsl == NULL) { + lsl = argv[0]; + } else { + lsl++; + } + + if (!strcmp(lsl, cmds[i].cmd)) + return cmds[i].main(argc, argv); + } + ARGBEGIN { case 'i': for (i = 0; i < nelem(cmds); i++) - printf("%s\n", cmds[i].cmd); + if (cmds[i].flags & DOINSTALL) + printf("%s\n", cmds[i].cmd); return 0; default: usage(); diff --git a/sieve.c b/sieve.c @@ -0,0 +1,82 @@ +/* + * Copy me if you can + * by parazyd + */ + +#include <stdio.h> +#include <string.h> + +#include "arg.h" +#include "ind.h" + +char *argv0; + + +int gento(char *line) { + char *type, *email, *what, *mbox; + + type = strtok(line, ","); + if (!type) return 1; + + email = strtok(NULL, ","); + if (!email) return 1; + + what = strtok(NULL, ","); + if (!what) return 1; + + mbox = strtok(NULL, ","); + if (!mbox) return 1; + + printf("if header :contains [\"To\",\"Cc\"] \"%s\"", email); + printf(" { fileinto :create \"%s\"; stop; }\n", mbox); + + einfo("to: %s -> %s\n", email, mbox); + + return 0; +} + +int genfrom(char *line) { + char *type, *email, *what, *mbox; + + type = strtok(line, ","); + if (!type) return 1; + + email = strtok(NULL, ","); + if (!email) return 1; + + what = strtok(NULL, ","); + if (!what) return 1; + + mbox = strtok(NULL, ","); + if (!mbox) return 1; + + printf("if header :contains \"From\" \"%s\"", email); + printf(" { fileinto :create \"%s\"; stop; }\n", mbox); + + einfo("from: %s -> %s\n", email, mbox); + + 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"); + if (!strncmp("to", l, 2)) { + if (gento(l)) + ewarn("invalid line: %d\n", c); + } + else if (!strncmp("from", l, 4)) { + if (genfrom(l)) + ewarn("invalid line: %d\n", c); + } + } + printf("\n"); + + return 0; +} diff --git a/sieve.h b/sieve.h @@ -0,0 +1,11 @@ +/* + * Copy me if you can + * by parazyd + */ + +#ifndef __SIEVE_H__ +#define __SIEVE_H__ + +int sievemain(int argc, char *argv[]); + +#endif