10 #include "readsubdir.h"
11 #include "auto_qmail.h"
14 #include "date822fmt.h"
15 #include "readwrite.h"
21 void die(n
) int n
; { substdio_flush(subfdout
); _exit(n
); }
23 void warn(s1
,s2
) char *s1
; char *s2
;
27 substdio_puts(subfdout
,s1
);
28 substdio_puts(subfdout
,s2
);
29 substdio_puts(subfdout
,": ");
30 substdio_puts(subfdout
,x
);
31 substdio_puts(subfdout
,"\n");
34 void die_nomem() { substdio_puts(subfdout
,"fatal: out of memory\n"); die(111); }
35 void die_chdir() { warn("fatal: unable to chdir",""); die(111); }
36 void die_opendir(fn
) char *fn
; { warn("fatal: unable to opendir ",fn
); die(111); }
38 void err(id
) unsigned long id
;
41 foo
[fmt_ulong(foo
,id
)] = 0;
42 warn("warning: trouble with #",foo
);
48 char fnremote
[FMTQFN
];
49 char fnbounce
[FMTQFN
];
52 stralloc sender
= {0};
59 unsigned int fmtstats(s
)
67 datetime_tai(&dt
,qtime
);
68 i
= date822fmt(s
,&dt
) - 7/*XXX*/; len
+= i
; if (s
) s
+= i
;
69 i
= fmt_str(s
," GMT #"); len
+= i
; if (s
) s
+= i
;
70 i
= fmt_ulong(s
,id
); len
+= i
; if (s
) s
+= i
;
71 i
= fmt_str(s
," "); len
+= i
; if (s
) s
+= i
;
72 i
= fmt_ulong(s
,size
); len
+= i
; if (s
) s
+= i
;
73 i
= fmt_str(s
," <"); len
+= i
; if (s
) s
+= i
;
74 i
= fmt_str(s
,sender
.s
+ 1); len
+= i
; if (s
) s
+= i
;
75 i
= fmt_str(s
,"> "); len
+= i
; if (s
) s
+= i
;
78 i
= fmt_str(s
," bouncing"); len
+= i
; if (s
) s
+= i
;
86 void out(s
,n
) char *s
; unsigned int n
;
90 substdio_put(subfdout
,((*s
>= 32) && (*s
<= 126)) ? s
: "_",1);
95 void outs(s
) char *s
; { out(s
,str_len(s
)); }
96 void outok(s
) char *s
; { substdio_puts(subfdout
,s
); }
100 if (!stralloc_ready(&stats
,fmtstats(FMT_LEN
))) die_nomem();
101 stats
.len
= fmtstats(stats
.s
);
102 out(stats
.s
,stats
.len
);
117 if (chdir(auto_qmail
) == -1) die_chdir();
118 if (chdir("queue") == -1) die_chdir();
119 readsubdir_init(&rs
,"info",die_opendir
);
121 while (x
= readsubdir_next(&rs
,&id
))
124 fmtqfn(fnmess
,"mess/",id
,1);
125 fmtqfn(fninfo
,"info/",id
,1);
126 fmtqfn(fnlocal
,"local/",id
,1);
127 fmtqfn(fnremote
,"remote/",id
,1);
128 fmtqfn(fnbounce
,"bounce/",id
,0);
130 if (stat(fnmess
,&st
) == -1) { err(id
); continue; }
132 flagbounce
= !stat(fnbounce
,&st
);
134 fd
= open_read(fninfo
);
135 if (fd
== -1) { err(id
); continue; }
136 substdio_fdbuf(&ss
,read
,fd
,inbuf
,sizeof(inbuf
));
137 if (getln(&ss
,&sender
,&match
,0) == -1) die_nomem();
138 if (fstat(fd
,&st
) == -1) { close(fd
); err(id
); continue; }
144 for (channel
= 0;channel
< 2;++channel
)
146 fd
= open_read(channel ? fnremote
: fnlocal
);
149 if (errno
!= error_noent
)
156 if (getln(&ss
,&line
,&match
,0) == -1) die_nomem();
163 outok(channel ?
"\tremote\t" : "\tlocal\t");