home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2_409E.SZH / ARC_E.C < prev    next >
Text File  |  1991-07-09  |  21KB  |  712 lines

  1. /*
  2.   $Header: arc_e.c 3.3 87/12/12 00:39:56 Bob Exp $
  3.  
  4.                           The Conference Mail System
  5.  
  6.               This module was originally written by Bob Hartman
  7.                        Sysop of FidoNet node 1:132/101
  8.  
  9.    Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061
  10.  
  11.  The Conference Mail System  is a  complete Echomail processing package.  It
  12.  is a superset of the original  Echomail utilities created by Jeff Rush, and
  13.  also contains ideas gleaned from the  ARCmail,  Renum,  oMMM, MGM, and Opus
  14.  programs that were created by various software authors.
  15.  
  16.  This program source code is being released with the following provisions:
  17.  
  18.  1.  You are  free to make  changes to this source  code for use on your own
  19.  machine,  however,  altered source files may not be distributed without the
  20.  consent of Spark Software.
  21.  
  22.  2.  You may distribute "patches"  or  "diff" files for any changes that you
  23.  have made, provided that the "patch" or "diff" files are also sent to Spark
  24.  Software for inclusion in future releases of the entire package.   A "diff"
  25.  file for the source archives may also contain a compiled version,  provided
  26.  it is  clearly marked as not  being created  from the original source code.
  27.  No other  executable  versions may be  distributed without  the  consent of
  28.  Spark Software.
  29.  
  30.  3.  You are free to include portions of this source code in any program you
  31.  develop, providing:  a) Credit is given to Spark Software for any code that
  32.  may is used, and  b) The resulting program is free to anyone wanting to use
  33.  it, including commercial and government users.
  34.  
  35.  4.  There is  NO  technical support  available for dealing with this source
  36.  code, or the accompanying executable files.  This source  code  is provided
  37.  as is, with no warranty expressed or implied (I hate legalease).   In other
  38.  words, if you don't know what to do with it,  don't use it,  and if you are
  39.  brave enough to use it, you're on your own.
  40.  
  41.  Spark Software may be contacted by modem at (603) 888-8179 (node 1:132/101)
  42.  on the public FidoNet network, or at the address given above.
  43.  
  44.  To use this code you will need Microsoft C version 4.0, and also Microsoft
  45.  Macro Assembler version 4.0.
  46.  
  47. */
  48.  
  49. /*
  50.    $Log:    arc_e.c $
  51.  * Revision 4.09d 91/06/11           GJS
  52.  * Update for to include statistics and logging
  53.  *
  54.  * Revision 3.3  87/12/12  00:39:56  Bob
  55.  * Source code release
  56.  *
  57. */
  58.  
  59. #include <stdio.h>
  60. #include <dos.h>
  61. #include <ctype.h>
  62. #include <fcntl.h>
  63. #include <io.h>
  64. #include <time.h>
  65. #include <string.h>
  66. #include <malloc.h>
  67. #include <stdlib.h>
  68. #include <process.h>
  69. #include <sys\types.h>
  70. #include <sys\stat.h>
  71. #include "fastecho.h"
  72.  
  73. #if STATS
  74.    #include "stats.h"
  75. #endif
  76.  
  77. #define DEBUG 0
  78.  
  79. static char *asuffix[] =
  80.     { "SU?", "MO?", "TU?", "WE?", "TH?", "FR?", "SA?", NULL };
  81. extern SEACONFIG config;
  82. extern AREAS_PTR areas[];
  83. extern char board_name[], sysop_name[];
  84. extern int tot_areas;
  85. extern char bbsfile[];
  86. extern char *arc_cmd[];
  87. extern int nread;
  88. extern int arc_args;
  89. extern int last_msg;
  90. extern int high_one;
  91.  
  92. #if STATS
  93.    extern int  mail_msgs;
  94.    extern long mail_size;
  95. #endif
  96.  
  97. extern int convert;
  98. extern int dup_size;
  99. extern struct tm *t2;
  100. extern struct _stamp cur_stamp;
  101. extern int pass_thru;
  102. extern int route_thru;
  103. extern int toss_net, toss_node;
  104. extern int num_pw;
  105. extern PW_PTR pw[];
  106. extern int got_a;
  107. extern int check_nodes;
  108. extern int kill_null;
  109. extern int kill_pkt;
  110. int bad_pkt = 0;
  111. int bad_pw = 0;
  112. extern int bad_msgs;
  113. extern int msgs_tossed;
  114. extern WBUFFER wbuffs[];
  115. extern KILLPTR killer;
  116. extern long secs_from_1980();
  117. extern int last_toss_area;
  118. extern int dup_msgs;
  119. extern int dup_file;
  120. extern char dup_name[];
  121.  
  122. int arcmail ()
  123. {
  124.     int i, j, k, l, done;
  125.     char archive[80];
  126.     char arcname[64];
  127.     char cmd[80];
  128. #ifdef IBMC
  129.     char tnet[5];
  130.     char tnode[5];
  131. #endif
  132.  
  133.     for (i = 0; asuffix[i]; i++)
  134.         {
  135.         sprintf (archive, "%s\\*.%s", config.filepath, asuffix[i]);
  136.         j = 0;
  137.         (void) filedir (archive, j, arcname, 0);
  138.         done = 0;
  139.         while (arcname[0] != '\0')
  140.             {
  141. #if DEBUG
  142.             printf ("Got filename '%s' for j = %d\n", arcname, j);
  143. #endif
  144.             for (k = 0; k < 8; k++)
  145.                 {
  146.                 if (isdigit (arcname[k]) ||
  147.                      ((arcname[k] >= 'A') && (arcname[k] <= 'F')))
  148.                     {
  149.                     continue;
  150.                     }
  151.                 else
  152.                     {
  153.                     done = 1;
  154.                     break;
  155.                     }
  156.                 }
  157.             if ((done) || ((i != 7) && (!isalnum(arcname[strlen(arcname)-1]))))
  158.                 {
  159. #if DEBUG
  160.                 printf ("Not an arcmail style packet\n");
  161. #endif
  162.                 done = 0;
  163.                 ++j;
  164.                 }
  165.             else
  166.                 {
  167.                 sprintf (cmd, "%s\\%s", config.filepath, arcname);
  168. #ifndef IBMC
  169.                 sscanf (arcname, "%04x%04x.", &toss_net, &toss_node);
  170. #else
  171.                 sscanf (arcname, "%4s%4s.", tnet, tnode);
  172.                 sscanf (tnet, "%04x", &toss_net);
  173.                 sscanf (tnode, "%04x", &toss_node);
  174. #endif
  175.                 toss_net += config.net[1];
  176.                 toss_node += config.node[1];
  177.  
  178.                 #if STATS
  179.                    LogArchive(cmd, toss_net, toss_node);
  180.                 #endif
  181.  
  182.                 printf ("Unpacking packet '%s' from %d/%d\n", cmd, toss_net, toss_node);
  183.                 strcpy (arc_cmd[arc_args], cmd);
  184.                 if (spawnvp (P_WAIT, arc_cmd[0], arc_cmd))
  185.                     {
  186.                     printf ("\nError while attempting to unARC '%s'\n", cmd);
  187.                     printf ("If packets were unARC'd, then '%s' will be deleted\n", cmd);
  188.                     printf ("otherwise it will be left intact for future processing\n");
  189.                     }
  190.                 if (tosspkt ("."))
  191.                     {
  192.                     printf ("\nNo ARCmail packets from '%s' - ARCHIVE NOT REMOVED!\n", cmd);
  193.                     ++j;
  194.                     }
  195.                 else
  196.                     {
  197.                     printf ("\nTossing successful - deleting ARCmail packet '%s'\n", cmd);
  198.                     unlink (cmd);
  199.                     }
  200.                 for (l = 0; l < j; l++)
  201.                     {
  202.                     (void) filedir (archive, l, arcname, 0);
  203.                     }
  204.                 }
  205.             (void) filedir (archive, j, arcname, 0);
  206.             }
  207.         }
  208.     return (0);
  209. }
  210.  
  211. void netit (
  212.    MSG_PTR header,
  213.    char   *holder,
  214.    int     body_count,
  215.    char   *netpath,
  216.    int    *high_one)
  217. {
  218.    int f, j;
  219.    char junk[80];
  220.  
  221. #if DEBUG
  222.    printf ("in netit() with body_count = %d\n", body_count);
  223. #endif
  224.  
  225.    /* Determine if it is to us */
  226.    for (j = 1; j <= config.num_addrs; j++)
  227.    {
  228.       if (  (config.net[j] == header->dest_net)
  229.           &&(config.node[j] == header->dest   ))
  230.       {
  231.          /* It matches one of our addresses! */
  232.          break;
  233.       }
  234.    }
  235.    if (j > config.num_addrs)
  236.    {
  237. #if DEBUG
  238.       printf ("Putting in MSGFWD bit\n");
  239. #endif
  240.       header->attr |= MSGFWD;
  241.    }
  242.  
  243.    ++(*high_one);
  244.    sprintf (junk, "%s\\%d.MSG", netpath, *high_one);
  245. #if DEBUG
  246.    printf ("attempting to open '%s'\n", junk);
  247. #endif
  248.  
  249.    if ((f = open (junk, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IREAD|S_IWRITE)) == -1)
  250.    {
  251.       printf ("Cannot open file '%s' for message.  Message lost\n", junk);
  252.       return;
  253.    }
  254. #if DEBUG
  255.    printf ("attempting to write header\n");
  256. #endif
  257.    if (write_header (f, header) != sizeof (MSG))
  258.    {
  259.       printf ("Could not write to file '%s'.  Message lost\n", junk);
  260.       (void) fast_close (f);
  261.       return;
  262.    }
  263. #if DEBUG
  264.    printf ("attempting to write body\n");
  265. #endif
  266.    if (fast_write (f, holder, body_count) != body_count)
  267.    {
  268.       printf ("Could not write to file '%s'.  Message lost\n", junk);
  269.       (void) fast_close (f);
  270.       return;
  271.    }
  272. #if DEBUG
  273.    printf ("returning from netit\n");
  274. #endif
  275.    (void) fast_close (f);
  276.    ++msgs_tossed;
  277.    return;
  278. }
  279.  
  280. int unpackpkt (char *pktname)
  281. {
  282.    int i, j, foo, foo1, foo2, foo3, v;
  283.    int body_count;
  284.    char *q1;
  285.    char *holder;
  286.    char *holder1;
  287.    static char header[sizeof(MSG)+10000];
  288.    MSG_PTR h;
  289.    int f, err;
  290.    PKTHDR p;
  291.    PACKED p1;
  292.    extern last_loc;
  293.  
  294.    /* Read in the Packet header */
  295.    if ((f = open (pktname, O_RDONLY|O_BINARY)) == -1)
  296.    {
  297.       printf ("Could not open packet '%s'\n", pktname);
  298.       return (1);
  299.    }
  300. #if DEBUG
  301.    printf ("Got Packet opened\n");
  302. #endif
  303.    if (wbuffs[f].wbuff == NULL)
  304.    {
  305.       wbuffs[f].wbuff = wbuffs[f].wptr = _fmalloc (BIGSIZE);
  306.       if (wbuffs[f].wbuff != NULL)
  307.          wbuffs[f].wsize = 0;
  308.    }
  309. #if DEBUG
  310.    printf ("Got buffer\n");                         /*DEBUG*/
  311. #endif
  312.  
  313.    if (fast_read (f, (char *) &p, sizeof (PKTHDR)) != sizeof (PKTHDR))
  314.    {
  315.       _ffree (wbuffs[f].wbuff);
  316.       wbuffs[f].wbuff = wbuffs[f].wptr = NULL;
  317.       wbuffs[f].wsize = -1;
  318.       (void) fast_close (f);
  319.       printf ("Packet '%s' was a short packet\n", pktname);
  320.       return (0);
  321.    }
  322. #if DEBUG
  323.    printf ("Got full header\n");                         /*DEBUG*/
  324. #endif
  325.    /* See if it is addressed to us */
  326.    for (i = 1; i <= config.num_addrs; i++)
  327.    {
  328.       if ((p.dest_net == config.net[i]) && (p.dest_node == config.node[i]))
  329.          break;
  330.    }
  331.  
  332.    /*AK*/ /*WRA*/
  333.    /* Departure here.  If -S, only then do we do this stuff */
  334.    if (check_nodes)
  335.    {
  336.       if (toss_net == 0 && toss_node == 0)
  337.       {
  338.          toss_net  = p.orig_net;
  339.          toss_node = p.orig_node;
  340.       }
  341.  
  342.       else if (toss_net != p.orig_net || toss_node != p.orig_node)
  343.       {
  344.          (void) fast_close (f);
  345.          printf ("Packet '%s' origin %d/%d differs from arcmail origin %d/%d\n",
  346.              pktname, p.orig_net, p.orig_node, toss_net, toss_node);
  347.          _ffree (wbuffs[f].wbuff);
  348.          wbuffs[f].wbuff = wbuffs[f].wptr = NULL;
  349.          wbuffs[f].wsize = -1;
  350.          (void) fast_close (f);
  351.          bad_pkt = 1;
  352.          if (kill_pkt)
  353.             return (0);
  354.          else
  355.             return (1);
  356.       }
  357.    }
  358.  
  359.    /* It was to us */
  360.    if (i <= config.num_addrs)
  361.    {
  362. #if DEBUG
  363.       printf ("Its addressed to us\n");                         /*DEBUG*/
  364. #endif
  365.       for (i = 0; i < num_pw; i++)
  366.       {
  367.          /* Find out if we have a password for this guy */
  368.          if ((pw[i]->net == p.orig_net) && (pw[i]->node == p.orig_node))
  369.          {
  370.             /* We do, so uppercase it */
  371.             for (j = 0; j < 8; j++)
  372.             {
  373.                p.password[j] = (char) toupper (p.password[j]);
  374.             }
  375.             /* Do they match? */
  376.             if (strcmp (p.password, pw[i]->password))
  377.             {
  378.                /* No match!  Bad news */
  379.                printf ("Packet '%s' does not have proper password for node %d/%d\n",
  380.                   pktname, p.orig_net, p.orig_node);
  381.                _ffree (wbuffs[f].wbuff);
  382.                wbuffs[f].wbuff = wbuffs[f].wptr = NULL;
  383.                wbuffs[f].wsize = -1;
  384.                (void) fast_close (f);
  385.                bad_pw = 1;
  386.                return (1);
  387.             }
  388.          }
  389.       }
  390.    }
  391. #if DEBUG
  392.    printf ("Passed PW check    \n");                         /*DEBUG*/
  393. #endif
  394.    last_toss_area = -1;
  395.    dup_msgs = 0;
  396.    holder1 = malloc ((unsigned) (NUMBLOCKS*1024 + sizeof (MSG)));
  397.    if (holder1 == NULL)
  398.    {
  399.       (void) fast_close (f);
  400.       printf ("Could not malloc() message space, aborting\n");
  401.       exit (2);
  402.    }
  403. #if DEBUG
  404.    printf ("Passed msg space   \n");                         /*DEBUG*/
  405. #endif
  406.    killer = (KILLPTR) calloc (dup_size, sizeof(KILL));
  407.    if (killer == NULL)
  408.    {
  409.       v = _freect (50*sizeof (KILL));
  410.       printf ("Not enough memory to kill dups based on last %d messages\n", dup_size);
  411.       printf ("Try using '-D %d' on the command line - exiting\n", v*50);
  412.       exit (2);
  413.    }
  414.  
  415.    holder = holder1+sizeof(MSG);
  416.    h = (MSG_PTR) header;
  417.  
  418.    /* while version != 0 */
  419.    if (fast_read (f, (char *) &p1, 2) != 2)
  420.    {
  421.       p1.ver = 0;
  422.       printf ("Packet '%s' was a short packet\n", pktname);
  423.    }
  424.  
  425.    i = 0;
  426.    while (p1.ver == PKTVER)
  427.    {
  428.       ++i;
  429.       if (fast_read (f, (char *) &(p1.orig_node), sizeof (PACKED) - 2) != sizeof (PACKED) -2)
  430.       {
  431.          printf ("Packet '%s' was a short packet\n", pktname);
  432.          break;
  433.       }
  434.       /* Fill in the message structure and read in message */
  435.       memset ((char *) h, 0, sizeof (MSG));
  436.       if (get_to_null (f, h->date, &foo)
  437.           || get_to_null (f, h->to, &foo1)
  438.           || get_to_null (f, h->from, &foo2)
  439.           || get_to_null (f, h->subj, &foo3)
  440.           || get_to_null (f, holder, &body_count))
  441.       {
  442.          printf ("Packet '%s' was a short packet\n", pktname);
  443.          break;
  444.       }
  445.       if ((foo > 20) || (foo1 > 36) || (foo2 > 36) || (foo3 > 72))
  446.       {
  447.          printf ("Packet '%s' contains invalid data - aborting packet\n", pktname);
  448.          break;
  449.       }
  450. #if DEBUG
  451.       printf ("Passed hdr check   \n");                         /*DEBUG*/
  452. #endif
  453.  
  454.       /* Fill in the rest of the message header */
  455.       do_date (h);
  456. #if DEBUG
  457.       printf ("Passed do_date (h) \n");                         /*DEBUG*/
  458. #endif
  459.       h->times = 0;
  460.       h->dest = p1.dest_node;
  461.       h->orig = p1.orig_node;
  462.       h->cost = p1.cost;
  463.       h->orig_net = p1.orig_net;
  464.       h->dest_net = p1.dest_net;
  465.       h->reply = 0;
  466.       h->attr = p1.attr&(int)NO_CLEAR;
  467.       h->up = 0;
  468. #if DEBUG
  469.       printf ("Header filled in   \n");                         /*DEBUG*/
  470. #endif
  471.  
  472.       /* See if we should toss it */
  473.       got_a = 0;
  474.  
  475.       q1 = holder;
  476.       if (*q1 == 1)
  477.       {
  478.          ++q1;
  479.          --body_count;
  480.          got_a = 1;
  481.       }
  482.       while ((isspace ((*q1)&0x7f)) || (*q1 == 1))
  483.       {
  484.          ++q1;
  485.          --body_count;
  486.       }
  487. #if DEBUG
  488.       printf ("Body contains %d bytes\n", body_count);                         /*DEBUG*/
  489. #endif
  490.  
  491.       /* Is it an AREA: file */
  492.       if ((body_count == 0) && (kill_null))
  493.       {
  494.          printf ("MAIL PKT %s:MSG %d -> NULL MSG - DELETED\n", pktname, i);
  495.       }
  496.       else if (strncmp (q1, "AREA:", 5) != 0)
  497.       {
  498. #if DEBUG
  499.          printf ("not echomail\n");
  500. #endif
  501.          /* Just write it into the netmail area */
  502.          printf ("MAIL PKT %s:MSG %d -=> MAIL:%d.MSG from %d/%d\n",
  503.             pktname, i, high_one+1, ((MSG *) h)->orig_net, ((MSG *) h)->orig);
  504.  
  505. #if STATS
  506.          mail_msgs++;
  507.          mail_size += body_count + sizeof(MSG);
  508. #endif
  509.  
  510.          netit (h, holder, body_count, config.mailpath, &high_one);
  511.       }
  512.       /* It is echomail, but is it to us? */
  513.       else
  514.       {
  515. #if DEBUG
  516.          printf ("It is echomail\n");
  517. #endif
  518.          for (j = 1; j <= config.num_addrs; j++)
  519.          {
  520.             if (  (config.net[j] == h->dest_net)
  521.                 &&(config.node[j] == h->dest   ))
  522.             {
  523.                /* It matches one of our addresses! */
  524. #if DEBUG
  525.                printf ("It is addressed to us as %d/%d\n", h->dest_net, h->dest);
  526. #endif
  527.                break;
  528.             }
  529.          }
  530.          if (j > config.num_addrs)
  531.          {
  532. #if DEBUG
  533.             printf ("Not to us\n");
  534. #endif
  535.             if (route_thru < 0)
  536.             {
  537.                /* Just write it into the netmail area */
  538.                printf ("MAIL PKT %s:MSG %d -=> MAIL:%d.MSG\n", pktname, i, high_one+1);
  539.                netit (h, holder, body_count, config.mailpath, &high_one);
  540.             }
  541.             else
  542.             {
  543.                /* Just write it into the routethru area */
  544.                if (*(areas[route_thru]->msgs_in_area) == -1)
  545.                {
  546.                   /* Need to get high message number here */
  547.                   /* First go to the proper directory */
  548.                   (void) high_msg (areas[route_thru]->msg_path,
  549.                      areas[route_thru]->msgs_in_area, &foo);
  550.                   printf ("Found %d messages in area %s\n",
  551.                      *(areas[route_thru]->msgs_in_area),
  552.                       areas[route_thru]->area_name);
  553.                   if (*areas[route_thru]->msgs_in_area == 0)
  554.                      *areas[route_thru]->msgs_in_area = 1;
  555.                }
  556.  
  557.                printf ("MAIL PKT %s:MSG %d -=> ROUTETHRU:%d.MSG\n", pktname,
  558.                   i, *(areas[route_thru]->msgs_in_area) + 1);
  559.                netit (h, holder, body_count, areas[route_thru]->msg_path,
  560.                   areas[route_thru]->msgs_in_area);
  561.             }
  562.          }
  563.          else
  564.          {
  565.             /* Toss it properly */
  566. #if DEBUG
  567.             printf ("Tossing it\n");
  568. #endif
  569.             if ((err = tossit (pktname, header, q1, body_count-5, f, i, 5-sizeof(MSG), 1)) < 0)
  570.             {
  571.                printf (" in message %d in packet '%s'\n", i, pktname);
  572.                if (bad_msgs < 0)
  573.                {
  574.                   if (err != -2)
  575.                   {
  576.                      /* Just write it into the netmail area */
  577.                      printf ("*** Message rerouted to netmail area as MAIL:%d.MSG ***\n", high_one+1);
  578.                      netit (h, holder, body_count, config.mailpath, &high_one);
  579.                   }
  580.                   else
  581.                   {
  582.                      printf ("*** Message skipped\n");
  583.                   }
  584.                }
  585.                else
  586.                {
  587.                   /* Just write it into the bad_msgs area */
  588.                   if (*(areas[bad_msgs]->msgs_in_area) == -1)
  589.                   {
  590.                      /* Need to get high message number here */
  591.                      /* First go to the proper directory */
  592.                      (void) high_msg (areas[bad_msgs]->msg_path,
  593.                          areas[bad_msgs]->msgs_in_area, &foo);
  594.                      printf ("Found %d messages in area %s\n",
  595.                             *(areas[bad_msgs]->msgs_in_area),
  596.                          areas[bad_msgs]->area_name);
  597.                      if (*areas[bad_msgs]->msgs_in_area == 0)
  598.                         *areas[bad_msgs]->msgs_in_area = 1;
  599.                   }
  600.  
  601.                   printf ("MAIL PKT %s:MSG %d -=> BAD_MSGS:%d.MSG\n", pktname,
  602.                      i, *(areas[bad_msgs]->msgs_in_area) + 1);
  603.                   netit (h, holder, body_count, areas[bad_msgs]->msg_path,
  604.                      areas[bad_msgs]->msgs_in_area);
  605.                }
  606.             }
  607.          }
  608.       }
  609.       if (fast_read (f, (char *) &p1, 2) != 2)
  610.       {
  611.          printf ("Packet '%s' was a short packet\n", pktname);
  612.             break;
  613.       }
  614.    }
  615.  
  616.    if (last_toss_area >= 0)
  617.    {
  618.       /* Write out old killer data */
  619.       sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
  620.       dup_file = open (dup_name, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
  621.       (void) fast_write (dup_file, (unsigned char *)&dup_msgs, sizeof (int));
  622.       v = MAGIC;
  623.       (void) fast_write (dup_file, (unsigned char *)&v, sizeof (int));
  624.       (void) fast_write (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
  625.       (void) fast_close (dup_file);
  626.    }
  627.  
  628.    _ffree (wbuffs[f].wbuff);
  629.    wbuffs[f].wbuff = wbuffs[f].wptr = NULL;
  630.    wbuffs[f].wsize = -1;
  631.    (void) fast_close (f);
  632.    free (holder1);
  633.    free (killer);
  634.    /* Else return 0 */
  635.    return (0);
  636. }
  637.  
  638. int tosspkt (char *dir)
  639. {
  640.    int j, k, ret, ct;
  641.    char pktname[20];
  642.    char pktname1[64];
  643.    char pktn[64];
  644.  
  645.    j = 0;
  646.    ret = 1;
  647.    sprintf (pktn, "%s\\*.PKT", dir);
  648.    ct = strlen (dir) + 1;
  649.    (void) filedir (pktn, j, pktname, 0);
  650.    while (pktname[0] != '\0')
  651.    {
  652.       sprintf (pktname1, "%s\\%s", dir, pktname);
  653.  
  654. #if STATS
  655.       LogPacket(pktname1);
  656. #endif
  657.  
  658.       printf ("Tossing packet '%s'\n", pktname1);
  659.       if (unpackpkt (pktname1))
  660.       {
  661.          bad_pkt = 1;
  662.          printf ("Problem with packet '%s' ", pktname1);
  663.          if (pktname[8] != '.')
  664.          {
  665.             printf ("- continuing\n");
  666.             ++j;
  667.          }
  668.          else
  669.          {
  670.             strcpy (&pktname[9], "BAD");
  671.             sprintf (pktn, "%s\\%s", dir, pktname);
  672.             if (rename (pktname1, pktn) == 0)
  673.             {
  674.                printf ("renamed '%s'\n", pktn);
  675.             }
  676.             else
  677.             {
  678.                printf ("rename failed, packet removed\n");
  679.                unlink (pktname1);
  680.             }
  681.             sprintf (pktn, "%s\\*.PKT", dir);
  682.             for(k = 0; k < j; k++)
  683.             {
  684.                (void) filedir (pktn, k, pktname, 0);
  685.             }
  686.          }
  687.       }
  688.       else
  689.       {
  690.          ret = 0;
  691.  
  692. #if STATS
  693.          LogAreas(areas, tot_areas);
  694. #endif
  695.  
  696.          unlink (pktname1);
  697.          for (k = 0; k < j; k++)
  698.          {
  699.             (void) filedir (pktn, k, pktname, 0);
  700.          }
  701.       }
  702.       (void) filedir (pktn, j, pktname, 0);
  703.    }
  704.    return (ret);
  705. }
  706.  
  707. void arc_e ()
  708. {
  709.     /* Now unARC all the other ARCmail and toss that stuff */
  710.     (void) arcmail();
  711. }
  712.