55static void out(
char *s,
int len)
58 else buffer_putflush(buffer_1,s,len);
61static void outs(
char *s) {
out(s,str_len(s)); }
64static void temp() {
_exit(111); }
68 buffer_putsflush(buffer_2,
"qmail-inject: fatal: out of memory\n");
71static void die_invalid(stralloc *
sa)
73 buffer_putsflush(buffer_2,
"qmail-inject: fatal: invalid header field: ");
74 buffer_putflush(buffer_2,
sa->s,
sa->len);
79 buffer_putsflush(buffer_2,
"qmail-inject: fatal: unable to run qmail-queue\n");
82static void die_chdir()
84 buffer_putsflush(buffer_2,
"qmail-inject: fatal: internal bug\n");
90 buffer_putsflush(buffer_2,
"qmail-inject: fatal: read error\n");
93static void doordie(stralloc *
sa,
int r)
97 buffer_putsflush(buffer_2,
"qmail-inject: fatal: unable to parse this line:\n");
98 buffer_putflush(buffer_2,
sa->s,
sa->len);
105static stralloc sauninit = {0};
114static void exitnicely()
132 for (i = 0; i <
hrrlist.len; ++i) {
137 for (i = 0; i <
hrlist.len; ++i) {
147 buffer_puts(buffer_2,
"qmail-inject: fatal: ");
148 buffer_puts(buffer_2,qqx + 1);
149 buffer_puts(buffer_2,
"\n");
150 buffer_flush(buffer_2);
153 buffer_puts(buffer_2,
"qmail-inject: fatal: ");
154 buffer_puts(buffer_2,qqx + 1);
155 buffer_puts(buffer_2,
"\n");
156 buffer_flush(buffer_2);
165static void savedh_append(stralloc *
h)
173static void savedh_print()
177 for (i = 0; i <
savedh.len; ++i)
188static void rwroute(token822_alloc *
addr)
196static void rwextraat(token822_alloc *
addr)
202 for (i = 0; i <
addr->len; ++i)
207static void rwextradot(token822_alloc *
addr)
213 for (i = 0; i <
addr->len; ++i)
218static void rwnoat(token822_alloc *
addr)
223 for (i = 0; i <
addr->len; ++i)
228 for (i =
addr->len - 1; i >= 0; --i)
233 for (i = 0; i < shift; ++i)
237static void rwnodot(token822_alloc *
addr)
242 for (i = 0; i <
addr->len; ++i) {
248 for (i = 0; i <
addr->len; ++i) {
257 for (i =
addr->len - 1; i >= 0; --i)
262 for (i = 0; i < shift; ++i)
266static void rwplus(token822_alloc *
addr)
272 if (!
addr->t[0].slen)
return;
273 if (
addr->t[0].s[
addr->t[0].slen - 1] !=
'+')
return;
280 for (i =
addr->len - 1; i >= 0; --i)
285 for (i = 0; i < shift; ++i)
289static void rwgeneric(token822_alloc *
addr)
291 if (!
addr->len)
return;
295 if (!
addr->t[0].slen)
299 if (!
addr->len)
return;
301 if (!
addr->len)
return;
303 if (!
addr->len)
return;
309static int setreturn(token822_alloc *
addr)
321static int rwreturn(token822_alloc *
addr)
328static int rwsender(token822_alloc *
addr)
334static void rwappend(token822_alloc *
addr,saa *xl)
338 xl->sa[xl->len] = sauninit;
344static int rwhrr(token822_alloc *
addr)
351static int rwhr(token822_alloc *
addr)
358static int rwtocc(token822_alloc *
addr)
372static void doheaderfield(stralloc *
h)
396 rw = rwreturn;
break;
400 rw = rwsender;
break;
410 if (htype ==
H_BCC)
return;
417static void dobody(stralloc *
h)
423token822_alloc
tr = {0};
425static void dorecip(
char *s)
432 buffer_puts(buffer_2,
"qmail-inject: fatal: unable to parse address: ");
433 buffer_puts(buffer_2,s);
434 buffer_putsflush(buffer_2,
"\n");
443token822_alloc
df = {0};
445static void defaultfrommake()
448 fullname = env_get(
"QMAILNAME");
449 if (!fullname) fullname = env_get(
"MAILNAME");
450 if (!fullname) fullname = env_get(
"NAME");
455 df.t[
df.len].s =
"From";
456 df.t[
df.len].slen = 4;
463 df.t[
df.len].s = fullname;
464 df.t[
df.len].slen = str_len(fullname);
491 df.t[
df.len].s = fullname;
492 df.t[
df.len].slen = str_len(fullname);
507static void dodefaultreturnpath()
524 drp.t[
drp.len].s =
"Return-Path";
553static void mft_init()
558 x = env_get(
"QMAILMFTFILE");
569static void finishmft()
572 static stralloc
sa = {0};
573 static stralloc sa2 = {0};
584 outs(
"Mail-Followup-To: ");
596static void finishheader()
604 dodefaultreturnpath();
607 static stralloc
sa = {0};
608 static stralloc sa2 = {0};
614 outs(
"Return-Path: <");
640 outs(
"Resent-Cc: recipient list not shown: ;\n");
655 outs(
"Cc: recipient list not shown: ;\n");
662static void getcontrols()
664 static stralloc
sa = {0};
674 x = env_get(
"QMAILDEFAULTDOMAIN");
682 x = env_get(
"QMAILDEFAULTHOST");
690 x = env_get(
"QMAILPLUSDOMAIN");
698 x = env_get(
"QMAILIDHOST");
702#define RECIP_DEFAULT 1
704#define RECIP_HEADER 3
707int main(
int argc,
char *
const *argv)
717 qmopts = env_get(
"QMAILINJECT");
756 while ((opt = getoptb(argc,(
char **)argv,
"aAhHnNf:")) != opteof)
761 case 'H': recipstrategy =
RECIP_AH;
break;
789 if (
headerbody(buffer_0,doheaderfield,finishheader,dobody) == -1)
int constmap_init(struct constmap *cm, char *s, int len, int flagcolon)
int control_rldef(stralloc *sa, char *fn, int flagme, char *def)
int control_readfile(stralloc *sa, char *fn, int flagme)
int stralloc_copys(stralloc *, char const *)
int headerbody(buffer *b, void(*dohf)(), void(*hdone)(), void(*dobl)())
int hfield_valid(char *s, int len)
int hfield_known(char *s, int len)
#define H_RETURNRECEIPTTO
void h(char *, char *, int, int, int)
void perm(char *prefix1, char *prefix2, char *prefix3, char *file, int type, int uid, int gid, int mode)
int newfield_msgidmake(char *, int, datetime_sec)
int newfield_datemake(datetime_sec newfield_date)
GEN_ALLOC_readyplus(prioq, struct prioq_elt, p, len, a, i, n, x, 100, prioq_readyplus)
stralloc defaultreturnpath
stralloc control_plusdomain
stralloc control_defaultdomain
GEN_ALLOC_typedef(GEN_ALLOC_readyplus(saa, GEN_ALLOC_readyplus(stralloc, GEN_ALLOC_readyplus(sa, GEN_ALLOC_readyplus(len, GEN_ALLOC_readyplus(a)
stralloc control_defaulthost
token822_alloc defaulthost
stralloc defaultdomainbuf
token822_alloc plusdomain
token822_alloc defaultdomain
void qmail_to(struct qmail *, char *)
void qmail_from(struct qmail *, char *)
void qmail_put(struct qmail *, char *, int)
char * qmail_close(struct qmail *)
int qmail_open(struct qmail *)
int quote2(stralloc *, char *)
int quote_need(char *, unsigned int)
int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf)
stralloc stralloc *int token822_addrlist(token822_alloc *, token822_alloc *, token822_alloc *, int(*)())
int token822_unquote(stralloc *, token822_alloc *)
void token822_reverse(token822_alloc *)
int token822_ready(token822_alloc *, unsigned int)
int token822_unparse(stralloc *, token822_alloc *, unsigned int)
int token822_readyplus(token822_alloc *, unsigned int)