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