nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

forward.c (1275B)


      1 #include "sig.h"
      2 #include "readwrite.h"
      3 #include "env.h"
      4 #include "qmail.h"
      5 #include "strerr.h"
      6 #include "substdio.h"
      7 #include "fmt.h"
      8 
      9 #define FATAL "forward: fatal: "
     10 
     11 void die_nomem() { strerr_die2x(111,FATAL,"out of memory"); }
     12 
     13 struct qmail qqt;
     14 
     15 GEN_QMAILPUT_WRITE(&qqt)
     16 
     17 char inbuf[SUBSTDIO_INSIZE];
     18 char outbuf[1];
     19 substdio ssin = SUBSTDIO_FDBUF(read,0,inbuf,sizeof(inbuf));
     20 substdio ssout = SUBSTDIO_FDBUF(qmail_put_write,-1,outbuf,sizeof(outbuf));
     21 
     22 char num[FMT_ULONG];
     23 
     24 int main(int argc, char **argv)
     25 {
     26   char *sender;
     27   char *dtline;
     28   char *qqx;
     29   int i;
     30  
     31   sig_pipeignore();
     32  
     33   sender = env_get("NEWSENDER");
     34   if (!sender)
     35     strerr_die2x(100,FATAL,"NEWSENDER not set");
     36   dtline = env_get("DTLINE");
     37   if (!dtline)
     38     strerr_die2x(100,FATAL,"DTLINE not set");
     39  
     40   if (qmail_open(&qqt) == -1)
     41     strerr_die2sys(111,FATAL,"unable to fork: ");
     42   qmail_puts(&qqt,dtline);
     43   if (substdio_copy(&ssout,&ssin) != 0)
     44     strerr_die2sys(111,FATAL,"unable to read message: ");
     45   substdio_flush(&ssout);
     46 
     47   num[fmt_ulong(num,qmail_qp(&qqt))] = 0;
     48  
     49   qmail_from(&qqt,sender);
     50   for (i = 1; i < argc; i++)
     51     qmail_to(&qqt,argv[i]);
     52   qqx = qmail_close(&qqt);
     53   if (*qqx) strerr_die2x(*qqx == 'D' ? 100 : 111,FATAL,qqx + 1);
     54   strerr_die2x(0,"forward: qp ",num);
     55 }