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