home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / VP2SRC.ZIP / TOSS.C < prev    next >
Text File  |  1991-04-20  |  28KB  |  862 lines

  1. /*
  2.   $Header: toss.c 3.3 87/12/12 00:45:34 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:    toss.c $
  51.  * Revision 3.3  87/12/12  00:45:34  Bob
  52.  * Source code release
  53.  *
  54. */
  55.  
  56. #include <stdio.h>
  57. #include <ctype.h>
  58. #include <fcntl.h>
  59. #include <io.h>
  60. #include <time.h>
  61. #include <process.h>
  62. #include <string.h>
  63. #include <malloc.h>
  64. #include <sys\types.h>
  65. #include <sys\stat.h>
  66. #include "fastecho.h"
  67.  
  68. #define DEBUG 0
  69.  
  70. extern char *opus_date;
  71. extern char *fido_date;
  72. extern char *mspace_err;
  73. extern char *mnspace_err;
  74. extern char *ntoss_err;
  75. extern char *open_err;
  76. extern int tossed_some;
  77. extern int check_nodes;
  78. extern int pass_thru;
  79. extern int bad_msgs;
  80. extern int mail_high;
  81. extern SEACONFIG config;
  82. extern AREAS_PTR areas[];
  83. extern char board_name[], sysop_name[];
  84. extern int tot_areas;
  85. extern char *arc_cmd[];
  86. extern int nread;
  87. extern int arc_args;
  88. extern int last_msg;
  89. extern int high_one;
  90. extern int convert;
  91. extern struct tm *t2;
  92. extern struct _stamp cur_stamp;
  93. extern struct _stamp zero_stamp;
  94. extern KILLPTR killer;
  95. extern long secs_from_1980();
  96. int toss_net;
  97. int toss_node;
  98. int got_a;
  99. int last_toss_area;
  100. int dup_msgs;
  101. int dup_file;
  102. int dup_size;
  103. char dup_name[64];
  104. extern int no_matrix;
  105. extern int msgs_tossed;
  106. extern int msg_dups;
  107. extern char *weekday[];
  108.  
  109. char *_months[12] = {
  110.         "JANUARY", "FEBRUARY", "MARCH",     "APRIL",   "MAY",      "JUNE",
  111.         "JULY",    "AUGUST",   "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
  112. };
  113.  
  114. void do_date (MSG_PTR h1)
  115. {
  116.     int y, d, h, m, s;
  117.     int i;
  118.     char m1[100], junk[100], *tst1;
  119.  
  120.     tst1 = h1->date;
  121.     /* If it is a null date, then put in new format */
  122.     if (h1->date[0] == '\0')
  123.     {
  124.         /* If it is Opus, then put in Opus format */
  125.         if (convert == 1)
  126.         {
  127.             /*
  128.             sprintf (h1->date, opus_date,
  129.             t2->tm_mday, _months[t2->tm_mon], t2->tm_year,
  130.             t2->tm_hour, t2->tm_min, t2->tm_sec);
  131.             h1->date[4] = tolower (h1->date[4]);
  132.             h1->date[5] = tolower (h1->date[5]);
  133.             h1->date[19] = 0xff;
  134.             */
  135.             *tst1++ = ((char) (t2->tm_mday / 10)) + '0';
  136.             *tst1++ = ((char) (t2->tm_mday % 10)) + '0';
  137.             *tst1++ = ' ';
  138.             *tst1++ = _months[t2->tm_mon][0];
  139.             *tst1++ = (char) tolower (_months[t2->tm_mon][1]);
  140.             *tst1++ = (char) tolower (_months[t2->tm_mon][2]);
  141.             *tst1++ = ' ';
  142.             *tst1++ = ((char) (t2->tm_year / 10)) + '0';
  143.             *tst1++ = ((char) (t2->tm_year % 10)) + '0';
  144.             *tst1++ = ' ';
  145.             *tst1++ = ((char) (t2->tm_hour / 10)) + '0';
  146.             *tst1++ = ((char) (t2->tm_hour % 10)) + '0';
  147.             *tst1++ = ':';
  148.             *tst1++ = ((char) (t2->tm_min  / 10)) + '0';
  149.             *tst1++ = ((char) (t2->tm_min  % 10)) + '0';
  150.             *tst1++ = ':';
  151.             *tst1++ = ((char) (t2->tm_sec  / 10)) + '0';
  152.             *tst1++ = ((char) (t2->tm_sec  % 10)) + '0';
  153.             *tst1++ = '\0';
  154.             *tst1++ = 0xff;
  155.             h1->_date_written = h1->_date_arrived = cur_stamp;
  156.         }
  157.         else
  158.         {
  159.             /*
  160.             sprintf (h1->date, fido_date,
  161.             weekday[t2->tm_wday], t2->tm_mday, _months[t2->tm_mon],
  162.             t2->tm_year, t2->tm_hour, t2->tm_min);
  163.             h1->date[8] = tolower (h1->date[8]);
  164.             h1->date[9] = tolower (h1->date[9]);
  165.             */
  166.             *tst1++ = weekday[t2->tm_wday][0];
  167.             *tst1++ = (char) tolower (weekday[t2->tm_wday][1]);
  168.             *tst1++ = (char) tolower (weekday[t2->tm_wday][2]);
  169.             *tst1++ = ' ';
  170.             *tst1++ = ((char) (t2->tm_mday / 10)) + '0';
  171.             *tst1++ = ((char) (t2->tm_mday % 10)) + '0';
  172.             *tst1++ = ' ';
  173.             *tst1++ = _months[t2->tm_mon][0];
  174.             *tst1++ = (char) tolower (_months[t2->tm_mon][1]);
  175.             *tst1++ = (char) tolower (_months[t2->tm_mon][2]);
  176.             *tst1++ = ' ';
  177.             *tst1++ = ((char) (t2->tm_year / 10)) + '0';
  178.             *tst1++ = ((char) (t2->tm_year % 10)) + '0';
  179.             *tst1++ = ' ';
  180.             *tst1++ = ((char) (t2->tm_hour / 10)) + '0';
  181.             *tst1++ = ((char) (t2->tm_hour % 10)) + '0';
  182.             *tst1++ = ':';
  183.             *tst1++ = ((char) (t2->tm_min  / 10)) + '0';
  184.             *tst1++ = ((char) (t2->tm_min  % 10)) + '0';
  185.             *tst1++ = '\0';
  186.             h1->_date_written = h1->_date_arrived = zero_stamp;
  187.         }
  188.         return;
  189.     }
  190.  
  191.     s = 0;
  192.     /* It is old format, so convert to new format */
  193.     if ((i = sscanf (h1->date, "%d %s %d %d:%d:%d", &d, m1, &y, &h, &m, &s)) != 6)
  194.     {
  195.         if ((i = sscanf (h1->date, "%s %d %s %d %d:%d", junk, &d, m1, &y, &h, &m)) < 5)
  196.         {
  197.             /* Cannot recognize old format, so put in default */
  198.             /* If it is Opus, then put in Opus format */
  199.             if (convert == 1)
  200.             {
  201.                 /*
  202.                 sprintf (h1->date, opus_date,
  203.                 t2->tm_mday, _months[t2->tm_mon], t2->tm_year,
  204.                 t2->tm_hour, t2->tm_min, t2->tm_sec);
  205.                 h1->date[4] = tolower (h1->date[4]);
  206.                 h1->date[5] = tolower (h1->date[5]);
  207.                 h1->date[19] = 0xff;
  208.                 */
  209.                 *tst1++ = ((char) (t2->tm_mday / 10)) + '0';
  210.                 *tst1++ = ((char) (t2->tm_mday % (unsigned) 10)) + '0';
  211.                 *tst1++ = ' ';
  212.                 *tst1++ = _months[t2->tm_mon][0];
  213.                 *tst1++ = (char) tolower (_months[t2->tm_mon][1]);
  214.                 *tst1++ = (char) tolower (_months[t2->tm_mon][2]);
  215.                 *tst1++ = ' ';
  216.                 *tst1++ = ((char) (t2->tm_year / (unsigned) 10)) + '0';
  217.                 *tst1++ = ((char) (t2->tm_year % (unsigned) 10)) + '0';
  218.                 *tst1++ = ' ';
  219.                 *tst1++ = ((char) (t2->tm_hour / (unsigned) 10)) + '0';
  220.                 *tst1++ = ((char) (t2->tm_hour % (unsigned) 10)) + '0';
  221.                 *tst1++ = ':';
  222.                 *tst1++ = ((char) (t2->tm_min  / (unsigned) 10)) + '0';
  223.                 *tst1++ = ((char) (t2->tm_min  % (unsigned) 10)) + '0';
  224.                 *tst1++ = ':';
  225.                 *tst1++ = ((char) (t2->tm_sec  / (unsigned) 10)) + '0';
  226.                 *tst1++ = ((char) (t2->tm_sec  % (unsigned) 10)) + '0';
  227.                 *tst1++ = '\0';
  228.                 *tst1++ = 0xff;
  229.                 h1->_date_written = h1->_date_arrived = cur_stamp;
  230.             }
  231.             else
  232.             {
  233.                 /*
  234.                 sprintf (h1->date, fido_date,
  235.                 weekday[t2->tm_wday], t2->tm_mday, _months[t2->tm_mon],
  236.                 t2->tm_year, t2->tm_hour, t2->tm_min);
  237.                 h1->date[8] = tolower (h1->date[8]);
  238.                 h1->date[9] = tolower (h1->date[9]);
  239.                 */
  240.                 *tst1++ = weekday[t2->tm_wday][0];
  241.                 *tst1++ = (char) tolower (weekday[t2->tm_wday][1]);
  242.                 *tst1++ = (char) tolower (weekday[t2->tm_wday][2]);
  243.                 *tst1++ = ' ';
  244.                 *tst1++ = ((char) (t2->tm_mday / (unsigned) 10)) + '0';
  245.                 *tst1++ = ((char) (t2->tm_mday % (unsigned) 10)) + '0';
  246.                 *tst1++ = ' ';
  247.                 *tst1++ = _months[t2->tm_mon][0];
  248.                 *tst1++ = (char) tolower (_months[t2->tm_mon][1]);
  249.                 *tst1++ = (char) tolower (_months[t2->tm_mon][2]);
  250.                 *tst1++ = ' ';
  251.                 *tst1++ = ((char) (t2->tm_year / (unsigned) 10)) + '0';
  252.                 *tst1++ = ((char) (t2->tm_year % (unsigned) 10)) + '0';
  253.                 *tst1++ = ' ';
  254.                 *tst1++ = ((char) (t2->tm_hour / (unsigned) 10)) + '0';
  255.                 *tst1++ = ((char) (t2->tm_hour % (unsigned) 10)) + '0';
  256.                 *tst1++ = ':';
  257.                 *tst1++ = ((char) (t2->tm_min  / (unsigned) 10)) + '0';
  258.                 *tst1++ = ((char) (t2->tm_min  % (unsigned) 10)) + '0';
  259.                 *tst1++ = '\0';
  260.                 h1->_date_written = h1->_date_arrived = zero_stamp;
  261.             }
  262.             return;
  263.         }
  264.     }
  265.     m1[0] = (char) toupper (m1[0]);
  266.     m1[1] = (char) toupper (m1[1]);
  267.     m1[2] = (char) toupper (m1[2]);
  268.     i = 0;
  269. /*  while ((strncmp (_months[i], m1, 3) != 0) && (i != 12))
  270.         ++i;   */
  271.     for ( i=0; i<12; i++)
  272.     {
  273.         if (strncmp(_months[i], m1, 3) == 0)
  274.             break;
  275.     }
  276.  
  277.     /* If we have an undecipherable month, jam in this month */
  278.     if (i == 12)
  279.     {
  280.         if (strncmp("MEI", m1, 3) == 0)
  281.             i = 4;
  282.         else
  283.             i = t2->tm_mon;
  284.     }
  285.     /* Now we have all the pieces, plug them in */
  286.     /*
  287.     sprintf (h1->date, opus_date,
  288.     d, _months[i], y, h, m, s);
  289.     h1->date[4] = tolower (h1->date[4]);
  290.     h1->date[5] = tolower (h1->date[5]);
  291.     */
  292.     *tst1++ = ((char) (d / (unsigned) 10)) + '0';
  293.     *tst1++ = ((char) (d % (unsigned) 10)) + '0';
  294.     *tst1++ = ' ';
  295.     *tst1++ = _months[i][0];
  296.     *tst1++ = (char) tolower (_months[i][1]);
  297.     *tst1++ = (char) tolower (_months[i][2]);
  298.     *tst1++ = ' ';
  299.     *tst1++ = ((char) (y / (unsigned) 10)) + '0';
  300.     *tst1++ = ((char) (y % (unsigned) 10)) + '0';
  301.     *tst1++ = ' ';
  302.     *tst1++ = ((char) (h / (unsigned) 10)) + '0';
  303.     *tst1++ = ((char) (h % (unsigned) 10)) + '0';
  304.     *tst1++ = ':';
  305.     *tst1++ = ((char) (m  / (unsigned) 10)) + '0';
  306.     *tst1++ = ((char) (m  % (unsigned) 10)) + '0';
  307.     *tst1++ = ':';
  308.     *tst1++ = ((char) (s  / (unsigned) 10)) + '0';
  309.     *tst1++ = ((char) (s  % (unsigned) 10)) + '0';
  310.     *tst1++ = '\0';
  311.     if (convert == 1)
  312.     {
  313.         h1->date[19] = 0xff;
  314.         h1->_date_arrived = cur_stamp;
  315.         h1->_date_written.date = ((y - 80)<<9) + ((i+1)<<5) + d;
  316.         h1->_date_written.time = (h<<11) + (m<<5) + (s>>1);
  317.     }
  318.     else
  319.     {
  320.         h1->date[19] = '\0';
  321.         h1->_date_written = h1->_date_arrived = zero_stamp;
  322.     }
  323.  
  324. }
  325.  
  326. int findkill (KILLPTR k1)
  327. {
  328.    int i;
  329.  
  330.    if (k1->seconds == 1000000000L)
  331.       return (0);
  332.  
  333.    for (i = 0; i < dup_size; i++)
  334.       {
  335.         if (killer[i].seconds == k1->seconds)
  336.             {
  337.             if (   (killer[i].from    == k1->from)
  338.                  && (killer[i].to      == k1->to  )
  339.                  && (killer[i].subject == k1->subject)
  340.                  && (killer[i].seconds != 1000000000L))
  341.             {
  342.             return (i + 1);
  343.             }
  344.          }
  345.       }
  346.  
  347.    killer[dup_msgs] = *k1;
  348.    ++dup_msgs;
  349.    if (dup_msgs >= dup_size)
  350.       {
  351.       dup_msgs = 0;
  352.       }
  353.    return (0);
  354. }
  355.  
  356. int toss (char *dir)
  357. {
  358.     int i, j, foo, v;
  359.     int *msg_nums;
  360.     int body_count;
  361.     char *t, *t1, *q1;
  362.     char *holder;
  363.     char *holder1;
  364.     char header[sizeof(MSG)+10];
  365.     MSG_PTR h;
  366.     int f;
  367. /*  int err; */
  368.     char fname[80];
  369.  
  370.    last_toss_area = -1;
  371.    dup_msgs = 0;
  372.     holder1 = malloc ((unsigned) (NUMBLOCKS*1024 + sizeof (MSG)));
  373.     msg_nums = (int *) malloc ((unsigned) (NUMMSGS * sizeof (int)));
  374.     killer = (KILLPTR) calloc (dup_size, sizeof(KILL));
  375.     if (holder1 == NULL)
  376.         {
  377.         printf (mspace_err);
  378.         exit (2);
  379.         }
  380.     if (msg_nums == NULL)
  381.         {
  382.         printf (mnspace_err);
  383.         exit (2);
  384.         }
  385.    if (killer == NULL)
  386.       {
  387.       v = _freect (50*sizeof (KILL));
  388.       printf ("Not enough memory to kill dups based on last %d messages\n", dup_size);
  389.       printf ("Try using '-D %d' on the command line - exiting\n", v*50);
  390.       exit (2);
  391.       }
  392.  
  393.     get_msg_lst (msg_nums, &last_msg, dir, 0);
  394.     if (last_msg == 0)
  395.         {
  396.         mail_high = high_one = 0;
  397.         printf ("No messages to process\n");
  398.         free (holder1);
  399.         free ((char *) msg_nums);
  400.       free (killer);
  401.         return (0);
  402.         }
  403.     else
  404.         {
  405.         mail_high = high_one = msg_nums[last_msg-1];
  406.         }
  407.    if (no_matrix)
  408.       {
  409.       free (holder1);
  410.       free ((char *) msg_nums);
  411.       free (killer);
  412.       printf ("Not processing MAIL area\n");
  413.       return (0);
  414.       }
  415.     printf ("Processing messages numbered %d-%d in MAIL area '%s'\n",
  416.         msg_nums[0], msg_nums[last_msg-1], dir);
  417.     strcpy (fname, dir);
  418.     t1 = fname + strlen (fname);
  419.    *t1++ = '\\';
  420.     holder = holder1+sizeof(MSG);
  421.     h = (MSG_PTR) header;
  422.     t = header+sizeof(MSG);
  423.  
  424.     for (i = 0; i < last_msg; i++)
  425.         {
  426.       got_a = 0;
  427.         sprintf (t1, "%d.MSG", msg_nums[i]);
  428.       /*itoa (msg_nums[i], t1, 10);
  429.       strcat (t1, ".MSG");*/
  430. #if DEBUG
  431.       printf ("Doing file %s\n", fname);
  432. #endif
  433.         if((f = open (fname, O_RDONLY|O_BINARY)) == -1)
  434.             {
  435. #if DEBUG
  436.             printf ("not opened\n");
  437. #endif
  438.             high_one = msg_nums[i];
  439.             continue;
  440.             }
  441.         if (fast_read (f, header, sizeof(MSG)+8) != (sizeof (MSG) + 8))
  442.             {
  443. #if DEBUG
  444.             printf ("not proper size\n");
  445. #endif
  446.             (void) fast_close (f);
  447.             high_one = msg_nums[i];
  448.             continue;
  449.             }
  450.  
  451.         q1 = t;
  452.         if (*q1 == 1)
  453.             {
  454.             ++q1;
  455.          got_a = 1;
  456.             }
  457.         while ((isspace ((*q1)&0x7f)) || (*q1 == 1))
  458.             ++q1;
  459.  
  460.         /* Is it an AREA: file */
  461.         if (strncmp (q1, "AREA:", 5) != 0)
  462.             {
  463. #if DEBUG
  464.             printf ("not echomail\n");
  465. #endif
  466.             (void) fast_close (f);
  467.             high_one = msg_nums[i];
  468.             continue;
  469.             }
  470. #if DEBUG
  471.         printf ("It is Echomail to %d/%d\n", h->dest_net, h->dest);
  472. #endif
  473.         /* Is the message to us */
  474.         for (j = 1; j <= config.num_addrs; j++)
  475.             {
  476.             if (  (config.net[j] == h->dest_net)
  477.                  &&(config.node[j] == h->dest   ))
  478.                 {
  479.                 /* It matches one of our addresses! */
  480. #if DEBUG
  481.                 printf ("It is addressed to us as %d/%d\n", h->dest_net, h->dest);
  482. #endif
  483.                 break;
  484.                 }
  485.             }
  486.         if (j > config.num_addrs)
  487.             {
  488.             (void) fast_close (f);
  489.             high_one = msg_nums[i];
  490.             continue;
  491.             }
  492.         strncpy (holder, q1, 8-(int) (q1-t));
  493.  
  494.         body_count = read_all (f, holder+(8-(int) (q1-t)));
  495.  
  496. #if DEBUG
  497.         printf ("body_count = %d\n", body_count);
  498. #endif
  499.  
  500.         do_date (h);
  501.       toss_net = h->orig_net;
  502.       toss_node = h->orig;
  503.         if (tossit (fname, header, holder1, body_count, f, msg_nums[i], 5, 0) < 0)
  504.             {
  505.             printf (" in message %d\n", msg_nums[i]);
  506.          if (bad_msgs >= 0)
  507.             {
  508.             /* Just write it into the bad_msgs area */
  509.                 if (*(areas[bad_msgs]->msgs_in_area) == -1)
  510.                 {
  511.                 /* Need to get high message number here */
  512.                /* First go to the proper directory */
  513.                     (void) high_msg (areas[bad_msgs]->msg_path,
  514.                   areas[bad_msgs]->msgs_in_area, &foo);
  515.              printf ("Found %d messages in area %s\n",
  516.                         *(areas[bad_msgs]->msgs_in_area),
  517.                     areas[bad_msgs]->area_name);
  518.                if (*areas[bad_msgs]->msgs_in_area == 0)
  519.                   *areas[bad_msgs]->msgs_in_area = 1;
  520.                    }
  521.  
  522.             printf ("MAIL:%d.MSG -=> %s:%d.MSG\n", msg_nums[i],
  523.                 areas[bad_msgs]->area_name, *(areas[bad_msgs]->msgs_in_area)+1);
  524.             netit ((MSG_PTR)header, holder, body_count+5, areas[bad_msgs]->msg_path,
  525.                areas[bad_msgs]->msgs_in_area);
  526.             unlink (fname);
  527.             }
  528.             }
  529.         }
  530.  
  531.    if (last_toss_area >= 0)
  532.       {
  533.       /* Write out old killer data */
  534.       sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
  535.       dup_file = open (dup_name, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
  536.       (void) fast_write (dup_file, (unsigned char *)&dup_msgs, sizeof (int));
  537.       v = MAGIC;
  538.       (void) fast_write (dup_file, (unsigned char *)&v, sizeof (int));
  539.       (void) fast_write (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
  540.       (void) fast_close (dup_file);
  541.       last_toss_area = -1;
  542.       }
  543.  
  544.     free (holder1);
  545.     free ((char *) msg_nums);
  546.    free (killer);
  547.    return (0);
  548. }
  549.  
  550. int tossit (
  551.    char *fname,
  552.    char *header,
  553.    char *holder1,
  554.    int   body_count,
  555.    int   f,
  556.    int   msg_num,
  557.    int   area,
  558.    int   delit)
  559. {
  560. /*  int i, j, foo, zzl1, v; */
  561.     int i, j, foo, v;
  562.     char *body;
  563.     char *ptr, *ptr1;
  564.     char *holder;
  565. /*  char *zz1;              */
  566.     MSG_PTR h;
  567.     int f1;
  568.    int st;
  569.     char fname1[80];
  570.     char old_char;
  571.    KILL k1;
  572.  
  573.     /* Now see if it is tossable */
  574.     holder = holder1+sizeof(MSG)+area;
  575.     h = (MSG_PTR) header;
  576.     ptr = holder;
  577. #if DEBUG
  578.     printf ("ptr = '%10.10s'\n", ptr);
  579. #endif
  580.     /* It is tossable! */
  581.     /* First get the area to put it in */
  582.     while ((isspace ((*ptr&0x7f)) || (*ptr == 1)) && (ptr != (holder + body_count)))
  583.         ptr++;
  584.     ptr1 = ptr;
  585.     while ((!isspace ((*ptr1&0x7f))) && (ptr1 != (holder + body_count)))
  586.         ptr1++;
  587.     old_char = *ptr1;
  588.     *ptr1 = '\0';
  589.     if (*ptr == '\0')
  590.         {
  591.         printf ("Can't find the AREA name after the AREA:");
  592.         if (!delit)
  593.             (void) fast_close (f);
  594.         *ptr1 = old_char;
  595.         return (-1);
  596.         }
  597.     else
  598.         {
  599.         body = ptr1 + 1;
  600.         }
  601. #if DEBUG
  602.     printf ("It goes into area '%s'\n", ptr);
  603. #endif
  604.  
  605.     /* Now find it in our list of areas */
  606.     for (j = 0; j < tot_areas; j++)
  607.         {
  608.         if (stricmp (areas[j]->area_name, ptr) == 0)
  609.             {
  610.             /* Found it */
  611.             break;
  612.             }
  613.         }
  614.  
  615. #if DEBUG
  616.     printf ("tot_areas = %d, j = %d\n", tot_areas, j);
  617. #endif
  618.  
  619.     if (j == tot_areas)
  620.         {
  621.       if (pass_thru >= 0)
  622.          {
  623.          j = pass_thru;
  624.          body = holder1+sizeof(MSG)+area-5;
  625.          *ptr1 = old_char;
  626.          }
  627.       else
  628.          {
  629.         printf ("Unknown Area Name '%s'", ptr);
  630.         if (!delit)
  631.             (void) fast_close (f);
  632.         *ptr1 = old_char;
  633.         return (-1);
  634.          }
  635.         }
  636.  
  637.    i = -1;
  638.    /* Now check the node numbers if we are supposed to do that */
  639.    if (check_nodes)
  640.       {
  641.       /* First check to see if it is from us */
  642.         for (i = 1; i <= config.num_addrs; i++)
  643.             {
  644.             if (  (config.net[i] == h->orig_net)
  645.                  &&(config.node[i] == h->orig   ))
  646.                 {
  647.                 /* It matches one of our addresses! */
  648.                 break;
  649.                 }
  650.             }
  651.         if (i <= config.num_addrs)
  652.             {
  653.          printf (ntoss_err, h->orig_net, h->orig);
  654.          if (!delit)
  655.             (void) fast_close (f);
  656.          *ptr1 = old_char;
  657.          return (-1);
  658.             }
  659.       for (i = 0; i < areas[j]->num_nodes; i++)
  660.          {
  661.          if ((areas[j]->net[i] == toss_net) &&
  662.              (areas[j]->node[i] == toss_node))
  663.             {
  664.             break;
  665.             }
  666.          }
  667.       }
  668.  
  669.  
  670.    /*zzl1 = strlen (areas[j]->msg_path);*/
  671.    if (i >= areas[j]->num_nodes)
  672.       {
  673.       printf (ntoss_err, toss_net, toss_node);
  674.       if (!delit)
  675.          (void) fast_close (f);
  676.       *ptr1 = old_char;
  677.       return (-1);
  678.       }
  679.     else
  680.         {
  681.  
  682.       if (killer != NULL)
  683.          {
  684.          if (last_toss_area != j)
  685.             {
  686.             if (last_toss_area >= 0)
  687.                {
  688.                /* Write out old killer data */
  689.                sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
  690.                dup_file = open (dup_name, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
  691.                (void) fast_write (dup_file, (unsigned char *)&dup_msgs, sizeof (int));
  692.                v = MAGIC;
  693.                (void) fast_write (dup_file, (unsigned char *)&v, sizeof (int));
  694.                (void) fast_write (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
  695.                (void) fast_close (dup_file);
  696.                memset (killer, 0, dup_size * sizeof (KILL));
  697.                dup_msgs = 0;
  698.                }
  699.  
  700.             if ((areas[j]->flags & ROUTETHRU) ||
  701.                (areas[j]->flags & PASS_THRU) ||
  702.                (areas[j]->flags & BAD_MSGS))
  703.                {
  704.                last_toss_area = -1;
  705.                }
  706.             else
  707.                {
  708.                last_toss_area = j;
  709.                /* Input new killer data */
  710.                sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
  711.  
  712.                if ((dup_file = open (dup_name, O_RDONLY|O_BINARY)) != -1)
  713.                   {
  714.  
  715.                   if (fast_read (dup_file, (unsigned char *)&dup_msgs, sizeof (int)) != sizeof (int))
  716.                      {
  717.  
  718.                      dup_msgs = 0;
  719.                      (void) fast_close (dup_file);
  720.  
  721.                      }
  722.                   else
  723.                      {
  724.                      v = 0;
  725.  
  726.                      if (fast_read (dup_file, (unsigned char *)&v, sizeof (int)) != sizeof (int))
  727.                         {
  728.  
  729.                         dup_msgs = 0;
  730.                         }
  731.                      else if (v != MAGIC)
  732.                         {
  733.  
  734.                         dup_msgs = 0;
  735.                         }
  736.                      else
  737.                         {
  738.  
  739.                         (void) fast_read (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
  740.  
  741.                         }
  742.                      (void) fast_close (dup_file);
  743.  
  744.                      }
  745.                   }
  746.                else
  747.                   {
  748.                   dup_msgs = 0;
  749.                   }
  750.                }
  751.             }
  752.  
  753.  
  754.          /* Now calculate the killer data for this one */
  755.         k1.seconds = secs_from_1980 (h);
  756.         k1.from = calcrc (h->from);
  757.         k1.to = calcrc (h->to);
  758.          if ((toupper(h->subj[0]) == 'R') &&
  759.              (toupper(h->subj[1]) == 'E') &&
  760.              (h->subj[2] == ':') &&
  761.              (h->subj[3] == ' '))
  762.             {
  763.             st = 4;
  764.             }
  765.          else
  766.             st = 0;
  767.  
  768.         k1.subject = calcrc (&(h->subj[st]));
  769.  
  770.          /* If it is in the data base, then don't toss it */
  771.          if (! ((areas[j]->flags & ROUTETHRU) ||
  772.             (areas[j]->flags & PASS_THRU) ||
  773.             (areas[j]->flags & BAD_MSGS)))
  774.             {
  775.             if (findkill (&k1))
  776.                {
  777.                 printf ("DUPLICATE MESSAGE");
  778.                if (!delit)
  779.                   (void) fast_close (f);
  780.                *ptr1 = old_char;
  781.                ++msg_dups;
  782.                return (-2);
  783.                }
  784.             }
  785.          }
  786.  
  787.  
  788.         if (*(areas[j]->msgs_in_area) == -1)
  789.             {
  790.             /* Need to get high message number here */
  791.             /* First go to the proper directory */
  792.             (void) high_msg (areas[j]->msg_path, areas[j]->msgs_in_area, &foo);
  793.             printf ("Found %d messages in area %s\n",
  794.                 *(areas[j]->msgs_in_area), areas[j]->area_name);
  795.          if (*areas[j]->msgs_in_area <= 0)
  796.             *areas[j]->msgs_in_area = 1;
  797.             }
  798.  
  799.         /* Create new name */
  800.         sprintf (fname1, "%s\\%d.MSG", areas[j]->msg_path,
  801.             ++*(areas[j]->msgs_in_area));
  802.       /*
  803.       strcpy (fname1, areas[j]->msg_path);
  804.       zz1 = &(fname1[zzl1]);
  805.       *zz1++ = '\\';
  806.       itoa (++*(areas[j]->msgs_in_area), zz1, 10);
  807.       strcat (zz1, ".MSG");
  808.       */
  809. #if DEBUG
  810.       printf ("I am really going '%s' -=> '%s'\n", fname, fname1);
  811. #endif
  812.  
  813.         if (delit)
  814.             printf ("MAIL PKT %s:MSG %d -=> %s:%d.MSG\n", fname, msg_num,
  815.                 areas[j]->area_name, *(areas[j]->msgs_in_area));
  816.         else
  817.             printf ("MAIL:%d.MSG -=> %s:%d.MSG\n", msg_num,
  818.                 areas[j]->area_name, *(areas[j]->msgs_in_area));
  819.         h->attr &= SAVED;
  820.         h->cost = 0;
  821.         if (*body == '\n')
  822.             ++body;
  823.         body_count -= (body - holder);
  824.         body = body - sizeof (MSG);
  825.         memcpy (body, header, sizeof (MSG));
  826.         body_count += sizeof (MSG);
  827. #if DEBUG
  828.         printf ("Got body containing %d characters\n", body_count);
  829. #endif
  830.         /* Open file */
  831.         f1 = open (fname1, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
  832.         if (f1 == -1)
  833.             {
  834.             printf (open_err, fname1);
  835.             exit (2);
  836.             }
  837.         /* Write the header after clearing the proper bits */
  838.         if (write_body (f1, body, body_count, f) < body_count)
  839.             {
  840.             printf ("Didn't properly write the message body, aborting\n");
  841.             exit (2);
  842.             }
  843.         if (fast_close (f1) != 0)
  844.             {
  845.             printf ("Pretty strange, couldn't fast_close after write, aborting\n");
  846.             exit (2);
  847.             }
  848. #if DEBUG
  849.         printf ("If I got here then I should have properly written the message\n");
  850. #endif
  851.         if (!delit)
  852.             {
  853.             (void) fast_close (f);
  854.             unlink (fname);
  855.             }
  856.         }
  857.     tossed_some = 1;
  858.    ++msgs_tossed;
  859.     return (0);
  860. }
  861.  
  862.