Import ezmlm 0.53
[ezmlm] / ezmlm-reject.c
CommitLineData
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
8int flagrejectcommands = 1;
9int flagneedsubject = 1;
10
11int flaghavesubject = 0;
12int flaghavecommand = 0;
13
14char buf0[256];
15substdio ss0 = SUBSTDIO_FDBUF(read,0,buf0,sizeof(buf0));
16stralloc line = {0};
17
18void main(argc,argv)
19int argc;
20char **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,"\
69ezmlm-reject: fatal: I need a nonempty Subject line in every message.\n\
70If you are trying to subscribe or unsubscribe, WRONG ADDRESS!\n\
71Do not send administrative requests to the mailing list.\n\
72Send an empty message to ...-help@... for automated assistance.");
73
74 if (flagrejectcommands && flaghavecommand)
75 strerr_die1x(100,"\
76ezmlm-reject: fatal: Your Subject line looks like a command word.\n\
77If you are trying to subscribe or unsubscribe, WRONG ADDRESS!\n\
78Do not send administrative requests to the mailing list.\n\
79Send an empty message to ...-help@... for automated assistance.");
80
81 _exit(0);
82}