home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BSRC_250.LZH / FTSC.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  25KB  |  801 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-91, 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.250.    */
  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:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.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 this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. #define rb_plus "r+b"
  51.  
  52. int FTSC_callback (char *);
  53. int FTSC_time (long);
  54. int FTSC_sendmail (void);
  55. int FTSC_recvmail (int);
  56.  
  57. #define NUM_FLAGS 4
  58.  
  59. void FTSC_sender (int wz)
  60. {
  61.    int j;
  62.    char junkbuff[128];
  63.    long t1;
  64.  
  65.    XON_DISABLE ();
  66.    first_block = 0;
  67.  
  68.    if (!wz)
  69.       {
  70.       first_block = 1;
  71.       status_line (MSG_TXT(M_SEND_FALLBACK));
  72.       who_is_he = 0;
  73.       (void) sprintf (junkbuff, "*%s (%s)",
  74.                          newnodedes.SystemName,
  75.                             Full_Addr_Str (&remote_addr));
  76.       status_line (junkbuff);
  77.       }
  78.  
  79.    Netmail_Session = 1;
  80.  
  81.    (void) FTSC_sendmail ();
  82.    t1 = timerset (4500);
  83.  
  84.    /* See what the receiver would like us to do */
  85.    while ((!timeup (t1)) && CARRIER)
  86.       {
  87.       if ((j = PEEKBYTE ()) >= 0)
  88.          {
  89.          switch (j)
  90.             {
  91.             case TSYNC:
  92.                CLEAR_INBOUND ();
  93.                if (FTSC_recvmail (1))
  94.                   goto get_out;
  95.                t1 = timerset (4500);
  96.                break;
  97.  
  98.             case SYN:
  99.                CLEAR_INBOUND ();
  100.                if (on_our_nickel)
  101.                   (void) SEA_recvreq ();
  102.                else
  103.                   {
  104.                   SENDBYTE (CAN);
  105.                   status_line (MSG_TXT(M_REFUSING_IN_FREQ));
  106.                   }
  107.                t1 = timerset (4500);
  108.                break;
  109.  
  110.             case ENQ:
  111.                CLEAR_INBOUND ();
  112.                SEA_sendreq ();
  113.                goto get_out;
  114.  
  115.             case NAK:
  116.             case 'C':
  117.                CLEAR_INBOUND ();
  118.                SENDBYTE (EOT);
  119.                t1 = timerset (4500);
  120.                break;
  121.  
  122.             default:
  123.                CLEAR_INBOUND ();
  124.                SENDBYTE (SUB);
  125.                break;
  126.             }
  127.          }
  128.       else
  129.          {
  130.          time_release ();
  131.          }
  132.       }
  133.  
  134.    if (!CARRIER)
  135.       {
  136.       status_line (MSG_TXT(M_NO_CARRIER));
  137.       CLEAR_INBOUND ();
  138.       first_block = 0;
  139.       return;
  140.       }
  141.  
  142.    if (timeup (t1))
  143.       {
  144.       (void) FTSC_recvmail (1);
  145.       status_line (MSG_TXT(M_TOO_LONG));
  146.       }
  147.  
  148. get_out:
  149.    first_block = 0;
  150.    t1 = timerset (100);
  151.    while (!timeup (t1))
  152.       time_release ();
  153.    if (!wz)
  154.       status_line (MSG_TXT(M_0001_END));
  155. }
  156.  
  157. int FTSC_receiver (int wz)
  158. {
  159.    char fname[64];
  160.    int havemail, done, np;
  161.    unsigned int i;
  162.    long t1, t2;
  163.    struct stat buf;
  164.    char *HoldName;
  165.    struct FILEINFO dta;
  166.    ADDR tmp;
  167.  
  168.    first_block = 0;
  169.    XON_DISABLE ();
  170.  
  171.    if (!wz)
  172.       {
  173.      first_block = 1;
  174.       status_line (MSG_TXT(M_RECV_FALLBACK));
  175.       who_is_he = 1;
  176.       }
  177.  
  178.    Netmail_Session = 1;
  179.  
  180.    CLEAR_INBOUND ();
  181.  
  182.    /* Save the state of pickup for now */
  183.    done = no_pickup;
  184.    no_pickup = 0;
  185.    if (FTSC_recvmail (0))
  186.       {
  187.       /* Restore the state of pickup */
  188.       no_pickup = done;
  189.       if (!wz)
  190.          status_line (MSG_TXT(M_0001_END));
  191.       first_block = 0;
  192.       return (1);
  193.       }
  194.  
  195.    /* Restore the state of pickup */
  196.    no_pickup = done;
  197.  
  198.    remote_addr = called_addr;
  199.  
  200.    HoldName = HoldAreaNameMunge(&called_addr);
  201.  
  202.    /* Now see if we should send anything back to him */
  203.    (void) sprintf (fname, "%s%s.?UT", HoldName, Hex_Addr_Str (&remote_addr));
  204.    havemail = !dfind (&dta, fname, 0);
  205.  
  206.    if (!havemail)
  207.       {
  208.       (void) sprintf (fname, "%s%s.?LO", HoldName, Hex_Addr_Str (&remote_addr));
  209.       havemail = !dfind (&dta, fname, 0);
  210.       }
  211.  
  212.    if (!havemail)
  213.       {
  214.       for (np = 0; np <= ALIAS_CNT; np++)
  215.          {
  216.          if (alias[np].Net == 0)
  217.             break;
  218.          (void) sprintf (fname, "%s%s.REQ", CURRENT.sc_Inbound, Hex_Addr_Str (&(alias[np])));
  219.          havemail = !dfind (&dta, fname, 0);
  220.          if (havemail)
  221.             break;
  222.          }
  223.       }
  224.  
  225.    if (!havemail)
  226.       {
  227.       status_line (MSG_TXT(M_NOTHING_TO_SEND), Full_Addr_Str (&remote_addr));
  228.       }
  229.    else
  230.       {
  231.       /* OS/2 likes this */
  232.       while (!dfind (&dta, NULL, 1))
  233.          ;
  234.       status_line (MSG_TXT(M_GIVING_MAIL), Full_Addr_Str (&remote_addr));
  235.       /* Send the TSYNC's until we get a C or NAK or CAN back */
  236.       t1 = timerset (3000);                      /* set 30 second timeout */
  237.       done = 0;
  238.       while (!timeup (t1) && CARRIER && !done)   /* till then or CD lost  */
  239.          {
  240.          SENDBYTE (TSYNC);
  241.  
  242.          t2 = timerset (300);
  243.          while (CARRIER && (!timeup (t2)) && !done)
  244.             {
  245.             switch (TIMED_READ (0))
  246.                {
  247.                case 'C':
  248.                case NAK:
  249.                   done = 1;
  250.                   (void) FTSC_sendmail ();
  251.                   break;
  252.  
  253.                case CAN:
  254.                   done = 1;
  255.                   status_line (MSG_TXT(M_REFUSE_PICKUP), Full_Addr_Str (&remote_addr));
  256.                   break;
  257.  
  258.                default:
  259.                   time_release ();
  260.                }
  261.             }
  262.          }
  263.       }
  264.  
  265.    first_block = 0;
  266.  
  267.    if (wz)
  268.       return TRUE;                      /* All done if this is WaZOO */
  269.  
  270.    /* Now see if we want to request anything */
  271.    tmp = remote_addr;
  272.  
  273.    /* For a point, massage the address to get the right .REQ filename */
  274.  
  275.    if (tmp.Point != 0)
  276.       {
  277.       tmp.Node  = tmp.Point;
  278.       tmp.Point = 0;
  279.       tmp.Net   = (pvtnet > 0) ? (unsigned int) pvtnet : 0;
  280.       }        
  281.  
  282.    (void) sprintf (fname, "%s%s.REQ", HoldName, Hex_Addr_Str (&tmp));
  283.    if (!stat (fname, &buf))
  284.       {
  285.       /* Send the SYN character and wait for an ENQ or CAN */
  286.       t1 = timerset (3000);                      /* set 30 second timeout */
  287.       done = 0;
  288.       while (!timeup (t1) && CARRIER && !done)   /* till then or CD lost  */
  289.          {
  290.          SENDBYTE (SYN);
  291.  
  292.          t2 = timerset (500);
  293.          while (CARRIER && (!timeup (t2)) && !done)
  294.             {
  295.             i = (unsigned) TIMED_READ (0);
  296.  
  297.             switch (i)
  298.                {
  299.                case ENQ:
  300.                   SEA_sendreq ();
  301.                   break;
  302.  
  303.                case CAN:
  304.                   done = 1;
  305.                   break;
  306.  
  307.                case 'C':
  308.                case NAK:
  309.                   SENDBYTE (EOT);
  310.                   break;
  311.  
  312.                case SUB:
  313.                   SENDBYTE (SYN);
  314.                   break;
  315.  
  316.                default:
  317.                   time_release ();
  318.                }
  319.             }
  320.          }
  321.       }
  322.  
  323.    /* Finally, can he request anything from us */
  324.    if (!no_requests)
  325.       (void) SEA_recvreq ();
  326.  
  327.    status_line (MSG_TXT(M_0001_END));
  328.    return TRUE;
  329. }
  330.  
  331. int FTSC_sendmail ()
  332. {
  333.    FILE *fp;
  334.    char fname[80];
  335.    char s[80];
  336.    char *sptr;
  337.    char *HoldName;
  338.    int c;
  339.    int i;
  340.    int j = 0;
  341.    struct stat buf;
  342.    struct _pkthdr *tmppkt;
  343.    time_t t1;
  344.    struct tm *tm1;
  345.  
  346.    XON_DISABLE ();
  347.  
  348.    sptr = s;
  349.    /*--------------------------------------------------------------------*/
  350.    /* Send all waiting ?UT files (mail packets)                          */
  351.    /*--------------------------------------------------------------------*/
  352.    *ext_flags = 'O';
  353.    HoldName = HoldAreaNameMunge(&called_addr);
  354.    for (c = 0; c < NUM_FLAGS; c++)
  355.       {
  356. #ifndef JACK_DECKER
  357.       if (caller && (ext_flags[c] == 'H'))
  358.          continue;
  359. #endif
  360.  
  361.       (void) sprintf (fname,
  362.                "%s%s.%cUT",
  363.                HoldName, Hex_Addr_Str (&called_addr), ext_flags[c]);
  364.  
  365.       if (!stat (fname, &buf))
  366.          break;
  367.       }                                          /* for */
  368.  
  369.    /*--- Build a dummy PKT file name */
  370.    invent_pkt_name (s);
  371.  
  372.    status_line (MSG_TXT(M_PACKET_MSG));
  373.  
  374.    if (c == NUM_FLAGS)
  375.       {
  376.       (void) sprintf (fname,
  377.                "%s%s.OUT",
  378.                HoldName, Hex_Addr_Str (&called_addr));
  379.       if ((fp = fopen (fname, "wb")) == NULL)
  380.          {
  381.          (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  382.          return (1);
  383.          }
  384.       t1 = time (NULL);
  385.       tm1 = localtime (&t1);
  386.  
  387.       tmppkt = (struct _pkthdr *) calloc (1, sizeof (struct _pkthdr));
  388.       if (tmppkt == NULL)
  389.          {
  390.          status_line (MSG_TXT(M_MEM_ERROR));
  391.          (void) fclose (fp);
  392.          return (1);
  393.          }
  394.       tmppkt->orig_node = (int) alias[assumed].Node;
  395.       tmppkt->dest_node = called_addr.Node;
  396.       tmppkt->ver = PKTVER;
  397.       tmppkt->orig_net = (int) alias[assumed].Net;
  398.       tmppkt->dest_net = called_addr.Net;
  399.       tmppkt->product = PRDCT_CODE;
  400.       if (n_getpassword (&called_addr))
  401.          {
  402.          if (remote_password != NULL)
  403.             {
  404.             (void) strupr (remote_password);
  405.             (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  406.             }
  407.          }
  408.       tmppkt->orig_zone = (int) alias[assumed].Zone;
  409.       tmppkt->dest_zone = called_addr.Zone;
  410.  
  411.       if (((called_addr.Domain != NULL)
  412.       &&  (called_addr.Domain != alias[assumed].Domain)
  413.       &&  (my_addr.Domain != NULL))
  414.       ||  (alias[assumed].Point != 0))
  415.          {
  416.          /* Make it a type 2.2 packet instead */
  417.          tmppkt->year = alias[assumed].Point;
  418.          tmppkt->month = called_addr.Point;
  419.          tmppkt->day = 0;
  420.          tmppkt->hour = 0;
  421.          tmppkt->minute = 0;
  422.          tmppkt->second = 0;
  423.          tmppkt->rate = 2;
  424.          if (alias[assumed].Domain != NULL)
  425.             {
  426.             for (i = 0; domain_name[i] != NULL; i++)
  427.                {
  428.                if (domain_name[i] == alias[assumed].Domain)
  429.                   {
  430.                   break;
  431.                   }
  432.                }
  433.             if (i < 49)
  434.                {
  435.                (void) strncpy ((char *)tmppkt->B_fill2, domain_abbrev[i], 8);
  436.                }
  437.             }
  438.  
  439.          for (i = 0; domain_name[i] != NULL; i++)
  440.             {
  441.           if (domain_name[i] == called_addr.Domain)
  442.              {
  443.              break;
  444.                }
  445.             }
  446.          if ((i < 49) && (domain_name[i] != NULL))
  447.           {
  448.           (void) strncpy ((char *)&(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  449.             }
  450.          }
  451.       else
  452.          {
  453.          tmppkt->year = tm1->tm_year;
  454.          tmppkt->month = tm1->tm_mon;
  455.          tmppkt->day = tm1->tm_mday;
  456.          tmppkt->hour = tm1->tm_hour;
  457.          tmppkt->minute = tm1->tm_min;
  458.          tmppkt->second = tm1->tm_sec;
  459.          tmppkt->rate = 0;
  460.          }
  461.  
  462.       (void) fwrite ((char *) tmppkt, sizeof (struct _pkthdr), 1, fp);
  463.       free (tmppkt);
  464.       (void) fwrite ("\0\0", 2, 1, fp);
  465.       (void) fclose (fp);
  466.       }
  467.    else
  468.       {
  469.       if ((fp = fopen (fname, rb_plus)) == NULL)
  470.          {
  471.          (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  472.          return (1);
  473.          }
  474.       tmppkt = (struct _pkthdr *) calloc (1, sizeof (struct _pkthdr));
  475.       if (tmppkt == NULL)
  476.          {
  477.          status_line (MSG_TXT(M_MEM_ERROR));
  478.          return (1);
  479.          }
  480.       if (fread (tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  481.          {
  482.          (void) got_error (MSG_TXT(M_READ_MSG), fname);
  483.          free (tmppkt);
  484.          (void) fclose (fp);
  485.          return (1);
  486.          }
  487.  
  488.       if (n_getpassword (&called_addr))
  489.          {
  490.          if (remote_password != NULL)
  491.             {
  492.             (void) strupr (remote_password);
  493.             (void) strncpy ((char *) (tmppkt->password), remote_password, 8);
  494.             }
  495.          }
  496.  
  497.  
  498.       /* Make sure the zone info is in there */
  499.  
  500.       tmppkt->orig_node = (int) alias[assumed].Node;
  501.       tmppkt->orig_net  = (int) alias[assumed].Net;
  502.       tmppkt->orig_zone = (int) alias[assumed].Zone;
  503.       tmppkt->dest_zone = called_addr.Zone;
  504.  
  505.       if ((called_addr.Domain != NULL) &&
  506.           (called_addr.Domain != alias[assumed].Domain) &&
  507.           (my_addr.Domain != NULL))
  508.          {
  509.          /* Make it a type 2.2 packet instead */
  510.          tmppkt->year = alias[assumed].Point;
  511.          tmppkt->month = called_addr.Point;
  512.          tmppkt->day = 0;
  513.          tmppkt->hour = 0;
  514.          tmppkt->minute = 0;
  515.          tmppkt->second = 0;
  516.          tmppkt->rate = 2;
  517.          if (alias[assumed].Domain != NULL)
  518.             {
  519.             for (i = 0; domain_name[i] != NULL; i++)
  520.                {
  521.                if (domain_name[i] == alias[assumed].Domain)
  522.                   {
  523.                   break;
  524.                   }
  525.                }
  526.             if (i < 49)
  527.                {
  528.          (void) strncpy ((char *)tmppkt->B_fill2, domain_abbrev[i], 8);
  529.          }
  530.       }
  531.    for (i = 0; domain_name[i] != NULL; i++)
  532.       {
  533.       if (domain_name[i] == called_addr.Domain)
  534.          {
  535.          break;
  536.          }
  537.       }
  538.    if (i < 49)
  539.       {
  540.       (void) strncpy ((char *)&(tmppkt->B_fill2[8]), domain_abbrev[i], 8);
  541.             }
  542.          }
  543.  
  544.       (void) fseek (fp, 0L, SEEK_SET);
  545.       (void) fwrite (tmppkt, 1, sizeof (struct _pkthdr), fp);
  546.       (void) fclose (fp);
  547.       free (tmppkt);
  548.       }
  549.  
  550.    net_problems = (no_sealink) ? Telink_Send_File (fname, s) : SEAlink_Send_File (fname, s);
  551.  
  552.    if (net_problems != 0)
  553.       {
  554.       if (c == NUM_FLAGS)
  555.          (void) unlink (fname);
  556.       return (net_problems);
  557.       }
  558.  
  559.    /* Delete the sent packet */
  560.    (void) unlink (fname);
  561.  
  562.  
  563.    /*--------------------------------------------------------------------*/
  564.    /* Send files listed in ?LO files (attached files)                    */
  565.    /*--------------------------------------------------------------------*/
  566.    *ext_flags = 'F';
  567.    status_line (" %s %s", MSG_TXT(M_OUTBOUND), MSG_TXT(M_FILE_ATTACHES));
  568.  
  569.    if (!do_FLOfile (ext_flags, FTSC_callback))
  570.       return FALSE;
  571.  
  572.  
  573.    /*--------------------------------------------------------------------*/
  574.    /* Send our File requests to other system if it's a WaZOO             */
  575.    /*--------------------------------------------------------------------*/
  576.  
  577.    if (requests_ok && remote_capabilities)
  578.       {
  579.       (void) sprintf (fname, request_template, HoldName, Hex_Addr_Str (&called_addr));
  580.       if (!stat (fname, &buf))
  581.          {
  582.          if (!(((unsigned) remote_capabilities) & WZ_FREQ))
  583.             status_line (MSG_TXT(M_FREQ_DECLINED));
  584.          else
  585.             {
  586.             status_line (MSG_TXT(M_MAKING_FREQ));
  587.             if (FTSC_callback (fname))
  588.                (void) unlink (fname);
  589.             }
  590.          }
  591.       }
  592.  
  593.    /*--------------------------------------------------------------------*/
  594.    /* Process WaZOO file requests from other system                      */
  595.    /*--------------------------------------------------------------------*/
  596.  
  597.    j = respond_to_file_requests (j, FTSC_callback, FTSC_time);
  598.  
  599.    /* Now close out the file attaches */
  600.    sent_mail = 1;
  601.    *sptr = 0;
  602.    status_line (" %s %s %s", MSG_TXT(M_END_OF), MSG_TXT(M_OUTBOUND), MSG_TXT(M_FILE_ATTACHES));
  603.   (void) Batch_Send (NULL);
  604.    return TRUE;
  605. }
  606.  
  607. int FTSC_recvmail (int outbound_session)
  608. {
  609.    char fname[80];
  610.    char fname1[80];
  611.    char fname2[80];
  612.    struct _pkthdr tmppkt;
  613.    FILE *fp, *fp1;
  614.    int done;
  615.    int j;
  616.    char *starting_inbound;
  617.  
  618.    status_line (MSG_TXT(M_RECV_MAIL));
  619.  
  620.    if (!CARRIER)
  621.       {
  622.       status_line (MSG_TXT(M_NO_CARRIER));
  623.       CLEAR_INBOUND ();
  624.       return (1);
  625.       }
  626.  
  627.    XON_DISABLE ();
  628.  
  629.    done = 0;
  630.  
  631.    /* If we don't want to pickup stuff */
  632.    if (no_pickup)
  633.       {
  634.       status_line (MSG_TXT(M_NO_PICKUP));
  635.       SENDBYTE (CAN);
  636.       }
  637.    else
  638.       {
  639.       status_line (" %s %s", MSG_TXT(M_INBOUND), MSG_TXT(M_MAIL_PACKET));
  640.       /* Invent a dummy name for the packet */
  641.       invent_pkt_name (fname1);
  642.  
  643.       /* Receive the packet with special netmail protocol */
  644.       CLEAR_INBOUND ();
  645.  
  646.       starting_inbound = CURRENT.sc_Inbound;
  647.  
  648.       if (Xmodem_Receive_File (CURRENT.sc_Inbound, fname1) == 0)
  649.          {
  650.          got_packet = 1;
  651.          }
  652.       (void) sprintf (fname, "%s%s", starting_inbound, fname1);
  653.  
  654.       /* Check the password if there is one */
  655.       if ((!remote_capabilities) &&
  656.           (!outbound_session)    &&
  657.           (n_getpassword (&remote_addr)))
  658.          {
  659.          if (remote_password != NULL)
  660.             {
  661.             got_packet = 0;
  662.             if ((fp = fopen (fname, rb_plus)) == NULL)
  663.                {
  664.                (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  665.                status_line (MSG_TXT(M_PWD_ERR_ASSUMED));
  666.                return (1);
  667.                }
  668.             if (fread (&tmppkt, 1, sizeof (struct _pkthdr), fp) < sizeof (struct _pkthdr))
  669.                {
  670.                (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  671.                status_line (MSG_TXT(M_PWD_ERR_ASSUMED));
  672.                (void) fclose (fp);
  673.                return (1);
  674.                }
  675.             (void) fclose (fp);
  676.             if (n_password ((char *) (tmppkt.password), remote_password))
  677.                {
  678.                tmppkt.orig_zone = 0;
  679.                (void) strcpy (fname1, fname);
  680.                j = (int) strlen (fname) - 3;
  681.                (void) strcpy (&(fname[j]), "Bad");
  682.                if (rename (fname1, fname))
  683.                   {
  684.                   status_line (MSG_TXT(M_CANT_RENAME_MAIL), fname1);
  685.                   }
  686.                else
  687.                   {
  688.                   status_line (MSG_TXT(M_MAIL_PACKET_RENAMED), fname);
  689.                   }
  690.                return (1);
  691.                }
  692.             }
  693.          got_packet = 1;
  694.          }
  695.   /*
  696.    *  See if things changed after the fact. If so, we want to move
  697.    *  the mail packet from the non-secured directory into the
  698.    *  secured one. This is slightly tricky. Start with a simple rename
  699.    *  and if that doesn't work (it might not if we're spanning drives)
  700.    *  do a simple copy/unlink.
  701.    *
  702.    *  Steal resources such as 'done' and 'Secbuf' wherever that makes sense.
  703.    */
  704.  
  705.       if (strcmp (starting_inbound, CURRENT.sc_Inbound) != 0)
  706.          {
  707.          (void) strcpy (fname2, CURRENT.sc_Inbound);
  708.          (void) strcat (fname2, fname1);
  709.  
  710.      /*  Try the easy case first. A straight rename. */
  711.  
  712.          done = 1;
  713.  
  714.          if (rename (fname2, fname))
  715.             {
  716.  
  717.      /*     If we get here, the straight rename didn't work. Let's
  718.       *     do a copy. Use Secbuf since while we are here, we're
  719.       *     not doing any file transfers.
  720.       */
  721.             done = 0;   /* default is failure till files are open */
  722.  
  723.             if ((fp = fopen (fname, rb_plus)) == NULL)
  724.                {
  725.                (void) got_error (MSG_TXT(M_OPEN_MSG), fname);
  726.                }
  727.             else
  728.                if ((fp1 = fopen (fname2, "wb")) == NULL)
  729.                   {
  730.                   (void) got_error (MSG_TXT(M_OPEN_MSG), fname2);
  731.                   }
  732.                else /* Here both packets are open */
  733.                     /* Steal Secbuf because nobody's using it now */
  734.                   {
  735.                   done = 1;   /* default is success now */
  736.  
  737.                   while ((j = fread (Secbuf, 1, WAZOOMAX, fp)) > 0)
  738.                      {
  739.                      if (fwrite (Secbuf, j, 1, fp1) != 1)
  740.                         {
  741.                         (void) got_error (MSG_TXT(M_WRITE_MSG), fname2);
  742.                         done = 0;   /* only possible failure = write err */
  743.                         break;
  744.                         }
  745.                      }
  746.                   (void) fclose (fp1);
  747.  
  748.                   if (done == 0)  /* Figure out which file to delete */
  749.                      (void) unlink (fname2);
  750.                   else
  751.                      (void) unlink (fname);
  752.                   }
  753.             }
  754.          if (done == 0)
  755.             status_line (MSG_TXT(M_CANT_RENAME_MAIL), fname);
  756.          else
  757.             status_line (MSG_TXT(M_MAIL_PACKET_RENAMED), fname2);
  758.          }
  759.  
  760.   /*
  761.    * If this was an inbound session, we need to set up the
  762.    * node flags for the node.
  763.    */
  764.       got_mail = got_packet;
  765.       if (!outbound_session)
  766.          {
  767.          if (flag_file (TEST_AND_SET, &remote_addr, 1))
  768.             return (1);
  769.          called_addr = remote_addr;
  770.          }
  771.  
  772.        done = 0;
  773.       /* Now receive the files if possible */
  774.       status_line (" %s %s", MSG_TXT(M_INBOUND), MSG_TXT(M_FILE_ATTACHES));
  775.       done = Batch_Receive (CURRENT.sc_Inbound);
  776.       }
  777.  
  778.    status_line (" %s %s %s", MSG_TXT(M_END_OF), MSG_TXT(M_INBOUND), MSG_TXT(M_FILE_ATTACHES));
  779.    CLEAR_INBOUND ();
  780.    return (done);
  781. }
  782.  
  783. int FTSC_callback (char *sptr)
  784. {
  785.    net_problems = Batch_Send (sptr);
  786.    if (net_problems != 0)
  787.       {
  788.       net_problems = 1;
  789.       return FALSE;
  790.       }
  791.    return TRUE;
  792. }
  793.  
  794. int FTSC_time (long filesize)
  795. {
  796.    int i;
  797.    i = (int) (filesize * 10 / cur_baud.rate_value * 100 / 94);
  798.    return (i);
  799. }
  800.  
  801.