home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / OS2 / BSRCP240.ZIP / FTSC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-22  |  18.1 KB  |  754 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                            */
  3. /*                                                                            */
  4. /*        ------------         Bit-Bucket Software, Co.                        */
  5. /*        \ 10001101 /         Writers and Distributors of                    */
  6. /*         \ 011110 /          Freely Available<tm> Software.                 */
  7. /*          \ 1011 /                                                            */
  8. /*           ------                                                            */
  9. /*                                                                            */
  10. /*    (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                            */
  12. /*                                                                            */
  13. /*                   This module was written by Bob Hartman                    */
  14. /*                                                                            */
  15. /*                                                                            */
  16. /*                   BinkleyTerm FTSC Mail Session Routines                    */
  17. /*                                                                            */
  18. /*                                                                            */
  19. /*      For complete    details  of the licensing restrictions, please refer    */
  20. /*      to the License  agreement,  which  is published in its entirety in    */
  21. /*      the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  22. /*                                                                            */
  23. /*      USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*      BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*      THIS    AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,    OR IF YOU DO    */
  26. /*      NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*      SOFTWARE CO.    AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*      SHOULD YOU  PROCEED TO USE THIS FILE    WITHOUT HAVING    ACCEPTED THE    */
  29. /*      TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*      AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.        */
  31. /*                                                                            */
  32. /*                                                                            */
  33. /* You can contact Bit Bucket Software Co. at any one of the following        */
  34. /* addresses:                                                                */
  35. /*                                                                            */
  36. /* Bit Bucket Software Co.          FidoNet  1:104/501, 1:132/491, 1:141/491    */
  37. /* P.O. Box 460398                  AlterNet 7:491/0                            */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                  Internet f491.n132.z1.fidonet.org         */
  40. /*                                                                            */
  41. /* Please feel free to contact us at any time to share your comments about    */
  42. /* our software and/or licensing policies.                                    */
  43. /*                                                                            */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. #include <stdio.h>
  47. #include <signal.h>
  48. #include <ctype.h>
  49. #include <conio.h>
  50. #include <time.h>
  51. #include <string.h>
  52. #include <io.h>
  53. #include <stdlib.h>
  54. #include <errno.h>
  55. #include <sys\types.h>
  56. #include <sys\stat.h>
  57.  
  58. #ifdef __TURBOC__
  59. #include <alloc.h>
  60. #else
  61. #include <malloc.h>
  62. #endif
  63.  
  64. #define WAZOO_SECTION
  65. #define MATRIX_SECTION
  66.  
  67. #define isBITBRAIN 0x1b
  68.  
  69. #include "com.h"
  70. #include "xfer.h"
  71. #include "zmodem.h"
  72. #include "keybd.h"
  73. #include "sbuf.h"
  74. #include "sched.h"
  75. #include "externs.h"
  76. #include "prototyp.h"
  77. #include "defines.h"
  78.  
  79. #define rb_plus "r+b"
  80.  
  81. static int FTSC_callback (char *);
  82. static int FTSC_sendmail (void);
  83. static int FTSC_recvmail (void);
  84.  
  85. static int is_wazoo_session;
  86.  
  87. #define NUM_FLAGS 4
  88.  
  89. void FTSC_sender (wz)
  90. int wz;
  91. {
  92.    int j;
  93.    char junkbuff[128];
  94.    long t1, timerset ();
  95.  
  96.    is_wazoo_session = wz;
  97.    XON_DISABLE ();
  98.    first_block = 0;
  99.  
  100.    if (!wz)
  101.       {
  102.        first_block = 1;
  103.       status_line (msgtxt[M_SEND_FALLBACK]);
  104.       who_is_he = 0;
  105.       (void) sprintf (junkbuff, "*%s (%s)",
  106.                newnodedes.SystemName,
  107.                Full_Addr_Str (&remote_addr));
  108.       status_line (junkbuff);
  109.       }
  110.  
  111.    Netmail_Session = 1;
  112.  
  113.    (void) FTSC_sendmail ();
  114.    t1 = timerset (4500);
  115.  
  116.    /* See what the receiver would like us to do */
  117.    while ((!timeup (t1)) && CARRIER)
  118.       {
  119.       if ((j = PEEKBYTE ()) >= 0)
  120.          {
  121.          switch (j)
  122.             {
  123.             case TSYNC:
  124.                CLEAR_INBOUND ();
  125.                if (FTSC_recvmail ())
  126.                   goto get_out;
  127.                t1 = timerset (4500);
  128.                break;
  129.  
  130.             case SYN:
  131.                CLEAR_INBOUND ();
  132.                if (on_our_nickel)
  133.                   (void) SEA_recvreq ();
  134.                else
  135.                   {
  136.                   SENDBYTE (CAN);
  137.                   status_line (msgtxt[M_REFUSING_IN_FREQ]);
  138.                   }
  139.                t1 = timerset (4500);
  140.                break;
  141.  
  142.             case ENQ:
  143.                CLEAR_INBOUND ();
  144.                SEA_sendreq ();
  145.                goto get_out;
  146.  
  147.             case NAK:
  148.             case 'C':
  149.                CLEAR_INBOUND ();
  150.                SENDBYTE (EOT);
  151.                t1 = timerset (4500);
  152.                break;
  153.  
  154.             default:
  155.                CLEAR_INBOUND ();
  156.                SENDBYTE (SUB);
  157.                break;
  158.             }
  159.          }
  160.       else
  161.          {
  162.          time_release ();
  163.          }
  164.       }
  165.  
  166.    if (!CARRIER)
  167.       {
  168.       status_line (msgtxt[M_NO_CARRIER]);
  169.       CLEAR_INBOUND ();
  170.       first_block = 0;
  171.       return;
  172.       }
  173.  
  174.    if (timeup (t1))
  175.       {
  176.       (void) FTSC_recvmail ();
  177.       status_line (msgtxt[M_TOO_LONG]);
  178.       }
  179.  
  180. get_out:
  181.    first_block = 0;
  182.    t1 = timerset (100);
  183.    while (!timeup (t1))
  184.       time_release ();
  185.    if (!wz)
  186.       status_line (msgtxt[M_0001_END]);
  187. }
  188.  
  189. int FTSC_receiver (wz)
  190. int wz;
  191. {
  192.    char fname[64];
  193.    int havemail, done, np;
  194.    unsigned int i;
  195.    long t1, t2, timerset ();
  196.    struct FILEINFO dt1;
  197.    struct stat buf;
  198.    char *HoldName;
  199.  
  200.    is_wazoo_session = wz;
  201.    first_block = 0;
  202.    XON_DISABLE ();
  203.  
  204.    if (!wz)
  205.       {
  206.        first_block = 1;
  207.       status_line (msgtxt[M_RECV_FALLBACK]);
  208.       who_is_he = 1;
  209.       }
  210.  
  211.    Netmail_Session = 1;
  212.  
  213.    CLEAR_INBOUND ();
  214.  
  215.    /* Save the state of pickup for now */
  216.    done = no_pickup;
  217.    no_pickup = 0;
  218.    if (FTSC_recvmail ())
  219.       {
  220.       /* Restore the state of pickup */
  221.       no_pickup = done;
  222.       if (!wz)
  223.          status_line (msgtxt[M_0001_END]);
  224.       first_block = 0;
  225.       return (1);
  226.       }
  227.  
  228.    /* Restore the state of pickup */
  229.    no_pickup = done;
  230.  
  231.    remote_addr.Zone = called_addr.Zone;
  232.    remote_addr.Net = called_addr.Net;
  233.    remote_addr.Node = called_addr.Node;
  234.  
  235.    /* If we have the flag file written, then we shouldn't send anything back */
  236.    if (flag_file (TEST_AND_SET, &called_addr, 1))
  237.       {
  238.       havemail = 1;
  239.       goto no_send;
  240.       }
  241.  
  242.    HoldName = HoldAreaNameMunge(&called_addr);
  243.  
  244.    /* Now see if we should send anything back to him */
  245.    (void) sprintf (fname, "%s%s.?UT", HoldName, Hex_Addr_Str (&remote_addr));
  246.    havemail = dfind (&dt1, fname, 0);
  247.  
  248.    if (havemail)
  249.       {
  250.       (void) sprintf (fname, "%s%s.?LO", HoldName, Hex_Addr_Str (&remote_addr));
  251.       havemail = dfind (&dt1, fname, 0);
  252.       }
  253.  
  254.    if (havemail)
  255.       {
  256.       for (np = 0; np <= ALIAS_CNT; np++)
  257.          {
  258.          if (alias[np].Net == 0)
  259.             break;
  260.          (void) sprintf (fname, "%s%s.REQ", CurrentNetFiles, Hex_Addr_Str (&(alias[np])));
  261.          havemail = dfind (&dt1, fname, 0);
  262.          if (!havemail)
  263.             break;
  264.          }
  265.       }
  266.  
  267. no_send:
  268.  
  269.    if (havemail)
  270.       {
  271.       status_line (msgtxt[M_NOTHING_TO_SEND], Full_Addr_Str (&remote_addr));
  272.       }
  273.    else
  274.       {
  275.       status_line (msgtxt[M_GIVING_MAIL], Full_Addr_Str (&remote_addr));
  276.       /* Send the TSYNC's until we get a C or NAK or CAN back */
  277.       t1 = timerset (3000);                      /* set 30 second timeout */
  278.       done = 0;
  279.       while (!timeup (t1) && CARRIER && !done)     /* till then or CD lost  */
  280.          {
  281.          SENDBYTE (TSYNC);
  282.  
  283.          t2 = timerset (300);
  284.          while (CARRIER && (!timeup (t2)) && !done)
  285.             {
  286.             switch (TIMED_READ (0))
  287.                {
  288.                case 'C':
  289.                case NAK:
  290.                   done = 1;
  291.                   (void) FTSC_sendmail ();
  292.                   break;
  293.  
  294.                case CAN:
  295.                   done = 1;
  296.                   status_line (msgtxt[M_REFUSE_PICKUP], Full_Addr_Str (&remote_addr));
  297.                   break;
  298.  
  299.                default:
  300.                   time_release ();
  301.                }
  302.             }
  303.          }
  304.       }
  305.  
  306.    first_block = 0;
  307.  
  308.    if (wz)
  309.       {
  310.       flag_file (CLEAR_FLAG, &called_addr, 1);
  311.       return TRUE;                        /* All done if this is WaZOO */
  312.       }
  313.  
  314.    /* Now see if we want to request anything */
  315.    (void) sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&remote_addr));
  316.    if (!stat (fname, &buf))
  317.       {
  318.       /* Send the SYN character and wait for an ENQ or CAN */
  319.       t1 = timerset (3000);                      /* set 30 second timeout */
  320.       done = 0;
  321.       while (!timeup (t1) && CARRIER && !done)     /* till then or CD lost  */
  322.          {
  323.          SENDBYTE (SYN);
  324.  
  325.          t2 = timerset (500);
  326.          while (CARRIER && (!timeup (t2)) && !done)
  327.             {
  328.             i = (unsigned) TIMED_READ (0);
  329.  
  330.             switch (i)
  331.                {
  332.                case ENQ:
  333.                   SEA_sendreq ();
  334.                   break;
  335.  
  336.                case CAN:
  337.                   done = 1;
  338.                   break;
  339.  
  340.                case 'C':
  341.                case NAK:
  342.                   SENDBYTE (EOT);
  343.                   break;
  344.  
  345.                case SUB:
  346.                   SENDBYTE (SYN);
  347.                   break;
  348.  
  349.                default:
  350.                   time_release ();
  351.                }
  352.             }
  353.          }
  354.       }
  355.  
  356.    /* Finally, can he request anything from us */
  357.    if (!no_requests)
  358.       (void) SEA_recvreq ();
  359.  
  360.    status_line (msgtxt[M_0001_END]);
  361.    flag_file (CLEAR_FLAG, &called_addr, 1);
  362.    return TRUE;
  363. }
  364.  
  365. static int FTSC_sendmail ()
  366. {
  367.    FILE *fp;
  368.    char fname[80];
  369.    char s[80];
  370.    char *sptr;
  371.    char *HoldName;
  372.    int c;
  373.    int i;
  374.    int j = 0;
  375.    struct stat buf;
  376.    struct _pkthdr *tmppkt;
  377.    long t1, time (), timerset ();
  378.    struct tm *tm1, *localtime ();
  379.  
  380.    XON_DISABLE ();
  381.  
  382.    sptr = s;
  383.    /*--------------------------------------------------------------------*/
  384.    /* Send all waiting ?UT files (mail packets)                          */
  385.    /*--------------------------------------------------------------------*/
  386.    *ext_flags = 'O';
  387.    HoldName = HoldAreaNameMunge(&called_addr);
  388.    for (c = 0; c < NUM_FLAGS; c++)
  389.       {
  390. #ifndef JACK_DECKER
  391.       if (caller && (ext_flags[c] == 'H'))
  392.          continue;
  393. #endif
  394.  
  395.       (void) sprintf (fname,
  396.                "%s%s.%cUT",
  397.                HoldName, Hex_Addr_Str (&called_addr), ext_flags[c]);
  398.  
  399.       if (!stat (fname, &buf))
  400.          break;
  401.       }                                          /* for */
  402.  
  403.    /*--- Build a dummy PKT file name */
  404.    invent_pkt_name (s);
  405.  
  406.    status_line (msgtxt[M_PACKET_MSG]);
  407.  
  408.    if (c == NUM_FLAGS)
  409.       {
  410.       (void) sprintf (fname,
  411.                "%s%s.OUT",
  412.                HoldName, Hex_Addr_Str (&called_addr));
  413.       if ((fp = fopen (fname, "wb")) == NULL)
  414.          {
  415.          (void) got_error (msgtxt[M_OPEN_MSG], fname);
  416.          return (1);
  417.          }
  418.       t1 = time (NULL);
  419.       tm1 = localtime (&t1);
  420.  
  421.       tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
  422.       if (tmppkt == NULL)
  423.          {
  424.          status_line (msgtxt[M_MEM_ERROR]);
  425.          (void) fclose (fp);
  426.          return (1);
  427.          }
  428.       tmppkt->orig_node = (int) alias[assumed].Node;
  429.       tmppkt->dest_node = called_addr.Node;
  430.       tmppkt->ver = PKTVER;
  431.       tmppkt->orig_net = (int) alias[assumed].Net;
  432.       tmppkt->dest_net = called_addr.Net;
  433.       tmppkt->product = isBITBRAIN;
  434.       if (n_getpassword (&called_addr))
  435.          {
  436.          if (remote_password != NULL)
  437.             {
  438.             (void) strupr (remote_password);
  439.             (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  440.             }
  441.          }
  442.       tmppkt->orig_zone = (int) alias[assumed].Zone;
  443.       tmppkt->dest_zone = called_addr.Zone;
  444.  
  445.       if ((called_addr.Domain != NULL) &&
  446.           (called_addr.Domain != alias[assumed].Domain) &&
  447.           (my_addr.Domain != NULL))
  448.          {
  449.          /* Make it a type 2.2 packet instead */
  450.          tmppkt->year = alias[assumed].Point;
  451.          tmppkt->month = called_addr.Point;
  452.          tmppkt->day = 0;
  453.          tmppkt->hour = 0;
  454.          tmppkt->minute = 0;
  455.          tmppkt->second = 0;
  456.          tmppkt->rate = 2;
  457.          if (alias[assumed].Domain != NULL)
  458.             {
  459.             for (i = 0; domain_name[i] != NULL; i++)
  460.                {
  461.                if (domain_name[i] == alias[assumed].Domain)
  462.                   {
  463.                   break;
  464.                   }
  465.                }
  466.             if (i < 49)
  467.                {
  468.                strncpy (tmppkt->B_fill2, domain_abbrev[i], 8);
  469.                }
  470.             }
  471.          for (i = 0; domain_name[i] != NULL; i++)
  472.             {
  473.             if (domain_name[i] == called_addr.Domain)
  474.                {
  475.                break;
  476.                }
  477.             }
  478.          if (i < 49)
  479.             {
  480.             strncpy (&(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  481.             }
  482.          }
  483.       else
  484.          {
  485.          tmppkt->year = tm1->tm_year;
  486.          tmppkt->month = tm1->tm_mon;
  487.          tmppkt->day = tm1->tm_mday;
  488.          tmppkt->hour = tm1->tm_hour;
  489.          tmppkt->minute = tm1->tm_min;
  490.          tmppkt->second = tm1->tm_sec;
  491.          tmppkt->rate = 0;
  492.          }
  493.  
  494.       (void) fwrite ((char *) tmppkt, sizeof (struct _pkthdr), 1, fp);
  495.       free (tmppkt);
  496.       (void) fwrite ("\0\0", 2, 1, fp);
  497.       (void) fclose (fp);
  498.       }
  499.    else
  500.       {
  501.       if ((fp = fopen (fname, rb_plus)) == NULL)
  502.          {
  503.          (void) got_error (msgtxt[M_OPEN_MSG], fname);
  504.          return (1);
  505.          }
  506.       tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
  507.       if (tmppkt == NULL)
  508.          {
  509.          status_line (msgtxt[M_MEM_ERROR]);
  510.          return (1);
  511.          }
  512.       if (fread (tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  513.          {
  514.          (void) got_error (msgtxt[M_READ_MSG], fname);
  515.          free (tmppkt);
  516.          (void) fclose (fp);
  517.          return (1);
  518.          }
  519.  
  520.       if (n_getpassword (&called_addr))
  521.          {
  522.          if (remote_password != NULL)
  523.             {
  524.             (void) strupr (remote_password);
  525.             (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  526.             }
  527.          }
  528.  
  529.  
  530.       /* Make sure the zone info is in there */
  531.  
  532.       tmppkt->orig_node = (int) alias[assumed].Node;
  533.       tmppkt->orig_net    = (int) alias[assumed].Net;
  534.       tmppkt->orig_zone = (int) alias[assumed].Zone;
  535.       tmppkt->dest_zone = called_addr.Zone;
  536.  
  537.       if ((called_addr.Domain != NULL) &&
  538.           (called_addr.Domain != alias[assumed].Domain) &&
  539.           (my_addr.Domain != NULL))
  540.          {
  541.          /* Make it a type 2.2 packet instead */
  542.          tmppkt->year = alias[assumed].Point;
  543.          tmppkt->month = called_addr.Point;
  544.          tmppkt->day = 0;
  545.          tmppkt->hour = 0;
  546.          tmppkt->minute = 0;
  547.          tmppkt->second = 0;
  548.          tmppkt->rate = 2;
  549.          if (alias[assumed].Domain != NULL)
  550.             {
  551.             for (i = 0; domain_name[i] != NULL; i++)
  552.                {
  553.                if (domain_name[i] == alias[assumed].Domain)
  554.                   {
  555.                   break;
  556.                   }
  557.                }
  558.             if (i < 49)
  559.                {
  560.                strncpy (tmppkt->B_fill2, domain_abbrev[i], 8);
  561.                }
  562.             }
  563.          for (i = 0; domain_name[i] != NULL; i++)
  564.             {
  565.             if (domain_name[i] == called_addr.Domain)
  566.                {
  567.                break;
  568.                }
  569.             }
  570.          if (i < 49)
  571.             {
  572.             strncpy (&(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  573.             }
  574.          }
  575.  
  576.       (void) fseek (fp, 0L, SEEK_SET);
  577.       (void) fwrite (tmppkt, 1, sizeof (struct _pkthdr), fp);
  578.       (void) fclose (fp);
  579.       free (tmppkt);
  580.       }
  581.  
  582.    net_problems = (no_sealink) ? Telink_Send_File (fname, s) : SEAlink_Send_File (fname, s);
  583.  
  584.    if (net_problems != 0)
  585.       {
  586.       if (c == NUM_FLAGS)
  587.          (void) unlink (fname);
  588.       return (net_problems);
  589.       }
  590.  
  591.    /* Delete the sent packet */
  592.    (void) unlink (fname);
  593.  
  594.  
  595.    /*--------------------------------------------------------------------*/
  596.    /* Send files listed in ?LO files (attached files)                     */
  597.    /*--------------------------------------------------------------------*/
  598.    *ext_flags = 'F';
  599.    status_line (" %s %s", msgtxt[M_OUTBOUND], msgtxt[M_FILE_ATTACHES]);
  600.  
  601.    if (!do_FLOfile (ext_flags, FTSC_callback))
  602.       return FALSE;
  603.  
  604.  
  605.    /*--------------------------------------------------------------------*/
  606.    /* Send our File requests to other system if it's a WaZOO             */
  607.    /*--------------------------------------------------------------------*/
  608.  
  609.    if (requests_ok && remote_capabilities)
  610.       {
  611.       (void) sprintf (fname, request_template, HoldName, Hex_Addr_Str (&called_addr));
  612.       if (!stat (fname, &buf))
  613.          {
  614.          if (!(((unsigned) remote_capabilities) & WZ_FREQ))
  615.             status_line (msgtxt[M_FREQ_DECLINED]);
  616.          else
  617.             {
  618.             status_line (msgtxt[M_MAKING_FREQ]);
  619.             if (FTSC_callback (fname))
  620.                (void) unlink (fname);
  621.             }
  622.          }
  623.       }
  624.  
  625.    /*--------------------------------------------------------------------*/
  626.    /* Process WaZOO file requests from other system                      */
  627.    /*--------------------------------------------------------------------*/
  628.  
  629.    j = respond_to_file_requests (j, FTSC_callback);
  630.  
  631.    /* Now close out the file attaches */
  632.    sent_mail = 1;
  633.    *sptr = 0;
  634.    status_line (" %s %s %s", msgtxt[M_END_OF], msgtxt[M_OUTBOUND], msgtxt[M_FILE_ATTACHES]);
  635.     (void) Batch_Send (NULL);
  636.    t1 = timerset (100);
  637.    return TRUE;
  638. }
  639.  
  640. static int FTSC_recvmail ()
  641. {
  642.    char fname[80];
  643.    char fname1[80];
  644.    struct _pkthdr tmppkt;
  645.    FILE *fp;
  646.    int done;
  647.    int j;
  648.    char *p;
  649.    extern char *receive_file ();
  650.  
  651.    status_line (msgtxt[M_RECV_MAIL]);
  652.  
  653.    if (!CARRIER)
  654.       {
  655.       status_line (msgtxt[M_NO_CARRIER]);
  656.       CLEAR_INBOUND ();
  657.       return (1);
  658.       }
  659.  
  660.    XON_DISABLE ();
  661.  
  662.     done = 0;
  663.  
  664.    /* If we don't want to pickup stuff */
  665.    if (no_pickup)
  666.       {
  667.       status_line (msgtxt[M_NO_PICKUP]);
  668.       SENDBYTE (CAN);
  669.       }
  670.    else
  671.       {
  672.       status_line (" %s %s", msgtxt[M_INBOUND], msgtxt[M_MAIL_PACKET]);
  673.       /* Invent a dummy name for the packet */
  674.       invent_pkt_name (fname1);
  675.  
  676.       /* Receive the packet with special netmail protocol */
  677.       CLEAR_INBOUND ();
  678.       p = CurrentNetFiles;
  679.       if (Xmodem_Receive_File (CurrentNetFiles, fname1) == 0)
  680.          {
  681.          got_packet = 1;
  682.          }
  683.       (void) sprintf (fname, "%s%s", p, fname1);
  684.  
  685.       /* Check the password if there is one */
  686.       if ((!remote_capabilities) && (n_getpassword (&remote_addr)))
  687.          {
  688.          if (remote_password != NULL)
  689.             {
  690.             got_packet = 0;
  691.             if ((fp = fopen (fname, rb_plus)) == NULL)
  692.                {
  693.                (void) got_error (msgtxt[M_OPEN_MSG], fname);
  694.                status_line (msgtxt[M_PWD_ERR_ASSUMED]);
  695.                return (1);
  696.                }
  697.             if (fread (&tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  698.                {
  699.                (void) got_error (msgtxt[M_OPEN_MSG], fname);
  700.                status_line (msgtxt[M_PWD_ERR_ASSUMED]);
  701.                (void) fclose (fp);
  702.                return (1);
  703.                }
  704.             (void) fclose (fp);
  705.             if (strnicmp (remote_password, (char *) (tmppkt.password), 8))
  706.                {
  707.                tmppkt.orig_zone = 0;
  708.                strncpy (fname1, remote_password, 8);
  709.                fname1[8] = '\0';
  710.                status_line (msgtxt[M_PWD_ERROR], tmppkt.password, fname1);
  711.                (void) strcpy (fname1, fname);
  712.                j = (int) strlen (fname) - 3;
  713.                (void) strcpy (&(fname[j]), "Bad");
  714.                if (rename (fname1, fname))
  715.                   {
  716.                   status_line (msgtxt[M_CANT_RENAME_MAIL], fname1);
  717.                   }
  718.                else
  719.                   {
  720.                   status_line (msgtxt[M_MAIL_PACKET_RENAMED], fname);
  721.                   }
  722.                return (1);
  723.                }
  724.             }
  725.          got_packet = 1;
  726.          }
  727.       called_addr.Zone = remote_addr.Zone;
  728.       called_addr.Net = remote_addr.Net;
  729.       called_addr.Node = remote_addr.Node;
  730.       got_mail = got_packet;
  731.  
  732.       done = 0;
  733.       /* Now receive the files if possible */
  734.       status_line (" %s %s", msgtxt[M_INBOUND], msgtxt[M_FILE_ATTACHES]);
  735.       done = Batch_Receive (CurrentNetFiles);
  736.       }
  737.  
  738.    status_line (" %s %s %s", msgtxt[M_END_OF], msgtxt[M_INBOUND], msgtxt[M_FILE_ATTACHES]);
  739.    CLEAR_INBOUND ();
  740.    return (done);
  741. }
  742.  
  743. static int FTSC_callback (sptr)
  744. char *sptr;
  745. {
  746.    net_problems = Batch_Send (sptr);
  747.    if (net_problems != 0)
  748.       {
  749.       net_problems = 1;
  750.       return FALSE;
  751.       }
  752.    return TRUE;
  753. }
  754.