aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/upas/ml/mlowner.c
blob: 4ac46b868ef51d22530ca0478990d3865c302a59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "common.h"
#include "dat.h"

Biobuf in;

String *from;
String *sender;


void
usage(void)
{
	fprint(2, "usage: %s address-list-file listname\n", argv0);
	exits("usage");
}

void
main(int argc, char **argv)
{
	String *msg;
	char *alfile;
	char *listname;

	ARGBEGIN{
	}ARGEND;

	rfork(RFENVG);

	if(argc < 2)
		usage();
	alfile = argv[0];
	listname = argv[1];

	if(Binit(&in, 0, OREAD) < 0)
		sysfatal("opening input: %r");

	msg = s_new();

	/* discard the 'From ' line */
	if(s_read_line(&in, msg) == nil)
		sysfatal("reading input: %r");

	/* read up to the first 128k of the message.  more is redculous */
	if(s_read(&in, s_restart(msg), 128*1024) <= 0)
		sysfatal("reading input: %r");

	/* parse the header */
	yyinit(s_to_c(msg), s_len(msg));
	yyparse();

	/* get the sender */
	getaddrs();
	if(from == nil)
		from = sender;
	if(from == nil)
		sysfatal("message must contain From: or Sender:");

	if(strstr(s_to_c(msg), "remove")||strstr(s_to_c(msg), "unsubscribe"))
		writeaddr(alfile, s_to_c(from), 1, listname);
	else if(strstr(s_to_c(msg), "subscribe"))
		writeaddr(alfile, s_to_c(from), 0, listname);

	exits(0);
}