2016-07-11 14:11:52 +00:00
|
|
|
#include <sys/stat.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
2016-07-11 14:11:52 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
2016-07-18 15:06:41 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2016-07-11 14:11:52 +00:00
|
|
|
|
|
|
|
#include "blaze822.h"
|
|
|
|
|
2016-07-11 14:28:22 +00:00
|
|
|
static size_t l;
|
|
|
|
static char *hdr;
|
|
|
|
|
2016-07-11 14:11:52 +00:00
|
|
|
void
|
2016-07-11 14:28:22 +00:00
|
|
|
header(char *file)
|
2016-07-11 14:11:52 +00:00
|
|
|
{
|
|
|
|
struct message *msg;
|
|
|
|
|
|
|
|
msg = blaze822(file);
|
|
|
|
if (!msg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char *v = blaze822_hdr_(msg, hdr, l);
|
|
|
|
if (v)
|
|
|
|
printf("%s\n", v);
|
|
|
|
}
|
|
|
|
|
2016-07-14 13:40:57 +00:00
|
|
|
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;
|
2016-07-15 14:51:43 +00:00
|
|
|
while ((h = blaze822_next_header(msg, h))) {
|
|
|
|
char d[4096];
|
|
|
|
blaze822_decode_rfc2047(d, h, sizeof d, "UTF-8");
|
|
|
|
|
|
|
|
printhdr(d);
|
|
|
|
}
|
2016-07-14 13:40:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 14:11:52 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2016-07-20 13:37:09 +00:00
|
|
|
void (*cb)(char *) = headerall;
|
|
|
|
|
|
|
|
if (argc >= 2 && argv[1][0] == '-') {
|
2016-07-14 13:40:57 +00:00
|
|
|
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 = ':';
|
|
|
|
|
2016-07-20 13:37:09 +00:00
|
|
|
cb = header;
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 1 && isatty(0)) {
|
|
|
|
char *cur[] = { "." };
|
|
|
|
blaze822_loop(1, cur, cb);
|
2016-07-14 13:40:57 +00:00
|
|
|
} else {
|
2016-07-20 13:37:09 +00:00
|
|
|
blaze822_loop(argc-1, argv+1, cb);
|
2016-07-14 13:40:57 +00:00
|
|
|
}
|
2016-07-11 14:11:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|