23#define WHO "new-inject"
27 logmsg(
WHO,111,FATAL,
"out of memory");
51static void rewritelist(stralloc *list)
54 if (!stralloc_copy(list,&
tmp)) nomem();
67static void recipient_add(
char *addr)
74static void recipient_addlist(stralloc *list)
79 for (j = i = 0; j < list->len; ++j)
81 if (list->s[i] ==
'+')
82 if (!stralloc_catb(&
recipients,list->s + i + 1,j - i)) nomem();
87static void sender_get(stralloc *list)
92 for (j = i = 0; j < list->len; ++j)
94 if (list->s[i] ==
'+')
95 if (!stralloc_copyb(&
sender,list->s + i + 1,j - i)) nomem();
103static void put(
char *
buf,
int len)
108 buffer_put(buffer_1,
buf,len);
111static void spit(
char *
buf)
116static void putlist(
char *
name,stralloc *list)
118 if (!list->len)
return;
144 {
"date", 0, 0, 0, 0, &
date, 0 }
145, {
"to", 0, 0, 0, &
to, 0, 0 }
146, {
"cc", 0, 0, 0, &
cc, 0, 0 }
147, {
"bcc", 0, 0, 0, &
bcc, 0, 0 }
148, {
"apparently-to", 0, 0, 0, &
bcc, 0, 0 }
149, {
"notice-requested-upon-delivery-to", 0, 0, 0, &
nrudt, 0, 0 }
150, {
"from", 0, 0, 0, &
from, 0, 0 }
152, {
"reply-to", 0, 0, 0, &
replyto, 0, 0 }
154, {
"mail-followup-to", 0, 0, 0, &
followupto, 0, 0 }
155, {
"return-path", 0, 0, 0, &
returnpath, 0, 0 }
158, {
"message-id", 0, &
msgid, 0, 0, 0, 0 }
159, {
"received", 0, &
top, 0, 0, 0, 0 }
160, {
"delivered-to", 0, &
top, 0, 0, 0, 0 }
161, {
"errors-to", 0, &
top, 0, 0, 0, 0 }
162, {
"return-receipt-to", 0, &
top, 0, 0, 0, 0 }
163, {
"resent-sender", 0, &
top, 0, 0, 0, 0 }
164, {
"resent-from", 0, &
top, 0, 0, 0, 0 }
165, {
"resent-reply-to", 0, &
top, 0, 0, 0, 0 }
166, {
"resent-to", 0, &
top, 0, 0, 0, 0 }
167, {
"resent-cc", 0, &
top, 0, 0, 0, 0 }
168, {
"resent-bcc", 0, &
top, 0, 0, 0, 0 }
169, {
"resent-date", 0, &
top, 0, 0, 0, 0 }
170, {
"resent-message-id", 0, &
top, 0, 0, 0, 0 }
171, {
"content-length", 0, 0, 0, 0, 0, 0 }
172, { 0, 0, &
bottom, 0, 0, 0, 0 }
175static void envelope_make()
181 recipient_addlist(&
to);
182 recipient_addlist(&
cc);
183 recipient_addlist(&
bcc);
194 if (!stralloc_cats(&
sender,
"-@[]")) nomem();
195 if (!stralloc_0(&
sender)) nomem();
199static void envelope_print()
204 spit(
"Envelope-Sender: ");
209 spit(
"Envelope-Recipients:\n");
220static void datemsgid_print()
232 if (!stralloc_copys(&
msgid,
"Message-ID: <")) nomem();
240 if (!stralloc_cats(&
msgid,
">\n")) nomem();
245static void from_print()
247 putlist(
"From: ",&
from);
250 if (!stralloc_0(&
tmp2)) nomem();
260static int inmft(stralloc *list)
265 for (j = i = 0; j < list->len; ++j)
267 if (list->s[i] ==
'+')
268 if (constmap(&
mapmft,list->s + i + 1,j - i - 1))
275static void response_print()
277 putlist(
"Reply-To: ",&
replyto);
282 if (inmft(&
to) || inmft(&
cc)) {
289static void to_print()
291 if (!
to.len && !
cc.len)
292 spit(
"Cc: recipient list not shown: ;\n");
295 putlist(
"Notice-Requested-Upon-Delivery-To: ",&
nrudt);
298static void finishheader()
304 logmsg(
WHO,111,FATAL,
"unable to run qmail-queue: ");
335static void finishmessage()
342 buffer_flush(buffer_1);
352 if (*qqx) logmsg(
WHO,*qqx ==
'D' ? 100 : 111,FATAL,qqx + 1);
383 while ((opt = getoptb(argc,argv,
"nNaAhHFIMRSf:")) != opteof)
387 case 'a':
case 'A':
case 'h':
case 'H':
recipstrategy = opt;
break;
395 logmsg(
WHO,100,USAGE,
"new-inject [ -nNaAhHFIMRS ] [ -f sender ] [ recip ... ]\n");
400 logmsg(
WHO,111,FATAL,
"unable to init leapsecs: ");
406 logmsg(
WHO,111,FATAL,
"unable to read $QMAILMFTFILE: ");
415 logmsg(
WHO,111,FATAL,
"unable to read $QMAILREWRITEFILE: ");
442 logmsg(
WHO,111,FATAL,
"can't append to rewrite");
447 if (!stralloc_copys(&
sender,
"")) nomem();
450 if (!stralloc_0(&
sender)) nomem();
459 recipient_add(*argv++);
462 unsigned char nowpack[TAI_PACK];
465 tai_pack((
char *)nowpack,&
start);
466 u = nowpack[4]; u <<= 8;
467 u += nowpack[5]; u <<= 8;
468 u += nowpack[6]; u <<= 8;
487 if (getln(buffer_0,&
line,&
match,
'\n') == -1)
488 logmsg(
WHO,111,FATAL,
"unable to read input: ");
491 if (!stralloc_append(&
line,
"\n")) nomem();
496 if (
line.len != 1) put(
"\n",1);
int config_copy(config_str *c, config_str *d)
int config_env(config_str *c, char *s)
int config_default(config_str *c, char *s)
int config_readfile(config_str *c, char *fn)
int rewritehost_list(stralloc *, char *, unsigned int, stralloc *)
int rewritehost_addr(stralloc *, char *, unsigned int, stralloc *)
int mess822_quote(stralloc *, char *, char *)
int mess822_line(mess822_header *, stralloc *)
int mess822_end(mess822_header *)
int mess822_ok(stralloc *)
int mess822_fold(stralloc *, stralloc *, char *, int)
int mess822_date(stralloc *, mess822_time *)
int mess822_begin(mess822_header *, mess822_action *)
int mess822_quotelist(stralloc *, stralloc *)
int rwhconfig(config_str *, stralloc *)
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 flagenveloperecipients
stralloc enveloperecipients
void caltime_utc(struct caltime *ct, struct tai *t, int *pwday, int *pyday)