home *** CD-ROM | disk | FTP | other *** search
/ The Arcade BBS / arcadebbs.zip / arcadebbs / bbstools / FIDO / NETS200.ZIP / NETS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-21  |  57.0 KB  |  1,644 lines

  1. /*******************************************************************/
  2. /* This software was written by Matt Logan over nearly a year for  */
  3. /* the WWIVnet/Fidonet community.  This software may be freely     */
  4. /* modified and re-compiled.  Modified source must accompanied by  */
  5. /* the original source if it is made availiable on any public BBS. */
  6. /* Modified versions on the binaries may not be posted on any      */
  7. /* public BBS.  All documenation, source, and executables must be  */
  8. /* included in any distribution of this software.  All Copyright   */
  9. /* notices must be left intact in the source and included          */
  10. /* documentation files.                                            */
  11. /*                                                                 */
  12. /* The intent here is to provide the WWIV/FIDONET community with   */
  13. /* reliable access to the lastest versions of this software.  I    */
  14. /* would ask that any modifications that prove to be very useful   */
  15. /* be made availiable to me so that I may include them in future   */
  16. /* releases of this software.  This software may not be sold for   */
  17. /* profit for any reason.  I intend to keep NetSEX a Public Domain */
  18. /* utility FOREVER.                                                */
  19. /*                                                                 */
  20. /*                                                                 */
  21. /* Addresses:                                                      */
  22. /*              USENET:  matt@eecs.cs.pdx.edu                      */
  23. /*             WWIVNET:  1@5317                                    */
  24. /*                                                                 */
  25. /*             US MAIL:  Matt Logan                                */
  26. /*                       11790 S.W. Denney Rd.                     */
  27. /*                       Beaverton Oregon 97005                    */
  28. /*                                                                 */
  29. /*                                                                 */
  30. /* Contributions are welcome and will most likely be applied to my */
  31. /* tuition payments for my last year in college as a Physics/Music */
  32. /* major at Portland State University.                             */
  33. /*                                                       06/14/90  */
  34. /*******************************************************************/
  35.  
  36.  
  37.  
  38. /* NETS.c                                                           */
  39. /*                                                                  */
  40. /*    Converts FIDO packets into WWIV packets and vice versa.       */
  41. /*                                                                  */
  42. /*                                                                  */
  43. /* REVISION HISTORY:                                                */
  44. /*                                                                  */
  45. /*    Matt Logan - 09/25/89 Initial version.                        */
  46. /*                                                                  */
  47. /*    Matt Logan - 11/10/89 Added Aliases, Local and Sub Commands.  */
  48. /*                                                                  */
  49. /*    Matt Logan - 11/17/89 Processed fido messages get bit 10 in   */
  50. /*                          the Attribute field set instead of      */
  51. /*                          being deleted.                          */
  52. /*                                                                  */
  53. /*    Matt Logan - 01/05/90 A whole Lotta stuff fixed, optimized    */
  54. /*                          added. Points, OUT_ALIAS.               */
  55. /*                                                                  */
  56. /*    Matt Logan - 02/11/90 Version 0.89 a ^AWWIVGATE: line is now  */
  57. /*                          used to mark messages as processed.  A  */
  58. /*                          few more bugs have been fixed.          */
  59. /*                          P<N>.NET Files are now created instead  */
  60. /*                          of being appended (Dangerous) and the   */
  61. /*                          limit on the number of BBS's has been   */
  62. /*                          removed.                                */
  63. /*    J. Garzik, - 09/06/91 Version 2.00.  First "legal" gateway    */
  64. /*    J. Rybacek,           version.  Many code changes.  See       */
  65. /*    P. Tremblay           README.200 for all the changes.         */
  66.  
  67.  
  68. #include <stdio.h>
  69. #include <stdlib.h>
  70. #include <alloc.h>
  71. #include <sys/stat.h>
  72. #include <dos.h>
  73. #include <dir.h>
  74. #include <time.h>
  75. #include <fcntl.h>
  76. #include <string.h>
  77. #include "NET.H"
  78. #include "NETS.H"
  79. #include "NETSFUNC.H"
  80.  
  81.  
  82. int TextLog;                                     /* v2.00 */
  83. unsigned int *system_index;                      /* v2.00 */
  84. unsigned int syscount;                           /* v2.00 */
  85. struct date datep;
  86. struct time timep;
  87. short sub_list[50];
  88. unsigned int sub_type, host_system;
  89. long list_len, Log_Count, Ltime;
  90. log_entry *Ldata;
  91. char Log_Update;
  92. FILE *Net, *Sub, *Log;
  93. char Path[81];                                   /* v2.00 */
  94. char MailDir[81];                                /* v2.00 */
  95. char Search[81];                                 /* v2.00 */
  96. char Number[10];
  97. unsigned short MyNode, LocalNode;
  98. int FidoNet, FidoNode, FidoZone;
  99. char Buffer[300];                                /* v2.00 */
  100. char Banner[81];                                 /* v2.00 */
  101. char wwivpath[81];                               /* v2.00 */
  102. char *MBuf;
  103. long MLength;
  104. net_header_rec header;
  105. struct Alias *Alias;
  106. int NumAlias;
  107. int LineCount;
  108. char area[40], bd_flag, export_flag;
  109. int destNet, destNode;
  110. char tname[81];                                  /* v2.00 */
  111. int Point, ToPoint, Zone, FNet, FNode;
  112. unsigned short CNode, WWIVgate;
  113. char NetString[11];
  114. char s[160];                                     /* v2.00 */
  115. char logdir[81];                                 /* v2.00 */
  116. unsigned char kill_after_process, debug;         /* v2.00 */
  117.  
  118. void main(argc, argv)
  119.   int argc;
  120.   char **argv;
  121. {
  122.   long clock1, clock2;
  123.  
  124.   time(&clock1);
  125.   printf("NetSEX! Version %s Copyright Matt Logan 1989, 1990\n", Version);
  126.   printf("%s\n", ctime(&clock1));
  127.   NetString[0] = 0;
  128.   TextLog = -1;                                  /* v2.00 */
  129.   CNode = 0;
  130.   kill_after_process = 0;
  131.   debug = 0;
  132.   Alloc();
  133.   if (argc == 2 || (argc == 3 && strcmpi(argv[2], "/WF") == 0)) {
  134.     printf("Running Import then Export\n");
  135.     Load_Log(argv[1]);
  136.     Import(argv);
  137.     Export(argv);
  138.   } else if (argc == 3 && strcmpi(argv[2], "/FW") == 0) {
  139.     printf("Running Export then Import\n");
  140.     Load_Log(argv[1]);
  141.     Export(argv);
  142.     Import(argv);
  143.   } else if (argc == 3 && strcmpi(argv[2], "/W") == 0) {
  144.     printf("Running Import only\n");
  145.     Load_Log(argv[1]);
  146.     Import(argv);
  147.   } else if (argc == 3 && strcmpi(argv[2], "/F") == 0) {
  148.     printf("Running Export only\n");
  149.     Load_Log(argv[1]);
  150.     Export(argv);
  151.   } else {
  152.     printf("Usage: %s <DATAPATH> [/FW]\n", argv[0]);
  153.     Free();
  154.     exit(0);
  155.   }
  156.   Save_Log(argv[1]);
  157.   Free();
  158.   time(&clock2);
  159.   sprintf(s, "Total time: %ld Seconds",          /* v2.00 */
  160.           clock2 - clock1);                      /* v2.00 */
  161.   if (TextLog != -1) {                           /* v2.00 */
  162.     TextLogEntry("");                            /* v2.00 */
  163.     TextLogEntry(s);                             /* v2.00 */
  164.     TextLogEntry("");                            /* v2.00 */
  165.   }                                              /* v2.00 */
  166.   puts("");
  167.   puts(s);                                       /* v2.00 */
  168. }
  169.  
  170. void Alloc()                                     /* v2.00 */
  171. {
  172.   MBuf = (char *) malloc(33000);
  173.   if (MBuf == NULL) {
  174.     printf("Can't allocate Memory");
  175.     exit(-1);
  176.   }
  177. }
  178.  
  179. void Free()                                      /* v2.00 */
  180. {
  181.   free(MBuf);
  182.   free(Alias);
  183. }
  184.  
  185. void Import(argv)
  186.   char **argv;
  187. {
  188.  
  189.   long msg_cnt, byte_cnt;
  190.   FILE *fd1, *fd2;
  191.   int x, y, z, no_end;
  192.   long Position;
  193.   unsigned char c;
  194.   unsigned short syst;
  195.   char Subject[80];
  196.   char ToUser[37];
  197.   char Name[80];
  198.   char AName[80];
  199.   char Date[80];
  200.   struct ffblk ffblk;
  201.   int done;
  202.   int MailFlag;
  203.   unsigned char print_flag;
  204.   char *B2;
  205.  
  206.   printf("\n\nImporting...\n");
  207.   strcpy(wwivpath, argv[1]);
  208.   if (wwivpath[strlen(wwivpath) - 1] == '\\')    /* v2.00 */
  209.     wwivpath[strlen(wwivpath) - 1] = 0;          /* v2.00 */
  210.   if (wwivpath[strlen(wwivpath) - 1] == '/')     /* v2.00 */
  211.     wwivpath[strlen(wwivpath) - 1] = 0;          /* v2.00 */
  212.   fd2 = NULL;                                    /* v2.00 */
  213.   export_flag = 0;
  214.   MailDir[0] = 0;
  215.   LocalNode = 0;
  216.   NumAlias = 0;
  217.   LineCount = 0;
  218.   Banner[0] = 0;
  219.   sprintf(Buffer, "%s/FIDO.NET", wwivpath);
  220.   Net = fopen(Buffer, "rt");
  221.   if (Net == NULL) {
  222.     printf("Can't Find %s\n", Buffer);
  223.     exit(-1);
  224.   }
  225.   x = 0;
  226.   do {
  227.     if (fd2 != NULL)                                       /* v2.00 */
  228.       fclose(fd2);                                         /* v2.00 */
  229.     x++;
  230.     sprintf(Buffer, "%s/P%d.NET", wwivpath, x);
  231.     fd2 = fopen(Buffer, "rb");
  232.   } while ((fd2 != NULL) && (x < 32767));                  /* v2.00 */
  233.   if (fd2 != NULL) {                                       /* v2.00 */
  234.     printf("Error,  couldn't open a P*.NET FILE\n");       /* v2.00 */
  235.     fclose(fd2);                                           /* v2.00 */
  236.     exit(1);                                               /* v2.00 */
  237.   }                                                        /* v2.00 */
  238.   while (NextEnt() == 0) {
  239.     sprintf(Search, "%s/*.MSG", Path);
  240.     msg_cnt = 0;
  241.     byte_cnt = 0;
  242.     print_flag = 0;
  243.     done = findfirst(Search, &ffblk, 0);
  244.     while (!done) {
  245.       sprintf(Search, "%s/%s", Path, ffblk.ff_name);
  246.       fd1 = fopen(Search, "r+b");
  247.       if (fd1 == NULL) {
  248.         printf("Error opening file %s\n", Search);
  249.         exit(-1);
  250.       }
  251.       /* Find out if this message has already been processed */
  252.       fseek(fd1, 0, 0);
  253.       fread(AName, 36, 1, fd1);
  254.       fread(tname, 36, 1, fd1);
  255.       fseek(fd1, 166, 0);
  256.       fread(&destNode, 2, 1, fd1);
  257.       fseek(fd1, 174, 0);
  258.       fread(&destNet, 2, 1, fd1);
  259.  
  260.       /* If it hasn't been processed,  process it! */
  261.       if (strncmp(AName, "QMail", 5) != 0 && (ffblk.ff_fsize < 28000)) {
  262.         msg_cnt++;
  263.         gettime(&timep);
  264.         getdate(&datep);
  265.         header.tosys = host_system;
  266.         header.touser = 0;
  267.         header.fromsys = MyNode;
  268.         header.fromuser = 0;
  269.         header.main_type = main_type_pre_post;
  270.         header.minor_type = sub_type;
  271.         header.list_len = list_len;
  272.         header.daten = dostounix(&datep, &timep);
  273.         header.method = 0;
  274.         header.length = 0;
  275.  
  276.         /* This loop reads the header and gets some info from it */
  277.  
  278.         /* This is only used if running mail */
  279.         fseek(fd1, 36, 0);
  280.         fread(ToUser, 36, 1, fd1);
  281.  
  282.         fread(Subject, 72, 1, fd1);
  283.         fread(Date, 20, 1, fd1);
  284.  
  285.         /* Put the proper Fido Net/Node number in the name */
  286.         fseek(fd1, 168, 0);
  287.         fread(&FNode, 2, 1, fd1);
  288.         fseek(fd1, 172, 0);
  289.         fread(&FNet, 2, 1, fd1);
  290.         fseek(fd1, 190, 0);
  291.  
  292.         Zone = FidoZone;
  293.         Point = 0;
  294.         ToPoint = 0;
  295.         WWIVgate = 0;
  296.         header.length = MLength = ProcMess(fd1);
  297. /*        if (debug) {
  298.           printf("fidonet %d\n", (int)FidoNet);
  299.           printf("Fidonode %d\n", (int)FidoNode);
  300.           printf("destnet %d\n", (int)destNet);
  301.           printf("destnode %d\n", (int)destNode);
  302.           printf("FNode %d\n", (int)FNode);
  303.           printf("FNet %d\n", (int)FNet);
  304.           printf(" What? %d\n", (int)~(22 == 2 && 1 == 1));
  305.         }                                                   */
  306.         if (((destNet == FidoNet && destNode == FidoNode
  307.               && ToPoint == 0) || sub_type != 0)
  308.             && WWIVgate != LocalNode) {
  309.           fseek(fd1, 0, 2L);
  310.           x = ftell(fd1) - sizeof(struct MessageHdr);
  311.           B2 = malloc(x);
  312.           if (B2 == NULL) {                                /* v2.00 */
  313.             printf("Error, not enough memory\n");
  314.             exit(-1);
  315.           }
  316.           fseek(fd1, sizeof(struct MessageHdr), 0L);
  317.           fread(B2, x, 1, fd1);
  318.           fseek(fd1, sizeof(struct MessageHdr), 0L);
  319.           fprintf(fd1, "%cWWIVGATE: %d%c%c",
  320.                   1, LocalNode, 13, 10);
  321.           fwrite(B2, x, 1, fd1);
  322.           free(B2);
  323.           if (Point == 0 && Zone == FidoZone) {            /* v2.00 */
  324.             sprintf(Name, "%s OF %d/%d", AName,            /* v2.00 */
  325.                           FNet, FNode);                    /* v2.00 */
  326.           } else if (Point != 0 && Zone == FidoZone) {     /* v2.00 */
  327.             sprintf(Name, "%s OF %d/%d.%d", AName, FNet,   /* v2.00 */
  328.                           FNode, Point);                   /* v2.00 */
  329.           } else if (Point == 0 && Zone != FidoZone) {     /* v2.00 */
  330.             sprintf(Name, "%s OF %d:%d/%d", AName, Zone,   /* v2.00 */
  331.                           FNet, FNode);                    /* v2.00 */
  332.           } else {                                         /* v2.00 */
  333.             sprintf(Name, "%s OF %d:%d/%d.%d", AName,      /* v2.00 */
  334.                           Zone, FNet, FNode, Point);       /* v2.00 */
  335.           }                                                /* v2.00 */
  336.           byte_cnt += header.length;
  337.           if (print_flag == 0) {
  338.             if (sub_type == 0) {
  339.               sprintf(s, "Mail:");               /* v2.00 */
  340.               TextLogEntry(s);                   /* v2.00 */
  341.               puts(s);                           /* v2.00 */
  342.             } else {
  343.               sprintf(s, "Sub %ld:",             /* v2.00 */
  344.                       (long) sub_type);          /* v2.00 */
  345.               TextLogEntry(s);                   /* v2.00 */
  346.               puts(s);                           /* v2.00 */
  347.             }
  348.                                                  /* v2.00 */
  349.             sprintf(s, "Date       Time     %-5s %-13.13s %s", "Size", "To", "From");
  350.             TextLogEntry(s);                     /* v2.00 */
  351.             puts(s);                             /* v2.00 */
  352.                                                  /* v2.00 */
  353.             sprintf(s, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  354.             TextLogEntry(s);                     /* v2.00 */
  355.             puts(s);                             /* v2.00 */
  356.             print_flag = 1;
  357.           }
  358.           sprintf(s, "%19.19s %5ld %-13.13s %s", /* v2.00 */
  359.                     Date,                        /* v2.00 */
  360.                     (long) header.length, ToUser,/* v2.00 */
  361.                      Name);                      /* v2.00 */
  362.           TextLogEntry(s);                       /* v2.00 */
  363.           puts(s);                               /* v2.00 */
  364.           header.length += (strlen(Subject) + 1) + (strlen(Name) + 2) +
  365.                            (strlen(Date) + 2);
  366.           if (sub_type == 0)
  367.             MailFlag = ParseName(ToUser);
  368.           if (Banner[0] != 0)
  369.             header.length += (strlen(Banner));
  370.           /* Write Header */
  371.           if (fd2 == NULL)
  372.             fd2 = fopen(Buffer, "w+b");
  373.           fwrite(&header, sizeof(header), 1, fd2);
  374.           if (sub_type == 0 && MailFlag == 1) {
  375.             fwrite(ToUser, strlen(ToUser), 1, fd2);
  376.             c = 0;
  377.             fwrite(&c, 1, 1, fd2);
  378.           }
  379.           /* Write Title, Name and Date */
  380.           fwrite(Subject, strlen(Subject), 1, fd2);
  381.           c = 0;
  382.           fwrite(&c, 1, 1, fd2);
  383.           fwrite(Name, strlen(Name), 1, fd2);
  384.           c = 13;
  385.           fwrite(&c, 1, 1, fd2);
  386.           c = 10;
  387.           fwrite(&c, 1, 1, fd2);
  388.           fwrite(Date, strlen(Date), 1, fd2);
  389.           c = 13;
  390.           fwrite(&c, 1, 1, fd2);
  391.           c = 10;
  392.           fwrite(&c, 1, 1, fd2);
  393.           /* Write Body of text */
  394.           fwrite(MBuf, MLength, 1, fd2);
  395.           /* Write Banner if there is one */
  396.           if (Banner[0] != 0) {
  397.             fwrite(Banner, strlen(Banner), 1, fd2);
  398.           }
  399.         }
  400.       }
  401.       fclose(fd1);
  402.       if (kill_after_process)                              /* v2.00 */
  403.         unlink(Search);                                    /* v2.00 */
  404.       done = findnext(&ffblk);
  405.     }
  406.     if (print_flag != 0) {
  407.                                                  /* v2.00 */
  408.       sprintf(s, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  409.       TextLogEntry(s);                           /* v2.00 */
  410.       puts(s);                                   /* v2.00 */
  411.                                                  /* v2.00 */
  412.       sprintf(s, "%ld Messages, %ld Bytes\r\n", msg_cnt, byte_cnt);
  413.       TextLogEntry(s);                           /* v2.00 */
  414.       puts(s);                                   /* v2.00 */
  415.       for (x = 0; x != Log_Count; x++) {
  416.         if (strcmp(area, Ldata[x].name) == 0)
  417.           break;
  418.       }
  419.       if (x == Log_Count) {
  420.         Log_Count++;
  421.         if (Ldata == NULL) {
  422.           Ldata = (log_entry *) malloc(sizeof(log_entry));
  423.         } else {
  424.           Ldata = (log_entry *) realloc(Ldata, Log_Count * sizeof(log_entry));
  425.         }
  426.         if (Ldata != NULL) {                               /* v2.00 */
  427.           for (y = 0; y != 40; y++)
  428.             Ldata[x].name[y] = 0;
  429.           strcpy(Ldata[x].name, area);
  430.           Ldata[x].sub_type = sub_type;
  431.           Ldata[x].host = host_system;
  432.           Ldata[x].in_messages = 0;
  433.           Ldata[x].out_messages = 0;
  434.           Ldata[x].in_bytes = 0;
  435.           Ldata[x].out_bytes = 0;
  436.         }                                                  /* v2.00 */
  437.       }
  438.       if (Ldata != NULL) {                                 /* v2.00 */
  439.         Ldata[x].in_messages += msg_cnt;
  440.         Ldata[x].in_bytes += byte_cnt;
  441.       }                                                    /* v2.00 */
  442.     }
  443.   }
  444.   fclose(fd2);
  445.   fclose(Net);
  446. }
  447.  
  448. void GetSystemInfo(sysnum, sysdata)              /* v2.00 */
  449.   unsigned int sysnum;
  450.   Stats *sysdata;
  451. {
  452.   int x, y;
  453.   FILE *tempfile;
  454.   net_system_list_rec nslr;
  455.   char s1[81];
  456.   Stats sysdat;
  457.  
  458.   sysdat = *sysdata;
  459.   sysdat.sysnum = 0;
  460.   sysdat.phone[0] = 0;
  461.   sysdat.name[0] = 0;
  462.   for (x = 0; x < syscount; x++)
  463.     if (system_index[x] == sysnum)
  464.       break;
  465.   if (x < syscount) {
  466.     sprintf(s1, "%s/BBSDATA.NET", wwivpath);
  467.     tempfile = fopen(s1, "rb");
  468.     if (tempfile == NULL) {
  469.       printf("Can't find %s\n", s1);
  470.       exit(-1);
  471.     }
  472.     fseek(tempfile, (long)(x) * sizeof(net_system_list_rec), SEEK_SET);
  473.     fread((void *)(&nslr), sizeof(net_system_list_rec), 1, tempfile);
  474.     fclose(tempfile);
  475.     sysdat.sysnum = sysnum;
  476.     strcpy(sysdat.phone, nslr.phone);
  477.     strcpy(sysdat.name, nslr.name);
  478.   }
  479.   *sysdata = sysdat;
  480. }
  481.  
  482. void ReadBBSIndex()                              /* v2.00 */
  483. {
  484.   char s1[161];
  485.   int f;
  486.   long l;
  487.  
  488.   syscount = 0;
  489.   sprintf(s1, "%s\\BBSDATA.IND", wwivpath);
  490.   f = open(s1, O_RDWR | O_BINARY);
  491.   if (f < 0) {
  492.     printf("could not find file.\n");
  493.     exit(1);
  494.   }
  495.   l = filelength(f);
  496.   syscount = (int)(l/2);
  497.   system_index = (unsigned int *) malloc(syscount * 2);
  498.   if (system_index == NULL)
  499.     exit(1);
  500.   read(f, (void *)system_index, l);
  501.   close(f);
  502. }
  503.  
  504. void Export(argv)
  505.   char **argv;
  506. {
  507.   long msg_cnt, byte_cnt;
  508.   FILE *fd1, *fd2;
  509.   int x, y, z, no_end;
  510.   long Position;
  511.   unsigned char c;
  512.   unsigned short syst;
  513.   char Subject[80];
  514.   char ToUser[37];
  515.   char Name[80];
  516.   char Date[80];
  517.   struct ffblk ffblk;
  518.   int done;
  519.   int MailFlag;
  520.   unsigned short Attribute;
  521.   int max_msg;
  522.   long fpos1, fpos2;
  523.   unsigned short didit = 65535;
  524.   struct MessageHdr Fmessage;
  525.   unsigned char print_flag;
  526.   Stats static_stat;                             /* v2.00 */
  527.   unsigned int last_system_checked;              /* v2.00 */
  528.  
  529.   last_system_checked = 0;                       /* v2.00 */
  530.   export_flag = 1;
  531.   sprintf(&Fmessage.fill[0], "NETSEX");
  532.   printf("Exporting...\n");
  533.   strcpy(wwivpath, argv[1]);
  534.   if (wwivpath[strlen(wwivpath) - 1] == '\\')    /* v2.00 */
  535.     wwivpath[strlen(wwivpath) - 1] = 0;          /* v2.00 */
  536.   if (wwivpath[strlen(wwivpath) - 1] == '/')     /* v2.00 */
  537.     wwivpath[strlen(wwivpath) - 1] = 0;          /* v2.00 */
  538.   printf("Loading bbsdata index...");
  539.   ReadBBSIndex();
  540.   printf("Done.  %d Systems.\n", syscount);
  541.   MailDir[0] = 0;
  542.   LocalNode = 0;
  543.   NumAlias = 0;
  544.   LineCount = 0;
  545.   /* Set Banner to null for now */
  546.   Banner[0] = 0;
  547.   if (debug)
  548.     printf("Initialized variables\n");
  549.   sprintf(Buffer, "%s/FIDO.NET", wwivpath);
  550.   Net = fopen(Buffer, "rt");
  551.   if (Net == NULL) {
  552.     printf("Can't Find %s\n", Buffer);
  553.     exit(-1);
  554.   }
  555.   while (NextEnt() == 0) {
  556.     /* This Section of code finds the WWIV messages and converts them       */
  557.     /* into FIDO messages                                              */
  558.  
  559.     print_flag = 0;
  560.     if (bd_flag == 1) {
  561.       sprintf(Search, "%s/*.MSG", Path);
  562.       max_msg = 0;
  563.       done = findfirst(Search, &ffblk, 0);
  564.       while (!done) {
  565.         if (atol(ffblk.ff_name) > max_msg)
  566.           max_msg = atol(ffblk.ff_name);
  567.         done = findnext(&ffblk);
  568.       }
  569.       if (max_msg == 0)
  570.         max_msg = 1;
  571.       if (debug)
  572.         printf("Highest message number = %d\n", max_msg);
  573.       msg_cnt = 0;
  574.       byte_cnt = 0;
  575.       sprintf(Buffer, "%s/s%d.NET", wwivpath, MyNode);
  576.       fd1 = fopen(Buffer, "r+b");
  577.       if (fd1 != NULL) {
  578.         /* read Header */
  579.         while (fread(&header, sizeof(header), 1, fd1) == 1) {
  580.           fpos1 = ftell(fd1) - 16;
  581.           /* Check to see if the message needs to be processed */
  582.           if (
  583.           /* This part checks for posts to the sub currently being processed */
  584.               (header.main_type == main_type_post && header.minor_type == sub_type)
  585.           /* This part checks for Email */
  586.               || (header.main_type == main_type_email_name)
  587.             ) {
  588.             fpos2 = ftell(fd1);
  589.             fseek(fd1, fpos1, 0);
  590.             /* Mark this message as processed */
  591.             fwrite(&didit, sizeof(didit), 1, fd1);
  592.             fseek(fd1, fpos2, 0);
  593.             if (print_flag == 0) {
  594.               if (sub_type == 0) {
  595.                 sprintf(s, "Mail:");             /* v2.00 */
  596.                 TextLogEntry(s);                 /* v2.00 */
  597.                 puts(s);                         /* v2.00 */
  598.               } else {
  599.                                                  /* v2.00 */
  600.                 sprintf(s, "Sub %ld:", (long) sub_type);
  601.                 TextLogEntry(s);                 /* v2.00 */
  602.                 puts(s);                         /* v2.00 */
  603.               }
  604.                                                  /* v2.00 */
  605.               sprintf(s, "Date       Time     %-5s %-13.13s %s", "Size", "From", "To");
  606.               TextLogEntry(s);                   /* v2.00 */
  607.               puts(s);                           /* v2.00 */
  608.                                                  /* v2.00 */
  609.               sprintf(s, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  610.               TextLogEntry(s);                   /* v2.00 */
  611.               puts(s);                           /* v2.00 */
  612.               print_flag = 1;
  613.             }
  614.             Zone = FidoZone;
  615.             x = Fidoize(fd1, &Fmessage);
  616.             if (Zone != FidoZone) {
  617.               Fmessage.destNet = FidoZone;
  618.               Fmessage.destNode = Zone;
  619.             }
  620.             max_msg++;
  621.             msg_cnt++;
  622.             byte_cnt += x;
  623.             sprintf(Buffer, "%s\\%d.MSG", Path, max_msg);
  624.             fd2 = fopen(Buffer, "wb");
  625.             if (fd2 == NULL) {
  626.               printf("Can't write to %s\n", Buffer);
  627.               exit(-1);
  628.             }
  629.             /* Write out the message */
  630.             fwrite(&Fmessage, sizeof(Fmessage), 1, fd2);
  631.             if (Point != 0)
  632.               fprintf(fd2, "%cTOPT %d%c%c", 1, Point, 13, 10);
  633.             if (Zone != FidoZone)
  634.               fprintf(fd2, "%cINTL %d:%d/%d %d:%d/%d%c%c", 1,
  635.                       Zone, FNet, FNode, FidoZone, FidoNet, FidoNode, 13, 10);
  636.             fprintf(fd2, "%cWWIVGATE: %d %s N%d U%d%c%c", 1, LocalNode,
  637.                     NetString, (int) header.fromsys, (int) header.fromuser, 13, 10);
  638.             fwrite(MBuf, x, 1, fd2);
  639.             c = 13;
  640.             fwrite(&c, 1, 1, fd2);
  641.             c = 10;
  642.             fwrite(&c, 1, 1, fd2);
  643.             if (strncmp(Fmessage.toUserName, "UUCP", 4) != 0) {
  644.               if (last_system_checked != header.fromsys) { /* v2.00 */
  645.                 GetSystemInfo(header.fromsys, &static_stat);/* v2.00 */
  646.                 last_system_checked = static_stat.sysnum;  /* v2.00 */
  647.               }                                            /* v2.00 */
  648.               if (static_stat.sysnum == 0)                 /* v2.00 */
  649.                 z = -1;                                    /* v2.00 */
  650.               fprintf( fd2,"--- NetSEX v%s%c%c",Version,   /* v2.00 */
  651.                            13,10);                         /* v2.00 */
  652.               if (z != -1)                                 /* v2.00 */
  653.                 fprintf(fd2, " # Origin: %s @%d - %s[%s]%c%c", /* v2.00 */
  654.                               NetString,                   /* v2.00 */
  655.                               (int)header.fromsys,         /* v2.00 */
  656.                               static_stat.name,            /* v2.00 */
  657.                               static_stat.phone, 13, 10);  /* v2.00 */
  658.               fprintf(fd2," * Origin: %s/FIDOnet Gateway (%d:%d/%d)%c%c",
  659.                               NetString,                   /* v2.00 */
  660.                               FidoZone, FidoNet,           /* v2.00 */
  661.                               FidoNode, 13, 10);           /* v2.00 */
  662.               c = 13;                                      /* v2.00 */
  663.               fwrite(&c, 1, 1, fd2);                       /* v2.00 */
  664.               c = 10;                                      /* v2.00 */
  665.               fwrite(&c, 1, 1, fd2);                       /* v2.00 */
  666.             }
  667.             c = 0;
  668.             fwrite(&c, 1, 1, fd2);
  669.             fclose(fd2);
  670.           } else {
  671.             fseek(fd1, header.length, 1);
  672.           }
  673.         }
  674.         fclose(fd1);
  675.       }
  676.     }
  677.     if (print_flag != 0) {
  678.                                                  /* v2.00 */
  679.       sprintf(s, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  680.       TextLogEntry(s);                           /* v2.00 */
  681.       puts(s);                                   /* v2.00 */
  682.                                                  /* v2.00 */
  683.       sprintf(s, "%ld Messages, %ld Bytes\r\n", msg_cnt, byte_cnt);
  684.       TextLogEntry(s);                           /* v2.00 */
  685.       puts(s);                                   /* v2.00 */
  686.       for (x = 0; x != Log_Count; x++)
  687.         if (strcmp(area, Ldata[x].name) == 0)
  688.           break;
  689.       if (x == Log_Count) {
  690.         Log_Count++;
  691.         if (Ldata == NULL) {
  692.           Ldata = (log_entry *) malloc(sizeof(log_entry));
  693.         } else {
  694.           Ldata = (log_entry *) realloc(Ldata, Log_Count * sizeof(log_entry));
  695.         }
  696.         if (Ldata != NULL) {                               /* v2.00 */
  697.           for (y = 0; y != 40; y++)
  698.             Ldata[x].name[y] = 0;
  699.           strcpy(Ldata[x].name, area);
  700.           Ldata[x].sub_type = sub_type;
  701.           Ldata[x].host = host_system;
  702.           Ldata[x].in_messages = 0;
  703.           Ldata[x].out_messages = 0;
  704.           Ldata[x].in_bytes = 0;
  705.           Ldata[x].out_bytes = 0;
  706.         }                                                  /* v2.00 */
  707.       }
  708.       if (Ldata != NULL) {                                 /* v2.00 */
  709.         Ldata[x].out_messages += msg_cnt;
  710.         Ldata[x].out_bytes += byte_cnt;
  711.       }                                                    /* v2.00 */
  712.     }
  713.   }
  714.   sprintf(Buffer, "%s/s%d.NET", wwivpath, (int) MyNode);
  715.   unlink(Buffer);
  716.   return;
  717. }
  718.  
  719. int NextEnt()
  720. {
  721.   char Line[160], Line2[160], s4[160];                     /* v2.00 */
  722.   int x, y, z, done = 0;
  723.   int tot;
  724.   int Res;
  725.  
  726.   if (debug)
  727.     printf("Entering NextEnt()\n");
  728.   while (done == 0) {
  729.     LineCount++;
  730.     if (fgets(Line, 160, Net) == NULL)
  731.       /* Bail out if no more to process */
  732.       return (-1);
  733.     /* Copy in case we need the EXACT line */
  734.     strcpy(Line2, Line);
  735.     strupr(Line);
  736.     if (strncmp("SUB: ", Line, 5) == 0) {
  737.       if (debug)
  738.         printf("%s", Line);
  739.       strcpy(s4, Line);                                    /* v2.00 */
  740.       strtok(s4, " ");                                     /* v2.00 */
  741.       sub_type = atol(strtok(NULL, " "));                  /* v2.00 */
  742.       if (sub_type < 1)                                    /* v2.00 */
  743.         return(-1);                                        /* v2.00 */
  744.       if (debug)                                           /* v2.00 */
  745.         printf("Sub type %d\n", sub_type);                 /* v2.00 */
  746.       host_system = atol(strtok(NULL, " "));               /* v2.00 */
  747.       if (host_system < 1)                                 /* v2.00 */
  748.         return(-1);                                        /* v2.00 */
  749.       if (debug)                                           /* v2.00 */
  750.         printf("Host system %d\n", host_system);           /* v2.00 */
  751.       strcpy(Path, strtok(NULL, " "));                     /* v2.00 */
  752.       if (Path[0] == 0)                                    /* v2.00 */
  753.         return(-1);                                        /* v2.00 */
  754.       if (debug)                                           /* v2.00 */
  755.         printf("Search path: *%s*\n", Path);               /* v2.00 */
  756.       strcpy(area, strtok(NULL, " "));                     /* v2.00 */
  757.       if (area[0] == 0)                                    /* v2.00 */
  758.         return(-1);                                        /* v2.00 */
  759.       if (debug)                                           /* v2.00 */
  760.         printf("Fidonet area: %s\n", area);                /* v2.00 */
  761.       strcpy(s, strtok(NULL, " "));                        /* v2.00 */
  762.       if (s[0] == 'Y')                                     /* v2.00 */
  763.         bd_flag = 1;                                       /* v2.00 */
  764.       else                                                 /* v2.00 */
  765.         bd_flag = 0;                                       /* v2.00 */
  766.       if ((bd_flag == 1) && (debug))
  767.         printf("Sub is bi-directional\n");
  768.       if ((export_flag == 0) || (bd_flag == 1))
  769.         done = 1;
  770.       Line[0] = ';';
  771.                                                            /* v2.00 */
  772.     } else if (strncmp("KILL_AFTER_PROCESS", Line, 18) == 0) {
  773.       kill_after_process = 1;                              /* v2.00 */
  774.     } else if (strncmp("DEBUG", Line, 5) == 0) {           /* v2.00 */
  775.       debug = 1;                                           /* v2.00 */
  776.     } else if (((strncmp("IN_ALIAS: ", Line, 10) == 0) && (export_flag == 0)) ||
  777.                ((strncmp("OUT_ALIAS: ", Line, 11) == 0) && (export_flag == 1))) {
  778.       x = 9 + export_flag;
  779.       while (Line[x] != '=' && x < strlen(Line))
  780.         x++;
  781.       if (x >= strlen(Line)) {
  782.         printf("Error in ALIAS Command, Line %d\n%s\n", LineCount, Line);
  783.         exit(0);
  784.       }
  785.       Line[x] = 0;
  786.       Line2[strlen(Line2) - 1] = 0;
  787.       y = 0;
  788.       while ((strcmpi(Alias[y].in, &Line[10 + export_flag]) != 0)
  789.              && (y < NumAlias))
  790.         y++;
  791.       if (y == NumAlias) {
  792.         if (debug)
  793.           printf("New Alias\n");
  794.         if (y == 0) {
  795.           Alias = (struct Alias *) malloc(sizeof(struct Alias));
  796.         } else {
  797.           Alias = (struct Alias *) realloc(Alias, (NumAlias + 1) * sizeof(struct Alias));
  798.         }
  799.         if (Alias == NULL) {                               /* v2.00 */
  800.           sprintf(s, "WARNING: Not enough memory.  Stopped at alias #%d", NumAlias);
  801.           TextLogEntry(s);                                 /* v2.00 */
  802.           puts(s);                                         /* v2.00 */
  803.           NumAlias = 0;                                    /* v2.00 */
  804.         }                                                  /* v2.00 */
  805.         strcpy(Alias[NumAlias].in, &Line[10 + export_flag]);
  806.         strcpy(Alias[NumAlias].out, &Line2[x + 1]);
  807.         if (debug)
  808.           printf("Aliasing %s to %s\n", Alias[NumAlias].in, Alias[NumAlias].out);
  809.         NumAlias++;
  810.       } else if (strlen(&Line2[x + 1]) == 0) {
  811.         if (debug)
  812.           printf("De-Aliasing %s\n", Alias[y].in);
  813.         for (z = y; z != NumAlias - 1; z++) {
  814.           strcpy(Alias[z].in, Alias[z + 1].in);
  815.           strcpy(Alias[z].out, Alias[z + 1].out);
  816.         }
  817.         NumAlias--;
  818.         Alias = (struct Alias *) realloc(Alias, NumAlias * sizeof(struct Alias));
  819.       } else {
  820.         if (debug)
  821.           printf("Changing Alias of %s to %s\n", Alias[y].in, &Line2[x + 1]);
  822.         strcpy(Alias[y].out, &Line2[x + 1]);
  823.       }
  824.  
  825.       Line[0] = ';';
  826.     } else if (strncmp("IN_ALIAS: ", Line, 10) == 0 ||
  827.                strncmp("OUT_ALIAS: ", Line, 11) == 0) {
  828.       Line[0] = ';';
  829.     } else if (strncmp("BANNER: ", Line, 8) == 0) {
  830.       /* Limit Length to 80 chars */
  831.       tot = 0;
  832.       for (x = 8; x < strlen(Line2); x++) {
  833.         /* Check for ^C */
  834.         if (Line2[x] == 3) {
  835.           x++;
  836.           x++;                                             /* v2.00 */
  837.         } else {
  838.           tot++;
  839.         }
  840.         if (tot == 80) {
  841.           Line2[x + 1] = 0;
  842.           break;
  843.         }
  844.       }
  845.       strcpy(Banner, &Line2[8]);
  846.       Line[0] = ';';
  847.       if (debug)
  848.         printf("BANNER: %s\n", Banner);
  849.     } else if (strncmp("NODE: ", Line, 6)==0) {
  850.       MyNode = atol(&Line[6]);
  851.       Line[0] = ';';
  852.     } else if (strncmp("FNODE: ", Line,7)==0) {
  853.       FidoNode = (unsigned short) atol(&Line[7]);
  854.       Line[0] = ';';
  855.     } else if (strncmp("FNET: ", Line, 6)==0) {
  856.       FidoNet = (unsigned short) atol(&Line[6]);
  857.       Line[0] = ';';
  858.     } else if (strncmp("FZONE: ", Line,7)==0) {
  859.       FidoZone = (unsigned short) atol(&Line[7]);
  860.       Line[0] = ';';
  861.     } else if (strncmp("LOCAL: ", Line,7)==0) {
  862.       LocalNode = atol(&Line[7]);
  863.       Line[0] = ';';
  864.     } else if (strncmp("MAIL: ", Line, 6)==0) {
  865.       strcpy(MailDir, &Line[6]);
  866.       MailDir[strlen(MailDir) - 1] = 0;
  867.       /* Process the mail */
  868.       strcpy(area, "Mail");
  869.       strcpy(Path, MailDir);
  870.       MailDir[0] = 0;
  871.       sub_type = 0;
  872.       bd_flag = 1;
  873.       if (debug)
  874.         printf("Processing Mail\n");
  875.       done = 1;
  876.       Line[0] = ';';
  877.     } else if (strncmp("COORDINATOR: ", Line, 13) == 0) {
  878.       CNode = atol(&Line[13]);
  879.       Line[0] = ';';
  880.     } else if (strncmp("NETWORK: ", Line, 9) == 0) {
  881.       strcpy(NetString, &Line2[9]);
  882.       NetString[strlen(NetString) - 1] = 0;
  883.       Line[0] = ';';
  884.     } else if (strncmp("LOGS: ", Line, 6)==0) {  /* v2.00 */
  885.       strcpy(logdir, &Line[6]);                  /* v2.00 */
  886.       logdir[strlen(logdir) - 1] = 0;            /* v2.00 */
  887.       logdir[strlen(logdir)] = 0;                /* v2.00 */
  888.       logdir[strlen(logdir) + 1] = 0;            /* v2.00 */
  889.       if (logdir[strlen(logdir) - 1] != 92)      /* v2.00 */
  890.         logdir[strlen(logdir)] = 92;             /* v2.00 */
  891.       Line[0] = ';';                             /* v2.00 */
  892.     } else if (Line[0] != ';' && Line[0] != 10) {
  893.       puts("Unrecognized command in FIDO.NET:");
  894.       puts(Line2);
  895.     }
  896.   }
  897.   return (0);
  898. }
  899.  
  900. int ReadLine(Buffer, fd)
  901.   unsigned char *Buffer;
  902.   FILE *fd;
  903. {
  904.   int x = 0;
  905.   while (fread(&Buffer[x], 1, 1, fd) == 1) {
  906.     if (Buffer[x] == 10 || Buffer[x] == 141) {
  907.       ;
  908.     } else if (Buffer[x] == 13) {
  909.       Buffer[x + 1] = 0;
  910.       return (0);
  911.     } else {
  912.       x++;
  913.       if (x > 718) {
  914.         Buffer[x] = 0;
  915.         return (x);
  916.       }
  917.     }
  918.  
  919.   }
  920.   Buffer[x] = 0;
  921.   return (-1);
  922. }
  923.  
  924. int ProcMess(fd)
  925.   FILE *fd;
  926. {
  927.   int x, y, z, flagaddr;
  928.   char Buffer[720];
  929.  
  930.   y = 0;
  931.   flagaddr = 0;
  932.  
  933.   /* Add the To: line from the fido message to the message text */
  934.   if (sub_type != 0) {
  935.     sprintf(MBuf, "To: %s\r\n\r\n", tname);
  936.     y = strlen(MBuf);
  937.   }
  938.   do {
  939.     x = ReadLine(Buffer, fd);
  940.   if (Buffer[0] == 1 && strncmp("FMPT ", &Buffer[1],5)==0) /* v2.00 */
  941.     Point = atoi(&Buffer[6]);                              /* v2.00 */
  942.     if ((Buffer[0] == 1) &&                                /* v2.00 */
  943.       (strncmp("MSGID:", &Buffer[1], 6) == 0)) {           /* v2.00 */
  944.       z = 9;                                               /* v2.00 */
  945.       while ((Buffer[z] != ' ') && (Buffer[z] != 0))       /* v2.00 */
  946.         z++;                                               /* v2.00 */
  947.       Buffer[z]=0;                                         /* v2.00 */
  948.       Faddress(&Buffer[8]);                                /* v2.00 */
  949.       flagaddr = 1;                                        /* v2.00 */
  950.       if (debug)
  951.         printf("Origin Address found in ^AMSGID: Flag: %i:%i/%i\n"
  952.                ,Zone,FNet,FNode);
  953.     }
  954.     /* Ignore ^A Lines and AREA: and SEEN-BY: and EID: */
  955.     if (Buffer[0] != 1
  956.         && strncmp("AREA:", Buffer, 5) != 0
  957.         && strncmp("SEEN-BY:", Buffer, 8) != 0
  958.         && strncmp("EID:", Buffer, 4) != 0
  959.         && strncmp("TOPT ", Buffer, 4) != 0
  960.         && strncmp("FMPT:", Buffer, 4) != 0
  961.         && !(Buffer[0] == 13 && y == 0)) {
  962.  
  963.       for (z = 0; z != strlen(Buffer); z++) {
  964.         if (Buffer[z] == 13) {
  965.           MBuf[y] = 13;
  966.           y++;
  967.           MBuf[y] = 10;
  968.           y++;
  969.         } else {
  970.           MBuf[y] = Buffer[z];
  971.           y++;
  972.         }
  973.       }
  974.     } else if (Buffer[0] == 1 && strncmp("FMPT ", &Buffer[1], 5) == 0) {
  975.       Point = atoi(&Buffer[6]);
  976.     } else if (Buffer[0] == 1 && strncmp("TOPT ", &Buffer[1], 5) == 0) {
  977.       ToPoint = atoi(&Buffer[6]);
  978.     } else if (Buffer[0] == 1 && strncmp("INTL ", &Buffer[1], 5) == 0) {
  979.       z = 6;
  980.       while (Buffer[z] != ' ') {
  981.         z++;
  982.       }
  983.       Buffer[z] = 0;
  984.       Faddress(&Buffer[5]);
  985.       destNode = FNode;
  986.       destNet = FNet;
  987.       Faddress(&Buffer[z + 1]);
  988.       flagaddr = 1;
  989.     } else if (Buffer[0] == 1 && strncmp("WWIVGATE: ", &Buffer[1], 10) == 0) {
  990.       WWIVgate = atoi(&Buffer[11]);
  991.       if (WWIVgate == LocalNode) {
  992.         if (debug)
  993.           printf("Message Already Processed.\r\n");
  994.         return (0);
  995.       }
  996.     }
  997.     if ((!flagaddr && Buffer[0] != 1) &&                           /* v2.00 */
  998.         (strncmp("* Origin:", &Buffer[1], 9) == 0)) {              /* v2.00 */
  999.       if (debug)                                                   /* v2.00 */
  1000.         printf("Origin Line Processing: %s\n\n\r",&Buffer[10]);    /* v2.00 */
  1001.       ZapAddr(&Buffer[10]);                                        /* v2.00 */
  1002.       if (debug)                                                   /* v2.00 */
  1003.         printf("Origin Address found in Origin Line: %i:%i/%i\n\n" /* v2.00 */
  1004.                ,Zone,FNet,FNode);                                  /* v2.00 */
  1005.     }                                                              /* v2.00 */
  1006.   } while (x >= 0);
  1007.   return (y);
  1008.  
  1009. }
  1010.  
  1011. int ParseName(Name)
  1012.   char *Name;
  1013. {
  1014.   int Number, Node, x, y;
  1015.   char temp[40];
  1016.  
  1017.   for (x = 0; x != NumAlias; x++) {
  1018.     if (strcmpi(Name, Alias[x].in) == 0) {
  1019.       if (debug)
  1020.         printf("%s Aliased to %s.", Name, Alias[x].out);
  1021.       strcpy(Name, Alias[x].out);
  1022.       break;
  1023.     }
  1024.   }
  1025.  
  1026.   if (Name[0] == 'N') {
  1027.     Node = atol(&Name[1]);
  1028.   } else {
  1029.     Node = 0;
  1030.   }
  1031.  
  1032.   if (debug)
  1033.     printf(" To: %s\n Node = %d.", Name, Node);
  1034.   y = strlen(Name);
  1035.   x = 0;
  1036.   while ((x < y) && (Name[x] != ' ')) {
  1037.     x++;
  1038.   }
  1039.  
  1040.   /* No Node Number ? */
  1041.   /* Must be local mail */
  1042.   if (x >= y || Node <= 0) {
  1043.     if (debug)
  1044.       printf(" Mail to %s\n", Name);
  1045.     header.length += strlen(Name) + 1;
  1046.     header.main_type = main_type_email_name;
  1047.     header.list_len = 0;
  1048.     header.tosys = LocalNode;
  1049.     return (1);
  1050.   }
  1051.   if (Name[x + 1] == 'U') {
  1052.     Number = atol(&Name[x + 2]);
  1053.   } else {
  1054.     Number = 0;
  1055.   }
  1056.  
  1057.   if (debug)
  1058.     printf("Number = %d\n", Number);
  1059.   /* Mail sent to User Number at Node Number */
  1060.   if (Number != 0) {
  1061.     if (debug)
  1062.       printf(" Mail to user # %d @ %d.\n", Number, Node);
  1063.     header.main_type = main_type_email;
  1064.     header.list_len = 0;
  1065.     header.tosys = Node;
  1066.     header.touser = Number;
  1067.     return (2);
  1068.   }
  1069.   /* Name E-Mail Bound for another system */
  1070.   if ((Number == 0) && (Node != 0)) {
  1071.     strcpy(temp, &Name[x + 1]);
  1072.     strcpy(Name, temp);
  1073.     if (debug)
  1074.       printf(" Mail to %s@%d.\n", Name, Node);
  1075.     header.length += strlen(Name) + 1;
  1076.     header.main_type = main_type_email_name;
  1077.     header.list_len = 0;
  1078.     header.tosys = 5317;
  1079.     return (1);
  1080.   }
  1081.   return (-1);
  1082. }
  1083.  
  1084. int Fidoize(file, Fheader)
  1085.   FILE *file;
  1086.   struct MessageHdr *Fheader;
  1087. {
  1088.   int length, x, mlength, y, z, x1;
  1089.   struct tm *tm;
  1090.   unsigned char c;
  1091.   char ch[81];
  1092.   int Line, LineMkr;
  1093.   char *Mon[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
  1094.                    "Oct", "Nov", "Dec"};
  1095.  
  1096.   length = 0;
  1097.   mlength = 0;
  1098.   if (sub_type == 0) {
  1099.     /* Read in the TO field */
  1100.     x = 0;
  1101.     do {
  1102.       if (fread(&Fheader -> toUserName[x], 1, 1, file) != 1) {
  1103.         printf("Error in s%ld file\n", MyNode);
  1104.         exit(-1);
  1105.       }
  1106.       x++;
  1107.       length++;
  1108.     } while (Fheader -> toUserName[x - 1] != 0);
  1109.     strupr(Fheader -> toUserName);
  1110.     for (; x != 36; x++)
  1111.       Fheader -> toUserName[x] = 0;
  1112.   } else {
  1113.     strcpy(Fheader -> toUserName, "All");
  1114.     for (x = 3; x != 36; x++) {
  1115.       Fheader -> toUserName[x] = 0;
  1116.     }
  1117.   }
  1118.   /* Read in the subject field */
  1119.   x = 0;
  1120.   do {
  1121.     if (fread(&Fheader -> subject[x], 1, 1, file) != 1) {
  1122.       printf("Error in s%ld file\n", MyNode);
  1123.       exit(-1);
  1124.     }
  1125.     x++;
  1126.     length++;
  1127.   } while ((Fheader -> subject[x - 1] != 0) && (x < 70));
  1128.   for (x = x; x != 72; x++)
  1129.     Fheader -> subject[x] = 0;
  1130.   /* Read in the FROM field */
  1131.   x = 0;
  1132.   do {
  1133.     if (fread(&tname[x], 1, 1, file) != 1) {
  1134.       printf("Error in s%ld file\n", MyNode);
  1135.       exit(-1);
  1136.     }
  1137.     x++;
  1138.     length++;
  1139.   } while (tname[x - 1] != 13);
  1140.   tname[x - 1] = 0;
  1141.   fread(&c, 1, 1, file);
  1142.   length++;
  1143.   while (tname[x] != '#')
  1144.     x--;
  1145.   tname[x] = 0;
  1146.   while (tname[strlen(tname) - 1] == ' ')                  /* v2.00 */
  1147.     tname[strlen(tname) - 1] = 0;                          /* v2.00 */
  1148.   sprintf(Fheader -> fromUserName, "N%d U%d (%s)",         /* v2.00 */
  1149.                                    (int)header.fromsys,    /* v2.00 */
  1150.                                    (int)header.fromuser,   /* v2.00 */
  1151.                                    tname);                 /* v2.00 */
  1152.   for (x = 0; x != NumAlias; x++) {
  1153.     if (strcmpi(Fheader -> fromUserName, Alias[x].in) == 0) {
  1154.       strcpy(Fheader -> fromUserName, Alias[x].out);
  1155.       break;
  1156.     }
  1157.   }
  1158.   for (x = strlen(Fheader -> fromUserName); x != 36; x++)
  1159.     Fheader -> fromUserName[x] = 0;
  1160.   /* Read in the DATE field */
  1161.   x = 0;
  1162.   do {
  1163.     if (fread(&Fheader -> dateTime[0], 1, 1, file) != 1) {
  1164.       printf("Error in s%ld file\n", MyNode);
  1165.       exit(-1);
  1166.     }
  1167.     x++;
  1168.     length++;
  1169.   } while (Fheader -> dateTime[0] != 13);
  1170.   Fheader -> dateTime[x - 1] = 0;
  1171.   fread(&c, 1, 1, file);
  1172.   length++;
  1173.   tm = localtime(&(long) header.daten);
  1174.   sprintf(Fheader -> dateTime, "%02d %s %02d  %02d:%02d:%02d", tm -> tm_mday, Mon[tm -> tm_mon],
  1175.           tm -> tm_year, tm -> tm_hour, tm -> tm_min, tm -> tm_sec);
  1176.   /* Read in the text */
  1177.   x = 0;
  1178.   /* If Not going to uucp,  put in another from field */
  1179.   if (debug)
  1180.     printf("to: %s\n", Fheader -> toUserName);
  1181.   LineMkr = x;
  1182.   do {
  1183.     if (fread(&c, 1, 1, file) != 1) {
  1184.       printf("Error in file\n");
  1185.       exit(0);
  1186.     }
  1187.     if (c == 13 || (c < 128 && c > 31)) {
  1188.       MBuf[x] = c;
  1189.       length++;
  1190.       x++;
  1191.     } else if (c > 127) {
  1192.       /* French Accents -> unaccentuated equivalent */     /* v2.00 */
  1193.       switch(c) {                                          /* v2.00 */
  1194.         case 130:                                          /* v2.00 */
  1195.         case 136:                                          /* v2.00 */
  1196.         case 137:                                          /* v2.00 */
  1197.         case 138:                                          /* v2.00 */
  1198.           MBuf[x]=101;                                     /* v2.00 */
  1199.           break;         /* e */                           /* v2.00 */
  1200.         case 131:                                          /* v2.00 */
  1201.         case 132:                                          /* v2.00 */
  1202.         case 133:                                          /* v2.00 */
  1203.           MBuf[x]=97;                                      /* v2.00 */
  1204.           break;         /* a */                           /* v2.00 */
  1205.         case 139:                                          /* v2.00 */
  1206.         case 140:                                          /* v2.00 */
  1207.           MBuf[x]=105;                                     /* v2.00 */
  1208.           break;         /* i */                           /* v2.00 */
  1209.         case 147:                                          /* v2.00 */
  1210.         case 148:                                          /* v2.00 */
  1211.           MBuf[x]=111;                                     /* v2.00 */
  1212.           break;         /* o */                           /* v2.00 */
  1213.         case 150:                                          /* v2.00 */
  1214.         case 151:                                          /* v2.00 */
  1215.         case 129:                                          /* v2.00 */
  1216.           MBuf[x]=117;                                     /* v2.00 */
  1217.           break;         /* u */                           /* v2.00 */
  1218.         case 135:                                          /* v2.00 */
  1219.           MBuf[x]=99;                                      /* v2.00 */
  1220.           break;         /* c */                           /* v2.00 */
  1221.         default:                                           /* v2.00 */
  1222.           MBuf[x]=' ';                                     /* v2.00 */
  1223.       }                                                    /* v2.00 */
  1224.       length++;
  1225.       x++;
  1226.       /* WWIV Color Code */
  1227.     } else if (c == 3) {
  1228.       fread(&c, 1, 1, file);
  1229.       length += 2;
  1230.       /* Word Wrap */
  1231.     } else if (c == 1) {
  1232.       fread(&c, 1, 1, file);
  1233.       fread(&c, 1, 1, file);
  1234.       length += 3;
  1235.       MBuf[x] = 10;
  1236.       x++;
  1237.     } else {
  1238.       length++;
  1239.     }
  1240.   } while (length < header.length);
  1241.   MBuf[x] = 0;
  1242.   if (debug)
  1243.     printf("----- Text Follows -----\n%s\n", MBuf);
  1244.   mlength += x;
  1245.   Fheader -> timesRead = 0;
  1246.   Fheader -> destNode = 0;
  1247.   Fheader -> origNode = FidoNode;
  1248.   Fheader -> cost = 0;          /* This used to mark the message as processed */
  1249.   Fheader -> origNet = FidoNet;
  1250.   Fheader -> destNet = 0;
  1251.   Fheader -> replyTo = 0;
  1252.   Fheader -> Attribute = (unsigned short) 0;
  1253.   if (sub_type == 0) {
  1254.     Fheader->Attribute = (unsigned short)257 ;             /* v2.00 */
  1255.     x = strlen(Fheader -> toUserName);
  1256.     while (Fheader -> toUserName[x] != 'O') {
  1257.       x--;
  1258.     }
  1259.     x--;
  1260.                                                  /* v2.00 */
  1261.     if (strncmpi(" OF ", &Fheader -> toUserName[x], 4) == 0) {
  1262.       Fheader -> toUserName[x] = 0;
  1263.       Faddress(&Fheader -> toUserName[x + 4]);
  1264.       Fheader -> destNode = FNode;
  1265.       Fheader -> destNet = FNet;
  1266.       if (debug)
  1267.         printf("Headed for %d/%d\n", Fheader -> destNet, Fheader -> destNode);
  1268.     }
  1269.   }
  1270.   /* Check to see if the message has a RE: */
  1271.   if (strncmp("RE:", &MBuf[LineMkr], 3) == 0) {
  1272.     if (debug)
  1273.       printf("Found a RE:\n");
  1274.     /* Find where the "RE:" line ends and block move... */
  1275.     x = LineMkr;
  1276.     while (MBuf[x] != 13) {
  1277.       x++;
  1278.     }
  1279.     /* Make RE: the new subject line */          /* v2.00 */
  1280.     strncpy(Fheader -> subject, &MBuf[LineMkr], x - LineMkr);
  1281.       if (debug)
  1282.         printf("Added RE: to the subject Line\n");
  1283.     /* I am assuming that the standard RE: line ends in two <CR> */
  1284.     x += 2;
  1285.     for (length = x; length != mlength; length++)
  1286.       MBuf[length - (x - LineMkr)] = MBuf[length];
  1287.     mlength -= (x - LineMkr);
  1288.   }
  1289.   x = LineMkr;
  1290.   /* Check to see if the message has a To: */
  1291.                                                  /* v2.00 */
  1292.   if ((sub_type != 0) && ((strncmp("BY:", &MBuf[LineMkr], 3) == 0) ||
  1293.       (strncmpi("To:", &MBuf[LineMkr], 3) == 0))) {
  1294.     if (debug)
  1295.       printf("Found a To/BY:\n");                  /* v2.00 */
  1296.     /* Find where the "To:" line ends and block move... */
  1297.     x = LineMkr;
  1298.     while (MBuf[x] != 13) {
  1299.       x++;
  1300.     }
  1301.     /* Add the To: into the to line */
  1302.     if ((3 + x - LineMkr) < 35) {
  1303.       strncpy(Fheader -> toUserName, &MBuf[LineMkr + 4], x - LineMkr - 4);
  1304.       if (debug)
  1305.         printf("Change ToUser Field\n");
  1306.     }
  1307.     /* I am assuming that the standard To: line ends in two <CR> */
  1308.     x += 1;
  1309.     for (length = x; length != mlength; length++) {
  1310.       MBuf[length - (x - LineMkr)] = MBuf[length];
  1311.     }
  1312.     mlength -= (x - LineMkr);
  1313.   }
  1314.   /* Going to FIDONET - alternate adressing mode */
  1315.                                                  /* v2.00 */
  1316.   if ((sub_type != 0) && (strncmp("FIDONET", Fheader -> toUserName, 7) == 0) &&
  1317.       ((strncmpi("BY:", &MBuf[LineMkr], 3) == 0) ||
  1318.        (strncmpi("To:", &MBuf[LineMkr], 3) == 0))) {
  1319.  
  1320.     if (debug)
  1321.       printf("Found a FIDONET To/BY:\n");          /* v2.00 */
  1322.     /* Find where the "To:" line ends and block move... */
  1323.     x = LineMkr;
  1324.     while (MBuf[x] != 13) {
  1325.       x++;
  1326.     }
  1327.     /* Add the To: into the to line */
  1328.     if ((3 + x - LineMkr) < 35) {
  1329.       strncpy(Fheader -> toUserName, &MBuf[LineMkr + 4], x - LineMkr - 4);
  1330.       if (debug)
  1331.         printf("Added To: to the subject Line\n");
  1332.     }
  1333.     /* I am assuming that the standard To: line ends in two <CR> */
  1334.     x += 1;
  1335.     for (length = x; length != mlength; length++) {
  1336.       MBuf[length - (x - LineMkr)] = MBuf[length];
  1337.     }
  1338.     mlength -= (x - LineMkr);
  1339.     x1 = strlen(Fheader -> toUserName) - 1;
  1340.     while (x1 > 0 &&
  1341.            ((Fheader -> toUserName[x1] != 'O') ||
  1342.             (Fheader -> toUserName[x1] != 'o')))           /* v2.00 */
  1343.       x1--;
  1344.     x1--;
  1345.     strcpy(ch,&Fheader->toUserName[x+4]);                  /* v2.00 */
  1346.     if (strncmpi(" OF ", strupr(ch) , 4) == 0) {           /* v2.00 */
  1347.       Fheader->toUserName[x] = 0;                          /* v2.00 */
  1348.       Faddress(&Fheader->toUserName[x+4]);                 /* v2.00 */
  1349.       Fheader->destNode = FNode;                           /* v2.00 */
  1350.       Fheader->destNet = FNet;                             /* v2.00 */
  1351.       if (debug)
  1352.         printf("Headed for %d/%d\n", Fheader -> destNet, Fheader -> destNode);
  1353.     } else {                                               /* v2.00 */
  1354.       Fheader->toUserName[x] = 0;                          /* v2.00 */
  1355.       Fheader->destNode = FidoNode;                        /* v2.00 */
  1356.       Fheader->destNet  = FidoNet;                         /* v2.00 */
  1357.     }                                                      /* v2.00 */
  1358.   }
  1359.   if (debug) {
  1360.     printf("To: %s ", Fheader -> toUserName);
  1361.     printf("From: %s ", Fheader -> fromUserName);
  1362.     printf("Subject: %s ", Fheader -> subject);
  1363.     printf("Date: %s\n", Fheader -> dateTime);
  1364.   }
  1365.   if (sub_type == 0) {
  1366.                                                  /* v2.00 */
  1367.     sprintf(s, "%s %5ld %-13.13s %s of %ld/%ld", Fheader->dateTime,
  1368.             (long) mlength, Fheader->fromUserName, Fheader->toUserName,
  1369.             (long) Fheader->destNet, (long) Fheader->destNode);
  1370.   } else {
  1371.                                                  /* v2.00 */
  1372.     sprintf(s, "%s %5ld %-13.13s %s", Fheader->dateTime,
  1373.             (long) mlength, Fheader->fromUserName, Fheader->toUserName);
  1374.   }
  1375.   TextLogEntry(s);                               /* v2.00 */
  1376.   puts(s);                                       /* v2.00 */
  1377.   return(mlength);
  1378. }
  1379.  
  1380. void Load_Log(path)
  1381.   char *path;
  1382. {
  1383.   char bb[80];
  1384.   long Ptime;
  1385.   struct stat buff;
  1386.   struct tm *tm2;
  1387.   int x;
  1388.   sprintf(bb, "%s/NETSEX.DAT", path);
  1389.   Log_Update = 0;
  1390.   time(&Ptime);
  1391.  
  1392.   if (stat(bb, &buff) == 0) {
  1393.     Log = fopen(bb, "rb");
  1394.     fread(&Ltime, sizeof(Ltime), 1, Log);
  1395.     Ldata = (log_entry *) malloc(buff.st_size - sizeof(Ltime));
  1396.     if ((Ldata == NULL) && ((buff.st_size - sizeof(Ltime)) > 0)) {  /* v2.00 */
  1397.       printf("Not enough memory to load log.\n");          /* v2.00 */
  1398.       exit(1);                                             /* v2.00 */
  1399.     }                                                      /* v2.00 */
  1400.     fread(Ldata, buff.st_size - sizeof(Ltime), 1, Log);
  1401.     fclose(Log);
  1402.     Log_Count = (buff.st_size - sizeof(Ltime)) / sizeof(log_entry);
  1403.  
  1404.     tm2 = localtime(&Ptime);
  1405.     /* Send out Log update if it is Sunday, or it has been more */
  1406.     /* Than a week since the last update */
  1407.     if ((Ptime - Ltime >= 604800) ||
  1408.         ((tm2 -> tm_wday == 0) && (Ptime - Ltime) > 86400)) {
  1409.       Log_Update = 1;
  1410.     }
  1411.   } else {
  1412.     Log_Count = 0;
  1413.     Ltime = Ptime;
  1414.     Ldata = NULL;
  1415.   }
  1416. }
  1417.  
  1418. void Save_Log(path)
  1419.   char *path;
  1420. {
  1421.   struct stat buff;
  1422.   char c, bb[80];
  1423.   int x, y, z;
  1424.  
  1425.   /* Send Log file off to the Coordinator... */
  1426.   if (Log_Update == 1 && CNode != 0) {
  1427.     printf("Sending out Log file\n");
  1428.     sprintf(bb, "%s/P1.NET", path);
  1429.     Net = fopen(bb, "a+b");
  1430.     gettime(&timep);
  1431.     getdate(&datep);
  1432.     header.tosys = CNode;
  1433.     header.touser = 0;
  1434.     header.fromsys = MyNode;
  1435.     header.fromuser = 0;
  1436.     header.main_type = main_type_external;
  1437.     header.minor_type = 6969;
  1438.     header.list_len = 0;
  1439.     header.daten = dostounix(&datep, &timep);
  1440.     header.method = 0;
  1441.     header.length = sizeof(long) + sizeof(LocalNode) + sizeof(FidoNode) +
  1442.                     sizeof(FidoNet) + sizeof(FidoZone) + 4 +
  1443.                     (sizeof(log_entry) * Log_Count);
  1444.     fwrite(&header, sizeof(header), 1, Net);
  1445.     fwrite(&Ltime, sizeof(long), 1, Net);
  1446.     fwrite(&LocalNode, sizeof(LocalNode), 1, Net);
  1447.     fwrite(&FidoNode, sizeof(FidoNode), 1, Net);
  1448.     fwrite(&FidoNet, sizeof(FidoNet), 1, Net);
  1449.     fwrite(&FidoZone, sizeof(FidoZone), 1, Net);
  1450.     fwrite(Version, 4, 1, Net);
  1451.     fwrite(Ldata, Log_Count * sizeof(log_entry), 1, Net);
  1452.     fclose(Net);
  1453.     sprintf(bb, "%s/NETSEX.DAT", path);
  1454.     time(&Ltime);
  1455.     Net = fopen(bb, "w+b");
  1456.     fwrite(&Ltime, sizeof(long), 1, Net);
  1457.     fclose(Net);
  1458.   } else {
  1459.     sprintf(bb, "%s/NETSEX.DAT", path);
  1460.     Log = fopen(bb, "w+b");
  1461.     fwrite(&Ltime, sizeof(Ltime), 1, Log);
  1462.     fwrite(Ldata, Log_Count * sizeof(log_entry), 1, Log);
  1463.     fclose(Log);
  1464.   }
  1465.   free(Ldata);
  1466. }
  1467.  
  1468. void Faddress(Buffer)
  1469.   char *Buffer;
  1470. {
  1471.   int x;
  1472.   int y;
  1473.   int g;
  1474.  
  1475.   char Pflag = 0;
  1476.   x = 0;
  1477.   y = x;
  1478.   g = strlen(Buffer);
  1479.   Zone = FidoZone;
  1480.   FNet = FidoNet;
  1481.   FNode = FidoNode;
  1482.   Point = 0;
  1483.   do {
  1484.     switch (Buffer[x]) {
  1485.     case ':':
  1486.       Buffer[x] = 0;
  1487.       Zone = atoi(&Buffer[y]);
  1488.       x++;
  1489.       y = x;
  1490.       break;
  1491.     case '/':
  1492.       Buffer[x] = 0;
  1493.       FNet = atoi(&Buffer[y]);
  1494.       x++;
  1495.       y = x;
  1496.       break;
  1497.     case '.':
  1498.       Pflag = 1;
  1499.       Buffer[x] = 0;
  1500.       FNode = atoi(&Buffer[y]);
  1501.       x++;
  1502.       y = x;
  1503.       break;
  1504.     case 0:
  1505.       if (Pflag == 0) {
  1506.         FNode = atoi(&Buffer[y]);
  1507.       } else {
  1508.         Point = atoi(&Buffer[y]);
  1509.       }
  1510.       x++;
  1511.       y = x;
  1512.       break;
  1513.     default:
  1514.       x++;
  1515.       break;
  1516.     }
  1517.   } while (g > x - 1);
  1518. }
  1519.  
  1520. void TextLogEntry(entrystring)                   /* v2.00 */
  1521.   char *entrystring;
  1522. {
  1523.   char s2[160];
  1524.   int x, y;
  1525.  
  1526.   if (TextLog == -1) {
  1527.     sprintf(s2, "%sNETSEX.LOG", logdir);
  1528.     TextLog = open(s2, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  1529.     if (TextLog > 0) {
  1530.       gettime(&timep);
  1531.       getdate(&datep);
  1532.       lseek(TextLog, 0L, SEEK_END);
  1533.       sprintf(s2, "NETSEX Log Entry for %02d/%02d/%02d at %02d:%02d:%02d.\r\n",
  1534.               datep.da_mon, datep.da_day, datep.da_year,
  1535.               timep.ti_hour, timep.ti_min, timep.ti_sec);
  1536.       write(TextLog, (void *) (&s2), strlen(s2));
  1537.       y = strlen(s2);
  1538.       for (x = 0; x < (y-2); x++)
  1539.         s2[x] = '=';
  1540.       write(TextLog, (void *) (&s2), strlen(s2));
  1541.     }
  1542.   }
  1543.   sprintf(s2, "%s\r\n", entrystring);
  1544.   write(TextLog, (void *) (&s2), strlen(s2));
  1545. }
  1546.  
  1547. void CloseTextLog()                              /* v2.00 */
  1548. {
  1549.   char s1[3];
  1550.  
  1551.   if (TextLog != -1) {
  1552.     s1[0] = 13;
  1553.     s1[1] = 10;
  1554.     s1[2] = 0;
  1555.     write(TextLog, (void *) (&s1), strlen(s1));
  1556.     close(TextLog);
  1557.   }
  1558.   TextLog = -1;
  1559. }
  1560.  
  1561. void ZapAddr(Buffer)                                       /* v2.00 */
  1562. char *Buffer;
  1563. {
  1564.   int x;
  1565.   int start;
  1566.  
  1567.   x = strlen(Buffer);
  1568.   ;
  1569.     s1[2] = 0;
  1570.     write(TextLog, (void *) (&s1), strlen(s1));
  1571.     close(TextLog);
  1572.   }
  1573.   TextLog = -1;
  1574. }
  1575.  
  1576. void ZapAddr(Buffer)                                       /* v2.00 */
  1577. char *Buffer;
  1578. {
  1579.   int x;
  1580. 1;
  1581. 1;
  1582. 1;
  1583. 1;
  1584. 1;
  1585. 1;
  1586. 1;
  1587. 1;
  1588. 1;
  1589. 1;
  1590. 1;
  1591. 1;
  1592. 1;
  1593. 1;
  1594. 1;
  1595. 1;
  1596. 1;
  1597. 1;
  1598. 1;
  1599. 1;
  1600. 1;
  1601. 1;
  1602. 1;
  1603. 1;
  1604. 1;
  1605. 1;
  1606. 1;
  1607. 1;
  1608. 1;
  1609. 1;
  1610. 1;
  1611. 1;
  1612. 1;
  1613. 1;
  1614. 1;
  1615. 1;
  1616. 1;
  1617. 1;
  1618. 1;
  1619. 1;
  1620. 1;
  1621. 1;
  1622. 1;
  1623. 1;
  1624. 1;
  1625. 1;
  1626. 1;
  1627. 1;
  1628. 1;
  1629. 1;
  1630. 1;
  1631. 1;
  1632. 1;
  1633. 1;
  1634. 1;
  1635. 1;
  1636. 1;
  1637. 1;
  1638. 1;
  1639. 1;
  1640. 1;
  1641. 1;
  1642. 1;
  1643. 1;
  1644. 1;
  1645.