home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
VP2SRC.ZIP
/
FASTTOSS.C
< prev
next >
Wrap
Text File
|
1991-04-24
|
14KB
|
449 lines
/*
$Header: fasttoss.c 3.3 87/12/12 00:42:18 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: fasttoss.c $
* Revision 3.3 87/12/12 00:42:18 Bob
* Source code release
*
*/
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <io.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <process.h>
#include <malloc.h>
#include <sys\types.h>
#include <sys\stat.h>
#include "fastecho.h"
#define DEBUG 0
extern char *REV;
extern char *NAME;
extern SEACONFIG config;
extern AREAS_PTR areas[];
extern char board_name[], sysop_name[];
extern int tot_areas;
extern char bbsfile[];
extern char *arc_cmd[];
extern int nread;
extern int arc_args;
extern int last_msg;
extern int high_one;
extern int convert;
extern int dup_size;
extern struct tm *t2;
extern struct _stamp cur_stamp;
extern struct _stamp zero_stamp;
int *msg_nums;
extern int seen_aka;
int tossed_some = 0;
int to_file = 0;
int check_nodes = 0;
extern int bad_pw;
extern int bad_pkt;
extern int f_file;
extern char *_months[];
extern char tearline[];
extern int kill_null;
int no_matrix = 0;
int msgs_tossed;
int msg_dups;
extern PW_PTR pw[];
extern int num_pw;
extern char *noareasbbs;
extern int toss_net, toss_node;
void fasttoss (int argc,char *argv[])
{
int i;
long t1, t1a;
char buff1[20], buff2[20];
char junk[80];
FILE *outputfile;
char *link_file=NULL;
printf ("Importing Messages to Conference Mail System:\n\n");
sscanf (REV, "$%s %s", buff1, buff2);
sprintf (tearline, NAME, buff2);
dup_size = DUPSIZE;
if (get_sea_config (&config) != 0)
{
if (get_fido_config (&config) != 0)
{
exit (2);
}
}
if (argc > 1)
{
if ((argv[1][0] != '-') && (argv[1][0] != '/'))
{
strcpy (junk, argv[1]);
++argv;
--argc;
}
else
{
printf (noareasbbs);
strcpy (junk, "AREAS.BBS");
}
while ((argc > 1) && ((argv[1][0] == '-') || (argv[1][0] == '/')))
{
++argv;
--argc;
switch (argv[0][1])
{
case 'A':
case 'a':
arc_args = 0;
if (argc > 1)
{
while (--argc)
{
arc_cmd[arc_args++] = argv[1];
++argv;
}
}
break;
case 'D':
case 'd':
dup_size = atoi (argv[1]);
++argv;
--argc;
break;
case 'F':
case 'f':
to_file = 1;
link_file = argv[1];
++argv;
--argc;
break;
case 'K':
case 'k':
kill_null = 1;
break;
case 'M':
case 'm':
no_matrix = 1;
break;
case 'N':
case 'n':
convert = 1;
break;
case 'O':
case 'o':
convert = 2;
break;
case 'S':
case 's':
check_nodes = 1;
break;
default:
printf ("Don't understand '%s'\n", argv[0]);
ft_usage ();
exit (2);
}
}
if (argc > 1)
{
ft_usage ();
}
}
else
{
printf (noareasbbs);
strcpy (junk, "AREAS.BBS");
}
if (arc_args == 0)
{
#ifndef OS2
arc_args = 1;
if ((arc_cmd[0] = malloc (7)) == NULL)
#else
arc_args = 2;
if (((arc_cmd[0] = malloc (5)) == NULL) ||
((arc_cmd[1] = malloc (3)) == NULL))
#endif
{
printf ("Out of memory compiling ARC command - exiting\n");
exit (2);
}
#ifndef OS2
strcpy (arc_cmd[0], "PKXARC");
#else
strcpy (arc_cmd[0], "ARC2");
strcpy (arc_cmd[1], "EO");
#endif
}
if ((arc_cmd[arc_args] = malloc (80)) == NULL)
{
printf ("Out of memory compiling ARC command - exiting\n");
exit (2);
}
#if DEBUG
printf ("ARC command has %d arguments\n(", arc_args);
for (i = 0; i < arc_args; i++)
printf ("%s ", arc_cmd[i]);
printf (")\n");
#endif
if (compile_areas (junk) != 0)
{
printf ("Could not process AREAS file\n");
exit (2);
}
/* Set up the data for the current time stamp */
t1 = time(NULL);
t2 = localtime (&t1);
cur_stamp.date = ((t2->tm_year - 80)<<9) + ((t2->tm_mon+1)<<5) + t2->tm_mday;
cur_stamp.time = (t2->tm_hour<<11) + (t2->tm_min<<5) + (t2->tm_sec>>1);
msgs_tossed = 0;
/* First toss everything found in the netmail area */
(void) toss (config.mailpath);
/* Now get rid of any packets that might already be there */
toss_net = toss_node = 0; /* AK */
(void) tosspkt(".");
toss_net = toss_node = 0; /* AK */
(void) tosspkt(config.filepath);
/* Now toss ARCmail packets if there is an ARCMail command */
if (arc_args > 0)
{
arc_cmd[arc_args+1] = "*.PKT";
arc_cmd[arc_args+2] = NULL;
arc_e ();
free (arc_cmd[arc_args]);
}
if (to_file)
{
unlink (link_file);
for (i = 0; i < tot_areas; i++)
{
if (*(areas[i]->msgs_in_area) != -1)
{
break;
}
}
if (i < tot_areas)
{
if ((outputfile = fopen (link_file, "w")) == NULL)
{
printf ("Could not open output file name '%s' - exiting\n", link_file);
exit (2);
}
for (i = 0; i < tot_areas; i++)
{
if (*(areas[i]->msgs_in_area) != -1)
{
fprintf (outputfile, "%s\r\n", areas[i]->area_name);
}
}
fclose (outputfile);
}
}
if (bad_pkt)
bad_pkt_msg();
t1a = time(NULL);
t1a = t1a - t1;
printf ("\nImporting %d messages with %d dups took %02ld:", msgs_tossed, msg_dups, t1a/3600);
t1a = t1a%3600;
printf ("%02ld:", t1a/60);
t1a = t1a%60;
printf ("%02ld\n", t1a);
if (!f_file)
exit(tossed_some?1:0);
for (i = 0; i < tot_areas; i++)
{
free (areas[i]->msg_path);
free (areas[i]->area_name);
if (!(areas[i]->flags & SIBLING))
free ((char *) areas[i]->msgs_in_area);
free ((char *) areas[i]->net);
free ((char *) areas[i]->node);
free ((char *) areas[i]->handle);
free ((char *) areas[i]->aname);
free ((char *) areas[i]);
}
for (i = 0; i < num_pw; i++)
{
free (pw[i]->password);
free (pw[i]);
}
}
void ft_usage ()
{
#ifdef OS2
printf ("Usage: VP2 IMPORT file [-O/N] [-D dups] [-F filename] [-A arc_cmd]\n");
#else
printf ("Usage: VP IMPORT file [-O/N] [-D dups] [-F filename] [-A arc_cmd]\n");
#endif
#ifndef NOHELP
printf (" where file is the filename to use for AREAS.BBS\n");
printf (" -O/N means to either convert dates to old (FIDO)\n");
printf (" format, or to new (Opus) format. Default is to\n");
printf (" do no conversion on the date string as received.\n");
printf (" -D dups means to allow killing of duplicate messages\n");
printf (" based on the last 'dups' messages received in each area.\n");
printf (" -F filename means to output to 'filename' all of\n");
printf (" area names that had files imported to them.\n");
printf (" and where -A arc_cmd is the command to use for\n");
printf (" unpacking ARCmail packets (if desired). The command\n");
printf (" is taken as the entire command line beyond the -A\n");
printf ("\nExamples:\n");
#ifdef OS2
printf (" VP2 IMPORT -A PKUNZIP2\n");
printf (" VP2 IMPORT MYAREAS.BBS -A ARC2 EO\n");
#else
printf (" VP IMPORT -A PKXARC\n");
printf (" VP IMPORT MYAREAS.BBS -A ARC X\n");
#endif /* OS2 */
#endif /* NOHELP */
exit (2);
}
void bad_pkt_msg ()
{
int f;
char fname1[80];
char mess[100];
MSG m;
/* Open message 1 */
/* Create the message file name */
sprintf (fname1, "%s\\%d.MSG", config.mailpath, high_one+1);
memset ((char *) &m, 0, sizeof (MSG));
/* Open up new message file */
if ((f = open (fname1, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE)) == -1)
{
/* Could not even create it */
printf ("\nCould not create message about bad packet!\n");
return;
}
strcpy (m.from, &tearline[6]);
m.from[strlen(m.from)-2] = '\0';
strcpy (m.to, sysop_name);
strcpy (m.subj, "Bad Packet(s) Encountered");
m.dest = m.orig = config.node[1];
m.dest_net = m.orig_net = config.net[1];
m.attr = MSGPRIVATE|MSGLOCAL;
/* If it is Opus, then put in Opus format */
sprintf (m.date, "%02d %3.3s %02d %02d:%02d:%02d",
t2->tm_mday, _months[t2->tm_mon], t2->tm_year,
t2->tm_hour, t2->tm_min, t2->tm_sec);
m.date[4] = (char) tolower (m.date[4]);
m.date[5] = (char) tolower (m.date[5]);
if (convert == 1)
{
m.date[19] = 0xff;
m._date_written = m._date_arrived = cur_stamp;
}
else
{
m.date[19] = '\0';
m._date_written = m._date_arrived = zero_stamp;
}
(void) fast_write (f, (char *) &m, sizeof (MSG));
strcpy (mess, "This message is to inform you that there are one or more ");
(void) fast_write (f, mess, strlen(mess));
strcpy (mess, "bad packets (named *.BAD) in the directory ");
(void) fast_write (f, mess, strlen(mess));
strcpy (mess, "where the Conference Mail System runs. These were ");
(void) fast_write (f, mess, strlen(mess));
#ifdef OS2
strcpy (mess, "detected by the IMPORT section of VP2 during the run ");
#else
strcpy (mess, "detected by the IMPORT section of VP during the run ");
#endif
(void) fast_write (f, mess, strlen(mess));
strcpy (mess, "that took place at the time this message originated.\r\r");
(void) fast_write (f, mess, strlen(mess));
if (bad_pw)
{
strcpy (mess, "At least one of the packets had an invalid password in it!!!");
(void) fast_write (f, mess, strlen(mess));
}
(void) fast_write (f, "\r\n", 2);
(void) fast_write (f, tearline, strlen (tearline));
(void) fast_write (f, "\r\n", 2);
(void) fast_close (f);
}