From 3d70bd5927759d4d09dfeddd05a94e369d5d54fc Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Mon, 11 Jul 2016 16:11:52 +0200 Subject: add hdr --- Makefile | 4 ++-- hdr.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 hdr.c diff --git a/Makefile b/Makefile index 925bf78..2d66f29 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ CFLAGS=-g -O1 -Wall -Wno-switch -Wextra -Wwrite-strings -fstack-protector-strong -D_FORTIFY_SOURCE=2 -ALL = scan thread +ALL = scan thread hdr all: $(ALL) scan: blaze822.o scan.o fmt_rfc2047.o - thread: blaze822.o thread.o +hdr: blaze822.o hdr.o clean: FRC -rm -f $(ALL) *.o diff --git a/hdr.c b/hdr.c new file mode 100644 index 0000000..63485b4 --- /dev/null +++ b/hdr.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "blaze822.h" + +void +header(char *hdr, size_t l, char *file) +{ + struct message *msg; + + msg = blaze822(file); + if (!msg) + return; + + char *v = blaze822_hdr_(msg, hdr, l); + if (v) + printf("%s\n", v); +} + +int +main(int argc, char *argv[]) +{ + char *line = 0; + size_t linelen = 0; + int read; + + int i = 0; + + size_t l = strlen(argv[1])+2; + char *hdr = malloc(l); + hdr[0] = 0; + char *s = hdr+1; + char *t = argv[1]; + while (*t) + *s++ = tolower(*t++); + *s = ':'; + + if (argc == 2 || (argc == 3 && strcmp(argv[1], "-") == 0)) { + while ((read = getdelim(&line, &linelen, '\n', stdin)) != -1) { + if (line[read-1] == '\n') line[read-1] = 0; + header(hdr, l, line); + i++; + } + } else { + for (i = 2; i < argc; i++) { + header(hdr, l, argv[i]); + } + i--; + } + + printf("%d mails scanned\n", i); + + return 0; +} -- cgit 1.4.1