Commit | Line | Data |
---|---|---|
5b62e993 MW |
1 | #include "strerr.h" |
2 | #include "substdio.h" | |
3 | #include "readwrite.h" | |
4 | #include "stralloc.h" | |
5 | #include "getln.h" | |
6 | #include "sgetopt.h" | |
7 | ||
8 | int flagrejectcommands = 1; | |
9 | int flagneedsubject = 1; | |
10 | ||
11 | int flaghavesubject = 0; | |
12 | int flaghavecommand = 0; | |
13 | ||
14 | char buf0[256]; | |
15 | substdio ss0 = SUBSTDIO_FDBUF(read,0,buf0,sizeof(buf0)); | |
16 | stralloc line = {0}; | |
17 | ||
18 | void main(argc,argv) | |
19 | int argc; | |
20 | char **argv; | |
21 | { | |
22 | int opt; | |
23 | char *x; | |
24 | int len; | |
25 | int match; | |
26 | ||
27 | while ((opt = getopt(argc,argv,"cCsS")) != opteof) | |
28 | switch(opt) { | |
29 | case 'c': flagrejectcommands = 1; break; | |
30 | case 'C': flagrejectcommands = 0; break; | |
31 | case 's': flagneedsubject = 1; break; | |
32 | case 'S': flagneedsubject = 0; break; | |
33 | default: | |
34 | strerr_die1x(100,"ezmlm-reject: usage: ezmlm-reject [ -cCsS ]"); | |
35 | } | |
36 | ||
37 | for (;;) { | |
38 | if (getln(&ss0,&line,&match,'\n') == -1) | |
39 | strerr_die2sys(111,"ezmlm-reject: fatal: ","unable to read input: "); | |
40 | if (!match) break; | |
41 | if (line.len == 1) break; | |
42 | ||
43 | x = line.s; len = line.len - 1; | |
44 | while (len && ((x[len - 1] == ' ') || (x[len - 1] == '\t'))) --len; | |
45 | ||
46 | if (case_startb(x,len,"subject:")) { | |
47 | x += 8; len -= 8; | |
48 | while (len && ((*x == ' ') || (*x == '\t'))) { ++x; --len; } | |
49 | if (len) { | |
50 | flaghavesubject = 1; | |
51 | ||
52 | if (len == 4) | |
53 | if (!case_diffb("help",4,x)) | |
54 | flaghavecommand = 1; | |
55 | ||
56 | if (len == 9) | |
57 | if (!case_diffb("subscribe",9,x)) | |
58 | flaghavecommand = 1; | |
59 | ||
60 | if (len == 11) | |
61 | if (!case_diffb("unsubscribe",11,x)) | |
62 | flaghavecommand = 1; | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | if (flagneedsubject && !flaghavesubject) | |
68 | strerr_die1x(100,"\ | |
69 | ezmlm-reject: fatal: I need a nonempty Subject line in every message.\n\ | |
70 | If you are trying to subscribe or unsubscribe, WRONG ADDRESS!\n\ | |
71 | Do not send administrative requests to the mailing list.\n\ | |
72 | Send an empty message to ...-help@... for automated assistance."); | |
73 | ||
74 | if (flagrejectcommands && flaghavecommand) | |
75 | strerr_die1x(100,"\ | |
76 | ezmlm-reject: fatal: Your Subject line looks like a command word.\n\ | |
77 | If you are trying to subscribe or unsubscribe, WRONG ADDRESS!\n\ | |
78 | Do not send administrative requests to the mailing list.\n\ | |
79 | Send an empty message to ...-help@... for automated assistance."); | |
80 | ||
81 | _exit(0); | |
82 | } |