home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
VP2SRC.ZIP
/
TOSS.C
< prev
next >
Wrap
Text File
|
1991-04-20
|
28KB
|
862 lines
/*
$Header: toss.c 3.3 87/12/12 00:45:34 Bob Exp $
The Conference Mail System
This module was originally written by Bob Hartman
Sysop of FidoNet node 1:132/101
Spark Software, 427-3 Amherst St, CS 2032, Suite 232, Nashua, NH 03061
The Conference Mail System is a complete Echomail processing package. It
is a superset of the original Echomail utilities created by Jeff Rush, and
also contains ideas gleaned from the ARCmail, Renum, oMMM, MGM, and Opus
programs that were created by various software authors.
This program source code is being released with the following provisions:
1. You are free to make changes to this source code for use on your own
machine, however, altered source files may not be distributed without the
consent of Spark Software.
2. You may distribute "patches" or "diff" files for any changes that you
have made, provided that the "patch" or "diff" files are also sent to Spark
Software for inclusion in future releases of the entire package. A "diff"
file for the source archives may also contain a compiled version, provided
it is clearly marked as not being created from the original source code.
No other executable versions may be distributed without the consent of
Spark Software.
3. You are free to include portions of this source code in any program you
develop, providing: a) Credit is given to Spark Software for any code that
may is used, and b) The resulting program is free to anyone wanting to use
it, including commercial and government users.
4. There is NO technical support available for dealing with this source
code, or the accompanying executable files. This source code is provided
as is, with no warranty expressed or implied (I hate legalease). In other
words, if you don't know what to do with it, don't use it, and if you are
brave enough to use it, you're on your own.
Spark Software may be contacted by modem at (603) 888-8179 (node 1:132/101)
on the public FidoNet network, or at the address given above.
To use this code you will need Microsoft C version 4.0, and also Microsoft
Macro Assembler version 4.0.
*/
/*
$Log: toss.c $
* Revision 3.3 87/12/12 00:45:34 Bob
* Source code release
*
*/
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
#include <process.h>
#include <string.h>
#include <malloc.h>
#include <sys\types.h>
#include <sys\stat.h>
#include "fastecho.h"
#define DEBUG 0
extern char *opus_date;
extern char *fido_date;
extern char *mspace_err;
extern char *mnspace_err;
extern char *ntoss_err;
extern char *open_err;
extern int tossed_some;
extern int check_nodes;
extern int pass_thru;
extern int bad_msgs;
extern int mail_high;
extern SEACONFIG config;
extern AREAS_PTR areas[];
extern char board_name[], sysop_name[];
extern int tot_areas;
extern char *arc_cmd[];
extern int nread;
extern int arc_args;
extern int last_msg;
extern int high_one;
extern int convert;
extern struct tm *t2;
extern struct _stamp cur_stamp;
extern struct _stamp zero_stamp;
extern KILLPTR killer;
extern long secs_from_1980();
int toss_net;
int toss_node;
int got_a;
int last_toss_area;
int dup_msgs;
int dup_file;
int dup_size;
char dup_name[64];
extern int no_matrix;
extern int msgs_tossed;
extern int msg_dups;
extern char *weekday[];
char *_months[12] = {
"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
"JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
};
void do_date (MSG_PTR h1)
{
int y, d, h, m, s;
int i;
char m1[100], junk[100], *tst1;
tst1 = h1->date;
/* If it is a null date, then put in new format */
if (h1->date[0] == '\0')
{
/* If it is Opus, then put in Opus format */
if (convert == 1)
{
/*
sprintf (h1->date, opus_date,
t2->tm_mday, _months[t2->tm_mon], t2->tm_year,
t2->tm_hour, t2->tm_min, t2->tm_sec);
h1->date[4] = tolower (h1->date[4]);
h1->date[5] = tolower (h1->date[5]);
h1->date[19] = 0xff;
*/
*tst1++ = ((char) (t2->tm_mday / 10)) + '0';
*tst1++ = ((char) (t2->tm_mday % 10)) + '0';
*tst1++ = ' ';
*tst1++ = _months[t2->tm_mon][0];
*tst1++ = (char) tolower (_months[t2->tm_mon][1]);
*tst1++ = (char) tolower (_months[t2->tm_mon][2]);
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_year / 10)) + '0';
*tst1++ = ((char) (t2->tm_year % 10)) + '0';
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_hour / 10)) + '0';
*tst1++ = ((char) (t2->tm_hour % 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (t2->tm_min / 10)) + '0';
*tst1++ = ((char) (t2->tm_min % 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (t2->tm_sec / 10)) + '0';
*tst1++ = ((char) (t2->tm_sec % 10)) + '0';
*tst1++ = '\0';
*tst1++ = 0xff;
h1->_date_written = h1->_date_arrived = cur_stamp;
}
else
{
/*
sprintf (h1->date, fido_date,
weekday[t2->tm_wday], t2->tm_mday, _months[t2->tm_mon],
t2->tm_year, t2->tm_hour, t2->tm_min);
h1->date[8] = tolower (h1->date[8]);
h1->date[9] = tolower (h1->date[9]);
*/
*tst1++ = weekday[t2->tm_wday][0];
*tst1++ = (char) tolower (weekday[t2->tm_wday][1]);
*tst1++ = (char) tolower (weekday[t2->tm_wday][2]);
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_mday / 10)) + '0';
*tst1++ = ((char) (t2->tm_mday % 10)) + '0';
*tst1++ = ' ';
*tst1++ = _months[t2->tm_mon][0];
*tst1++ = (char) tolower (_months[t2->tm_mon][1]);
*tst1++ = (char) tolower (_months[t2->tm_mon][2]);
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_year / 10)) + '0';
*tst1++ = ((char) (t2->tm_year % 10)) + '0';
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_hour / 10)) + '0';
*tst1++ = ((char) (t2->tm_hour % 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (t2->tm_min / 10)) + '0';
*tst1++ = ((char) (t2->tm_min % 10)) + '0';
*tst1++ = '\0';
h1->_date_written = h1->_date_arrived = zero_stamp;
}
return;
}
s = 0;
/* It is old format, so convert to new format */
if ((i = sscanf (h1->date, "%d %s %d %d:%d:%d", &d, m1, &y, &h, &m, &s)) != 6)
{
if ((i = sscanf (h1->date, "%s %d %s %d %d:%d", junk, &d, m1, &y, &h, &m)) < 5)
{
/* Cannot recognize old format, so put in default */
/* If it is Opus, then put in Opus format */
if (convert == 1)
{
/*
sprintf (h1->date, opus_date,
t2->tm_mday, _months[t2->tm_mon], t2->tm_year,
t2->tm_hour, t2->tm_min, t2->tm_sec);
h1->date[4] = tolower (h1->date[4]);
h1->date[5] = tolower (h1->date[5]);
h1->date[19] = 0xff;
*/
*tst1++ = ((char) (t2->tm_mday / 10)) + '0';
*tst1++ = ((char) (t2->tm_mday % (unsigned) 10)) + '0';
*tst1++ = ' ';
*tst1++ = _months[t2->tm_mon][0];
*tst1++ = (char) tolower (_months[t2->tm_mon][1]);
*tst1++ = (char) tolower (_months[t2->tm_mon][2]);
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_year / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_year % (unsigned) 10)) + '0';
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_hour / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_hour % (unsigned) 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (t2->tm_min / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_min % (unsigned) 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (t2->tm_sec / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_sec % (unsigned) 10)) + '0';
*tst1++ = '\0';
*tst1++ = 0xff;
h1->_date_written = h1->_date_arrived = cur_stamp;
}
else
{
/*
sprintf (h1->date, fido_date,
weekday[t2->tm_wday], t2->tm_mday, _months[t2->tm_mon],
t2->tm_year, t2->tm_hour, t2->tm_min);
h1->date[8] = tolower (h1->date[8]);
h1->date[9] = tolower (h1->date[9]);
*/
*tst1++ = weekday[t2->tm_wday][0];
*tst1++ = (char) tolower (weekday[t2->tm_wday][1]);
*tst1++ = (char) tolower (weekday[t2->tm_wday][2]);
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_mday / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_mday % (unsigned) 10)) + '0';
*tst1++ = ' ';
*tst1++ = _months[t2->tm_mon][0];
*tst1++ = (char) tolower (_months[t2->tm_mon][1]);
*tst1++ = (char) tolower (_months[t2->tm_mon][2]);
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_year / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_year % (unsigned) 10)) + '0';
*tst1++ = ' ';
*tst1++ = ((char) (t2->tm_hour / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_hour % (unsigned) 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (t2->tm_min / (unsigned) 10)) + '0';
*tst1++ = ((char) (t2->tm_min % (unsigned) 10)) + '0';
*tst1++ = '\0';
h1->_date_written = h1->_date_arrived = zero_stamp;
}
return;
}
}
m1[0] = (char) toupper (m1[0]);
m1[1] = (char) toupper (m1[1]);
m1[2] = (char) toupper (m1[2]);
i = 0;
/* while ((strncmp (_months[i], m1, 3) != 0) && (i != 12))
++i; */
for ( i=0; i<12; i++)
{
if (strncmp(_months[i], m1, 3) == 0)
break;
}
/* If we have an undecipherable month, jam in this month */
if (i == 12)
{
if (strncmp("MEI", m1, 3) == 0)
i = 4;
else
i = t2->tm_mon;
}
/* Now we have all the pieces, plug them in */
/*
sprintf (h1->date, opus_date,
d, _months[i], y, h, m, s);
h1->date[4] = tolower (h1->date[4]);
h1->date[5] = tolower (h1->date[5]);
*/
*tst1++ = ((char) (d / (unsigned) 10)) + '0';
*tst1++ = ((char) (d % (unsigned) 10)) + '0';
*tst1++ = ' ';
*tst1++ = _months[i][0];
*tst1++ = (char) tolower (_months[i][1]);
*tst1++ = (char) tolower (_months[i][2]);
*tst1++ = ' ';
*tst1++ = ((char) (y / (unsigned) 10)) + '0';
*tst1++ = ((char) (y % (unsigned) 10)) + '0';
*tst1++ = ' ';
*tst1++ = ((char) (h / (unsigned) 10)) + '0';
*tst1++ = ((char) (h % (unsigned) 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (m / (unsigned) 10)) + '0';
*tst1++ = ((char) (m % (unsigned) 10)) + '0';
*tst1++ = ':';
*tst1++ = ((char) (s / (unsigned) 10)) + '0';
*tst1++ = ((char) (s % (unsigned) 10)) + '0';
*tst1++ = '\0';
if (convert == 1)
{
h1->date[19] = 0xff;
h1->_date_arrived = cur_stamp;
h1->_date_written.date = ((y - 80)<<9) + ((i+1)<<5) + d;
h1->_date_written.time = (h<<11) + (m<<5) + (s>>1);
}
else
{
h1->date[19] = '\0';
h1->_date_written = h1->_date_arrived = zero_stamp;
}
}
int findkill (KILLPTR k1)
{
int i;
if (k1->seconds == 1000000000L)
return (0);
for (i = 0; i < dup_size; i++)
{
if (killer[i].seconds == k1->seconds)
{
if ( (killer[i].from == k1->from)
&& (killer[i].to == k1->to )
&& (killer[i].subject == k1->subject)
&& (killer[i].seconds != 1000000000L))
{
return (i + 1);
}
}
}
killer[dup_msgs] = *k1;
++dup_msgs;
if (dup_msgs >= dup_size)
{
dup_msgs = 0;
}
return (0);
}
int toss (char *dir)
{
int i, j, foo, v;
int *msg_nums;
int body_count;
char *t, *t1, *q1;
char *holder;
char *holder1;
char header[sizeof(MSG)+10];
MSG_PTR h;
int f;
/* int err; */
char fname[80];
last_toss_area = -1;
dup_msgs = 0;
holder1 = malloc ((unsigned) (NUMBLOCKS*1024 + sizeof (MSG)));
msg_nums = (int *) malloc ((unsigned) (NUMMSGS * sizeof (int)));
killer = (KILLPTR) calloc (dup_size, sizeof(KILL));
if (holder1 == NULL)
{
printf (mspace_err);
exit (2);
}
if (msg_nums == NULL)
{
printf (mnspace_err);
exit (2);
}
if (killer == NULL)
{
v = _freect (50*sizeof (KILL));
printf ("Not enough memory to kill dups based on last %d messages\n", dup_size);
printf ("Try using '-D %d' on the command line - exiting\n", v*50);
exit (2);
}
get_msg_lst (msg_nums, &last_msg, dir, 0);
if (last_msg == 0)
{
mail_high = high_one = 0;
printf ("No messages to process\n");
free (holder1);
free ((char *) msg_nums);
free (killer);
return (0);
}
else
{
mail_high = high_one = msg_nums[last_msg-1];
}
if (no_matrix)
{
free (holder1);
free ((char *) msg_nums);
free (killer);
printf ("Not processing MAIL area\n");
return (0);
}
printf ("Processing messages numbered %d-%d in MAIL area '%s'\n",
msg_nums[0], msg_nums[last_msg-1], dir);
strcpy (fname, dir);
t1 = fname + strlen (fname);
*t1++ = '\\';
holder = holder1+sizeof(MSG);
h = (MSG_PTR) header;
t = header+sizeof(MSG);
for (i = 0; i < last_msg; i++)
{
got_a = 0;
sprintf (t1, "%d.MSG", msg_nums[i]);
/*itoa (msg_nums[i], t1, 10);
strcat (t1, ".MSG");*/
#if DEBUG
printf ("Doing file %s\n", fname);
#endif
if((f = open (fname, O_RDONLY|O_BINARY)) == -1)
{
#if DEBUG
printf ("not opened\n");
#endif
high_one = msg_nums[i];
continue;
}
if (fast_read (f, header, sizeof(MSG)+8) != (sizeof (MSG) + 8))
{
#if DEBUG
printf ("not proper size\n");
#endif
(void) fast_close (f);
high_one = msg_nums[i];
continue;
}
q1 = t;
if (*q1 == 1)
{
++q1;
got_a = 1;
}
while ((isspace ((*q1)&0x7f)) || (*q1 == 1))
++q1;
/* Is it an AREA: file */
if (strncmp (q1, "AREA:", 5) != 0)
{
#if DEBUG
printf ("not echomail\n");
#endif
(void) fast_close (f);
high_one = msg_nums[i];
continue;
}
#if DEBUG
printf ("It is Echomail to %d/%d\n", h->dest_net, h->dest);
#endif
/* Is the message to us */
for (j = 1; j <= config.num_addrs; j++)
{
if ( (config.net[j] == h->dest_net)
&&(config.node[j] == h->dest ))
{
/* It matches one of our addresses! */
#if DEBUG
printf ("It is addressed to us as %d/%d\n", h->dest_net, h->dest);
#endif
break;
}
}
if (j > config.num_addrs)
{
(void) fast_close (f);
high_one = msg_nums[i];
continue;
}
strncpy (holder, q1, 8-(int) (q1-t));
body_count = read_all (f, holder+(8-(int) (q1-t)));
#if DEBUG
printf ("body_count = %d\n", body_count);
#endif
do_date (h);
toss_net = h->orig_net;
toss_node = h->orig;
if (tossit (fname, header, holder1, body_count, f, msg_nums[i], 5, 0) < 0)
{
printf (" in message %d\n", msg_nums[i]);
if (bad_msgs >= 0)
{
/* Just write it into the bad_msgs area */
if (*(areas[bad_msgs]->msgs_in_area) == -1)
{
/* Need to get high message number here */
/* First go to the proper directory */
(void) high_msg (areas[bad_msgs]->msg_path,
areas[bad_msgs]->msgs_in_area, &foo);
printf ("Found %d messages in area %s\n",
*(areas[bad_msgs]->msgs_in_area),
areas[bad_msgs]->area_name);
if (*areas[bad_msgs]->msgs_in_area == 0)
*areas[bad_msgs]->msgs_in_area = 1;
}
printf ("MAIL:%d.MSG -=> %s:%d.MSG\n", msg_nums[i],
areas[bad_msgs]->area_name, *(areas[bad_msgs]->msgs_in_area)+1);
netit ((MSG_PTR)header, holder, body_count+5, areas[bad_msgs]->msg_path,
areas[bad_msgs]->msgs_in_area);
unlink (fname);
}
}
}
if (last_toss_area >= 0)
{
/* Write out old killer data */
sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
dup_file = open (dup_name, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
(void) fast_write (dup_file, (unsigned char *)&dup_msgs, sizeof (int));
v = MAGIC;
(void) fast_write (dup_file, (unsigned char *)&v, sizeof (int));
(void) fast_write (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
(void) fast_close (dup_file);
last_toss_area = -1;
}
free (holder1);
free ((char *) msg_nums);
free (killer);
return (0);
}
int tossit (
char *fname,
char *header,
char *holder1,
int body_count,
int f,
int msg_num,
int area,
int delit)
{
/* int i, j, foo, zzl1, v; */
int i, j, foo, v;
char *body;
char *ptr, *ptr1;
char *holder;
/* char *zz1; */
MSG_PTR h;
int f1;
int st;
char fname1[80];
char old_char;
KILL k1;
/* Now see if it is tossable */
holder = holder1+sizeof(MSG)+area;
h = (MSG_PTR) header;
ptr = holder;
#if DEBUG
printf ("ptr = '%10.10s'\n", ptr);
#endif
/* It is tossable! */
/* First get the area to put it in */
while ((isspace ((*ptr&0x7f)) || (*ptr == 1)) && (ptr != (holder + body_count)))
ptr++;
ptr1 = ptr;
while ((!isspace ((*ptr1&0x7f))) && (ptr1 != (holder + body_count)))
ptr1++;
old_char = *ptr1;
*ptr1 = '\0';
if (*ptr == '\0')
{
printf ("Can't find the AREA name after the AREA:");
if (!delit)
(void) fast_close (f);
*ptr1 = old_char;
return (-1);
}
else
{
body = ptr1 + 1;
}
#if DEBUG
printf ("It goes into area '%s'\n", ptr);
#endif
/* Now find it in our list of areas */
for (j = 0; j < tot_areas; j++)
{
if (stricmp (areas[j]->area_name, ptr) == 0)
{
/* Found it */
break;
}
}
#if DEBUG
printf ("tot_areas = %d, j = %d\n", tot_areas, j);
#endif
if (j == tot_areas)
{
if (pass_thru >= 0)
{
j = pass_thru;
body = holder1+sizeof(MSG)+area-5;
*ptr1 = old_char;
}
else
{
printf ("Unknown Area Name '%s'", ptr);
if (!delit)
(void) fast_close (f);
*ptr1 = old_char;
return (-1);
}
}
i = -1;
/* Now check the node numbers if we are supposed to do that */
if (check_nodes)
{
/* First check to see if it is from us */
for (i = 1; i <= config.num_addrs; i++)
{
if ( (config.net[i] == h->orig_net)
&&(config.node[i] == h->orig ))
{
/* It matches one of our addresses! */
break;
}
}
if (i <= config.num_addrs)
{
printf (ntoss_err, h->orig_net, h->orig);
if (!delit)
(void) fast_close (f);
*ptr1 = old_char;
return (-1);
}
for (i = 0; i < areas[j]->num_nodes; i++)
{
if ((areas[j]->net[i] == toss_net) &&
(areas[j]->node[i] == toss_node))
{
break;
}
}
}
/*zzl1 = strlen (areas[j]->msg_path);*/
if (i >= areas[j]->num_nodes)
{
printf (ntoss_err, toss_net, toss_node);
if (!delit)
(void) fast_close (f);
*ptr1 = old_char;
return (-1);
}
else
{
if (killer != NULL)
{
if (last_toss_area != j)
{
if (last_toss_area >= 0)
{
/* Write out old killer data */
sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
dup_file = open (dup_name, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
(void) fast_write (dup_file, (unsigned char *)&dup_msgs, sizeof (int));
v = MAGIC;
(void) fast_write (dup_file, (unsigned char *)&v, sizeof (int));
(void) fast_write (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
(void) fast_close (dup_file);
memset (killer, 0, dup_size * sizeof (KILL));
dup_msgs = 0;
}
if ((areas[j]->flags & ROUTETHRU) ||
(areas[j]->flags & PASS_THRU) ||
(areas[j]->flags & BAD_MSGS))
{
last_toss_area = -1;
}
else
{
last_toss_area = j;
/* Input new killer data */
sprintf (dup_name, "%s\\CONFDUPS.DAT", areas[last_toss_area]->msg_path);
if ((dup_file = open (dup_name, O_RDONLY|O_BINARY)) != -1)
{
if (fast_read (dup_file, (unsigned char *)&dup_msgs, sizeof (int)) != sizeof (int))
{
dup_msgs = 0;
(void) fast_close (dup_file);
}
else
{
v = 0;
if (fast_read (dup_file, (unsigned char *)&v, sizeof (int)) != sizeof (int))
{
dup_msgs = 0;
}
else if (v != MAGIC)
{
dup_msgs = 0;
}
else
{
(void) fast_read (dup_file, (unsigned char *)killer, dup_size * sizeof (KILL));
}
(void) fast_close (dup_file);
}
}
else
{
dup_msgs = 0;
}
}
}
/* Now calculate the killer data for this one */
k1.seconds = secs_from_1980 (h);
k1.from = calcrc (h->from);
k1.to = calcrc (h->to);
if ((toupper(h->subj[0]) == 'R') &&
(toupper(h->subj[1]) == 'E') &&
(h->subj[2] == ':') &&
(h->subj[3] == ' '))
{
st = 4;
}
else
st = 0;
k1.subject = calcrc (&(h->subj[st]));
/* If it is in the data base, then don't toss it */
if (! ((areas[j]->flags & ROUTETHRU) ||
(areas[j]->flags & PASS_THRU) ||
(areas[j]->flags & BAD_MSGS)))
{
if (findkill (&k1))
{
printf ("DUPLICATE MESSAGE");
if (!delit)
(void) fast_close (f);
*ptr1 = old_char;
++msg_dups;
return (-2);
}
}
}
if (*(areas[j]->msgs_in_area) == -1)
{
/* Need to get high message number here */
/* First go to the proper directory */
(void) high_msg (areas[j]->msg_path, areas[j]->msgs_in_area, &foo);
printf ("Found %d messages in area %s\n",
*(areas[j]->msgs_in_area), areas[j]->area_name);
if (*areas[j]->msgs_in_area <= 0)
*areas[j]->msgs_in_area = 1;
}
/* Create new name */
sprintf (fname1, "%s\\%d.MSG", areas[j]->msg_path,
++*(areas[j]->msgs_in_area));
/*
strcpy (fname1, areas[j]->msg_path);
zz1 = &(fname1[zzl1]);
*zz1++ = '\\';
itoa (++*(areas[j]->msgs_in_area), zz1, 10);
strcat (zz1, ".MSG");
*/
#if DEBUG
printf ("I am really going '%s' -=> '%s'\n", fname, fname1);
#endif
if (delit)
printf ("MAIL PKT %s:MSG %d -=> %s:%d.MSG\n", fname, msg_num,
areas[j]->area_name, *(areas[j]->msgs_in_area));
else
printf ("MAIL:%d.MSG -=> %s:%d.MSG\n", msg_num,
areas[j]->area_name, *(areas[j]->msgs_in_area));
h->attr &= SAVED;
h->cost = 0;
if (*body == '\n')
++body;
body_count -= (body - holder);
body = body - sizeof (MSG);
memcpy (body, header, sizeof (MSG));
body_count += sizeof (MSG);
#if DEBUG
printf ("Got body containing %d characters\n", body_count);
#endif
/* Open file */
f1 = open (fname1, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE);
if (f1 == -1)
{
printf (open_err, fname1);
exit (2);
}
/* Write the header after clearing the proper bits */
if (write_body (f1, body, body_count, f) < body_count)
{
printf ("Didn't properly write the message body, aborting\n");
exit (2);
}
if (fast_close (f1) != 0)
{
printf ("Pretty strange, couldn't fast_close after write, aborting\n");
exit (2);
}
#if DEBUG
printf ("If I got here then I should have properly written the message\n");
#endif
if (!delit)
{
(void) fast_close (f);
unlink (fname);
}
}
tossed_some = 1;
++msgs_tossed;
return (0);
}