38#define WHO "ezmlm-warn"
46static void die_usage() {
logmsg(
WHO,100,USAGE,
"ezmlm-warn -dD -l secs -t days dir"); }
49stralloc outhost = {0};
50stralloc outlocal = {0};
78 if (mkdir(s,0755) == -1)
89char strnum[FMT_ULONG];
126 fd = open_read(
fn.s);
131 if (!
match) { close(
fd);
return; }
150 hdr_add2(
"\nList-ID: ",line.s,line.len);
170 ezcopy(&
qq,flagw ?
"text/bounce-probe" :
"text/bounce-warn",
flagcd);
178 fdhash = open_read(
fnhash.s);
183 buffer_init(&bt,buffer_unixread,fdhash,textbuf,
sizeof(textbuf));
185 if (getln(&bt,&line,&
match,
'\n') == -1)
193 if (!stralloc_copys(&line,
""))
die_nomem();
194 if (openreadclose(
fnhash.s,&line,256) < 0)
216 strnum[fmt_ulong(strnum,
when)] = 0;
217 cookie(hash,key.s,key.len,strnum,
addr.s,flagw ?
"P" :
"W");
218 if (!stralloc_copy(&line,&outlocal))
die_nomem();
219 if (!stralloc_cats(&line,flagw ?
"-return-probe-" :
"-return-warn-"))
221 if (!stralloc_cats(&line,strnum))
die_nomem();
222 if (!stralloc_cats(&line,
"."))
die_nomem();
224 if (!stralloc_cats(&line,
"-"))
die_nomem();
225 i = str_chr(
addr.s,
'@');
228 if (!stralloc_cats(&line,
"="))
die_nomem();
231 if (!stralloc_cats(&line,
"@"))
die_nomem();
232 if (!stralloc_cat(&line,&outhost))
die_nomem();
244 if (unlink(
fnhash.s) == -1)
248 if (unlink(
fn.s) == -1)
254 DIR *bouncedir, *bsdir, *hdir;
256 unsigned long bouncedate;
258 unsigned long lockout = 0L;
260 unsigned long ddir, dfile;
268 while ((
opt = getoptb(argc,argv,
"dDl:t:vV")) != opteof)
272 case 'l':
if (optarg) {
273 scan_ulong(optarg,&lockout);
276 case 't':
if (optarg) {
277 scan_ulong(optarg,&bouncetimeout);
278 bouncetimeout *= 3600L * 24L;
283 default: die_usage();
286 if (!
dir) die_usage();
287 if (chdir(
dir) == -1)
303 scan_ulong(
lastd.s,&ld);
305 lockout = bouncetimeout / 50;
306 if (ld + lockout >
when && ld <
when)
313 switch (openreadclose(
"key",&key,32)) {
320 if (!stralloc_cats(&outlocal,
"-digest"))
die_nomem();
340 if (!stralloc_cats(&line,
"/lockbounce"))
die_nomem();
345 if (!stralloc_cats(&line,
"/bounce/d"))
die_nomem();
347 bouncedir = opendir(line.s);
354 while ((d = readdir(bouncedir))) {
355 if (str_equal(d->d_name,
"."))
continue;
356 if (str_equal(d->d_name,
".."))
continue;
358 scan_ulong(d->d_name,&bouncedate);
365 if (bouncetimeout) ++bouncedate;
366 if (
when >= bouncedate * 10000 + bouncetimeout) {
371 bsdir = opendir(
bdname.s);
373 if (errno != ENOTDIR)
376 if (unlink(
bdname.s) == -1)
381 while ((ds = readdir(bsdir))) {
382 if (str_equal(ds->d_name,
"."))
continue;
383 if (str_equal(ds->d_name,
".."))
continue;
385 fn.s[
fn.len - 1] =
'/';
388 if ((ds->d_name[0] ==
'd') || (ds->d_name[0] ==
'w'))
389 doit(ds->d_name[0] ==
'w');
391 if (unlink(
fn.s) == -1)
395 if (rmdir(
bdname.s) == -1)
403 line.s[line.len - 2] =
'D';
404 fd = open_trunc(line.s);
409 if (buffer_put(&
bo,strnum,fmt_ulong(strnum,
when)) == -1)
411 if (buffer_put(&
bo,
"\n",1) == -1)
413 if (buffer_flush(&
bo) == -1)
420 if (rename(line.s,
fnlastd.s) == -1)
426 if (stat(
fnlasth.s,&st) == -1) {
437 if (ch >=
'a' && ch <=
'o')
443 if (!stralloc_cats(&line,
"/bounce/h/"))
die_nomem();
446 hdir = opendir(line.s);
452 while ((d = readdir(hdir))) {
453 if (str_equal(d->d_name,
"."))
continue;
454 if (str_equal(d->d_name,
".."))
continue;
459 if (stat(
fn.s,&st) == -1) {
460 if (errno == ENOENT)
continue;
463 if (
when > st.st_mtime + 3 * bouncetimeout)
464 if (unlink(
fn.s) == -1)
475 if (buffer_put(&
bo,
lasth.s,1) == -1)
477 if (buffer_put(&
bo,
"\n",1) == -1)
479 if (buffer_flush(&
bo) == -1)
int issub()
Returns (char *) to match if userhost is in the subscriber database dbname, 0 otherwise....
int quote2(stralloc *sa, const char *s)
const char auto_version[]
#define hdr_listsubject1(a)
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_TMP_QMAIL_QUEUE
int lockfile(const char *)
const char * qmail_close(struct qmail *)
void qmail_puts(struct qmail *, const char *)
void qmail_put(struct qmail *, const char *, int)
void qmail_from(struct qmail *, const char *)
void qmail_to(struct qmail *, const char *)
unsigned long qmail_qp(struct qmail *)
int qmail_open(struct qmail *, const stralloc *)
charset, outhost, outlocal and flagcd are shared
void closesql(void)
close connection to SQL server, if open
int getconf_line(stralloc *sa, const char *fn, int flagrequired, const char *dir)
void ezcopy(struct qmail *qqp, const char *fn, char q)
void set_cpoutlocal(const stralloc *ln)
void set_cpouthost(const stralloc *ln)
void encode_qp(const char *indata, unsigned int n, stralloc *outdata)
void hdr_from(const char *append)
void hdr_boundary(int last)
void hdr_datemsgid(unsigned long when)
void cookie(char *hash, const char *key, unsigned int keylen, const char *date, const char *addr, const char *action)
ssize_t qqwrite(int fd, char *buf, unsigned int len)
void code_qput(char *s, unsigned int n)
ssize_t qqwrite(int fd, char *buf, unsigned int len)
void hdr_transferenc(void)
void hdr_add2(const char *start, const char *value, unsigned int len)
void encode_b64(const unsigned char *indata, unsigned int n, stralloc *outdata, int control)
void hdr_ctype(enum ctype ctype)
void hdr_mime(enum ctype ctype)
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)