home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / IMPORT2.C < prev    next >
C/C++ Source or Header  |  1998-05-17  |  40KB  |  1,238 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <dir.h>
  21. #include <dos.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <stdlib.h>
  25. #include <io.h>
  26. #include <fcntl.h>
  27. #include <time.h>
  28. #include <sys\stat.h>
  29.  
  30. #include <cxl\cxlwin.h>
  31. #include <cxl\cxlvid.h>
  32. #include <cxl\cxlstr.h>
  33.  
  34. #include "lsetup.h"
  35. #include "sched.h"
  36. #include "msgapi.h"
  37. #include "prototyp.h"
  38. #include "externs.h"
  39.  
  40. #define Z_32UpdateCRC(c,crc) (cr3tab[((int) crc ^ c) & 0xff] ^ ((crc >> 8) & 0x00FFFFFFL))
  41.  
  42. struct _aidx {
  43. //   char areatag[32];
  44.    unsigned long areatag;
  45.    byte board;
  46.    word gold_board;
  47. };
  48.  
  49. extern struct _aidx *aidx;
  50. extern char *wtext[];
  51. extern int maxakainfo;
  52. extern struct _akainfo *akainfo;
  53.  
  54. int check_route_flag (int zone, int net, int node, int point);
  55. void fido_save_message2 (FILE *, char *);
  56. FILE *mopen (char *filename, char *mode);
  57. int mclose (FILE *fp);
  58. void mprintf (FILE *fp, char *format, ...);
  59. long mseek (FILE *fp, long position, int offset);
  60. int mputs (char *s, FILE *fp);
  61. int mread (char *s, int n, int e, FILE *fp);
  62. void put_tearline (FILE *fpd);
  63.  
  64. void build_aidx (void);
  65. int quick_rescan_echomail (int board, int zone, int net, int node, int point, int goldboard);
  66. void pip_rescan_echomail (int board, char *tag, int zone, int net, int node, int point);
  67. void fido_rescan_echomail (char *tag, int zone, int net, int node, int point);
  68. void squish_rescan_echomail (char *tag, int zone, int net, int node, int point);
  69.  
  70. static void rename_bad_tics (char *, char *);
  71.  
  72. struct _fwd_alias {
  73.    short zone;
  74.    short net;
  75.    short node;
  76.    short point;
  77.    bit   passive :1;
  78.    bit   receive :1;
  79.    bit   send    :1;
  80. };
  81.  
  82. #define MAX_FORWARD 50
  83.  
  84. /*
  85.    ! - Nodo passivo
  86.    < - Nodo a sola trasmissione (il nodo non riceve i files)
  87.    > - Nodo a sola ricezione (il nodo non puo' trasmettere files)
  88. */
  89.  
  90. static long xtol (char *p)
  91. {
  92.    long r = 0L;
  93.  
  94.     while (*p) {
  95.         if (isdigit (*p)) {
  96.             r *= 16L;
  97.             r += *p - '0';
  98.         }
  99.         else if (isxdigit (*p)) {
  100.             r *= 16L;
  101.             r += *p - 55;
  102.         }
  103.         p++;
  104.     }
  105.  
  106.     return (r);
  107. }
  108.  
  109. #define MAX_BUFFERING       2048
  110. #define MAX_DESCRIPTION     512
  111.  
  112. void import_tic_files ()
  113. {
  114.    FILE *fp, *fpcfg, *fpd, *fps;
  115.    int i, zo, ne, no, po, fzo, fne, fno, fpo, fds, fdd, d;
  116.    int wh, ozo, one, ono, opo, nrec, nsent, n_forw, nf, godelete;
  117.    char *inpath, filename[80], *linea, area[20], *descr, name[14], *p;
  118.    char pw[32], dpath[80], dpw[32], found, fi, repl[14], seen;
  119.    char path;
  120.    long crc, pos, crcf;
  121.    float t;
  122.    struct ffblk blk;
  123.    struct _wrec_t *wr;
  124.    struct tm *tim;
  125.    struct _sys tsys;
  126.    struct _fwd_alias *forward;
  127.  
  128.     forward = (struct _fwd_alias *)malloc (MAX_FORWARD * sizeof (struct _fwd_alias));
  129.    if (forward == NULL)
  130.       return;
  131.  
  132.    sprintf (filename, "%sSYSFILE.DAT", config->sys_path);
  133.    fpcfg = fopen (filename, "r+b");
  134.    if (fpcfg == NULL) {
  135.       free (forward);
  136.       return;
  137.    }
  138.  
  139.    fi = 0;
  140.    nrec = nsent = 0;
  141.    linea = (char *)malloc (MAX_BUFFERING + 1);
  142.    descr = (char *)malloc (MAX_DESCRIPTION + 1);
  143.  
  144.    local_status ("TIC");
  145.    wfill (7, 53, 11, 78, ' ', LCYAN|_BLACK);
  146.  
  147.    prints (7, 54, LCYAN|_BLACK, "   Packet:");
  148.    prints (8, 54, LCYAN|_BLACK, "     File:");
  149.    prints (9, 54, LCYAN|_BLACK, "     From:");
  150.    prints (10, 54, LCYAN|_BLACK, "Recv/Sent:");
  151.  
  152.    wh = wopen (12, 0, 24, 79, 0, LGREY|_BLACK, LCYAN|_BLACK);
  153.    wactiv (wh);
  154.    wtitle ("PROCESS TIC FILES", TLEFT, LCYAN|_BLACK);
  155.    wprints (0, 0, YELLOW|_BLACK, " File          Size     Area name            From");
  156.    printc (12, 0, LGREY|_BLACK, '├');
  157.    printc (12, 52, LGREY|_BLACK, '┴');
  158.    printc (12, 79, LGREY|_BLACK, '┤');
  159.    wr = wfindrec (wh);
  160.    wr->srow++;
  161.     wr->row++;
  162.  
  163.    for (d = 0; d < 3; d++) {
  164.       if ( (e_ptrs[cur_event]->echomail & (ECHO_PROT|ECHO_KNOW|ECHO_NORMAL)) ) {
  165.          if (d == 0 && config->prot_filepath[0] && (e_ptrs[cur_event]->echomail & ECHO_PROT))
  166.             inpath = config->prot_filepath;
  167.          if (d == 1 && config->know_filepath[0] && (e_ptrs[cur_event]->echomail & ECHO_KNOW))
  168.             inpath = config->know_filepath;
  169.          if (d == 2 && config->norm_filepath[0] && (e_ptrs[cur_event]->echomail & ECHO_NORMAL))
  170.             inpath = config->norm_filepath;
  171.       }
  172.       else {
  173.          if (d == 0 && config->prot_filepath[0])
  174.             inpath = config->prot_filepath;
  175.          if (d == 1 && config->know_filepath[0])
  176.             inpath = config->know_filepath;
  177.          if (d == 2 && config->norm_filepath[0])
  178.             inpath = config->norm_filepath;
  179.       }
  180.  
  181.       sprintf (filename, "%s*.TIC", inpath);
  182.       if (findfirst (filename, &blk, 0))
  183.          continue;
  184.  
  185.       if (!fi) {
  186.          status_line ("+Processing inbound TICs");
  187.          fi = 1;
  188.       }
  189.  
  190.       for (;;) {
  191.          sprintf (filename, "%s*.TIC", inpath);
  192.          if (findfirst (filename, &blk, 0))
  193.             break;
  194.  
  195.             sprintf (filename, "%s%s", inpath, blk.ff_name);
  196.             fp = fopen (filename, "rt");
  197.          if (fp == NULL)
  198.             continue;
  199.  
  200.          prints (7, 65, YELLOW|_BLACK, blk.ff_name);
  201.          descr[0] = repl[0] = '\0';
  202.          name[0] = area[0] = pw[0] = '\0';
  203.          crc = 0L;
  204.          fzo = fne = fno = fpo = 0;
  205.          ozo = one = ono = opo = 0;
  206.  
  207.          while (fgets (linea, MAX_BUFFERING - 2, fp) != NULL) {
  208.             while (strlen (linea) > 0 && (linea[strlen (linea) - 1] == 0x0D || linea[strlen (linea) - 1] == 0x0A))
  209.                linea[strlen (linea) - 1] = '\0';
  210.  
  211.             if (!strnicmp (linea, "Desc ", 5)) {
  212.                p = &linea[5];
  213.                if (strlen (p) > MAX_DESCRIPTION)
  214.                   p[MAX_DESCRIPTION] = '\0';
  215.                strcpy (descr, p);
  216.                continue;
  217.             }
  218.  
  219.             if ((p = strtok (linea, " ")) == NULL)
  220.                continue;
  221.  
  222.             if (!stricmp (p, "Area")) {
  223.                p = strtok (NULL, " ");
  224.                if (strlen (p) > 19)
  225.                   p[19] = '\0';
  226.                strcpy (area, p);
  227.             }
  228.             else if (!stricmp (p, "From")) {
  229.                     p = strtok (NULL, " ");
  230.                     fzo = config->alias[0].zone;
  231.                fne = config->alias[0].net;
  232.                fno = fpo = 0;
  233.                parse_netnode (p, &fzo, &fne, &fno, &fpo);
  234.                prints (9, 65, YELLOW|_BLACK, "            ");
  235.                if (strlen (p) > 14)
  236.                   p[14] = '\0';
  237.                prints (9, 65, YELLOW|_BLACK, p);
  238.             }
  239.             else if (!stricmp (p, "Origin")) {
  240.                p = strtok (NULL, " ");
  241.                ozo = config->alias[0].zone;
  242.                one = config->alias[0].net;
  243.                ono = opo = 0;
  244.                parse_netnode (p, &ozo, &one, &ono, &opo);
  245.             }
  246.             else if (!stricmp (p, "File")) {
  247.                p = strtok (NULL, " ");
  248.                if (strlen (p) > 12)
  249.                   p[12] = '\0';
  250.                strcpy (name, p);
  251.                prints (8, 65, YELLOW|_BLACK, "            ");
  252.                prints (8, 65, YELLOW|_BLACK, name);
  253.             }
  254.             else if (!stricmp (p, "Replaces")) {
  255.                p = strtok (NULL, " ");
  256.                if (strlen (p) > 12)
  257.                   p[12] = '\0';
  258.                strcpy (repl, p);
  259.             }
  260.             else if (!stricmp (p, "CRC")) {
  261.                if ((p = strtok (NULL, " ")) != NULL)
  262.                   crc = xtol (p);
  263.                     else
  264.                         crc = 0L;
  265.             }
  266.             else if (!stricmp (p, "Pw")) {
  267.                if ((p = strtok (NULL, " ")) != NULL) {
  268.                   if (strlen (p) > 31)
  269.                      p[31] = '\0';
  270.                   strcpy (pw, p);
  271.                }
  272.                else
  273.                   pw[0] = '\0';
  274.             }
  275.          }
  276.  
  277.          sprintf (filename, "%s%s", inpath, name);
  278.          fds = open (filename, O_RDONLY|O_BINARY);
  279.          if (fds != -1 && (pos = filelength (fds)) > 0L) {
  280.             crcf = 0xFFFFFFFFL;
  281.  
  282.             do {
  283.                nf = read (fds, linea, MAX_BUFFERING);
  284.                for (i = 0; i < nf; i++)
  285.                   crcf = Z_32UpdateCRC ((unsigned short)linea[i], crcf);
  286.             } while (nf == 2048);
  287.             close (fds);
  288.  
  289.             crcf = ~crcf;
  290.  
  291.             if (crc != 0L && crcf != crc) {
  292.                fclose (fp);
  293.                status_line ("!%s bad CRC! (%08lX / %08lX)", name, crcf, crc);
  294.                     rename_bad_tics (inpath, blk.ff_name);
  295.                continue;
  296.             }
  297.             }
  298.             else {
  299.             fclose (fp);
  300.             if (fds == -1)
  301.                status_line ("!%s not found in inbound area", name);
  302.             else
  303.                status_line ("!%s zero byte size", name);
  304.                 rename_bad_tics (inpath, blk.ff_name);
  305.             continue;
  306.          }
  307.  
  308.          sprintf (filename, "%d:%d/%d.%d", fzo, fne, fno, fpo);
  309.          sprintf (linea, " %-12.12s  %7ld  %-19.19s  %-24.24s", name, pos, area, filename);
  310.          wputs (linea);
  311.  
  312.          prints (10, 65, YELLOW|_BLACK, "            ");
  313.          sprintf (linea, "%d / %d", ++nrec, nsent);
  314.          prints (10, 65, YELLOW|_BLACK, linea);
  315.  
  316.          rewind (fpcfg);
  317.          found = 0;
  318.  
  319.          while (fread (&tsys.file_name, SIZEOF_FILEAREA, 1, fpcfg) == 1) {
  320.             if (!stricmp (tsys.tic_tag, area)) {
  321.                found = 1;
  322.                break;
  323.             }
  324.          }
  325.  
  326.          if (!found) {
  327.             if (config->tic_newareas_create[0]) {
  328.                zo = config->alias[0].zone;
  329.                ne = config->alias[0].net;
  330.                no = config->alias[0].node;
  331.                     po = config->alias[0].point;
  332.  
  333.                strcpy (linea, config->tic_newareas_create);
  334.                p = strtok (linea, " ");
  335.                if (p != NULL)
  336.                   do {
  337.                      parse_netnode2 (p, &zo, &ne, &no, &po);
  338.                      if (zo == fzo && ne == fne && no == fno && po == fpo) {
  339.                         found = 1;
  340.                         break;
  341.                      }
  342.                   } while ((p = strtok (NULL, " ")) != NULL);
  343.             }
  344.  
  345.             if (!found)
  346.                status_line ("!Unknown area \"%s\" in %s", area, blk.ff_name);
  347.             else {
  348.                i = tsys.file_num;
  349.  
  350.                memset ((char *)&tsys.file_name, 0, SIZEOF_FILEAREA);
  351.                tsys.file_num = i + 1;
  352.                tsys.file_priv = HIDDEN;
  353.                tsys.download_priv = HIDDEN;
  354.                tsys.upload_priv = HIDDEN;
  355.                strcpy (tsys.tic_tag, area);
  356.                strcpy (tsys.file_name, area);
  357.                strcat (tsys.file_name, " (New area)");
  358.  
  359.                mkdir ("FNEWAREA");
  360.  
  361.                if (strlen (area) > 8)
  362.                   area[8] = '\0';
  363.                sprintf (filename, "FNEWAREA\\%s", area);
  364.  
  365.                     if (mkdir (filename) == -1) {
  366.                         i = 0;
  367.                   do {
  368.                      i++;
  369.                      sprintf (filename, "FNEWAREA\\%s.%03d", area, i);
  370.                   } while (mkdir (filename) == -1);
  371.                }
  372.  
  373.                strcpy (area, tsys.tic_tag);
  374.  
  375.                getcwd (tsys.filepath, 25);
  376.                strcat (tsys.filepath, "\\");
  377.                strcat (tsys.filepath, filename);
  378.                strcat (tsys.filepath, "\\");
  379.  
  380.                if (fpo)
  381.                   sprintf (tsys.tic_forward1, "%d:%d/%d.%d ", fzo, fne, fno, fpo);
  382.                else
  383.                   sprintf (tsys.tic_forward1, "%d:%d/%d ", fzo, fne, fno);
  384.                if (config->tic_newareas_link[0])
  385.                   strcat (tsys.tic_forward1, config->tic_newareas_link);
  386.  
  387.  
  388.                fseek (fpcfg, 0L, SEEK_END);
  389.                fwrite (&tsys.file_name, SIZEOF_FILEAREA, 1, fpcfg);
  390.             }
  391.          }
  392.  
  393.          if (found) {
  394.             found = 0;
  395.             n_forw = 0;
  396.  
  397.             zo = config->alias[0].zone;
  398.             ne = config->alias[0].net;
  399.                 no = po = 0;
  400.  
  401.             strcpy (linea, tsys.tic_forward1);
  402.             if ((p = strtok (linea, " ")) != NULL)
  403.                do {
  404.                   forward[n_forw].passive = forward[n_forw].receive = forward[n_forw].send = 0;
  405.                   if (*p == '<') {
  406.                      forward[n_forw].send = 1;
  407.                      p++;
  408.                   }
  409.                   if (*p == '>') {
  410.                      forward[n_forw].receive = 1;
  411.                      p++;
  412.                   }
  413.                   if (*p == '!') {
  414.                      forward[n_forw].passive = 1;
  415.                      p++;
  416.                   }
  417.                   parse_netnode2 (p, &zo, &ne, &no, &po);
  418.                   if (!forward[n_forw].passive && !forward[n_forw].receive && zo == fzo && ne == fne && no == fno && po == fpo)
  419.                      found = 1;
  420.                   forward[n_forw].zone = zo;
  421.                   forward[n_forw].net = ne;
  422.                   forward[n_forw].node = no;
  423.                   forward[n_forw].point = po;
  424.                   n_forw++;
  425.                } while ((p = strtok (NULL, " ")) != NULL);
  426.  
  427.             strcpy (linea, tsys.tic_forward2);
  428.             if ((p = strtok (linea, " ")) != NULL)
  429.                do {
  430.                   forward[n_forw].passive = forward[n_forw].receive = forward[n_forw].send = 0;
  431.                   if (*p == '<') {
  432.                      forward[n_forw].send = 1;
  433.                             p++;
  434.                         }
  435.                   if (*p == '>') {
  436.                      forward[n_forw].receive = 1;
  437.                      p++;
  438.                   }
  439.                   if (*p == '!') {
  440.                      forward[n_forw].passive = 1;
  441.                      p++;
  442.                   }
  443.                   parse_netnode2 (p, &zo, &ne, &no, &po);
  444.                   if (!forward[n_forw].passive && !forward[n_forw].receive && zo == fzo && ne == fne && no == fno && po == fpo)
  445.                      found = 1;
  446.                   forward[n_forw].zone = zo;
  447.                   forward[n_forw].net = ne;
  448.                   forward[n_forw].node = no;
  449.                   forward[n_forw].point = po;
  450.                   n_forw++;
  451.                } while ((p = strtok (NULL, " ")) != NULL);
  452.  
  453.             strcpy (linea, tsys.tic_forward3);
  454.             if ((p = strtok (linea, " ")) != NULL)
  455.                do {
  456.                   forward[n_forw].passive = forward[n_forw].receive = forward[n_forw].send = 0;
  457.                   if (*p == '<') {
  458.                      forward[n_forw].send = 1;
  459.                      p++;
  460.                   }
  461.                   if (*p == '>') {
  462.                      forward[n_forw].receive = 1;
  463.                      p++;
  464.                   }
  465.                   if (*p == '!') {
  466.                      forward[n_forw].passive = 1;
  467.                             p++;
  468.                         }
  469.                   parse_netnode2 (p, &zo, &ne, &no, &po);
  470.                   if (!forward[n_forw].passive && !forward[n_forw].receive && zo == fzo && ne == fne && no == fno && po == fpo)
  471.                      found = 1;
  472.                   forward[n_forw].zone = zo;
  473.                   forward[n_forw].net = ne;
  474.                   forward[n_forw].node = no;
  475.                   forward[n_forw].point = po;
  476.                   n_forw++;
  477.                } while ((p = strtok (NULL, " ")) != NULL);
  478.  
  479.             if (!found)
  480.                status_line ("!Bad origin node %d:%d/%d.%d", fzo, fne, fno, fpo);
  481.             else if (found == 1) {
  482.                if (!get_bbs_record (fzo, fne, fno, fpo)) {
  483.                   wputs ("Bad Node\n");
  484.                   status_line ("!Node %d:%d/%d.%d not found", fzo, fne, fno, fpo);
  485.                   fclose (fp);
  486.                         rename_bad_tics (inpath, blk.ff_name);
  487.                   continue;
  488.                }
  489.  
  490.                if (nodelist.pw_tic[0] && stricmp (pw, nodelist.pw_tic)) {
  491.                   wputs ("Bad Pwd\n");
  492.                   status_line ("!Bad password from %d:%d/%d.%d", fzo, fne, fno, fpo);
  493.                   fclose (fp);
  494.                         rename_bad_tics (inpath, blk.ff_name);
  495.                         continue;
  496.                     }
  497.  
  498.                     strcpy (dpath, tsys.filepath);
  499.  
  500.                     if (repl[0]) {
  501.                         sprintf (filename, "%s%s", dpath, repl);
  502.                         if (unlink (filename) == -1)
  503.                             status_line ("*%s doesn't exist", filename);
  504.                         else
  505.                             status_line ("*Replaces: %s", repl);
  506.  
  507.                         sprintf (filename, "%sFILES.BBS", sys.filepath);
  508.                         sprintf (linea, "%sFILES.BBS", sys.filepath);
  509.  
  510.                         rename (filename, linea);
  511.                         godelete = 0;
  512.  
  513.                         fpd = fopen (filename, "wt");
  514.                         fps = fopen (linea, "rt");
  515.  
  516.                         while (fgets (linea, MAX_BUFFERING - 2, fps) != NULL) {
  517.                             if (godelete) {
  518.                                 if (linea[1] == '>')
  519.                                     continue;
  520.                                 else
  521.                                     godelete = 0;
  522.                             }
  523.                             if (!strncmp (linea, repl, strlen (repl))) {
  524.                                 godelete = 1;
  525.                                 continue;
  526.                             }
  527.                             fputs (linea, fpd);
  528.                         }
  529.  
  530.                         fclose (fps);
  531.                         fclose (fpd);
  532.                     }
  533.  
  534.                     status_line (" Moving %s%s to %s%s", inpath, name, dpath, name);
  535.  
  536. //               if (inpath[1] == ':' && dpath[1] == ':' && toupper (inpath[0]) == toupper (dpath[0])) {
  537. //                  sprintf (linea, "%s%s", dpath, name);
  538. //                  sprintf (filename, "%s%s", inpath, name);
  539. //                  unlink (linea);
  540. //                  rename (filename, linea);
  541. //               }
  542. //               else {
  543.                     sprintf (filename, "%s%s", dpath, name);
  544.                     fdd = open (filename, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
  545.  
  546.                     sprintf (filename, "%s%s", inpath, name);
  547.                     fds = open (filename, O_RDONLY|O_BINARY);
  548.  
  549.                     do {
  550.                         i = read (fds, linea, MAX_BUFFERING);
  551.                         if (write (fdd, linea, i) != i) {
  552.                             found = 0;
  553.                             status_line ("!Error during copy");
  554.                             break;
  555.                         }
  556.  
  557.                         t = ((float)filelength (fdd) * (float)100) / (float)filelength (fds);
  558.                         sprintf (linea, "\b\b\b\b\b%04.1f%%", t);
  559.                         wputs (linea);
  560.                         time_release ();
  561.                     } while (i == MAX_BUFFERING);
  562.  
  563.                     close (fdd);
  564.                     close (fds);
  565.  
  566.                     if (!found) {
  567.                         sprintf (filename, "%s%s", dpath, name);
  568.                         unlink (filename);
  569.                     }
  570. //               }
  571.  
  572.                     if (found) {
  573.                         unlink (filename);
  574.  
  575.                         status_line (":AREA: %s", area);
  576.                         status_line (":%s", descr);
  577.                         status_line (":Originated by %d:%d/%d.%d", ozo, one, ono, opo);
  578.  
  579.                         if (!stricmp (tsys.filepath, dpath) && tsys.filelist[0])
  580.                             fpd = fopen (tsys.filelist, "ab");
  581.                         else {
  582.                             sprintf (filename, "%sFILES.BBS", dpath);
  583.                             fpd = fopen (filename, "ab");
  584.                         }
  585.                         sprintf (filename, "%c  0%c ", config->dl_counter_limits[0], config->dl_counter_limits[1]);
  586.                         fprintf (fpd, "%-12.12s %s%s\r\n", strupr (name), config->keep_dl_count ? filename : "", descr);
  587.                         fclose (fpd);
  588.  
  589.                         crc = time (NULL);
  590.                         tim = gmtime (&crc);
  591.  
  592.                         for (nf = 0; nf < n_forw; nf++) {
  593.                             if (forward[nf].passive || forward[nf].send)
  594.                                 continue;
  595.  
  596.                             zo = forward[nf].zone;
  597.                             ne = forward[nf].net;
  598.                             no = forward[nf].node;
  599.                             po = forward[nf].point;
  600.  
  601.                             if (zo == fzo && ne == fne && no == fno && po == fpo)
  602.                                 continue;
  603.  
  604.                             if (!get_bbs_record (zo, ne, no, po))
  605.                                 dpw[0] = '\0';
  606.                             else
  607.                                 strcpy (dpw, nodelist.pw_tic);
  608.  
  609.                             rewind (fp);
  610.                             seen = 0;
  611.  
  612.                             while (fgets (linea, 1020, fp) != NULL) {
  613.                                 while (strlen (linea) > 0 && (linea[strlen (linea) - 1] == 0x0D || linea[strlen (linea) - 1] == 0x0A))
  614.                                     linea[strlen (linea) - 1] = '\0';
  615.  
  616.                                 p = strtok (linea, " ");
  617.                                 if (stricmp (p, "Seenby"))
  618.                                     continue;
  619.  
  620.                                 p = strtok (NULL, " ");
  621.                                 ozo = config->alias[0].zone;
  622.                                 one = config->alias[0].net;
  623.                                 ono = opo = 0;
  624.                                 parse_netnode (p, &ozo, &one, &ono, &opo);
  625.  
  626.                                 if (zo == ozo && ne == one && no == ono && po == opo) {
  627.                                     seen = 1;
  628.                                     break;
  629.                                 }
  630.                             }
  631.  
  632.                             p = "Normal";
  633.  
  634.                             if (!seen && p != NULL) {
  635.                                 rewind (fp);
  636.  
  637.                                 status_line ("+Sending %s to %d:%d/%d.%d %s", name, zo, ne, no, po, p);
  638.                                 if (po) {
  639.                                     sprintf (filename, "%s%04X%04X.PNT", HoldAreaNameMungeCreate (zo), ne, no);
  640.                                     mkdir (filename);
  641.                                 }
  642.  
  643.                                 do {
  644.                                     pos = time (NULL) % 1000000L;
  645.                                     if (po)
  646.                                         sprintf (filename, "%s%04X%04X.PNT\\LB%06lu.TIC", HoldAreaNameMungeCreate (zo), ne, no, pos);
  647.                                     else
  648.                                         sprintf (filename, "%sLB%06lu.TIC", HoldAreaNameMungeCreate (zo), pos);
  649.                                 } while (dexists (filename));
  650.  
  651.                                 fpd = fopen (filename, "wb");
  652.  
  653.                                 seen = 0;
  654.                                 path = 0;
  655.  
  656.                                 while (fgets (linea, 1020, fp) != NULL) {
  657.                                     while (strlen (linea) > 0 && (linea[strlen (linea) - 1] == 0x0D || linea[strlen (linea) - 1] == 0x0A))
  658.                                         linea[strlen (linea) - 1] = '\0';
  659.  
  660.                                     if (path == 1 && strnicmp (linea, "Path ", 5)) {
  661.                                         if ((i = nodelist.tic_akainfo) > 0)
  662.                                             i--;
  663.                                         fprintf (fpd, "Path %d:%d/%d %ld %s %s %02d %02d:%02d:%02d %d GMT\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node, crc, wtext[tim->tm_wday], mtext[tim->tm_mon], tim->tm_mday, tim->tm_hour, tim->tm_min, tim->tm_sec, tim->tm_year + 1900);
  664.                                         path = 2;
  665.                                     }
  666.  
  667.                                     if (seen == 1 && strnicmp (linea, "Seenby ", 7)) {
  668.                                         for (i = 0; i < MAX_ALIAS && config->alias[i].net; i++) {
  669.                                         if (config->alias[i].zone == config->alias[nodelist.tic_akainfo-1].zone)
  670.                                             if (config->alias[i].point)
  671.                                                 fprintf (fpd, "Seenby %d:%d/%d.%d\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node, config->alias[i].point);
  672.                                             else
  673.                                                 fprintf (fpd, "Seenby %d:%d/%d\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node);
  674.                                         }
  675.                                         { int nf;
  676.                                         for (nf = 0; nf < n_forw; nf++) {
  677.  
  678.                                             int zos, nes, nos, pos;
  679.  
  680.                                             if (forward[nf].passive || forward[nf].send)
  681.                                                 continue;
  682.  
  683.                                             zos = forward[nf].zone;
  684.                                             nes = forward[nf].net;
  685.                                             nos = forward[nf].node;
  686.                                             pos = forward[nf].point;
  687.  
  688.                                             if (zos == fzo && nes == fne && nos == fno && pos == fpo)
  689.                                                 continue;
  690.  
  691.                                             if (zos != zo)
  692.                                                 continue;
  693.  
  694.                                             if (pos)
  695.                                                 fprintf (fpd, "Seenby %d:%d/%d.%d\r\n", zos, nes, nos, pos);
  696.                                             else
  697.                                                 fprintf (fpd, "Seenby %d:%d/%d\r\n", zos, nes, nos);
  698.                                         }
  699.                                         }
  700.  
  701.                                         seen = 2;
  702.                                     }
  703.  
  704.                                     if (!strnicmp (linea, "From ", 5)) {
  705.                                         if ((i = nodelist.tic_akainfo) > 0)
  706.                                             i--;
  707.                                         fprintf (fpd, "From %d:%d/%d\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node);
  708.                                     }
  709.                                     else if (!strnicmp (linea, "Created by ", 11))
  710.                                         fprintf (fpd, "Created by %s (C) Copyright Marco Maccaferri - 1989-95\r\n", VERSION);
  711.                                     else if (!strnicmp (linea, "Pw ", 3))
  712.                                         fprintf (fpd, "Pw %s\r\n", strupr (dpw));
  713.                                     else
  714.                                           if (strnicmp(linea, "To ",3))
  715.                                             fprintf (fpd, "%s\r\n", linea);
  716.  
  717.                                     if (!strnicmp (linea, "Path ", 5))
  718.                                         path = 1;
  719.                                     else if (!strnicmp (linea, "Seenby ", 7))
  720.                                         seen = 1;
  721.                                 }
  722.  
  723.                                 if (path == 0) {
  724.                                     if ((i = nodelist.tic_akainfo) > 0)
  725.                                         i--;
  726.                                     if (config->alias[i].point)
  727.                                         fprintf (fpd, "Path %d:%d/%d.%d %ld %s %s %02d %02d:%02d:%02d %d GMT\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node, config->alias[i].point, crc, wtext[tim->tm_wday], mtext[tim->tm_mon], tim->tm_mday, tim->tm_hour, tim->tm_min, tim->tm_sec, tim->tm_year + 1900);
  728.                                     else
  729.                                         fprintf (fpd, "Path %d:%d/%d %ld %s %s %02d %02d:%02d:%02d %d GMT\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node, crc, wtext[tim->tm_wday], mtext[tim->tm_mon], tim->tm_mday, tim->tm_hour, tim->tm_min, tim->tm_sec, tim->tm_year + 1900);
  730.                                 }
  731.  
  732.                                 if (seen == 0) {
  733. //                                    for (i = 0; i < MAX_ALIAS && config->alias[i].net; i++){
  734.                                     if ((i = nodelist.tic_akainfo) > 0)
  735.                                         i--;
  736.                                         if (config->alias[i].point)
  737.                                             fprintf (fpd, "Seenby %d:%d/%d.%d\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node, config->alias[i].point);
  738.                                         else
  739.                                             fprintf (fpd, "Seenby %d:%d/%d\r\n", config->alias[i].zone, config->alias[i].net, config->alias[i].node);
  740. //                                    }
  741.                                     { int nf;
  742.                                     for (nf = 0; nf < n_forw; nf++) {
  743.  
  744.                                         int zos, nes, nos, pos;
  745.  
  746.                                         if (forward[nf].passive || forward[nf].send)
  747.                                             continue;
  748.  
  749.                                         zos = forward[nf].zone;
  750.                                         nes = forward[nf].net;
  751.                                         nos = forward[nf].node;
  752.                                         pos = forward[nf].point;
  753.  
  754.                                         if (zos == fzo && nes == fne && nos == fno && pos == fpo)
  755.                                             continue;
  756.  
  757.                                         if (zos != zo)
  758.                                             continue;
  759.  
  760.                                         if (pos)
  761.                                             fprintf (fpd, "Seenby %d:%d/%d.%d\r\n", zos, nes, nos, pos);
  762.                                         else
  763.                                             fprintf (fpd, "Seenby %d:%d/%d\r\n", zos, nes, nos);
  764.                                     }
  765.                                     }
  766.                                 //    if (po)
  767.                                 //        fprintf (fpd, "Seenby %d:%d/%d.%d\r\n", zo, ne, no, po);
  768.                                 //    else
  769.                                 //        fprintf (fpd, "Seenby %d:%d/%d\r\n", zo, ne, no);
  770.                                 }
  771.  
  772.  
  773.                                 fclose (fpd);
  774.  
  775.                                 if (po)
  776.                                     sprintf (filename, "%s%04X%04X.PNT\\%08X.%cLO", HoldAreaNameMungeCreate (zo), ne, no, po, check_route_flag (zo, ne, no, po));
  777.                                 else
  778.                                     sprintf (filename, "%s%04X%04X.%cLO", HoldAreaNameMungeCreate (zo), ne, no, check_route_flag (zo, ne, no, 0));
  779.  
  780.                                 fpd = fopen (filename, "at");
  781.                                 fprintf (fpd, "%s%s\n", dpath, name);
  782.                                 if (po)
  783.                                     fprintf (fpd, "^%s%04X%04X.PNT\\LB%06lu.TIC\n", HoldAreaNameMungeCreate (zo), ne, no, pos);
  784.                                 else
  785.                                     fprintf (fpd, "^%sLB%06lu.TIC\n", HoldAreaNameMungeCreate (zo), pos);
  786.                                 fclose (fpd);
  787.  
  788.                                 prints (10, 65, YELLOW|_BLACK, "            ");
  789.                                 sprintf (linea, "%d / %d", nrec, ++nsent);
  790.                                 prints (10, 65, YELLOW|_BLACK, linea);
  791.                             }
  792.                         }
  793.                     }
  794.                 }
  795.             }
  796.  
  797.             fclose (fp);
  798.  
  799.             if (found) {
  800.                 sprintf (filename, "%s%s", inpath, blk.ff_name);
  801.                 status_line ("+Deleting %s", filename);
  802.                 unlink (filename);
  803.             }
  804.             else
  805.                 rename_bad_tics (inpath, blk.ff_name);
  806.  
  807.             wputs ("\n");
  808.         }
  809.     }
  810.  
  811.     fclose (fpcfg);
  812.     wr->srow--;
  813.     wclose ();
  814.  
  815.     free (descr);
  816.     free (linea);
  817.  
  818.     if (!fi)
  819.         status_line (" No inbound TIC's to process");
  820.  
  821.     free (forward);
  822.     idle_system ();
  823. }
  824.  
  825. /*
  826.  
  827.                         if (stricmp (pw, dpw)) {
  828.                             status_line ("!Bad password from %d:%d/%d.%d", fzo, fne, fno, fpo);
  829.                             found = -1;
  830.                         }
  831.                         else {
  832.                             p = strtok (NULL, " ");
  833.                             if (strlen (p) > 9)
  834.                                 p[9] = '\0';
  835.                             strcpy (dflag, p);
  836.                             found = 1;
  837.                         }
  838.  
  839.                         break;
  840.                     }
  841. */
  842.  
  843. static void rename_bad_tics (path, name)
  844. char *path, *name;
  845. {
  846.     char filename[80], linea[80], c;
  847.  
  848.     c=name[8];
  849.     name[8] = '\0';
  850.     sprintf (filename, "%s%s.TIC", path, name);
  851.     sprintf (linea, "%s%s.BAD", path, name);
  852.  
  853.     rename (filename, linea);
  854.  
  855.     status_line("!Renamed %s to %s",filename,linea);
  856.  
  857. //   name[8] = 'T';
  858.     name[8] = c;
  859. }
  860.  
  861. //  2:332/402.0 Q 43 SYSOP_CHAT.ITA
  862.  
  863. void rescan_areas (void)
  864. {
  865.    FILE *fp;
  866.    int fd, wh, zo, ne, no, po, board, adjtime;
  867.    char linea[128], *p, *tag, type;
  868.    struct _wrec_t *wr;
  869.    struct date datep;
  870.    struct time timep;
  871.    struct _pkthdr2 pkthdr;
  872.  
  873.    if ((fp = fopen ("RESCAN.LOG", "rt")) == NULL)
  874.       return;
  875.  
  876.    status_line ("+Rescan message base");
  877.    local_status ("Rescan");
  878.    scan_system ();
  879.  
  880.    wh = wopen (12, 0, 24, 79, 0, LGREY|_BLACK, LCYAN|_BLACK);
  881.    wactiv (wh);
  882.     wtitle ("RESCAN ECHOMAIL", TLEFT, LCYAN|_BLACK);
  883.    wprints (0, 0, YELLOW|_BLACK, " Num.  Area tag               Base         Forward to");
  884.    printc (12, 0, LGREY|_BLACK, '├');
  885.    printc (12, 52, LGREY|_BLACK, '┴');
  886.    printc (12, 79, LGREY|_BLACK, '┤');
  887.    wr = wfindrec (wh);
  888.    wr->srow++;
  889.    wr->row++;
  890.  
  891.    build_aidx ();
  892.    totaltime = timerset (0);
  893.  
  894.    while (fgets (linea, 70, fp) != NULL) {
  895.       while (strlen (linea) > 0 && (linea[strlen (linea) - 1] == 0x0D || linea[strlen (linea) - 1] == 0x0A))
  896.          linea[strlen (linea) -1] = '\0';
  897.  
  898.       if ((p = strtok (linea, " ")) == NULL)
  899.          continue;
  900.       zo = config->alias[0].zone;
  901.       ne = config->alias[0].net;
  902.       no = po = 0;
  903.       parse_netnode (p, &zo, &ne, &no, &po);
  904.  
  905.       memset ((char *)&sys, 0, sizeof (struct _sys));
  906.  
  907.       if ((p = strtok (NULL, " ")) == NULL)
  908.          continue;
  909.       type = *p;
  910.  
  911.       if ((p = strtok (NULL, " ")) == NULL)
  912.          continue;
  913.       if (type == 'S' || type == 'M')
  914.          strcpy (sys.msg_path, p);
  915.       else if (type == 'Q' || type == 'P' || type == 'G')
  916.             board = atoi (p);
  917.  
  918.       if ((tag = strtok (NULL, " ")) == NULL)
  919.          continue;
  920.  
  921.       if (strlen (tag) > 31)
  922.          tag[31] = '\0';
  923.       strcpy (sys.echotag, strupr (tag));
  924.  
  925.       if (strlen (tag) > 14)
  926.          tag[14] = '\0';
  927.       prints (8, 65, YELLOW|_BLACK, tag);
  928.  
  929.       if (po)
  930.          sprintf (linea, "%s%04X%04X.PNT\\%08X.OUT", HoldAreaNameMungeCreate (zo), ne, no, po);
  931.       else
  932.          sprintf (linea, "%s%04X%04X.OUT", HoldAreaNameMungeCreate (zo), ne, no);
  933.       fd = open (linea, O_RDWR|O_BINARY);
  934.       if (fd != -1) {
  935.          if (filelength (fd) == 0L) {
  936.             close (fd);
  937.             unlink (linea);
  938.             adjtime = 1;
  939.          }
  940.          else {
  941.             close (fd);
  942.             adjtime = 0;
  943.          }
  944.       }
  945.       else
  946.          adjtime = 1;
  947.  
  948.       if (type == 'Q')
  949.          quick_rescan_echomail (board, zo, ne, no, po, 0);
  950.         else if (type == 'G')
  951.             quick_rescan_echomail (board, zo, ne, no, po, 1);
  952.         else if (type == 'S') {
  953.             sys.squish = 1;
  954.             squish_scan_message_base (0, sys.msg_path, 0);
  955.             if (sq_ptr != NULL) {
  956.                 while (MsgLock (sq_ptr) == -1)
  957.                     ;
  958.                 squish_rescan_echomail (sys.echotag, zo, ne, no, po);
  959.  
  960.                 MsgUnlock (sq_ptr);
  961.                 MsgCloseArea (sq_ptr);
  962.                 sq_ptr = NULL;
  963.             }
  964.         }
  965.         else if (type == 'M') {
  966.             scan_message_base (0, 0);
  967.             fido_rescan_echomail (sys.echotag, zo, ne, no, po);
  968.         }
  969.         else if (type == 'P')
  970.             pip_rescan_echomail (board, sys.echotag, zo, ne, no, po);
  971.  
  972.         if (adjtime) {
  973.             gettime (&timep);
  974.             getdate (&datep);
  975.  
  976.             fd = open (linea, O_RDWR|O_BINARY);
  977.             if (fd != -1) {
  978.                 if (filelength (fd) == 0L) {
  979.                     close (fd);
  980.                     unlink (linea);
  981.                 }
  982.                 else {
  983.                     read (fd, (char *)&pkthdr, sizeof (struct _pkthdr2));
  984.                     pkthdr.hour = timep.ti_hour;
  985.                     pkthdr.minute = timep.ti_min;
  986.                     pkthdr.second = timep.ti_sec;
  987.                     pkthdr.year = datep.da_year;
  988.                     pkthdr.month = datep.da_mon - 1;
  989.                     pkthdr.day = datep.da_day;
  990.                     lseek (fd, 0L, SEEK_SET);
  991.                     write (fd, (char *)&pkthdr, sizeof (struct _pkthdr2));
  992.                     close (fd);
  993.                 }
  994.             }
  995.         }
  996.     }
  997.  
  998.     if (sq_ptr != NULL) {
  999.         MsgUnlock (sq_ptr);
  1000.         MsgCloseArea (sq_ptr);
  1001.         sq_ptr = NULL;
  1002.     }
  1003.  
  1004.     if (aidx != NULL)
  1005.         free (aidx);
  1006.     if (akainfo != NULL)
  1007.       free (akainfo);
  1008.  
  1009.    fclose (fp);
  1010.    wclose ();
  1011.  
  1012.    memset ((char *)&sys, 0, sizeof (struct _sys));
  1013.    unlink ("RESCAN.LOG");
  1014. }
  1015.  
  1016. struct _msgzone {
  1017.    short dest_zone;
  1018.    short orig_zone;
  1019.    short dest_point;
  1020.    short orig_point;
  1021. };
  1022.  
  1023. void track_inbound_messages (FILE *fpd, struct _msg *msgt, int fzone)
  1024. {
  1025.     int i;
  1026.     if (!(msgt->attr & MSGLOCAL)) {
  1027.         if (fzone == 0)
  1028.             fzone = config->alias[0].zone;
  1029.         for (i = 0;i < MAX_ALIAS && config->alias[i].net; i++)
  1030.             if (config->alias[i].zone == fzone && config->alias[i].net == msgt->orig_net && config->alias[i].node == msgt->orig)
  1031.                 break;
  1032.         if (i < MAX_ALIAS && config->alias[i].net)
  1033.             return;
  1034.         if (!get_bbs_record (fzone, msgt->orig_net, msgt->orig, 0)) {
  1035.             status_line ("!Unlisted node: %d:%d/%d", fzone, msgt->orig_net, msgt->orig);
  1036.             mprintf (fpd, "==========================================================================\r\n");
  1037.             mprintf (fpd, "WARNING [%s]: The originating address on this message was\r\n", VERSION);
  1038.             mprintf (fpd, "=not= listed in the NodeList at %d:%d/%d.  Please ensure that you do\r\n", config->alias[0].zone, config->alias[0].net, config->alias[0].node);
  1039.             mprintf (fpd, "not send a reply via this system, as it will be bounced as undeliverable.\r\n");
  1040.             mprintf (fpd, "==========================================================================\r\n");
  1041.         }
  1042.     }
  1043. }
  1044.  
  1045. int track_outbound_messages (FILE *fpd, struct _msg *msgt, int fzone, int fpoint, int tzone, int tpoint)
  1046. {
  1047.     FILE *fp;
  1048.     int i, aka, m;
  1049.     char filename[80], buffer[2050];
  1050.     struct _msg tmsg;
  1051.     struct _msgzone mz;
  1052.  
  1053.     if (fzone == 0)
  1054.         fzone = config->alias[0].zone;
  1055.     if (tzone == 0)
  1056.         tzone = config->alias[0].zone;
  1057.  
  1058.     if (get_bbs_record (tzone, msgt->dest_net, msgt->dest, 0))
  1059.         return (1);
  1060.  
  1061. /*    for (i = 0;i < MAX_ALIAS && config->alias[i].net; i++)
  1062.         if (config->alias[i].zone == fzone && config->alias[i].net == msgt->orig_net && config->alias[i].node == msgt->orig)
  1063.             break;
  1064.     if (i < MAX_ALIAS && config->alias[i].net)
  1065.         return (1);
  1066. */
  1067. // Inizia mio patch
  1068.     for (i = 0;i < MAX_ALIAS && config->alias[i].net; i++)
  1069.         if (config->alias[i].zone == tzone && config->alias[i].net == msgt->dest_net && config->alias[i].node == msgt->dest)
  1070.             break;
  1071.     if (i < MAX_ALIAS && config->alias[i].net)
  1072.         return (1);
  1073.  
  1074.     for (i = 0;i < MAX_ALIAS && config->alias[i].net; i++)
  1075.         if (config->alias[i].zone == fzone && config->alias[i].net == msgt->orig_net && config->alias[i].node == msgt->orig)
  1076.             break;
  1077.     if (!(i < MAX_ALIAS && config->alias[i].net)){
  1078.         if (!get_bbs_record (fzone, msgt->orig_net, msgt->orig, 0))
  1079.             return (0);
  1080.         }
  1081. // Fino qui.
  1082. /*         if (!get_bbs_record (fzone, msgt->orig_net, msgt->orig, 0))
  1083.             return (0);
  1084. */
  1085.  
  1086.     for (i = 0;i < MAX_ALIAS && config->alias[i].net; i++)
  1087.         if (config->alias[i].zone == fzone)
  1088.             break;
  1089.     if (i < MAX_ALIAS && config->alias[i].net)
  1090.         aka = i;
  1091.     else
  1092.         aka = 0;
  1093.  
  1094.     memset (&tmsg, 0, sizeof (struct _msg));
  1095.     sprintf (filename, "%s%d.MSG", sys.msg_path, ++last_msg);
  1096.  
  1097.     status_line ("!Destination node %d:%d/%d unlisted", tzone, msgt->dest_net, msgt->dest);
  1098.  
  1099.     fp = fopen (filename, "wb");
  1100.     if (fp == NULL)
  1101.           return (0);
  1102.  
  1103.     tmsg.attr |= MSGPRIVATE;
  1104.  
  1105.     if (get_bbs_record (fzone, msgt->orig_net, msgt->orig, 0)) {
  1106.         mz.dest_zone = fzone;
  1107.         tmsg.dest_net = msgt->orig_net;
  1108.         tmsg.dest = msgt->orig;
  1109.         mz.dest_point = fpoint;
  1110.    }
  1111.    else {
  1112.       mz.dest_zone = config->alias[0].zone;
  1113.       tmsg.dest_net = config->alias[0].net;
  1114.       tmsg.dest = config->alias[0].node;
  1115.       mz.dest_point = config->alias[0].point;
  1116.    }
  1117.  
  1118.    mz.orig_zone = config->alias[aka].zone;
  1119.    tmsg.orig_net = config->alias[aka].net;
  1120.    tmsg.orig = config->alias[aka].node;
  1121.    mz.orig_point = config->alias[aka].point;
  1122.    memcpy (&tmsg.date_written, &mz, sizeof (struct _msgzone));
  1123.  
  1124.    strcpy (tmsg.from, VERSION);
  1125.    strcpy (tmsg.to, msgt->from);
  1126.    sprintf (tmsg.subj, "Netmail bounced by %d:%d/%d", config->alias[aka].zone, config->alias[aka].net, config->alias[aka].node);
  1127.    data (tmsg.date);
  1128.  
  1129.    if (fwrite ((char *)&tmsg, sizeof(struct _msg), 1, fp) != 1)
  1130.       return (0);
  1131.  
  1132.    if (config->alias[aka].point)
  1133.       fprintf (fp, "\001FMPT %d\r\n", config->alias[aka].point);
  1134.    if (fpoint)
  1135.       fprintf (fp, msgtxt[M_TOPT], fpoint);
  1136.    if (mz.dest_zone != config->alias[0].zone || mz.dest_zone != mz.orig_zone)
  1137.       fprintf (fp, msgtxt[M_INTL], mz.dest_zone, tmsg.dest_net, tmsg.dest, mz.orig_zone, tmsg.orig_net, tmsg.orig);
  1138.    fprintf (fp, msgtxt[M_MSGID], mz.orig_zone, tmsg.orig_net, tmsg.orig, mz.orig_point, time (NULL));
  1139.  
  1140.    fprintf (fp, "The destination address on the following message was =not= listed in the\r\n");
  1141.    fprintf (fp, "NodeList at %d:%d/%d. The message is, therefore, being returned as\r\n", config->alias[aka].zone, config->alias[aka].net, config->alias[aka].node);
  1142.    fprintf (fp, "undeliverable.  Sorry for any inconvenience.\r\n\r\n");
  1143.  
  1144.    fprintf (fp, "%s - Sysop, %d:%d/%d\r\n\r\n", config->sysop, config->alias[aka].zone, config->alias[aka].net, config->alias[aka].node);
  1145.  
  1146.    fprintf (fp, "--------------  b o u n c e d   m e s s a g e   f o l l o w s  --------------\r\n\r\n");
  1147.  
  1148.    fprintf (fp, "Date:  %s\r\n", msgt->date);
  1149.    fprintf (fp, "From:  %s (%d:%d/%d.%d)\r\n", msgt->from, fzone, msgt->orig_net, msgt->orig, fpoint);
  1150.    fprintf (fp, "To:    %s (%d:%d/%d.%d)\r\n", msgt->to, tzone, msgt->dest_net, msgt->dest, tpoint);
  1151.    fprintf (fp, "Subj:  %s\r\n\r\n", msgt->subj);
  1152.  
  1153.    mseek (fpd, 0L, SEEK_SET);
  1154.    do {
  1155.       i = mread (buffer, 1, 2048, fpd);
  1156.       buffer[2048] = '\0';
  1157.       for (m = 0; m < i; m++) {
  1158.          if (buffer[m] == 0x1A)
  1159.             buffer[m] = ' ';
  1160.          if (buffer[m] == 0x01)
  1161.             buffer[m] = '@';
  1162.       }
  1163.       if (strstr (buffer, "--- ") != NULL) {
  1164.          strsrep (buffer, "\n--- ", "\n-+- ");
  1165.          strsrep (buffer, "\r--- ", "\r-+- ");
  1166.       }
  1167.       if (fwrite (buffer, 1, i, fp) != i)
  1168.          return (0);
  1169.    } while (i == 2048);
  1170.  
  1171.    fprintf (fp, "\r\n---------------  e n d   o f   b o u n c e d   m e s s a g e  ---------------\r\n\r\n");
  1172.    put_tearline (fp);
  1173.  
  1174.    fputc ('\0', fp);
  1175.    fclose (fp);
  1176.  
  1177.    return (0);
  1178. }
  1179.  
  1180. int check_board_not_used (char goldbase, FILE *fp)
  1181. {
  1182.    int fd, board = 1;
  1183.    char filename[128], *location;
  1184.    struct _sys tsys;
  1185.  
  1186.    sprintf (filename, SYSMSG_PATH, config->sys_path);
  1187.    if ((fd = sh_open (filename, SH_DENYNONE, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1)
  1188.       return (0);
  1189.  
  1190.    if (fp != NULL) {
  1191.       rewind (fp);
  1192.  
  1193.       while (fgets (filename, 120, fp) != NULL) {
  1194.          if (filename[0] == ';')
  1195.             continue;
  1196.          while (filename[strlen (filename) - 1] == 0x0D || filename[strlen (filename) - 1] == 0x0A || filename[strlen (filename) - 1] == ' ')
  1197.             filename[strlen (filename) - 1] = '\0';
  1198.  
  1199.          if ((location = strtok (filename, " ")) == NULL)
  1200.             continue;
  1201.          location = strbtrim (location);
  1202.  
  1203.          if (goldbase) {
  1204.             if (toupper (location[0]) == 'G' && isdigit (location[1])) {
  1205.                if (atoi (++location) >= board)
  1206.                   board = atoi (location) + 1;
  1207.             }
  1208.          }
  1209.          else {
  1210.             if (isdigit (*location)) {
  1211.                if (atoi (location) >= board)
  1212.                   board = atoi (location) + 1;
  1213.             }
  1214.          }
  1215.       }
  1216.    }
  1217.  
  1218.    while (read (fd, &tsys, SIZEOF_MSGAREA) == SIZEOF_MSGAREA) {
  1219.       if (goldbase) {
  1220.          if (tsys.gold_board == board) {
  1221.             board++;
  1222.             lseek (fd, 0L, SEEK_SET);
  1223.          }
  1224.       }
  1225.       else {
  1226.          if (tsys.quick_board == board) {
  1227.             board++;
  1228.             lseek (fd, 0L, SEEK_SET);
  1229.          }
  1230.       }
  1231.    }
  1232.  
  1233.    close (fd);
  1234.  
  1235.    return (board);
  1236. }
  1237.  
  1238.