From a6ce4c720beca915d185f86660c2d52f261ef4b0 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Wed, 20 Jul 2016 13:51:42 +0200 Subject: mthread: rename from thread --- mhdr.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 mhdr.c (limited to 'mhdr.c') diff --git a/mhdr.c b/mhdr.c new file mode 100644 index 0000000..3fc4a7c --- /dev/null +++ b/mhdr.c @@ -0,0 +1,82 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "blaze822.h" + +static size_t l; +static char *hdr; + +void +header(char *file) +{ + struct message *msg; + + msg = blaze822(file); + if (!msg) + return; + + char *v = blaze822_hdr_(msg, hdr, l); + if (v) + printf("%s\n", v); +} + +static void +printhdr(char *hdr) +{ + int uc = 1; + + while (*hdr && *hdr != ':') { + putc(uc ? toupper(*hdr) : *hdr, stdout); + uc = (*hdr == '-'); + hdr++; + } + fputs(hdr, stdout); + fputc('\n', stdout); +} + +void +headerall(char *file) +{ + struct message *msg; + + msg = blaze822(file); + if (!msg) + return; + + char *h = 0; + while ((h = blaze822_next_header(msg, h))) { + char d[4096]; + blaze822_decode_rfc2047(d, h, sizeof d, "UTF-8"); + + printhdr(d); + } +} + +int +main(int argc, char *argv[]) +{ + if (argv[1] && argv[1][0] == '-') { + l = strlen(argv[1])+1; + hdr = malloc(l); + hdr[0] = 0; + char *s = hdr+1; + char *t = argv[1]+1; + while (*t) + *s++ = tolower(*t++); + *s = ':'; + + blaze822_loop(argc-2, argv+2, header); + } else { + blaze822_loop(argc-1, argv+1, headerall); + } + + return 0; +} -- cgit 1.4.1