dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

commit f44e90793792adb1053df7627fdc79d33af0027f
parent 14138b3923ba0d41913d7331e9adc51040df063e
Author: nibble <unknown>
Date:   Mon,  2 Nov 2009 13:18:45 +0100

* Added dmc-filter
  - add/remove/modify headers
  - filter headers/body
* Added dmc-filter into Makefile
Diffstat:
Makefile | 6+++++-
filter.c | 43+++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -8,7 +8,7 @@ endif CFLAGS+=-DHAVE_SSL=${HAVE_SSL} CFLAGS+=-DVERSION=\"${VERSION}\" -BINS=dmc-mbox dmc-smtp dmc-pop3 dmc-imap4 dmc-pack dmc-mbox +BINS=dmc-mbox dmc-smtp dmc-pop3 dmc-imap4 dmc-pack dmc-filter dmc-mbox all: config.mk ${BINS} @@ -26,6 +26,9 @@ dmc-mbox: mbox.o dmc-pack: pack.o ${CC} ${LDFLAGS} pack.o -o dmc-pack +dmc-filter: filter.o + ${CC} ${LDFLAGS} filter.o -o dmc-filter + dmc-pop3: pop3.o ${CC} ${LDFLAGS} ${SSL_LIBS} pop3.o -o dmc-pop3 @@ -41,6 +44,7 @@ install: cp -f dmc-pop3 ${PREFIX}/bin cp -f dmc-imap4 ${PREFIX}/bin cp -f dmc-pack ${PREFIX}/bin + cp -f dmc-filter ${PREFIX}/bin cp -f dmc-mbox ${PREFIX}/bin cp -f dmc-mdir ${PREFIX}/bin diff --git a/filter.c b/filter.c @@ -0,0 +1,43 @@ +/* dmc :: Copyleft -- nibble (at) develsec (dot) org */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main (int argc, char **argv) +{ + char b[1024], *ptr; + int edit = argc, print, i; + + for (i = 0; i < argc; i++) + if (!strcmp (argv[i], "-h")) { + printf ("usage: [fields | :] %s [-he] [new fields]\n", argv[0]); + return 1; + } else if (!strcmp (argv[i], "-e")) + edit = i + 1; + + memset (b, '\0', 1024); + /* Headers */ + while (fgets (b, 1023, stdin) && b[0] != '\n') + for (i = 0, print = 1; i < edit && argv[i]; i++) + if (strstr (b, argv[i])) { + for (i = edit; i < argc && argv[i]; i++) + if ((ptr = strchr (argv[i], ':')) && + !strncmp (b, argv[i], ptr - argv[i])) { + if (ptr[1] != '\0') + puts (argv[i]); + argv[i][0] = '\0'; + print = 0; + } + if (print) fputs (b, stdout); + } + /* New Headers */ + for (i = edit; i < argc; i++) + if ((ptr = strchr (argv[i], ':')) && ptr[1] != '\0') puts (argv[i]); + if (edit < argc) + puts (""); + /* Body */ + while ((argc < 2 || edit < argc) && fgets (b, 1023, stdin)) + fputs (b, stdout); + return 0; +}