Blob


1 #include "common.h"
2 #include "dat.h"
4 Biobuf in;
6 String *from;
7 String *sender;
10 void
11 usage(void)
12 {
13 fprint(2, "usage: %s address-list-file listname\n", argv0);
14 exits("usage");
15 }
17 void
18 main(int argc, char **argv)
19 {
20 String *msg;
21 char *alfile;
22 char *listname;
24 ARGBEGIN{
25 }ARGEND;
27 rfork(RFENVG);
29 if(argc < 2)
30 usage();
31 alfile = argv[0];
32 listname = argv[1];
34 if(Binit(&in, 0, OREAD) < 0)
35 sysfatal("opening input: %r");
37 msg = s_new();
39 /* discard the 'From ' line */
40 if(s_read_line(&in, msg) == nil)
41 sysfatal("reading input: %r");
43 /* read up to the first 128k of the message. more is redculous */
44 if(s_read(&in, s_restart(msg), 128*1024) <= 0)
45 sysfatal("reading input: %r");
47 /* parse the header */
48 yyinit(s_to_c(msg), s_len(msg));
49 yyparse();
51 /* get the sender */
52 getaddrs();
53 if(from == nil)
54 from = sender;
55 if(from == nil)
56 sysfatal("message must contain From: or Sender:");
58 if(strstr(s_to_c(msg), "remove")||strstr(s_to_c(msg), "unsubscribe"))
59 writeaddr(alfile, s_to_c(from), 1, listname);
60 else if(strstr(s_to_c(msg), "subscribe"))
61 writeaddr(alfile, s_to_c(from), 0, listname);
63 exits(0);
64 }