2016-07-25 11:11:33 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "blaze822.h"
|
|
|
|
|
2016-08-09 13:49:46 +00:00
|
|
|
static int aflag;
|
2016-07-25 11:11:33 +00:00
|
|
|
static char defaulthflags[] = "from:sender:reply-to:to:cc:bcc:"
|
|
|
|
"resent-from:resent-sender:resent-to:resent-cc:resent-bcc:";
|
|
|
|
static char *hflag = defaulthflags;
|
|
|
|
|
|
|
|
void
|
|
|
|
addr(char *file)
|
|
|
|
{
|
|
|
|
while (*file == ' ' || *file == '\t')
|
|
|
|
file++;
|
|
|
|
|
|
|
|
struct message *msg = blaze822(file);
|
2016-07-26 19:56:48 +00:00
|
|
|
if (!msg)
|
2016-07-25 11:11:33 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
char *h = hflag;
|
|
|
|
char *v;
|
|
|
|
while (*h) {
|
|
|
|
char *n = strchr(h, ':');
|
|
|
|
if (n)
|
|
|
|
*n = 0;
|
|
|
|
v = blaze822_chdr(msg, h);
|
|
|
|
if (v) {
|
|
|
|
char *disp, *addr;
|
|
|
|
while ((v = blaze822_addr(v, &disp, &addr))) {
|
|
|
|
if (disp && addr && strcmp(disp, addr) == 0)
|
|
|
|
disp = 0;
|
|
|
|
if (disp && addr) {
|
|
|
|
char dispdec[1024];
|
|
|
|
blaze822_decode_rfc2047(dispdec, disp,
|
|
|
|
sizeof dispdec - 1, "UTF-8");
|
|
|
|
dispdec[sizeof dispdec - 1] = 0;
|
|
|
|
|
2016-08-09 13:49:46 +00:00
|
|
|
if (aflag)
|
|
|
|
printf("%s\n", addr);
|
|
|
|
else
|
|
|
|
printf("%s <%s>\n",
|
|
|
|
dispdec, addr);
|
2016-07-25 11:11:33 +00:00
|
|
|
} else if (addr) {
|
|
|
|
printf("%s\n", addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n) {
|
|
|
|
*n = ':';
|
|
|
|
h = n + 1;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2016-07-26 19:56:48 +00:00
|
|
|
int c;
|
2016-08-09 13:49:46 +00:00
|
|
|
while ((c = getopt(argc, argv, "ah:")) != -1)
|
2016-07-26 19:56:48 +00:00
|
|
|
switch(c) {
|
2016-08-09 13:49:46 +00:00
|
|
|
case 'a': aflag = 1; break;
|
2016-07-26 19:56:48 +00:00
|
|
|
case 'h': hflag = optarg; break;
|
|
|
|
default:
|
2016-08-09 13:49:46 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: maddr [-a] [-h headers] [msgs...]\n");
|
2016-07-26 19:56:48 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-07-25 11:11:33 +00:00
|
|
|
|
2016-07-26 19:56:48 +00:00
|
|
|
if (argc == optind && isatty(0))
|
|
|
|
blaze822_loop1(":", addr);
|
|
|
|
else
|
2016-07-25 11:11:33 +00:00
|
|
|
blaze822_loop(argc-optind, argv+optind, addr);
|
|
|
|
|
2016-07-26 19:56:48 +00:00
|
|
|
return 0;
|
2016-07-25 11:11:33 +00:00
|
|
|
}
|