home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / FTSC.C < prev    next >
Text File  |  1991-08-15  |  18KB  |  753 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;
  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.          time_release ();
  162.       }
  163.  
  164.    if (!CARRIER)
  165.       {
  166.       status_line (msgtxt[M_NO_CARRIER]);
  167.       CLEAR_INBOUND ();
  168.       first_block = 0;
  169.       return;
  170.       }
  171.  
  172.    if (timeup (t1))
  173.       {
  174.       (void) FTSC_recvmail ();
  175.       status_line (msgtxt[M_TOO_LONG]);
  176.       }
  177.  
  178. get_out:
  179.    first_block = 0;
  180.    t1 = timerset (100);
  181.    while (!timeup (t1))
  182.       time_release ();
  183.    if (!wz)
  184.       status_line (msgtxt[M_0001_END]);
  185. }
  186.  
  187. int FTSC_receiver (wz)
  188. int wz;
  189. {
  190.    char fname[64];
  191.    int havemail, done, np;
  192.    unsigned int i;
  193.    long t1, t2;
  194.    struct FILEINFO dt1;
  195.    struct stat buf;
  196.    char *HoldName;
  197.  
  198.    is_wazoo_session = wz;
  199.    first_block = 0;
  200.    XON_DISABLE ();
  201.  
  202.    if (!wz)
  203.       {
  204.        first_block = 1;
  205.       status_line (msgtxt[M_RECV_FALLBACK]);
  206.       who_is_he = 1;
  207.       }
  208.  
  209.    Netmail_Session = 1;
  210.  
  211.    CLEAR_INBOUND ();
  212.  
  213.    /* Save the state of pickup for now */
  214.    done = no_pickup;
  215.    no_pickup = 0;
  216.    if (FTSC_recvmail ())
  217.       {
  218.       /* Restore the state of pickup */
  219.       no_pickup = done;
  220.       if (!wz)
  221.          status_line (msgtxt[M_0001_END]);
  222.       first_block = 0;
  223.       return (1);
  224.       }
  225.  
  226.    /* Restore the state of pickup */
  227.    no_pickup = done;
  228.  
  229.    remote_addr.Zone = called_addr.Zone;
  230.    remote_addr.Net = called_addr.Net;
  231.    remote_addr.Node = called_addr.Node;
  232.  
  233.    /* If we have the flag file written, then we shouldn't send anything back */
  234.    if (flag_file (TEST_AND_SET, &called_addr, 1))
  235.       {
  236.       havemail = 1;
  237.       goto no_send;
  238.       }
  239.  
  240.    HoldName = HoldAreaNameMunge(&called_addr);
  241.  
  242.    /* Now see if we should send anything back to him */
  243.    (void) sprintf (fname, "%s%s.?UT", HoldName, Hex_Addr_Str (&remote_addr));
  244.    havemail = dfind (&dt1, fname, 0);
  245.  
  246.    if (havemail)
  247.       {
  248.       (void) sprintf (fname, "%s%s.?LO", HoldName, Hex_Addr_Str (&remote_addr));
  249.       havemail = dfind (&dt1, fname, 0);
  250.       }
  251.  
  252.    if (havemail)
  253.       {
  254.       for (np = 0; np <= ALIAS_CNT; np++)
  255.          {
  256.          if (alias[np].Net == 0)
  257.             break;
  258.          (void) sprintf (fname, "%s%s.REQ", CurrentNetFiles, Hex_Addr_Str (&(alias[np])));
  259.          havemail = dfind (&dt1, fname, 0);
  260.          if (!havemail)
  261.             break;
  262.          }
  263.       }
  264.  
  265. no_send:
  266.  
  267.    if (havemail)
  268.       {
  269.       status_line (msgtxt[M_NOTHING_TO_SEND], Full_Addr_Str (&remote_addr));
  270.       }
  271.    else
  272.       {
  273.       status_line (msgtxt[M_GIVING_MAIL], Full_Addr_Str (&remote_addr));
  274.       /* Send the TSYNC's until we get a C or NAK or CAN back */
  275.       t1 = timerset (3000);                      /* set 30 second timeout */
  276.       done = 0;
  277.       while (!timeup (t1) && CARRIER && !done)     /* till then or CD lost  */
  278.          {
  279.          SENDBYTE (TSYNC);
  280.  
  281.          t2 = timerset (300);
  282.          while (CARRIER && (!timeup (t2)) && !done)
  283.             {
  284.             switch (TIMED_READ (0))
  285.                {
  286.                case 'C':
  287.                case NAK:
  288.                   done = 1;
  289.                   (void) FTSC_sendmail ();
  290.                   break;
  291.  
  292.                case CAN:
  293.                   done = 1;
  294.                   status_line (msgtxt[M_REFUSE_PICKUP], Full_Addr_Str (&remote_addr));
  295.                   break;
  296.  
  297.                default:
  298.                   time_release ();
  299.                }
  300.             }
  301.          }
  302.       }
  303.  
  304.    first_block = 0;
  305.  
  306.    if (wz)
  307.       {
  308.       flag_file (CLEAR_FLAG, &called_addr, 1);
  309.       return TRUE;                        /* All done if this is WaZOO */
  310.       }
  311.  
  312.    /* Now see if we want to request anything */
  313.    (void) sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&remote_addr));
  314.    if (!stat (fname, &buf))
  315.       {
  316.       /* Send the SYN character and wait for an ENQ or CAN */
  317.       t1 = timerset (3000);                      /* set 30 second timeout */
  318.       done = 0;
  319.       while (!timeup (t1) && CARRIER && !done)     /* till then or CD lost  */
  320.          {
  321.          SENDBYTE (SYN);
  322.  
  323.          t2 = timerset (500);
  324.          while (CARRIER && (!timeup (t2)) && !done)
  325.             {
  326.             i = (unsigned) TIMED_READ (0);
  327.  
  328.             switch (i)
  329.                {
  330.                case ENQ:
  331.                   SEA_sendreq ();
  332.                   break;
  333.  
  334.                case CAN:
  335.                   done = 1;
  336.                   break;
  337.  
  338.                case 'C':
  339.                case NAK:
  340.                   SENDBYTE (EOT);
  341.                   break;
  342.  
  343.                case SUB:
  344.                   SENDBYTE (SYN);
  345.                   break;
  346.  
  347.                default:
  348.                   time_release ();
  349.                }
  350.             }
  351.          }
  352.       }
  353.  
  354.    /* Finally, can he request anything from us */
  355.    if (!no_requests)
  356.       (void) SEA_recvreq ();
  357.  
  358.    status_line (msgtxt[M_0001_END]);
  359.    flag_file (CLEAR_FLAG, &called_addr, 1);
  360.    return TRUE;
  361. }
  362.  
  363. static int FTSC_sendmail ()
  364. {
  365.    FILE *fp;
  366.    char fname[80];
  367.    char s[80];
  368.    char *sptr;
  369.    char *HoldName;
  370.    int c;
  371.    int i;
  372.    int j = 0;
  373.    struct stat buf;
  374.    struct _pkthdr *tmppkt;
  375.    long t1, time ();
  376.    struct tm *tm1, *localtime ();
  377.  
  378.    XON_DISABLE ();
  379.  
  380.    sptr = s;
  381.    /*--------------------------------------------------------------------*/
  382.    /* Send all waiting ?UT files (mail packets)                          */
  383.    /*--------------------------------------------------------------------*/
  384.    *ext_flags = 'O';
  385.    HoldName = HoldAreaNameMunge(&called_addr);
  386.    for (c = 0; c < NUM_FLAGS; c++)
  387.       {
  388. #ifndef JACK_DECKER
  389.       if (caller && (ext_flags[c] == 'H'))
  390.          continue;
  391. #endif
  392.  
  393.       (void) sprintf (fname,
  394.                "%s%s.%cUT",
  395.                HoldName, Hex_Addr_Str (&called_addr), ext_flags[c]);
  396.  
  397.       if (!stat (fname, &buf))
  398.          break;
  399.       }                                          /* for */
  400.  
  401.    /*--- Build a dummy PKT file name */
  402.    invent_pkt_name (s);
  403.  
  404.    status_line (msgtxt[M_PACKET_MSG]);
  405.  
  406.    if (c == NUM_FLAGS)
  407.       {
  408.       (void) sprintf (fname,
  409.                "%s%s.OUT",
  410.                HoldName, Hex_Addr_Str (&called_addr));
  411.       if ((fp = fopen (fname, "wb")) == NULL)
  412.          {
  413.          (void) got_error (msgtxt[M_OPEN_MSG], fname);
  414.          return (1);
  415.          }
  416.       t1 = time (NULL);
  417.       tm1 = localtime (&t1);
  418.  
  419.       tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
  420.       if (tmppkt == NULL)
  421.          {
  422.          status_line (msgtxt[M_MEM_ERROR]);
  423.          (void) fclose (fp);
  424.          return (1);
  425.          }
  426.       tmppkt->orig_node = (int) alias[assumed].Node;
  427.       tmppkt->dest_node = called_addr.Node;
  428.       tmppkt->ver = PKTVER;
  429.       tmppkt->orig_net = (int) alias[assumed].Net;
  430.       tmppkt->dest_net = called_addr.Net;
  431.       tmppkt->product = isBITBRAIN;
  432.       if (n_getpassword (&called_addr))
  433.          {
  434.          if (remote_password != NULL)
  435.             {
  436.             (void) strupr (remote_password);
  437.             (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  438.             }
  439.          }
  440.       tmppkt->orig_zone = (int) alias[assumed].Zone;
  441.       tmppkt->dest_zone = called_addr.Zone;
  442.  
  443.       if ((called_addr.Domain != NULL) &&
  444.           (called_addr.Domain != alias[assumed].Domain) &&
  445.           (my_addr.Domain != NULL))
  446.          {
  447.          /* Make it a type 2.2 packet instead */
  448.          tmppkt->year = alias[assumed].Point;
  449.          tmppkt->month = called_addr.Point;
  450.          tmppkt->day = 0;
  451.          tmppkt->hour = 0;
  452.          tmppkt->minute = 0;
  453.          tmppkt->second = 0;
  454.          tmppkt->rate = 2;
  455.          if (alias[assumed].Domain != NULL)
  456.             {
  457.             for (i = 0; domain_name[i] != NULL; i++)
  458.                {
  459.                if (domain_name[i] == alias[assumed].Domain)
  460.                   {
  461.                   break;
  462.                   }
  463.                }
  464.             if (i < 49)
  465.                {
  466.                strncpy (tmppkt->B_fill2, domain_abbrev[i], 8);
  467.                }
  468.             }
  469.          for (i = 0; domain_name[i] != NULL; i++)
  470.             {
  471.             if (domain_name[i] == called_addr.Domain)
  472.                {
  473.                break;
  474.                }
  475.             }
  476.          if (i < 49)
  477.             {
  478.             strncpy (&(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  479.             }
  480.          }
  481.       else
  482.          {
  483.          tmppkt->year = tm1->tm_year;
  484.          tmppkt->month = tm1->tm_mon;
  485.          tmppkt->day = tm1->tm_mday;
  486.          tmppkt->hour = tm1->tm_hour;
  487.          tmppkt->minute = tm1->tm_min;
  488.          tmppkt->second = tm1->tm_sec;
  489.          tmppkt->rate = 0;
  490.          }
  491.  
  492.       (void) fwrite ((char *) tmppkt, sizeof (struct _pkthdr), 1, fp);
  493.       free (tmppkt);
  494.       (void) fwrite ("\0\0", 2, 1, fp);
  495.       (void) fclose (fp);
  496.       }
  497.    else
  498.       {
  499.       if ((fp = fopen (fname, rb_plus)) == NULL)
  500.          {
  501.          (void) got_error (msgtxt[M_OPEN_MSG], fname);
  502.          return (1);
  503.          }
  504.       tmppkt = (struct _pkthdr *) calloc (sizeof (struct _pkthdr), 1);
  505.       if (tmppkt == NULL)
  506.          {
  507.          status_line (msgtxt[M_MEM_ERROR]);
  508.          return (1);
  509.          }
  510.       if (fread (tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  511.          {
  512.          (void) got_error (msgtxt[M_READ_MSG], fname);
  513.          free (tmppkt);
  514.          (void) fclose (fp);
  515.          return (1);
  516.          }
  517.  
  518.       if (n_getpassword (&called_addr))
  519.          {
  520.          if (remote_password != NULL)
  521.             {
  522.             (void) strupr (remote_password);
  523.             (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  524.             }
  525.          }
  526.  
  527.  
  528.       /* Make sure the zone info is in there */
  529.  
  530.       tmppkt->orig_node = (int) alias[assumed].Node;
  531.       tmppkt->orig_net    = (int) alias[assumed].Net;
  532.       tmppkt->orig_zone = (int) alias[assumed].Zone;
  533.       tmppkt->dest_zone = called_addr.Zone;
  534.  
  535.       if ((called_addr.Domain != NULL) &&
  536.           (called_addr.Domain != alias[assumed].Domain) &&
  537.           (my_addr.Domain != NULL))
  538.          {
  539.          /* Make it a type 2.2 packet instead */
  540.          tmppkt->year = alias[assumed].Point;
  541.          tmppkt->month = called_addr.Point;
  542.          tmppkt->day = 0;
  543.          tmppkt->hour = 0;
  544.          tmppkt->minute = 0;
  545.          tmppkt->second = 0;
  546.          tmppkt->rate = 2;
  547.          if (alias[assumed].Domain != NULL)
  548.             {
  549.             for (i = 0; domain_name[i] != NULL; i++)
  550.                {
  551.                if (domain_name[i] == alias[assumed].Domain)
  552.                   {
  553.                   break;
  554.                   }
  555.                }
  556.             if (i < 49)
  557.                {
  558.                strncpy (tmppkt->B_fill2, domain_abbrev[i], 8);
  559.                }
  560.             }
  561.          for (i = 0; domain_name[i] != NULL; i++)
  562.             {
  563.             if (domain_name[i] == called_addr.Domain)
  564.                {
  565.                break;
  566.                }
  567.             }
  568.          if (i < 49)
  569.             {
  570.             strncpy (&(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  571.             }
  572.          }
  573.  
  574.       (void) fseek (fp, 0L, SEEK_SET);
  575.       (void) fwrite (tmppkt, 1, sizeof (struct _pkthdr), fp);
  576.       (void) fclose (fp);
  577.       free (tmppkt);
  578.       }
  579.  
  580.    net_problems = (no_sealink) ? Telink_Send_File (fname, s) : SEAlink_Send_File (fname, s);
  581.  
  582.    if (net_problems != 0)
  583.       {
  584.       if (c == NUM_FLAGS)
  585.          (void) unlink (fname);
  586.       return (net_problems);
  587.       }
  588.  
  589.    /* Delete the sent packet */
  590.    (void) unlink (fname);
  591.  
  592.  
  593.    /*--------------------------------------------------------------------*/
  594.    /* Send files listed in ?LO files (attached files)                     */
  595.    /*--------------------------------------------------------------------*/
  596.    *ext_flags = 'F';
  597.    status_line (" %s %s", msgtxt[M_OUTBOUND], msgtxt[M_FILE_ATTACHES]);
  598.  
  599.    if (!do_FLOfile (ext_flags, FTSC_callback))
  600.       return FALSE;
  601.  
  602.  
  603.    /*--------------------------------------------------------------------*/
  604.    /* Send our File requests to other system if it's a WaZOO             */
  605.    /*--------------------------------------------------------------------*/
  606.  
  607.    if (requests_ok && remote_capabilities)
  608.       {
  609.       (void) sprintf (fname, request_template, HoldName, Hex_Addr_Str (&called_addr));
  610.       if (!stat (fname, &buf))
  611.          {
  612.          if (!(((unsigned) remote_capabilities) & WZ_FREQ))
  613.             status_line (msgtxt[M_FREQ_DECLINED]);
  614.          else
  615.             {
  616.             status_line (msgtxt[M_MAKING_FREQ]);
  617.             if (FTSC_callback (fname))
  618.                (void) unlink (fname);
  619.             }
  620.          }
  621.       }
  622.  
  623.    /*--------------------------------------------------------------------*/
  624.    /* Process WaZOO file requests from other system                      */
  625.    /*--------------------------------------------------------------------*/
  626.  
  627.    j = respond_to_file_requests (j, FTSC_callback);
  628.  
  629.    /* Now close out the file attaches */
  630.    sent_mail = 1;
  631.    *sptr = 0;
  632.    status_line (" %s %s %s", msgtxt[M_END_OF], msgtxt[M_OUTBOUND], msgtxt[M_FILE_ATTACHES]);
  633.     (void) Batch_Send (NULL);
  634.    t1 = timerset (100);
  635.    return TRUE;
  636. }
  637.  
  638. static int FTSC_recvmail ()
  639. {
  640.    char fname[80];
  641.    char fname1[80];
  642.    struct _pkthdr tmppkt;
  643.    FILE *fp;
  644.    int done;
  645.    int j;
  646.    char *p;
  647.    extern char *receive_file ();
  648.  
  649.    status_line (msgtxt[M_RECV_MAIL]);
  650.  
  651.    if (!CARRIER)
  652.       {
  653.       status_line (msgtxt[M_NO_CARRIER]);
  654.       CLEAR_INBOUND ();
  655.       return (1);
  656.       }
  657.  
  658.    XON_DISABLE ();
  659.  
  660.     done = 0;
  661.  
  662.    /* If we don't want to pickup stuff */
  663.    if (no_pickup)
  664.       {
  665.       status_line (msgtxt[M_NO_PICKUP]);
  666.       SENDBYTE (CAN);
  667.       }
  668.    else
  669.       {
  670.       status_line (" %s %s", msgtxt[M_INBOUND], msgtxt[M_MAIL_PACKET]);
  671.       /* Invent a dummy name for the packet */
  672.       invent_pkt_name (fname1);
  673.  
  674.       /* Receive the packet with special netmail protocol */
  675.       CLEAR_INBOUND ();
  676.       p = CurrentNetFiles;
  677.       if (Xmodem_Receive_File (CurrentNetFiles, fname1) == 0)
  678.          {
  679.          got_packet = 1;
  680.          }
  681.       (void) sprintf (fname, "%s%s", p, fname1);
  682.  
  683.       /* Check the password if there is one */
  684.       if ((!remote_capabilities) && (n_getpassword (&remote_addr)))
  685.          {
  686.          if (remote_password != NULL)
  687.             {
  688.             got_packet = 0;
  689.             if ((fp = fopen (fname, rb_plus)) == NULL)
  690.                {
  691.                (void) got_error (msgtxt[M_OPEN_MSG], fname);
  692.                status_line (msgtxt[M_PWD_ERR_ASSUMED]);
  693.                return (1);
  694.                }
  695.             if (fread (&tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  696.                {
  697.                (void) got_error (msgtxt[M_OPEN_MSG], fname);
  698.                status_line (msgtxt[M_PWD_ERR_ASSUMED]);
  699.                (void) fclose (fp);
  700.                return (1);
  701.                }
  702.             (void) fclose (fp);
  703.             if (strnicmp (remote_password, (char *) (tmppkt.password), 8))
  704.                {
  705.                tmppkt.orig_zone = 0;
  706.                strncpy (fname1, remote_password, 8);
  707.                fname1[8] = '\0';
  708.                status_line (msgtxt[M_PWD_ERROR], tmppkt.password, fname1);
  709.                (void) strcpy (fname1, fname);
  710.                j = (int) strlen (fname) - 3;
  711.                (void) strcpy (&(fname[j]), "Bad");
  712.                if (rename (fname1, fname))
  713.                   {
  714.                   status_line (msgtxt[M_CANT_RENAME_MAIL], fname1);
  715.                   }
  716.                else
  717.                   {
  718.                   status_line (msgtxt[M_MAIL_PACKET_RENAMED], fname);
  719.                   }
  720.                return (1);
  721.                }
  722.             }
  723.          got_packet = 1;
  724.          }
  725.       called_addr.Zone = remote_addr.Zone;
  726.       called_addr.Net = remote_addr.Net;
  727.       called_addr.Node = remote_addr.Node;
  728.       got_mail = got_packet;
  729.  
  730.       done = 0;
  731.       /* Now receive the files if possible */
  732.       status_line (" %s %s", msgtxt[M_INBOUND], msgtxt[M_FILE_ATTACHES]);
  733.       done = Batch_Receive (CurrentNetFiles);
  734.       }
  735.  
  736.    status_line (" %s %s %s", msgtxt[M_END_OF], msgtxt[M_INBOUND], msgtxt[M_FILE_ATTACHES]);
  737.    CLEAR_INBOUND ();
  738.    return (done);
  739. }
  740.  
  741. static int FTSC_callback (sptr)
  742. char *sptr;
  743. {
  744.    net_problems = Batch_Send (sptr);
  745.    if (net_problems != 0)
  746.       {
  747.       net_problems = 1;
  748.       return FALSE;
  749.       }
  750.    return TRUE;
  751. }
  752. 
  753.