home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / src / uucp / uu_wtmail.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  5.7 KB  |  218 lines

  1. /*
  2.  *                      U U _ W T M A I L . C
  3.  *
  4.  *      Part of the UUCP channel of the MMDF Mail system developed
  5.  *      by Doug Kingston at the US Army, Ballistics Research Laboratory.
  6.  *                              <DPK@BRL>
  7.  *
  8.  *      Low-level IO to handle mail delivery to the UUCP
  9.  *      queuing system.  Calls are made from qu2uu_send.c.
  10.  *
  11.  *                  Original Version November 1981
  12.  */
  13.  
  14. #include "util.h"
  15. #include "mmdf.h"
  16. #include "ch.h"
  17. #include "ap.h"
  18.  
  19. extern struct ll_struct *logptr;
  20. extern Chan *curchan;
  21. extern char *Uuxstr, *Uuname;
  22. extern int errno;
  23. extern int pbroke;
  24.  
  25. extern int ap_outtype;
  26. extern AP_ptr ap_s2tree ();
  27.  
  28. /*
  29.  *      -----  Variables Local to this Module  -----
  30.  */
  31. static FILE     *uucpf;                   /* used by POPEN(III) */
  32. static char     nextnode[LINESIZE];
  33. static char     who[LINESIZE];
  34.  
  35. /* */
  36.  
  37. /*
  38.  *      uu_wtadr() takes the given host and address and generates
  39.  *      a valid uucp style address and verifies that the given host
  40.  *      is in the mapping tables.  If so, it then invokes UUCP with
  41.  *      the appropriate arguments.
  42.  */
  43. uu_wtadr (host, adr, sender, realfrom)
  44.     char    *host, *adr, *sender, *realfrom;
  45. {
  46.     char        *index(), *rindex();
  47.     FILE        *popen();
  48.     char        *bangptr;
  49.     time_t      timenow;
  50.     char        linebuf[LINESIZE];
  51.     char        *atp, *percentp, *lp;
  52.     AP_ptr      ap, local, domain;
  53.  
  54.     ap_outtype = AP_733;        /* LMCL */
  55.  
  56. #ifdef DEBUG
  57.     ll_log (logptr, LLOGBTR, "uu_wtadr()");
  58.     ll_log (logptr, LLOGFTR, "host='%s', adr='%s', sender='%s', realfrom='%s'",
  59.         host, adr, sender, realfrom );
  60.     ll_log (logptr, LLOGFTR, "ap_outtype = %o", ap_outtype);
  61. #endif
  62.  
  63.     strcpy(nextnode,"");
  64.     strcpy(who,"");
  65.  
  66.     if ((ap = ap_s2tree (adr)) == (AP_ptr) NOTOK)
  67.     {
  68.     ll_log (logptr, LLOGTMP, "Failure to parse address '%s'", adr);
  69.     return (RP_PARM);
  70.     }
  71.     ap_t2parts(ap, (AP_ptr *)0, (AP_ptr *)0, &local, &domain, (AP_ptr *)0);
  72.     lp = ap_p2s( (AP_ptr)0, (AP_ptr)0, local, domain, (AP_ptr)0);
  73.  
  74.     atp = index (lp, '@');
  75.     if (atp != (char *)0)
  76.     *atp++ = '\0';
  77.     if (lexequ(atp, host))
  78.     atp = (char *)0;    /* don't make path-to-foo!foo.uucp!user */
  79.     
  80.     percentp = rindex (lp, '%');
  81.     if (percentp != (char *) 0) {
  82.     *percentp = '\0';
  83.         if (atp)
  84.         sprintf (adr, "%s!%s!%s", atp, ++percentp, lp);
  85.         else
  86.         sprintf (adr, "%s!%s", ++percentp, lp);
  87.     } else if (atp) {
  88.     sprintf (adr, "%s!%s", atp, lp);
  89.     } else
  90.     strcpy(adr, lp);
  91.     free (lp);
  92.  
  93.     ll_log (logptr, LLOGFST, "address = '%s'", adr);
  94.  
  95.     if (!isstr(host))
  96.         strcpy(who, adr);
  97.     else {
  98.         switch(tb_k2val (curchan -> ch_table, TRUE, host, nextnode)) {
  99.         case NOTOK:
  100.         return (RP_USER);       /* No such host */
  101.         case MAYBE:
  102.             return (RP_NS);
  103.         }
  104.         sprintf(who, nextnode, adr);
  105.     }
  106.  
  107.     /* Extract first host name for destination */
  108.     if ((bangptr=index (who, '!')) != NULL)
  109.     {
  110.     /* There is at least one relay machine */
  111.     *bangptr++ = '\0';
  112.     strcpy (nextnode, who);
  113.     strcpy(who, bangptr);
  114.     }
  115.     else strcpy(nextnode, "");
  116.  
  117.     sprintf (linebuf, "%s %s!rmail \\(%s%s\\)",
  118.         Uuxstr, nextnode, *who=='~' ? "\\\\" : "", who);
  119.  
  120. #ifdef DEBUG
  121.     ll_log (logptr, LLOGFTR, "calling uux with <%s>", linebuf);
  122. #endif
  123.  
  124.     printx ("Queuing UUCP mail for %s via %s...\n",
  125.         who, nextnode);
  126.  
  127.     if ((uucpf = popen (linebuf, "w")) == NULL) {
  128.     ll_log (logptr, LLOGFAT, "can't popen UUX (errno %d)", errno);
  129.     return (RP_AGN);
  130.     }
  131.  
  132.     time (&timenow);
  133.     fprintf (uucpf, "From %s %.24s remote from %s\n",
  134.         realfrom, ctime(&timenow), Uuname);
  135.  
  136. #ifdef DEBUG
  137.     ll_log (logptr, LLOGFTR, "Done uu_wtadr().");
  138. #endif
  139.     return (RP_OK);
  140. }
  141. /* */
  142.  
  143. /*
  144.  *      UU_TXTCPY()
  145.  *
  146.  *      The special function of this guy is to grap the "From" line
  147.  *      from the message header and move it to the first line and to
  148.  *      put in standard UUCP form.  There are programs that depend
  149.  *      on this line on less sophisticated systems.  I hate to louse
  150.  *      up a perfectly good RFC733 letter but that's life!
  151.  *
  152.  *      Too refresh your memory, when this module is called, the "From"
  153.  *      line has already been written out onto the pipe.  We now want
  154.  *      copy the rest of the header out onto pipe a line at a time
  155.  *      so that we cat remove the original From line.
  156.  *
  157.  *      SEK - have changed this.  Do not mungle now so we
  158.  *      can use the deliver reformatting.
  159.  *      It seems preferable to leave the orginal From: line
  160.  *      Other sendmail and MMDF systems will prefer this
  161.  *      Older systems will have to lump it
  162.  */
  163.  
  164. uu_txtcpy()
  165. {
  166.     int     nread;
  167.     char    buffer[BUFSIZ];
  168.  
  169.     ll_log (logptr, LLOGFTR," uu_txtcpy()");
  170.  
  171.     qu_rtinit (0L);             /* ready to read the text             */
  172.  
  173.     nread = sizeof(buffer);
  174.     while (!pbroke && (rp_gval (qu_rtxt (buffer, &nread)) == RP_OK))
  175.     {                             /* send the text                      */
  176.     ll_log (logptr, LLOGFTR, "<%s>", buffer);
  177.     if (fwrite (buffer, sizeof *buffer, nread, uucpf) == 0) {
  178.         ll_log (logptr, LLOGFAT, "write on pipe error (errno %d)", errno);
  179.         ll_log (logptr, LLOGFAT, "pclose returned %d", pclose (uucpf));
  180.         return (RP_LIO);
  181.     }
  182.         nread = sizeof(buffer);
  183.  
  184.     }
  185.  
  186.     fflush(uucpf);              /* see if the pipe broke */
  187.     if (pbroke) {
  188.     ll_log (logptr, LLOGFAT, "pipe broke -- probably bad host");
  189.     pclose(uucpf);
  190.     return (RP_LIO);
  191.     }
  192.  
  193.     ll_log (logptr, LLOGFTR," uu_txtcpy() end");
  194.     return (RP_MOK);              /* got the text out                   */
  195. }
  196.  
  197. /*
  198.  *      uu_wttend()  --  Cleans up after the UUCP
  199.  */
  200. uu_wttend()
  201. {
  202.     if (pclose (uucpf) != 0)
  203.         return (RP_LIO);
  204.     return (RP_MOK);
  205. }
  206.  
  207. /* */
  208.  
  209. /*
  210.  *      LOWERFY()  -  convert string to lower case
  211.  */
  212. lowerfy (strp)
  213.     char *strp;
  214. {
  215.     while (*strp = uptolow (*strp))
  216.         strp++;
  217. }
  218.