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

  1. /*
  2.   $Header: fasttoss.c 3.3 87/12/12 00:42:18 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:    fasttoss.c $
  51.  * Revision 3.3  87/12/12  00:42:18  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 <math.h>
  62. #include <string.h>
  63. #include <stdlib.h>
  64. #include <process.h>
  65. #include <malloc.h>
  66. #include <sys\types.h>
  67. #include <sys\stat.h>
  68. #include "fastecho.h"
  69.  
  70. #define DEBUG 0
  71.  
  72. extern char *REV;
  73. extern char *NAME;
  74.  
  75. extern SEACONFIG config;
  76. extern AREAS_PTR areas[];
  77. extern char board_name[], sysop_name[];
  78. extern int tot_areas;
  79. extern char bbsfile[];
  80. extern char *arc_cmd[];
  81. extern int nread;
  82. extern int arc_args;
  83. extern int last_msg;
  84. extern int high_one;
  85. extern int convert;
  86. extern int dup_size;
  87. extern struct tm *t2;
  88. extern struct _stamp cur_stamp;
  89. extern struct _stamp zero_stamp;
  90. int *msg_nums;
  91. extern int seen_aka;
  92. int tossed_some = 0;
  93. int to_file = 0;
  94. int check_nodes = 0;
  95. extern int bad_pw;
  96. extern int bad_pkt;
  97. extern int f_file;
  98. extern char *_months[];
  99. extern char tearline[];
  100. extern int kill_null;
  101. int no_matrix = 0;
  102. int msgs_tossed;
  103. int msg_dups;
  104. extern PW_PTR pw[];
  105. extern int num_pw;
  106. extern char *noareasbbs;
  107. extern int toss_net, toss_node;
  108.  
  109. void fasttoss (int argc,char *argv[])
  110. {
  111.     int i;
  112.     long t1, t1a;
  113.     char buff1[20], buff2[20];
  114.     char junk[80];
  115.     FILE *outputfile;
  116.     char *link_file=NULL;
  117.  
  118.     printf ("Importing Messages to Conference Mail System:\n\n");
  119.  
  120.     sscanf (REV, "$%s %s", buff1, buff2);
  121.  
  122.     sprintf (tearline, NAME, buff2);
  123.  
  124.     dup_size = DUPSIZE;
  125.     if (get_sea_config (&config) != 0)
  126.         {
  127.         if (get_fido_config (&config) != 0)
  128.             {
  129.             exit (2);
  130.             }
  131.         }
  132.  
  133.     if (argc > 1)
  134.         {
  135.         if ((argv[1][0] != '-') && (argv[1][0] != '/'))
  136.             {
  137.             strcpy (junk, argv[1]);
  138.             ++argv;
  139.             --argc;
  140.             }
  141.         else
  142.             {
  143.             printf (noareasbbs);
  144.             strcpy (junk, "AREAS.BBS");
  145.             }
  146.         while ((argc > 1) && ((argv[1][0] == '-') || (argv[1][0] == '/')))
  147.             {
  148.             ++argv;
  149.             --argc;
  150.             switch (argv[0][1])
  151.                 {
  152.                 case 'A':
  153.                 case 'a':
  154.                     arc_args = 0;
  155.                     if (argc > 1)
  156.                         {
  157.                         while (--argc)
  158.                             {
  159.                             arc_cmd[arc_args++] = argv[1];
  160.                             ++argv;
  161.                             }
  162.                         }
  163.                     break;
  164.  
  165.                  case 'D':
  166.                  case 'd':
  167.                     dup_size = atoi (argv[1]);
  168.                     ++argv;
  169.                     --argc;
  170.                     break;
  171.  
  172.                  case 'F':
  173.                  case 'f':
  174.                     to_file = 1;
  175.                     link_file = argv[1];
  176.                     ++argv;
  177.                     --argc;
  178.                     break;
  179.  
  180.                  case 'K':
  181.                  case 'k':
  182.                     kill_null = 1;
  183.                     break;
  184.  
  185.                  case 'M':
  186.                  case 'm':
  187.                     no_matrix = 1;
  188.                     break;
  189.  
  190.                  case 'N':
  191.                  case 'n':
  192.                     convert = 1;
  193.                     break;
  194.  
  195.                  case 'O':
  196.                  case 'o':
  197.                     convert = 2;
  198.                     break;
  199.  
  200.                  case 'S':
  201.                  case 's':
  202.                     check_nodes = 1;
  203.                     break;
  204.  
  205.                 default:
  206.                     printf ("Don't understand '%s'\n", argv[0]);
  207.                     ft_usage ();
  208.                     exit (2);
  209.                 }
  210.             }
  211.         if (argc > 1)
  212.             {
  213.             ft_usage ();
  214.             }
  215.         }
  216.     else
  217.         {
  218.         printf (noareasbbs);
  219.         strcpy (junk, "AREAS.BBS");
  220.         }
  221.  
  222.  
  223.     if (arc_args == 0)
  224.         {
  225. #ifndef OS2
  226.         arc_args = 1;
  227.         if ((arc_cmd[0] = malloc (7)) == NULL)
  228. #else
  229.         arc_args = 2;
  230.         if (((arc_cmd[0] = malloc (5)) == NULL) ||
  231.             ((arc_cmd[1] = malloc (3)) == NULL))
  232. #endif
  233.             {
  234.             printf ("Out of memory compiling ARC command - exiting\n");
  235.             exit (2);
  236.             }
  237. #ifndef OS2
  238.         strcpy (arc_cmd[0], "PKXARC");
  239. #else
  240.         strcpy (arc_cmd[0], "ARC2");
  241.         strcpy (arc_cmd[1], "EO");
  242. #endif
  243.         }
  244.     if ((arc_cmd[arc_args] = malloc (80)) == NULL)
  245.         {
  246.         printf ("Out of memory compiling ARC command - exiting\n");
  247.         exit (2);
  248.         }
  249.  
  250. #if DEBUG
  251.     printf ("ARC command has %d arguments\n(", arc_args);
  252.     for (i = 0; i < arc_args; i++)
  253.         printf ("%s ", arc_cmd[i]);
  254.     printf (")\n");
  255. #endif
  256.  
  257.     if (compile_areas (junk) != 0)
  258.         {
  259.         printf ("Could not process AREAS file\n");
  260.         exit (2);
  261.         }
  262.     /* Set up the data for the current time stamp */
  263.     t1 = time(NULL);
  264.     t2 = localtime (&t1);
  265.     cur_stamp.date = ((t2->tm_year - 80)<<9) + ((t2->tm_mon+1)<<5) + t2->tm_mday;
  266.     cur_stamp.time = (t2->tm_hour<<11) + (t2->tm_min<<5) + (t2->tm_sec>>1);
  267.     msgs_tossed = 0;
  268.  
  269.     /* First toss everything found in the netmail area */
  270.     (void) toss (config.mailpath);
  271.  
  272.     /* Now get rid of any packets that might already be there */
  273.     toss_net = toss_node = 0;                               /* AK */
  274.     (void) tosspkt(".");
  275.     toss_net = toss_node = 0;                               /* AK */
  276.     (void) tosspkt(config.filepath);
  277.  
  278.     /* Now toss ARCmail packets if there is an ARCMail command */
  279.     if (arc_args > 0)
  280.         {
  281.         arc_cmd[arc_args+1] = "*.PKT";
  282.         arc_cmd[arc_args+2] = NULL;
  283.         arc_e ();
  284.         free (arc_cmd[arc_args]);
  285.         }
  286.  
  287.     if (to_file)
  288.     {
  289.         unlink (link_file);
  290.         for (i = 0; i < tot_areas; i++)
  291.         {
  292.             if (*(areas[i]->msgs_in_area) != -1)
  293.             {
  294.                 break;
  295.             }
  296.         }
  297.         if (i < tot_areas)
  298.         {
  299.             if ((outputfile = fopen (link_file, "w")) == NULL)
  300.             {
  301.                printf ("Could not open output file name '%s' - exiting\n", link_file);
  302.                exit (2);
  303.             }
  304.             for (i = 0; i < tot_areas; i++)
  305.             {
  306.                if (*(areas[i]->msgs_in_area) != -1)
  307.                {
  308.                    fprintf (outputfile, "%s\r\n", areas[i]->area_name);
  309.                }
  310.             }
  311.             fclose (outputfile);
  312.         }
  313.     }
  314.  
  315.     if (bad_pkt)
  316.         bad_pkt_msg();
  317.  
  318.     t1a = time(NULL);
  319.     t1a = t1a - t1;
  320.     printf ("\nImporting %d messages with %d dups took %02ld:", msgs_tossed, msg_dups, t1a/3600);
  321.     t1a = t1a%3600;
  322.     printf ("%02ld:", t1a/60);
  323.     t1a = t1a%60;
  324.     printf ("%02ld\n", t1a);
  325.  
  326.     if (!f_file)
  327.         exit(tossed_some?1:0);
  328.  
  329.     for (i = 0; i < tot_areas; i++)
  330.       {
  331.       free (areas[i]->msg_path);
  332.       free (areas[i]->area_name);
  333.       if (!(areas[i]->flags & SIBLING))
  334.          free ((char *) areas[i]->msgs_in_area);
  335.       free ((char *) areas[i]->net);
  336.       free ((char *) areas[i]->node);
  337.       free ((char *) areas[i]->handle);
  338.       free ((char *) areas[i]->aname);
  339.       free ((char *) areas[i]);
  340.       }
  341.    for (i = 0; i < num_pw; i++)
  342.       {
  343.       free (pw[i]->password);
  344.       free (pw[i]);
  345.       }
  346.     }
  347.  
  348. void ft_usage ()
  349. {
  350. #ifdef OS2
  351.     printf ("Usage: VP2 IMPORT file [-O/N] [-D dups] [-F filename] [-A arc_cmd]\n");
  352. #else
  353.     printf ("Usage: VP IMPORT file [-O/N] [-D dups] [-F filename] [-A arc_cmd]\n");
  354. #endif
  355. #ifndef NOHELP
  356.     printf ("       where file is the filename to use for AREAS.BBS\n");
  357.     printf ("       -O/N means to either convert dates to old (FIDO)\n");
  358.     printf ("       format, or to new (Opus) format.  Default is to\n");
  359.     printf ("       do no conversion on the date string as received.\n");
  360.     printf ("       -D dups means to allow killing of duplicate messages\n");
  361.     printf ("       based on the last 'dups' messages received in each area.\n");
  362.     printf ("       -F filename means to output to 'filename' all of\n");
  363.     printf ("       area names that had files imported to them.\n");
  364.     printf ("       and where -A arc_cmd is the command to use for\n");
  365.     printf ("       unpacking ARCmail packets (if desired).  The command\n");
  366.     printf ("       is taken as the entire command line beyond the -A\n");
  367.     printf ("\nExamples:\n");
  368. #ifdef OS2
  369.     printf ("       VP2 IMPORT -A PKUNZIP2\n");
  370.     printf ("       VP2 IMPORT MYAREAS.BBS -A ARC2 EO\n");
  371. #else
  372.     printf ("       VP IMPORT -A PKXARC\n");
  373.     printf ("       VP IMPORT MYAREAS.BBS -A ARC X\n");
  374. #endif /* OS2 */
  375. #endif /* NOHELP */
  376.     exit (2);
  377.     }
  378.  
  379. void bad_pkt_msg ()
  380. {
  381.     int f;
  382.     char fname1[80];
  383.     char mess[100];
  384.     MSG m;
  385.  
  386.     /* Open message 1 */
  387.     /* Create the message file name */
  388.     sprintf (fname1, "%s\\%d.MSG", config.mailpath, high_one+1);
  389.  
  390.    memset ((char *) &m, 0, sizeof (MSG));
  391.     /* Open up new message file */
  392.     if ((f = open (fname1, O_WRONLY|O_CREAT|O_BINARY, S_IREAD|S_IWRITE)) == -1)
  393.         {
  394.         /* Could not even create it */
  395.         printf ("\nCould not create message about bad packet!\n");
  396.         return;
  397.         }
  398.  
  399.     strcpy (m.from, &tearline[6]);
  400.     m.from[strlen(m.from)-2] = '\0';
  401.     strcpy (m.to, sysop_name);
  402.     strcpy (m.subj, "Bad Packet(s) Encountered");
  403.     m.dest     = m.orig     = config.node[1];
  404.     m.dest_net = m.orig_net = config.net[1];
  405.     m.attr = MSGPRIVATE|MSGLOCAL;
  406.    /* If it is Opus, then put in Opus format */
  407.     sprintf (m.date, "%02d %3.3s %02d %02d:%02d:%02d",
  408.         t2->tm_mday, _months[t2->tm_mon], t2->tm_year,
  409.         t2->tm_hour, t2->tm_min, t2->tm_sec);
  410.     m.date[4] = (char) tolower (m.date[4]);
  411.     m.date[5] = (char) tolower (m.date[5]);
  412.    if (convert == 1)
  413.       {
  414.        m.date[19] = 0xff;
  415.       m._date_written = m._date_arrived = cur_stamp;
  416.       }
  417.    else
  418.       {
  419.       m.date[19] = '\0';
  420.       m._date_written = m._date_arrived = zero_stamp;
  421.       }
  422.  
  423.     (void) fast_write (f, (char *) &m, sizeof (MSG));
  424.     strcpy (mess, "This message is to inform you that there are one or more ");
  425.     (void) fast_write (f, mess, strlen(mess));
  426.     strcpy (mess, "bad packets (named *.BAD) in the directory ");
  427.     (void) fast_write (f, mess, strlen(mess));
  428.     strcpy (mess, "where the Conference Mail System runs.  These were ");
  429.     (void) fast_write (f, mess, strlen(mess));
  430. #ifdef OS2
  431.     strcpy (mess, "detected by the IMPORT section of VP2 during the run ");
  432. #else
  433.     strcpy (mess, "detected by the IMPORT section of VP during the run ");
  434. #endif
  435.     (void) fast_write (f, mess, strlen(mess));
  436.     strcpy (mess, "that took place at the time this message originated.\r\r");
  437.     (void) fast_write (f, mess, strlen(mess));
  438.    if (bad_pw)
  439.       {
  440.       strcpy (mess, "At least one of the packets had an invalid password in it!!!");
  441.         (void) fast_write (f, mess, strlen(mess));
  442.       }
  443.     (void) fast_write (f, "\r\n", 2);
  444.    (void) fast_write (f, tearline, strlen (tearline));
  445.     (void) fast_write (f, "\r\n", 2);
  446.     (void) fast_close (f);
  447.     }
  448.  
  449.