X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fwhom.c;h=d313f05656097d0621b3e609404131abc029e75a;hp=4b15fbdc8163a107a52a31f29a44750d41dbd101;hb=ca2931beaec23f8e1d2f98d15d7e9974009278b0;hpb=52b505680a84ec29ff8b0a73553f96b002638132 diff --git a/uip/whom.c b/uip/whom.c index 4b15fbd..d313f05 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -22,13 +22,17 @@ static struct swit switches[] = { { "tocc", 0 }, #define NTOCCSW 3 { "notocc", 2 }, -#define BCCSW 4 +#define DCCSW 4 + { "dcc", 0 }, +#define NDCCSW 5 + { "nodcc", 2 }, +#define BCCSW 6 { "bcc", 0 }, -#define NBCCSW 5 +#define NBCCSW 7 { "nobcc", 2 }, -#define ALISW 6 +#define ALISW 8 { "alias", 0 }, -#define NALISW 7 +#define NALISW 9 { "noalias", 2 }, { NULL, 0 } }; @@ -39,7 +43,8 @@ static struct swit switches[] = { #define HRESENT (1<<1) #define HTO (1<<2) #define HCC (1<<3) -#define HBCC (1<<4) +#define HDCC (1<<4) +#define HBCC (1<<5) struct mailname head = {0}; struct mailname *mp = &head; @@ -48,10 +53,12 @@ static char *cmd; static int resent = 0; /* consider normal or resent headers */ static int toccsw = 1; /* list sighted recipients */ -static int bccsw = 1; /* list hidden recipients */ +static int dccsw = 1; /* list hidden dcc recipients */ +static int bccsw = 1; /* list hidden bcc recipients */ static int alisw = 1; /* expand aliases on rcpt addrs */ -static char *separator = "\t==BCC=="; +static char *dccsep = "\t==DCC=="; +static char *bccsep = "\t==BCC=="; /* @@ -60,6 +67,7 @@ static char *separator = "\t==BCC=="; static int process(char *); static void proc_hdr(char *, char *); static int print(void); +static int printdcc(void); static int printbcc(void); static void printone(struct mailname *); @@ -109,6 +117,13 @@ main(int argc, char **argv) toccsw = 0; continue; + case DCCSW: + dccsw = 1; + continue; + case NDCCSW: + dccsw = 0; + continue; + case BCCSW: bccsw = 1; continue; @@ -135,8 +150,8 @@ main(int argc, char **argv) if (!filep) { adios(EX_USAGE, NULL, "usage: %s [switches] file ...", invo_name); } - if (!toccsw && !bccsw) { - adios(EX_USAGE, NULL, "give -tocc or -bcc or both to produce output"); + if (!toccsw && !dccsw && !bccsw) { + adios(EX_USAGE, NULL, "use at least one of: -tocc -dcc -bcc"); } for (filep=0; files[filep]; filep++) { process(files[filep]); @@ -156,6 +171,19 @@ main(int argc, char **argv) naddrs += n; cmd = add("ali -list", NULL); + if ((n=printdcc()) && alisw) { + if (!(in = popen(cmd, "r"))) { + adios(EX_IOERR, "popen", "unable to"); + } + while (fgets(buf, sizeof buf, in)) { + fputs(buf, stdout); + } + pclose(in); + } + free(cmd); + naddrs += n; + + cmd = add("ali -list", NULL); if ((n=printbcc()) && alisw) { if (!(in = popen(cmd, "r"))) { adios(EX_IOERR, "popen", "unable to"); @@ -167,6 +195,7 @@ main(int argc, char **argv) } free(cmd); naddrs += n; + return naddrs ? 0 : 1; } @@ -242,12 +271,16 @@ proc_hdr(char *name, char *val) type = HTO; } else if (mh_strcasecmp(name, "cc")==0) { type = HCC; + } else if (mh_strcasecmp(name, "dcc")==0) { + type = HDCC; } else if (mh_strcasecmp(name, "bcc")==0) { type = HBCC; } else if (mh_strcasecmp(name, "resent-to")==0) { type = (HRESENT | HTO); } else if (mh_strcasecmp(name, "resent-cc")==0) { type = (HRESENT | HCC); + } else if (mh_strcasecmp(name, "resent-dcc")==0) { + type = (HRESENT | HDCC); } else if (mh_strcasecmp(name, "resent-bcc")==0) { type = (HRESENT | HBCC); } @@ -259,6 +292,9 @@ proc_hdr(char *name, char *val) if ((type&HTO || type&HCC) && !toccsw) { return; } + if ((type&HDCC) && !dccsw) { + return; + } if ((type&HBCC) && !bccsw) { return; } @@ -302,6 +338,30 @@ print(void) ** Walk through the list of addresses and print the right ones. */ static int +printdcc(void) +{ + int naddrs = 0; + + for (mp=head.m_next; mp; mp=mp->m_next) { + /* skip unless both are resent or neither one is */ + if (resent != (mp->m_type&HRESENT)) { + continue; + } + if (mp->m_type & HDCC) { + if (!naddrs && (toccsw || bccsw)) { + puts(dccsep); + } + naddrs++; + printone(mp); + } + } + return naddrs; +} + +/* +** Walk through the list of addresses and print the right ones. +*/ +static int printbcc(void) { int naddrs = 0; @@ -312,8 +372,8 @@ printbcc(void) continue; } if (mp->m_type & HBCC) { - if (!naddrs && toccsw) { - puts(separator); + if (!naddrs && (toccsw || dccsw)) { + puts(bccsep); } naddrs++; printone(mp);