ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
ezmlm-weed.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "stralloc.h"
3#include "str.h"
4#include "byte.h"
5#include "case.h"
6#include "readwrite.h"
7#include "buffer.h"
8#include "getln.h"
9#include "errtxt.h"
10#include "logmsg.h"
11
12#define WHO "ezmlm-weed"
13
19
20static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
21
22void get(stralloc *buf)
23{
24 int match;
25
26 if (getln(buffer_0,buf,&match,'\n') == -1)
27 logmsg(WHO,111,FATAL,ERR_READ_INPUT);
28 if (!match) _exit(0);
29}
30
31stralloc line = {0};
32stralloc line1 = {0};
33stralloc line2 = {0};
34stralloc line3 = {0};
35stralloc line4 = {0};
36stralloc line5 = {0};
37stralloc line6 = {0};
38stralloc line7 = {0};
39stralloc line8 = {0};
40
41stralloc boundary = {0};
42stralloc dsnline = {0};
43
44char warn1[] = " **********************************************";
45char warn2[] = " ** THIS IS A WARNING MESSAGE ONLY **";
46char warn3[] = " ** YOU DO NOT NEED TO RESEND YOUR MESSAGE **";
47char warn4[] = " **********************************************";
48
49int flagmds = 0;
50int flagsw = 0;
51int flagsr = 0;
52int flagas = 0;
53int flagbw = 0;
54int flagdsn = 0;
55
60
62{
63 if (line.s[0] == '-' && line.s[1] == '-' && line.len >= boundary.len + 3)
64 if (!byte_diff(line.s + 2,boundary.len,boundary.s)) /* boundary */
65 return 1;
66 return 0;
67}
68
69int main()
70{
71 unsigned int i,j;
72
73 for (;;) {
74 get(&line);
75 if (line.len == 1) break;
76 if (line.s[0] == ' ' || line.s[0] == '\t') { /* continuation */
77 if (flagdsn) {
78 if (!stralloc_catb(&dsnline,line.s,line.len - 1)) die_nomem();
79 continue;
80 }
81 }
82 flagdsn = 0;
83 if (stralloc_starts(&line,"Subject: success notice"))
84 _exit(99);
85 if (stralloc_starts(&line,"Subject: deferral notice"))
86 _exit(99);
87 if (stralloc_starts(&line,"Precedence: bulk"))
88 _exit(99);
89 if (stralloc_starts(&line,"Precedence: junk"))
90 _exit(99);
91 /* for Novell Groupwise; puh */
92 if (stralloc_starts(&line,"Subject: Message status - delivered"))
93 _exit(99);
94 if (stralloc_starts(&line,"Subject: Message status - opened"))
95 _exit(99);
96 if (stralloc_starts(&line,"Subject: Out of Office AutoReply:"))
97 _exit(99);
98
99 if (stralloc_starts(&line,"From: Mail Delivery Subsystem <MAILER-DAEMON@"))
100 flagmds = 1;
101 if (stralloc_starts(&line,"Subject: Warning: could not send message"))
102 flagsw = 1;
103 if (stralloc_starts(&line,"Subject: Returned mail: warning: cannot send message"))
104 flagsr = 1;
105 if (stralloc_starts(&line,"Auto-Submitted: auto-generated (warning"))
106 flagas = 1;
107 if (case_startb(line.s,line.len,"Content-type: multipart/report"))
108 if (!stralloc_copyb(&dsnline,line.s,line.len - 1)) die_nomem();
109 flagdsn = 1;
110 } /* end of header */
111
112 if (flagdsn) { /* always only one recipient/action */
113 flagdsn = 0; /* will be set for correct report type */
114 for (i=0; i < dsnline.len; i += 1+byte_chr(dsnline.s+i,dsnline.len-i,';')) {
115 while (dsnline.s[i] == ' ' || dsnline.s[i] == '\t')
116 if (++i >= dsnline.len) break;
117
118 if (case_startb(dsnline.s + i,dsnline.len - i,"report-type=")) {
119 i += 12;
120 while (dsnline.s[i] ==' ' || dsnline.s[i] =='\t' || dsnline.s[i] =='"')
121 if (++i >= dsnline.len) break;
122
123 if (case_startb(dsnline.s + i,dsnline.len - i,"delivery-status"))
124 flagdsn = 1;
125 } else if (case_startb(dsnline.s + i,dsnline.len - i,"boundary=")) {
126 i += 9;
127 while (dsnline.s[i] ==' ' || dsnline.s[i] =='\t')
128 if (++i >= dsnline.len) break;
129
130 if (dsnline.s[i] == '"') {
131 if (++i >= dsnline.len) break;
132 j = i + byte_chr(dsnline.s + i,dsnline.len - i,'"');
133 if (j >= dsnline.len) break;
134 } else {
135 j = i;
136 while (dsnline.s[j] !=' ' && dsnline.s[j] !='\t' && dsnline.s[j] !=';')
137 if (++j >= dsnline.len) break;
138 } /* got boundary */
139 if (!stralloc_copyb(&boundary,dsnline.s+i,j-i)) die_nomem();
140 }
141 }
142 }
143 if (flagdsn && boundary.len) { /* parse DSN message */
144 get(&line); /* if bad format we exit(0) via get() */
145 for (;;) {
146 if (isboundary()) {
147 if (line.len == boundary.len + 5 && line.s[line.len - 1] == '-'
148 && line.s[line.len - 2] == '-')
149 _exit(99); /* end: not failure report */
150
151 get(&line); /* Content-type */
152 if (case_startb(line.s,line.len,"content-type:")) {
153 i = 13;
154 while (line.s[i] == ' ' || line.s[i] == '\t')
155 if (++i >= line.len) break;
156
157 if (case_startb(line.s+i,line.len-i,"message/delivery-status")) {
158 for (;;) {
159 get(&line);
160 if (isboundary()) break;
161 if (case_startb(line.s,line.len,"action:")) {
162 i = 8;
163 while (line.s[i] == ' ' || line.s[i] == '\t')
164 if (++i >= line.len) break;
165
166 if (case_startb(line.s + i, line.len - i,"failed"))
167 _exit(0); /* failure notice */
168 else
169 _exit(99); /* there shouldn't be more than 1 action */
170 }
171 }
172 }
173 }
174 } else
175 get(&line);
176 }
177 }
178
179 get(&line1);
180 get(&line2);
181 get(&line3);
182 get(&line4);
183 get(&line5);
184 get(&line6);
185 get(&line7);
186 get(&line8);
187
188 if (stralloc_starts(&line1,"This is a MIME-encapsulated message"))
189 if (stralloc_starts(&line3,"--"))
190 if (stralloc_starts(&line5,warn1))
191 if (stralloc_starts(&line6,warn2))
192 if (stralloc_starts(&line7,warn3))
193 if (stralloc_starts(&line8,warn4))
194 flagbw = 1;
195
196 if (stralloc_starts(&line1,warn1))
197 if (stralloc_starts(&line2,warn2))
198 if (stralloc_starts(&line3,warn3))
199 if (stralloc_starts(&line4,warn4))
200 flagbw = 1;
201
202 if (flagmds && flagsw && flagas && flagbw) _exit(99);
203 if (flagmds && flagsr && flagbw) _exit(99);
204
205 _exit(0);
206
207 return 0;
208}
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
#define ERR_READ_INPUT
Definition errtxt.h:26
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
char boundary[COOKIE]
Definition ezmlm-get.c:89
stralloc line2
Definition ezmlm-get.c:92
int flagas
Definition ezmlm-weed.c:52
stralloc line1
Definition ezmlm-weed.c:32
char warn1[]
Definition ezmlm-weed.c:44
int flagbw
Definition ezmlm-weed.c:53
char warn4[]
Definition ezmlm-weed.c:47
int flagsw
Definition ezmlm-weed.c:50
char warn2[]
Definition ezmlm-weed.c:45
stralloc line5
Definition ezmlm-weed.c:36
stralloc dsnline
Definition ezmlm-weed.c:42
stralloc line8
Definition ezmlm-weed.c:39
char warn3[]
Definition ezmlm-weed.c:46
int flagdsn
Definition ezmlm-weed.c:54
stralloc line3
Definition ezmlm-weed.c:34
stralloc line6
Definition ezmlm-weed.c:37
int flagmds
Definition ezmlm-weed.c:49
int isboundary()
returns 1, if line.len contains the mime bondary, 0 otherwise
Definition ezmlm-weed.c:61
stralloc line4
Definition ezmlm-weed.c:35
stralloc line7
Definition ezmlm-weed.c:38
int flagsr
Definition ezmlm-weed.c:51
int main()
Definition ezmlm-weed.c:69
void get(stralloc *buf)
Definition ezmlm-weed.c:22
char buf[256]
Definition install.c:113
int match
Definition ezmlm-cgi.c:140
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32