10 void die_success() { _exit(0); }
11 void die_perm(s
) char *s
; { substdio_putsflush(subfderr
,s
); _exit(100); }
12 void die_temp(s
) char *s
; { substdio_putsflush(subfderr
,s
); _exit(111); }
13 void die_nomem() { die_temp("forward: fatal: out of memory\n"); }
17 int mywrite(fd
,buf
,len
) int fd
; char *buf
; int len
;
19 qmail_put(&qqt
,buf
,len
);
25 char inbuf
[SUBSTDIO_INSIZE
];
37 sender
= env_get("NEWSENDER");
38 if (!sender
) die_perm("forward: fatal: NEWSENDER not set\n");
39 dtline
= env_get("DTLINE");
40 if (!dtline
) die_perm("forward: fatal: DTLINE not set\n");
42 if (qmail_open(&qqt
) == -1) die_temp("forward: fatal: unable to fork\n");
43 qmail_puts(&qqt
,dtline
);
44 substdio_fdbuf(&ssin
,read
,0,inbuf
,sizeof(inbuf
));
45 substdio_fdbuf(&ssout
,mywrite
,-1,outbuf
,sizeof(outbuf
));
46 if (substdio_copy(&ssout
,&ssin
) != 0)
47 die_temp("forward: fatal: error while reading message\n");
48 substdio_flush(&ssout
);
50 qmail_from(&qqt
,sender
);
51 while (*++argv
) qmail_to(&qqt
,*argv
);
52 switch(qmail_close(&qqt
))
54 case 0: die_success();
55 case QMAIL_TOOLONG
: die_perm("forward: fatal: permanent qmail-queue error\n");
56 default: die_temp("forward: fatal: temporary qmail-queue error\n");