home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / uk-1.4 / part4 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  29.6 KB

  1. From: Jim Crammond <seismo!mcvax!cs.hw.ac.uk!jim>
  2. Subject: Sendmail UK-1.4 part 4 of 5
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 4, Issue 59
  7. Submitted by: Jim Crammond <seismo!mcvax!cs.hw.ac.uk!jim>
  8.  
  9.  
  10. #    This is a shell archive.
  11. #    Remove everything above and including the cut line.
  12. #    Then run the rest of the file through sh.
  13. -----cut here-----cut here-----cut here-----cut here-----
  14. #!/bin/sh
  15. # shar:    Shell Archiver
  16. #    Run the following text with /bin/sh to create:
  17. #    Support
  18. # This archive created: Sat Mar  1 14:35:21 1986
  19. echo shar: creating directory Support
  20. mkdir Support
  21. cd Support
  22. echo shar: extracting Makefile '(1208 characters)'
  23. cat << \SHAR_EOF > Makefile
  24. #
  25. #  Makefile for assorted programs related to Sendmail.
  26. #
  27. #    @(#)Makefile    UK-1.4 sendmail configuartion        12/2/86
  28. #
  29. CFLAGS=-O
  30. #CFLAGS=-O -Dvoid=int   # some pdp11's need this
  31.  
  32. # X25 flags:
  33. #    Add -DYORKD2_2 if you have the D2.2 York code distribution
  34. X25FLAGS=-I/usr/src/local/x25/usr/src/
  35.  
  36. UUCPFLAGS=-I/usr/src/local/ukuucp/uucp/
  37. UUCPLIB=/usr/src/local/ukuucp/uucp/uulib.a
  38.  
  39. uucp:    rmail muucp
  40.     cp rmail /bin/rmail
  41.     cp muucp /usr/lib/uucp/muucp
  42.     chown uucp /usr/lib/uucp/muucp
  43.     chgrp uucp /usr/lib/uucp/muucp
  44.     chmod 6711 /usr/lib/uucp/muucp
  45.  
  46. bitnet:    damail bsmtp
  47.     cp damail /usr/local/lib/rscs/damail
  48.     cp bsmtp /usr/local/lib/rscs/bsmtp
  49.  
  50. rmail:    rmail.c
  51.     cc $(CFLAGS) rmail.c -o rmail
  52.  
  53. muucp:    muucp.c
  54.     cc $(CFLAGS) $(UUCPFLAGS) muucp.c $(UUCPLIB) -o muucp
  55.  
  56. damail: damail.c
  57.     cc $(CFLAGS) damail.c -o damail
  58.  
  59. bsmtp: bsmtp.c
  60.     cc $(CFLAGS) bsmtp.c -o bsmtp
  61.  
  62.  
  63. janet:    mailer hhsend
  64.     cp mailer /usr/lib/x25
  65.     chown root /usr/lib/x25/mailer
  66.     chmod 755 /usr/lib/x25/mailer
  67.     cp hhsend /usr/lib/x25
  68.     chown root /usr/lib/x25/hhsend
  69.     chmod 4755 /usr/lib/x25/hhsend
  70.  
  71. mailer: mailer.c dlit.o
  72.     cc $(CFLAGS) $(X25FLAGS) mailer.c dlit.o -lx25 -o mailer
  73.  
  74. hhsend: hhsend.c dlit.o
  75.     cc $(CFLAGS) $(X25FLAGS) hhsend.c dlit.o -o hhsend
  76. SHAR_EOF
  77. if test 1208 -ne "`wc -c Makefile`"
  78. then
  79. echo shar: error transmitting Makefile '(should have been 1208 characters)'
  80. fi
  81. echo shar: extracting README '(2378 characters)'
  82. cat << \SHAR_EOF > README
  83. This directory contains some sendmail interface programs.
  84.  
  85. Interfaces
  86. ----------
  87. rmail.c:
  88.     This is a rewrite of the standard uucp -> sendmail interface program
  89.     which just a better job of deducing the From path from the
  90.     uucp from line(s), and also sets sendmail's $s macro.
  91.  
  92.     This replaces /bin/rmail supplied with BSD4.2.
  93.  
  94. muucp.c:
  95.     This is a sendmail -> uucp interface program. This takes a message
  96.     processed by sendmail and prepends a uucp From line then creates
  97.     the appropriate uucp files.
  98.  
  99.     This replaces /usr/bin/uux for sending mail over uucp.
  100.  
  101. damail.c:
  102.     This is a rewrite of the bitnet -> sendmail interface program
  103.     supplied with the Cornell version of the RSCS emulation package.
  104.     This reads the from person from the From: line and sets
  105.     sendmail's $s macro.
  106.  
  107.     This replaces /usr/local/lib/rscs/damail supplied with the RSCS
  108.     software.
  109.  
  110. bsmtp.c:
  111.     This is a sendmail -> "batched smtp" interface program for use
  112.     with the bitnet RSCS emulation package.  It allows bitnet users
  113.     to mail to people on other networks such as arpa and uucp.
  114.  
  115. mailer.c:
  116.     This is a janet -> sendmail interface program. This reads a
  117.     message in JNT mail format and converts it into a form suitable
  118.     for calling sendmail. This also sets sendmail's $s macro.
  119.  
  120.     This replaces /usr/lib/x25/mailer supplied with the York X25 software.
  121.  
  122. hhsend.c:
  123.     This is a sendmail -> janet interface program. This reads a
  124.     message processed by sendmail and converts it into JNT mail format,
  125.     then calls mhhcp to send it.
  126.  
  127.     This effectively replaces the /usr/lib/x25/hhmail supplied with the
  128.     York X25 software; the standard mail user interfaces together with
  129.     sendmail perform the other functions provided by hhmail.
  130.  
  131. dlit.c:
  132.     This contains routines used by the janet mailer interfaces, i.e.
  133.     mailer.c and hhsend.c, to handle address/domain literal conversions.
  134.  
  135.     Dlit.c contains a table of network names, dnic numbers and gateway
  136.     addresses to/from that network.  This table is obviously host
  137.     specific, thus the tables need to be edited before making the janet
  138.     sendmail interfaces.
  139.  
  140.  
  141. Installation
  142. ------------
  143. This directory contains a Makefile which should be able to create the
  144. various interface programs and install them in their expected places.
  145.  
  146. By saying "make <mailer>" the interfaces will be compiled and installed
  147. as appropriate for a given mailer.  Of course, you need to be superuser
  148. to do this.
  149. SHAR_EOF
  150. if test 2378 -ne "`wc -c README`"
  151. then
  152. echo shar: error transmitting README '(should have been 2378 characters)'
  153. fi
  154. echo shar: extracting damail.c '(3233 characters)'
  155. cat << \SHAR_EOF > damail.c
  156. /*
  157.  * rscs to sendmail mail interface
  158.  * invoked by the rscs master control daemon when a file with filetype MAIL
  159.  * is received over BITNET.
  160.  *
  161.  * The syntax is
  162.  *     damail <mailfile> <fromsys> <fromuser> <tosys> <touser>
  163.  *
  164.  * 
  165.  * Bill Nesheim
  166.  * Cornell U Dept of Computer Science
  167.  * August, 1983
  168.  *
  169.  * Rewritten by Jim Crammond
  170.  * Weizmann Institute
  171.  * Feb 1985
  172.  */
  173.  
  174. #include <stdio.h>
  175. #include <sys/file.h>
  176. #include <sys/wait.h>
  177. #include <sysexits.h>
  178. #include "../common/rscs.h"
  179. #include "../common/daemon.h"
  180.  
  181. #define MAILLOG "/usr/lib/rscs/maillog"
  182.  
  183. main(ac,av)
  184. int ac;
  185. char **av;
  186. {
  187.     FILE *mail, *outfile, *log;
  188.     char line[BUFSIZ], From[BUFSIZ], To[BUFSIZ];
  189.     char sender[20];
  190.     char *actime, *err;
  191.     long tm, time();
  192.     int loc, smpid, ppe[2];
  193.     union wait status;
  194.  
  195.     if(ac < 2) {
  196.         logerror("DAMAIL: No Mail File??");
  197.         return(TRUE);
  198.     }
  199.  
  200.     if((log = fopen(MAILLOG, "a")) == (FILE *)NULL) {
  201.         logerror("Can't open mail log file!");
  202.         return(FALSE);
  203.     }
  204.  
  205.     if((mail = fopen(av[1],"r")) == (FILE *)NULL) {
  206.         sprintf(line,"MTU: Can't open %s", av[1]);
  207.         logerror(line);
  208.         return(FALSE);
  209.     }                                   
  210.  
  211.     /* apparent source */
  212.     sprintf(From,"%s@%s.BITNET", av[3], av[2]);
  213.     /* apparent destination */
  214.     sprintf(To,"%s@%s.BITNET", av[5], av[4]);
  215.  
  216.     /* sender flag to sendmail */
  217.     convlower(av[2]);
  218.     sprintf(sender,"-oMs%s.bitnet", av[2]);
  219.  
  220.     /* try to find real destination and source */
  221.     while (fgets(line, BUFSIZ, mail) !=  NULL) 
  222.     {    
  223.         if (strncmp(line, "From:", 3) == 0) {
  224.             register char *p, *e;
  225.             char *index();
  226.             char *addr;
  227.  
  228.             p = line + 5;
  229.  
  230.             while (*p == ' ')
  231.                 p++;
  232.  
  233.             addr = p;
  234.  
  235.             if ( (p=index(addr, '<')) && (e=index(p, '>')) )
  236.             {    /*
  237.                  *  address of the form:  comment <address>
  238.                  */
  239.                 addr = ++p;
  240.                 *e = '\0';
  241.             }
  242.             else if ( (e=index(addr, '(')) )
  243.             {    /*
  244.                  *  address of the form:  address (comment) 
  245.                  */
  246.                 while (*--e == ' ')
  247.                     ;
  248.                 *++e = '\0';
  249.             }
  250.             else if ( (e=index(addr, '\n')) )
  251.                 *++e = '\0';
  252.  
  253.             strcpy(From, addr);
  254.             break;
  255.         }
  256.     }
  257.  
  258.     rewind(mail);
  259.     tm = time(0L); 
  260.     actime = (char *)ctime(&tm);
  261.     actime[19] = '\000';
  262.  
  263.     /* open pipe to sendmail */
  264.     pipe(ppe);
  265.     if((smpid=vfork()) == 0) {
  266.         close(0);
  267.         dup(ppe[0], 0);
  268.         execl("/usr/lib/sendmail", "sendmail",
  269.                 sender, "-odi", "-oem", "-f", From, To, 0);
  270.  
  271.         logerror("MTU: exec failed");
  272.         perror("reason");
  273.         _exit(1);
  274.     }
  275.  
  276.     if((outfile = fdopen(ppe[1], "w")) == (FILE *)NULL) {
  277.         logerror("MTU: pipe fdopen failure!");
  278.         return(FALSE);
  279.     }
  280.  
  281.     loc = 1;
  282.  
  283.     while (fgets(line, BUFSIZ, mail) !=  NULL) {
  284.         if (loc == 1) {
  285.             loc++;
  286.             if(strncmp(line, ":READ", 5) == 0)
  287.                 continue;
  288.         }
  289.  
  290.         fputs(line, outfile);
  291.     }
  292.  
  293.     fclose(outfile);
  294.     fclose(mail);
  295.     wait(&status);
  296.     switch(status.w_retcode) {
  297.     case EX_OK:
  298.         err="sent";
  299.         break;
  300.     case EX_NOUSER:
  301.         err="no such user";
  302.         break;
  303.     case EX_NOHOST:
  304.         err="host unknown";
  305.         break;
  306.     case EX_UNAVAILABLE:
  307.         err="service unavailable";
  308.         break;
  309.     default:
  310.         err="other";
  311.     }
  312.  
  313.     fprintf(log,"%s Received mail from %s %s (tag %s %s) \n",
  314.         actime, av[2], av[3], av[4], av[5]);
  315.     fprintf(log,"\t%s (%d) %s (%d) from %s to %s\n",
  316.         status.w_retcode ? "NOT SENT" : "Sent" , smpid, err, status.w_retcode, From, To);
  317.     fclose(log);
  318.  
  319.     unlink(av[1]);
  320.     return(status.w_retcode);
  321. }
  322. SHAR_EOF
  323. if test 3233 -ne "`wc -c damail.c`"
  324. then
  325. echo shar: error transmitting damail.c '(should have been 3233 characters)'
  326. fi
  327. echo shar: extracting dlit.c '(2250 characters)'
  328. cat << \SHAR_EOF > dlit.c
  329. /*
  330.  *    Domain literal handling.
  331.  *    This contains two routines to convert YBTS addresses to domain
  332.  *    literals, and vice versa.  To do this, there is a table of
  333.  *    network names together with their DNIC numbers and gateway addresses
  334.  *    to that network (if not directly connected).
  335.  *
  336.  *    Jim Crammond  <jim@hw.cs>    10/85
  337.  */
  338. #include <ctype.h>
  339.  
  340. #define MAXLEN    256
  341.  
  342. typedef struct
  343. {    char    *n_name;    /*  network name  */
  344.     char    *n_dnic;    /*  network id code  */
  345.     char    *n_gate;    /*  address to/from network gateway */
  346. } net;
  347.  
  348. /*
  349.  *  Host Dependent information.  The DNIC identifies the network
  350.  *  after any gateway addresses have been stripped. (A zero length
  351.  *  DNIC will match all addresses.) A null gateway address indicates
  352.  *  a direct connection to the network.
  353.  */
  354. net nets[] =
  355. {
  356.     "PSS",        "2342",        "00001500004000",
  357.     "EDNET",    "000015",    0,
  358.     "EDNET",    "000016",    0,
  359.     "JANET",    "0000",        "00001500009900",
  360.     0,        0,        0,
  361. };
  362.  
  363.  
  364. /*
  365.  *   addr_to_dlit  --  converts a YBTS strings into a domain literal
  366.  *
  367.  *    returns:    domain literal,  if successful
  368.  *            YBTS string otherwise
  369.  */
  370. char    *
  371. addr_to_dlit(addr)
  372. char    *addr;
  373. {
  374.     static    char    dlit[MAXLEN];
  375.     register char    *p;
  376.     net    *np;
  377.     int    len;
  378.  
  379.     for (np=nets; np->n_name; np++)
  380.     {    p = addr;
  381.         if (np->n_gate)
  382.         {    /*  match and skip gateway part of address  */
  383.             len = strlen(np->n_gate);
  384.             if (strncmp(p, np->n_gate, len) == 0)
  385.             {    p += len;
  386.                 if (*p != '.' && *p != '/')
  387.                     continue;
  388.                 p++;
  389.             }
  390.             else
  391.                 continue;
  392.         }
  393.  
  394.         len = strlen(np->n_dnic);
  395.         if (strncmp(p, np->n_dnic, len) == 0)
  396.         {    sprintf(dlit, "+%s.%s", np->n_name, p);
  397.             return(dlit);
  398.         }
  399.     }
  400.  
  401.     return(addr);
  402. }
  403.  
  404. /*
  405.  *   dlit_to_addr  --  converts a domain literal into a YBTS string
  406.  *
  407.  *    returns:    YBTS string,  if successful
  408.  *            domain literal otherwise
  409.  */
  410. char    *
  411. dlit_to_addr(dlit)
  412. char    *dlit;
  413. {
  414.     static    char    addr[MAXLEN];
  415.     register char    *p, *q;
  416.     net    *np;
  417.     char    pdn[20];
  418.  
  419.     if (*dlit == '+')
  420.     {    for (p=dlit+1, q=pdn; *p && *p != '.'; p++, q++)
  421.             *q = islower(*p) ? toupper(*p) : *p;
  422.         *q = '\0';
  423.         p++;
  424.  
  425.         for (np=nets; np->n_name; np++)
  426.         {    if (strcmp(pdn, np->n_name) == 0)
  427.             {    if (np->n_gate)
  428.                 {    /*  prepend gateway addr  */
  429.                     sprintf(addr, "%s.%s", np->n_gate, p);
  430.                     return(addr);
  431.                 }
  432.                 return(p);
  433.             }
  434.         }
  435.     }
  436.  
  437.     return(dlit);
  438. }
  439. SHAR_EOF
  440. if test 2250 -ne "`wc -c dlit.c`"
  441. then
  442. echo shar: error transmitting dlit.c '(should have been 2250 characters)'
  443. fi
  444. echo shar: extracting hhsend.c '(3110 characters)'
  445. cat << \SHAR_EOF > hhsend.c
  446. /*
  447.  *  hhsend  -  Sendmail -> JNT mailer interface.
  448.  *
  449.  *    This program takes a hostname and a list of addresses to send to as
  450.  *    arguments and a mail message as standard input and creates a file
  451.  *    containing a Janet header followed by the mail message, then
  452.  *    calls mhhcp to send it over the network.
  453.  *
  454.  *    Written by Jim Crammond.    <jim@hw.cs>    4/85
  455.  *
  456.  *    Modified to interpret a hostname which is a domain literal
  457.  *    or a raw address enclosed in '[' ']'.  Domain literal's are
  458.  *    converted to raw addresses before being passed to mhhcp.
  459.  *
  460.  *    Jim Crammond & Scott Larnach <scott@ed.cstvax>  10/85
  461.  */    
  462. #include <stdio.h>
  463. #include <signal.h>
  464. #include <sysexits.h>
  465. #include <sys/wait.h>
  466. #include "local.h"
  467.  
  468. #define    MAILMODE    (0660)        /* mode of created spool file */
  469.  
  470. #ifdef DEBUG
  471. #undef  SPOOLD
  472. #define SPOOLD "."
  473. #endif DEBUG
  474.  
  475. FILE    *mailf = NULL;
  476. char    sfile[ sizeof(SPOOLD) + 14 ];
  477. int    delete();
  478. char    *index();
  479. char    *dlit_to_addr();
  480.  
  481.  
  482. main(argc, argv)
  483. int    argc;
  484. char    *argv[];
  485. {
  486.     char    *myname;
  487.     char    *host;
  488.     char    **users;
  489.     int    nusers;
  490.  
  491.     myname = argv[0];
  492.  
  493.     if (argc < 3)
  494.     {    fprintf(stderr, "usage: %s host users...\n", myname);
  495.         exit(EX_USAGE);
  496.     }
  497.  
  498.     host = argv[1];
  499.     users = &argv[2];
  500.     nusers = argc - 2;
  501.  
  502.     /*  catch signals  */
  503.     signal(SIGHUP, delete);
  504.     signal(SIGINT, delete);
  505.     signal(SIGQUIT, delete);
  506.     signal(SIGTERM, delete);
  507.  
  508.     /*  send the mail  */
  509.     sendmail(host, users, nusers);
  510.  
  511.     /*  NOTREACHED  */
  512. }
  513.  
  514. /*
  515.  *  sendmail  -  creates a mail file for mhhcp and exec mhhcp.
  516.  */
  517. sendmail(host, users, nusers)
  518. char    *host;
  519. char    *users[];
  520. int    nusers;
  521. {
  522.     register char    *auser, *p;
  523.     char    line[BUFSIZ];
  524.     union    wait status;
  525.  
  526.     /*  create spool file  */
  527.     sprintf(sfile, "%s/M%06d", SPOOLD, getpid() );
  528.  
  529.     mailf = fopen(sfile, "w");
  530.     if (mailf == NULL)
  531.     {    fprintf(stderr, "cannot create mail spool file %s\n", sfile);
  532.         exit(EX_CANTCREAT);
  533.     }
  534.     chmod(sfile, MAILMODE);
  535.  
  536.  
  537.     /*  write out JNT-header  */
  538.     while (nusers > 1)
  539.     {    auser = users[ --nusers ];
  540.         fprintf(mailf, "%s,\n", auser);
  541.     }
  542.     auser = users[0];
  543.     fprintf(mailf, "%s\n\n", auser);
  544.  
  545.  
  546.     /*  write out header + message from stdin (supplied by sendmail)  */
  547.     while (fgets(line, sizeof(line), stdin) != NULL)
  548.         fputs(line, mailf);
  549.     
  550.     fclose(mailf);
  551.  
  552.     /*  handle domain literal  */
  553.     if (*host == '[')
  554.     {    host++;            /*  strip [ ]'s */
  555.         for (p = host; *p != ']'; p++);
  556.             *p = '\0';
  557.  
  558.         host = dlit_to_addr(host);
  559.     }
  560.  
  561. #ifdef DEBUG
  562.     fprintf(stderr,"call: %s %s %s\n", MHHCP, sfile, host);
  563.     exit(0);
  564. #endif DEBUG
  565.  
  566.     switch (fork())
  567.     {    case -1:
  568.             unlink(sfile);
  569.             exit(EX_TEMPFAIL);
  570.         case 0:
  571. #ifdef    YORKD2_2    /* no hhP logging by default now. Need -L flag */
  572.             execl(MHHCPPATH, MHHCP, "-L", sfile, host, 0);
  573. #else
  574.             execl(MHHCPPATH, MHHCP, sfile, host, 0);
  575. #endif
  576.             unlink(sfile);
  577.             exit(EX_UNAVAILABLE);
  578.         default:
  579.             wait(&status);
  580. #ifdef    YORKD2_2
  581.             if (status.w_retcode == 0)
  582. #else
  583.             if (status.w_retcode == 1)
  584. #endif
  585.                 exit(EX_OK);
  586.             else
  587.             {    unlink(sfile);
  588.                 exit(EX_NOHOST);
  589.             }
  590.     }
  591. }
  592.  
  593.  
  594. /*
  595.  *  delete  -  delete mail file and exit.  Called on any interrupt.
  596.  */
  597. delete()
  598. {    
  599.     if (mailf != NULL)
  600.     {    fclose(mailf);
  601.         unlink(sfile);
  602.     }
  603.     exit(EX_TEMPFAIL);
  604. }
  605. SHAR_EOF
  606. if test 3110 -ne "`wc -c hhsend.c`"
  607. then
  608. echo shar: error transmitting hhsend.c '(should have been 3110 characters)'
  609. fi
  610. echo shar: extracting mailer.c '(3804 characters)'
  611. cat << \SHAR_EOF > mailer.c
  612. /*
  613.  *  mailer  -  JNT -> Sendmail interface.
  614.  *
  615.  *    This program takes a mail file in JNT format and converts the
  616.  *    Janet header into an argument and then calls sendmail giving the
  617.  *    message part of the mail file as standard input.
  618.  *
  619.  *    Written by Jim Crammond.    <jim@hw.cs>    4/85
  620.  *
  621.  *    Fixed to send failed mail to postmaster.
  622.  *    Jim Reid <jim@strath.cs>            6/85
  623.  *
  624.  *    Improved handling of received YBTS addresses
  625.  *    Jim Crammond & Scott Larnach <scott@ed.cstvax>    7/85
  626.  *
  627.  *    Fixed format of domain literal to conform with
  628.  *    Greybook/NRS.  Jim Crammond & Scott Larnach     9/85
  629.  */    
  630. #include <stdio.h>
  631. #include <time.h>
  632. #include <pwd.h>
  633. #include <tdir.h>
  634. #include <sysexits.h>
  635. #include "local.h"
  636.  
  637. struct    tdirent    *gettdnam(), *td;
  638.  
  639. #define    CMDSIZ        5000            /*  command line size  */
  640. #define SENDMAIL    "/usr/lib/sendmail"    /*  sendmail rah rah  */
  641.  
  642. /* #define CATCHALL    /*  send all undeliverable mail to postmaster  */
  643.  
  644. char    cmd[CMDSIZ];
  645. char    line[BUFSIZ];
  646. char    *file, *via;
  647. FILE    *fopen(), *popen();
  648. FILE    *fp, *outp, *logfd;
  649. long    iop, time();
  650. char    *ctime();
  651. char    *rindex();
  652. char    *addr_to_dlit();
  653. int    LOGGING;
  654.  
  655. main(argc, argv)
  656. int    argc;
  657. char    *argv[];
  658. {
  659.     register char    *usersp, *c, *n;
  660.     char    *f;
  661.     int    ret;
  662.  
  663. #ifndef DEBUG
  664.     chdir(SPOOLD);        /* somewhere to dump core */
  665. #endif
  666.     if ((logfd = fopen(MAIL_LOG, "a")) == NULL)
  667.         LOGGING = 0;
  668.     else
  669.         LOGGING = 1;
  670.     chmod(MAIL_LOG, 0666);
  671.     time(&iop);
  672.     LOG("\n\nMail server started %s", ctime(&iop));
  673.  
  674.     file = argv[1];
  675.     via = argv[2];
  676.  
  677.     if ((fp = fopen(file, "r")) == NULL)
  678.     {    LOG("could not open %s\n", file);
  679.         done();
  680.     }
  681.  
  682.     /*
  683.      *  find out where this came from.
  684.      *  Strip the trailing FTP.MAIL, and pass the rest to gettdnam.
  685.      */
  686.     for (f = via; *f; f++)
  687.     {    if (*f == '/' || *f == '.')
  688.         {    if (strcmp(f+1, MAILADR) == 0)
  689.             {    *f = '\0';
  690.                 break;        /*  reached the FTP.MAIL bit  */
  691.             }
  692.         }
  693.     }
  694.  
  695.     /*
  696.      *  initialise command sendmail command line.
  697.      *  The sender macro is either set to the name returned by
  698.      *  gettdnam, or a domain literal returned by addr_to_dlit
  699.      */
  700.     if ((td = gettdnam(via, 0)) != 0)
  701.         sprintf(cmd, "%s -ba -oMs%s", SENDMAIL, td->td_name);
  702.     else
  703.         sprintf(cmd, "%s -ba -oMs[%s]", SENDMAIL, addr_to_dlit(via));
  704.  
  705.     usersp = cmd;
  706.     while (*usersp != '\0')
  707.         usersp++;
  708.  
  709.     /*
  710.      *  get list of addresses to send to in JNT-header form and
  711.      *  convert to a list of command line arguments.
  712.      */
  713.     while (fgets(line, BUFSIZ, fp) != NULL)
  714.     {    c = line;
  715.         while (*c == ' ' || *c == '\t')
  716.             c++;
  717.  
  718.         if (*c == '\n')
  719.             break;
  720.  
  721.         *usersp++ = ' ';
  722.  
  723.         while (*c != '\0' && *c != '\n')
  724.         {    if (*c == ',')
  725.             {    *usersp++ = ' ';
  726.                 c++;
  727.             }
  728.             else if (*c == '@' && *(c+1) == '[')
  729.             {    /*  strip domain literals  */
  730.                 while (*++c)
  731.                 {    if (*c == ']')
  732.                     {    c++;
  733.                         break;
  734.                     }
  735.                 }
  736.             }
  737.             else
  738.                 *usersp++ = *c++;
  739.         }
  740.     }
  741.     *usersp = '\0';
  742.  
  743.     /* call sendmail */
  744. #ifdef DEBUG
  745.     fprintf(stderr, "call: %s\n", cmd);
  746.     done();
  747. #endif DEBUG
  748.     LOG("%s\n", cmd);
  749.     outp = popen(cmd, "w");
  750.     while (fgets(line, sizeof(line), fp) != NULL)
  751.         fputs(line, outp);
  752.     ret = pclose(outp);
  753.  
  754. #ifdef CATCHALL
  755.     if (ret & 0xffff)
  756. #else
  757.     if (ret & 0xff)
  758. #endif
  759.     {    /*
  760.          *  sendmail failed - send to postmaster
  761.          */
  762.         LOG("%s failed, returning status %d\n", cmd, ret);
  763.         error_mail();
  764.         exit(EX_OSERR);
  765.     }
  766.     LOG("exit status %d\n", ret >> 8);
  767.     done();
  768. }
  769.  
  770. /*
  771.  *  Send garbaged mail to postmaster
  772.  */
  773. error_mail()
  774. {
  775.     FILE    *efp;
  776.  
  777.     if ((efp = popen("/bin/mail postmaster", "w")) != NULL)
  778.     {    fprintf(efp, "Mail from %s failed\n", via);
  779.         fprintf(efp, "Command line was: %s\n", cmd);
  780.         fprintf(efp, "Message body follows:\n");
  781.         rewind(fp);
  782.         while (fgets(line, sizeof(line), fp) != NULL)
  783.             fputs(line, efp);
  784.         pclose(efp);
  785.     }
  786. }
  787.  
  788. /* VARARGS1 */
  789. LOG(fmt, args)
  790. char    *fmt;
  791. {
  792.     if (LOGGING)
  793.     {    fprintf(logfd, fmt, args);
  794.         fflush(logfd);
  795.     }
  796.     return;
  797. }
  798.  
  799. done()
  800. {
  801.     unlink(file);
  802.     exit(EX_OK);
  803. }
  804. SHAR_EOF
  805. if test 3804 -ne "`wc -c mailer.c`"
  806. then
  807. echo shar: error transmitting mailer.c '(should have been 3804 characters)'
  808. fi
  809. echo shar: extracting muucp.c '(6688 characters)'
  810. cat << \SHAR_EOF > muucp.c
  811. /*
  812.  *  Send mail over uucp, using the UUCP Transmission Format
  813.  *  usage:  muucp [ -f<from> ] [ -H<hostname> ] host user1 user2 ....
  814.  */
  815.  
  816. /*
  817.  * "X" files use local system name, avoids conflict. Steve Bellovin
  818.  */
  819. #include "uucp.h"
  820. #include <sys/types.h>
  821.  
  822. #define GENSEND(f, a, b, c, d, e) {\
  823. fprintf(f, "S %s %s %s -%s %s 0666\n", a, b, c, d, e);\
  824. }
  825.  
  826.  
  827. main(argc, argv)
  828. char *argv[];
  829. {
  830.     char cfile[NAMESIZE];    /* send commands for files from here */
  831.     char dfile[NAMESIZE];    /* used for all data files from here */
  832.     char rxfile[NAMESIZE];    /* to be sent to xqt file (X. ...) */
  833.     char tfile[NAMESIZE];    /* temporary file name */
  834.     char tcfile[NAMESIZE];    /* temporary file name */
  835.     int cflag = 0;        /*  commands in C. file flag  */
  836.     int rflag = 0;        /*  C. files for receiving flag  */
  837.     char buf[BUFSIZ];
  838.     int startjob = 1;
  839.     char Grade = 'A';
  840.     char path[MAXFULLNAME];
  841.     char cmd[BUFSIZ];
  842.     char *ap, *cmdp;
  843.     char *xsys, local[8];
  844.     char *rfname, *From;
  845.     char *perc_to_uucp(), *tidy_addr();
  846.     FILE *fprx, *fpc, *fpd;
  847.     extern FILE *ufopen();
  848.     time_t now;
  849.     extern time_t time();
  850.     extern char *ctime();
  851.     int ret;
  852. #ifdef    SYSINFO
  853.     /* UKfix 021: LMCL.  Gather accounting info. (Orig by Piet Beertema) */
  854.     char *fromsys;
  855.     char *fromper;
  856.     extern char *getenv();
  857.     char locsys = 0;
  858.     long xfersize;
  859. #endif    SYSINFO
  860.     int orig_uid = getuid();
  861.  
  862.     strcpy(Progname, "muucp");
  863.     uucpname(Myname);
  864.     guinfo(orig_uid, User, path);
  865.     From = User;
  866.     rfname = Myname;
  867.     umask(WFMASK);
  868.  
  869.     Ofn = 1;
  870.     Ifn = 0;
  871.  
  872.     while (argc>1 && argv[1][0] == '-') {
  873.         switch(argv[1][1]){
  874.         case 'f':
  875.             From = &argv[1][2];
  876.             break;
  877.         case 'H':
  878.             if (argv[1][2] != '\0')
  879.                 rfname = &argv[1][2];
  880.             break;
  881.         case 'r':
  882.             startjob = 0;
  883.             break;
  884.         case 'g':
  885.             Grade = argv[1][2];
  886.             break;
  887.         case 'x':
  888.             chkdebug(orig_uid);
  889.             Debug = atoi(&argv[1][2]);
  890.             if (Debug <= 0)
  891.                 Debug = 1;
  892.             break;
  893.         default:
  894.             fprintf(stderr, "unknown flag %s\n", argv[1]);
  895.                 break;
  896.         }
  897.         --argc;  argv++;
  898.     }
  899.  
  900.     DEBUG(4, "\n\n** %s **\n", "START");
  901.  
  902.     /* find remote system name (argv[1]) */
  903.     xsys = *++argv;
  904.  
  905.     sprintf(Rmtname, "%.7s", mapname(xsys));
  906.     strcpy(xsys, Rmtname);        /*  Now ensure they're the same! */
  907.     DEBUG(4, "xsys %s\n", xsys);
  908.     if (versys(xsys) != 0) {
  909.         /*  bad system name  */
  910.         fprintf(stderr, "bad system name: %s\n", xsys);
  911.         cleanup(EX_NOHOST);
  912.     }
  913.  
  914. #ifdef    SYSINFO
  915.     /* UKfix 021: LMCL.  Allow for host groups. */
  916.     if (!(locsys = islocal( xsys )) && *exthost) { /* is this a local system? */
  917.         strcpy(local, exthost);
  918.     }
  919.     else
  920. #endif    SYSINFO
  921.         sprintf(local, "%.7s", Myname);
  922.  
  923.     subchdir(Spool);
  924.     gename(DATAPRE, local, 'X', rxfile);
  925.     fprx = ufopen(rxfile, "w");
  926.     ASSERT(fprx != NULL, "CAN'T OPEN", rxfile, 0);
  927.     gename(DATAPRE, local, 'T', tcfile);
  928.     fpc = ufopen(tcfile, "w");
  929.     ASSERT(fpc != NULL, "CAN'T OPEN", tcfile, 0);
  930.     fprintf(fprx, "%c %s %s\n", X_USER, User, local);
  931.  
  932.     gename(DATAPRE, local, 'B', dfile);
  933.     fpd = ufopen(dfile, "w");
  934.     ASSERT(fpd != NULL, "CAN'T OPEN", dfile, 0);
  935.  
  936.     /*  generate the UUCP From line  */
  937.     From = perc_to_uucp(From);
  938.     From = tidy_addr(From);
  939.     if (From == NULL)
  940.         From = User;
  941.     DEBUG(4, "from %s\n", From);
  942.     time(&now);
  943.     fprintf(fpd, "From %s %.24s remote from %s\n", From, ctime(&now), rfname);
  944. #ifdef SYSINFO
  945.     /*  account for everything  */
  946.     xfersize = 44 + strlen(From) + strlen(rfname);
  947. #endif SYSINFO
  948.  
  949.     /*  read in stdin (mail message) */
  950.     while (!feof(stdin)) {
  951.         ret = fread(buf, 1, BUFSIZ, stdin);
  952.         fwrite(buf, 1, ret, fpd);
  953. #ifdef    SYSINFO
  954.         /* UKfix 021: LMCL. tot up size of data to xfer */
  955.         xfersize += ret;
  956. #endif    SYSINFO
  957.     }
  958.  
  959.     fclose(fpd);
  960.     if (strcmp(local, xsys) != SAME) {
  961.         GENSEND(fpc, dfile, dfile, User, "", dfile);
  962.         cflag++;
  963.     }
  964.     fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
  965.     fprintf(fprx, "%c %s\n", X_STDIN, dfile);
  966.  
  967.     strcpy(cmd, "rmail ");
  968.     cmdp = cmd + 6;
  969.     for (++argv, --argc; argc > 1; argc--)
  970.     {    ap = *argv++;
  971.         while (*ap)
  972.             *cmdp++ = *ap++;
  973.         *cmdp++ = ' ';
  974.     }
  975.     *cmdp = '\0';
  976.  
  977.     DEBUG(4, "cmd - %s\n", cmd);
  978.     fprintf(fprx, "%c %s\n", X_CMD, cmd);
  979. #ifdef    SYSINFO
  980.     /* UKfix 021: LMCL.  Export accountable site/user
  981.      * (Orig by Piet Beertema).
  982.      */
  983.     if ((fromsys = getenv("ACCTSYS")) != NULL)
  984.         fprintf(fprx, "%c %s\n", X_ACCTSYS, fromsys);
  985.     else if( !locsys && *exthost )
  986.         fprintf(fprx, "%c %s\n", X_ACCTSYS, exthost);
  987.     if ((fromper = getenv("ACCTPER")) != NULL)
  988.         fprintf(fprx, "%c %s\n", X_ACCTPER, fromper );
  989.     /* For mail you record the senders address */
  990.     fprintf(fprx, "%c %ld %s\n", X_ACCTSZ, xfersize, From );
  991. #endif    SYSINFO
  992.     logent(cmd, "XQT QUE'D");
  993.     fclose(fprx);
  994.  
  995.     strcpy(tfile, rxfile);
  996.     tfile[0] = XQTPRE;
  997.     tfile[ strlen(tfile) - 5 ] = Grade;    /* UKfix 006 */
  998.     if (strcmp(xsys, local) == SAME) {
  999.         /* rti!trt: xmv() works across filesystems, link(II) doesnt */
  1000.         xmv(rxfile, tfile);
  1001.         if (startjob)
  1002.             if (rflag)
  1003.                 xuucico(xsys);
  1004.             else
  1005.                 xuuxqt();
  1006.     }
  1007.     else {
  1008.         GENSEND(fpc, rxfile, tfile, User, "", rxfile);
  1009.         cflag++;
  1010.     }
  1011.     fclose(fpc);
  1012.  
  1013.     if (cflag) {
  1014.         gename(CMDPRE, xsys, Grade, cfile);
  1015.         /* rti!trt: use xmv() rather than link(II) */
  1016.         xmv(tcfile, cfile);
  1017.         if (startjob)
  1018.             xuucico(xsys);
  1019.         cleanup(EX_OK);
  1020.     }
  1021.     else
  1022.         unlink(subfile(tcfile));
  1023. }
  1024.  
  1025. #define FTABSIZE 30
  1026. char Fname[FTABSIZE][NAMESIZE];
  1027. int Fnamect = 0;
  1028.  
  1029. /***
  1030.  *    cleanup - cleanup and unlink if error
  1031.  *
  1032.  *    return - none - do exit()
  1033.  */
  1034.  
  1035. cleanup(code)
  1036. int code;
  1037. {
  1038.     int i;
  1039.  
  1040.     logcls();
  1041.     rmlock(CNULL);
  1042.     if (code) {
  1043.         for (i = 0; i < Fnamect; i++)
  1044.             unlink(subfile(Fname[i]));
  1045.         fprintf(stderr, "%s failed. code %d\n", Progname, code);
  1046.     }
  1047.     DEBUG(1, "exit code %d\n", code);
  1048.     exit(code);
  1049. }
  1050.  
  1051. /***
  1052.  *    ufopen - open file and record name
  1053.  *
  1054.  *    return file pointer.
  1055.  */
  1056.  
  1057. FILE *ufopen(file, mode)
  1058. char *file, *mode;
  1059. {
  1060.     if (Fnamect < FTABSIZE)
  1061.         strcpy(Fname[Fnamect++], file);
  1062.     else
  1063.         logent("Fname", "TABLE OVERFLOW");
  1064.     return(fopen(subfile(file), mode));
  1065. }
  1066.  
  1067.  
  1068. /*
  1069. **  PERC_TO_UUCP  --  converts an address in Percent style into uucp style
  1070. **
  1071. **    e.g.  user%c.bitnet%b.arpa@a.uucp -> a.uucp!b.arpa!c.bitnet!user
  1072. */    
  1073. char    *
  1074. perc_to_uucp(addr)
  1075. char    *addr;
  1076. {
  1077.     static    char    buf[512];
  1078.     char    *bp = buf;
  1079.     char    *p;
  1080.  
  1081.     DEBUG(6, "perc_to_uucp(%s) ", addr);
  1082.  
  1083.     while ((p = rindex(addr,'@')) != NULL || (p = rindex(addr,'%')) != NULL)
  1084.     {
  1085.         *p++ = '\0';
  1086.         while (*p)
  1087.             *bp++ = *p++;
  1088.  
  1089.         *bp++ = '!';
  1090.     }
  1091.  
  1092.     strcpy(bp, addr);
  1093.     DEBUG(6, "returns %s\n", buf);
  1094.  
  1095.     return(buf);
  1096. }
  1097.  
  1098. /*
  1099. **  TIDY_ADDR  --  strips duplicate domain names from start of address
  1100. **
  1101. **    e.g.  cs.hw.AC.UK!cs.hw.AC.UK!jim -> cs.hw.AC.UK!jim
  1102. */    
  1103. char    *
  1104. tidy_addr(addr)
  1105. char    *addr;
  1106. {
  1107.     register char    *p, *q;
  1108.  
  1109.     DEBUG(6, "tidy_addr(%s) ", addr);
  1110.  
  1111.     p = addr;
  1112.     while ((q = index(p, '!')) != NULL)
  1113.     {    ++q;
  1114.         while (*p != '!' && *p == *q)
  1115.         {    p++;
  1116.             q++;
  1117.         }
  1118.         if (*p != '!' && *q != '!')
  1119.             break;
  1120.  
  1121.         addr = ++p;
  1122.     }
  1123.  
  1124.     DEBUG(6, "returns %s\n", addr);
  1125.  
  1126.     return(addr);
  1127. }
  1128. SHAR_EOF
  1129. if test 6688 -ne "`wc -c muucp.c`"
  1130. then
  1131. echo shar: error transmitting muucp.c '(should have been 6688 characters)'
  1132. fi
  1133. echo shar: extracting bsmtp.c '(1226 characters)'
  1134. cat << \SHAR_EOF > bsmtp.c
  1135. /*
  1136.  * sendmail to "batch smtp" mail interface.
  1137.  *    Generates an smtp format message for sending, as a message body, to
  1138.  * to special mailboxes at arpa/uucp bitnet gateways for forwarding on to
  1139.  * other networks.
  1140.  *
  1141.  * Usage is
  1142.  *     bsmtp <smtp-mailbox> <thisdomain> <sender> <addr1> <addr2> ...
  1143.  */
  1144.  
  1145. #include <stdio.h>
  1146. #include <sysexits.h>
  1147.  
  1148. #define VMCOPY    "/usr/bin/vmcopy"
  1149.  
  1150. main(argc, argv)
  1151. int    argc;
  1152. char    *argv[];
  1153. {
  1154.     char    buf[BUFSIZ], cmd[256];
  1155.     FILE    *outp, *popen();
  1156.     int    ret, i;
  1157.  
  1158.     if (argc < 5)
  1159.     {    fprintf(stderr, "usage: %s smtpuser mydomain sender addr...\n",
  1160.             argv[0]);
  1161.         exit(EX_USAGE);
  1162.     }
  1163.  
  1164.     sprintf(cmd,
  1165.         "%s %s class=M fname=MAILER ftype=MAIL width=80 device=PUNCH\n",
  1166.         VMCOPY, argv[1]);
  1167.  
  1168.     outp = popen(cmd, "w");
  1169.  
  1170.     fprintf(outp, "HELO %s\nTICK %d\nVERB ON\nMAIL From:<%s>\n",
  1171.         argv[2], getpid(), argv[3]);
  1172.  
  1173.     while (argc > 4)
  1174.     {    fprintf(outp, "RCPT To:<%s>\n", argv[4]);
  1175.         argv++;
  1176.         argc--;
  1177.     }
  1178.  
  1179.     fprintf(outp, "DATA\n");
  1180.     while (!feof(stdin))
  1181.     {    ret = fread(buf, 1, BUFSIZ, stdin);
  1182.         fwrite(buf, 1, ret, outp);
  1183.     }
  1184.     fprintf(outp, ".\nQUIT\n");
  1185.  
  1186.     i = pclose(outp);
  1187.  
  1188.     /*  check for errors  */
  1189.     if ((i & 0377) != 0)
  1190.     {
  1191.         fprintf(stderr, "pclose: status 0%o\n", i);
  1192.         exit(EX_OSERR);
  1193.     }
  1194.  
  1195.     exit((i >> 8) & 0377);
  1196. }
  1197. SHAR_EOF
  1198. if test 1226 -ne "`wc -c bsmtp.c`"
  1199. then
  1200. echo shar: error transmitting bsmtp.c '(should have been 1226 characters)'
  1201. fi
  1202. echo shar: extracting rmail.c '(3831 characters)'
  1203. cat << \SHAR_EOF > rmail.c
  1204. #ifndef lint
  1205. static char sccsid[] =    "@(#)rmail.c    4.4 (Berkeley) 8/11/83";
  1206. #endif
  1207.  
  1208. /*
  1209. **  RMAIL -- UUCP mail server.
  1210. **
  1211. **    This program reads the >From ... remote from ... lines that
  1212. **    UUCP is so fond of and turns them into something reasonable.
  1213. **    It calls sendmail giving it a -f option built from these
  1214. **    lines.
  1215. **
  1216. **    Modified to set the sender's hostname (deduced from first
  1217. **    "remote from host" line) and convert the final "user" part
  1218. **    from an address with '@' and '%' (which mmdf is so fond of)
  1219. **    in to a 'pure' uucp address.    -Jim Crammond, (hwcs!jim) 29/11/84
  1220. */
  1221.  
  1222. # include <stdio.h>
  1223. # include <sysexits.h>
  1224.  
  1225. typedef char    bool;
  1226. #define TRUE    1
  1227. #define FALSE    0
  1228.  
  1229. extern FILE    *popen();
  1230. extern char    *index();
  1231. extern char    *rindex();
  1232. char    *perc_to_uucp();
  1233.  
  1234. bool    Debug;
  1235.  
  1236. # define MAILER    "/usr/lib/sendmail"
  1237.  
  1238. main(argc, argv)
  1239.     char **argv;
  1240. {
  1241.     FILE *out;     /* output to sendmail */
  1242.     char lbuf[512];     /* one line of the message */
  1243.     char from[512];     /* accumulated path of sender */
  1244.     char ufrom[128]; /* user on remote system */
  1245.     char sys[64];     /* a system in path */
  1246.     char sysname[64]; /* system received from */
  1247.     char cmd[2000];
  1248.     register char *cp;
  1249.     register char *uf;    /* ptr into ufrom */
  1250.     int linecount;
  1251.     int i;
  1252.  
  1253. # ifdef DEBUG
  1254.     if (argc > 1 && strcmp(argv[1], "-T") == 0)
  1255.     {
  1256.         Debug = TRUE;
  1257.         argc--;
  1258.         argv++;
  1259.     }
  1260. # endif DEBUG
  1261.  
  1262.     if (argc < 2)
  1263.     {
  1264.         fprintf(stderr, "Usage: rmail user ...\n");
  1265.         exit(EX_USAGE);
  1266.     }
  1267.  
  1268.     (void) strcpy(from, "");
  1269.     (void) strcpy(sysname, "");
  1270.     (void) strcpy(ufrom, "/dev/null");
  1271.  
  1272.     linecount = 0;
  1273.     while (fgets(lbuf, sizeof lbuf, stdin) != NULL)
  1274.     {
  1275.         if (strncmp(lbuf, "From ", 5) != 0 && strncmp(lbuf, ">From ", 6) != 0)
  1276.             break;
  1277.         linecount++;
  1278.         (void) sscanf(lbuf, "%*s %s", ufrom);
  1279.         cp = lbuf;
  1280.         uf = ufrom;
  1281.  
  1282.         while ((cp = index(cp, 'r')) != NULL)
  1283.         {
  1284. #ifdef DEBUG
  1285.             if (Debug)
  1286.                 printf("cp='%s'\n", cp);
  1287. #endif
  1288.             if (sscanf(cp, "remote from %s", sys) == 1)
  1289.             {    (void) strcat(from, sys);
  1290.                 (void) strcat(from, "!");
  1291.                 if (linecount == 1)
  1292.                     (void) strcpy(sysname, sys);
  1293.                 break;
  1294.             }
  1295.             cp++;
  1296.         }
  1297. #ifdef DEBUG
  1298.         if (Debug)
  1299.             printf("ufrom='%s', sys='%s', from now '%s'\n", uf, sys, from);
  1300. #endif
  1301.     }
  1302.  
  1303.     /*
  1304.      *  check for percent style addresses in user field
  1305.      */
  1306.     if (index(uf, '@') != NULL || index(uf, '%') != NULL)
  1307.         uf = perc_to_uucp(uf);
  1308.  
  1309.     /*
  1310.      *  if this is a new style "From domain!user .. remote from system"
  1311.      *  header then don't prepend the system name to the from person
  1312.      */
  1313.     if (linecount == 1 && (cp = index(uf, '!')) != NULL)
  1314.     {    char  *p = index(uf, '.');
  1315.         if (p != NULL && p < cp)
  1316.             (void) strcpy(from, uf);
  1317.         else
  1318.             (void) strcat(from, uf);
  1319.     }
  1320.     else
  1321.         (void) strcat(from, uf);
  1322.  
  1323.     (void) sprintf(cmd, "%s -em -f%s", MAILER, from);
  1324.     if (*sysname != '\0')
  1325.     {    (void) strcat(cmd, " -oMs");
  1326.         (void) strcat(cmd, sysname);
  1327.     }
  1328.  
  1329.     while (*++argv != NULL)
  1330.     {
  1331.         (void) strcat(cmd, " '");
  1332.         if (**argv == '(')
  1333.             (void) strncat(cmd, *argv + 1, strlen(*argv) - 2);
  1334.         else
  1335.             (void) strcat(cmd, *argv);
  1336.         (void) strcat(cmd, "'");
  1337.     }
  1338. #ifdef DEBUG
  1339.     if (Debug)
  1340.         printf("cmd='%s'\n", cmd);
  1341. #endif
  1342.     out = popen(cmd, "w");
  1343.     fputs(lbuf, out);
  1344.     while (fgets(lbuf, sizeof lbuf, stdin))
  1345.         fputs(lbuf, out);
  1346.     i = pclose(out);
  1347.     if ((i & 0377) != 0)
  1348.     {
  1349.         fprintf(stderr, "pclose: status 0%o\n", i);
  1350.         exit(EX_OSERR);
  1351.     }
  1352.  
  1353.     exit((i >> 8) & 0377);
  1354. }
  1355.  
  1356.  
  1357. /*
  1358. **  PERC_TO_UUCP  --  converts an address in Percent style into uucp style
  1359. **
  1360. **    e.g.  user%c.bitnet%b.arpa@a.uucp -> a.uucp!b.arpa!c.bitnet!user
  1361. */    
  1362. char    *
  1363. perc_to_uucp(addr)
  1364. char    *addr;
  1365. {
  1366.     static    char    buf[512];
  1367.     char    *bp = buf;
  1368.     char    *p;
  1369.  
  1370. #ifdef DEBUG
  1371.     if (Debug)
  1372.         printf("perc_to_uucp(%s) ", addr);
  1373. #endif
  1374.  
  1375.     while ((p = rindex(addr,'@')) != NULL || (p = rindex(addr,'%')) != NULL)
  1376.     {
  1377.         *p++ = '\0';
  1378.         while (*p)
  1379.             *bp++ = *p++;
  1380.  
  1381.         *bp++ = '!';
  1382.     }
  1383.  
  1384.     strcpy(bp, addr);
  1385. #ifdef DEBUG
  1386.     printf("returns %s\n", buf);
  1387. #endif
  1388.     return(buf);
  1389. }
  1390. SHAR_EOF
  1391. if test 3831 -ne "`wc -c rmail.c`"
  1392. then
  1393. echo shar: error transmitting rmail.c '(should have been 3831 characters)'
  1394. fi
  1395. echo shar: done with directory Support
  1396. cd ..
  1397. #    End of shell archive
  1398. exit 0
  1399.  
  1400.