home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / ROUTE.CPP < prev    next >
C/C++ Source or Header  |  1996-10-14  |  24KB  |  616 lines

  1.  
  2. // ----------------------------------------------------------------------
  3. // Lora BBS Professional Edition - Version 3.00.1
  4. // Copyright (c) 1996 by Marco Maccaferri. All rights reserved.
  5. //
  6. // History:
  7. //    05/12/96 - Initial coding.
  8. // ----------------------------------------------------------------------
  9.  
  10. #include "_ldefs.h"
  11. #include "mail.h"
  12.  
  13. PSZ Exts[] = { "su0", "mo0", "tu0", "we0", "th0", "fr0", "sa0", NULL };
  14.  
  15. TRoute::TRoute (void)
  16. {
  17.    Cfg = NULL;
  18.    Log = NULL;
  19. }
  20.  
  21. TRoute::~TRoute (void)
  22. {
  23. }
  24.  
  25. VOID TRoute::MakeArcMailName (PSZ pszAddress, CHAR Flag)
  26. {
  27.    USHORT i, Found;
  28.    CHAR *p;
  29.    class TAddress Addr;
  30.    class TOutbound *Out;
  31.    struct stat statbuf;
  32.    struct dosdate_t d_date;
  33.  
  34.    _dos_getdate (&d_date);
  35.  
  36.    Addr.Parse (pszAddress);
  37.    if (Addr.Zone == 0 || Cfg->MailAddress.Zone == Addr.Zone) {
  38.       if (Addr.Point != 0)
  39.          sprintf (ArcMailName, "%s\\%04x%04x.pnt\\%08lx.%s", Outbound, Addr.Net, Addr.Node, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]);
  40.       else
  41.          sprintf (ArcMailName, "%s\\%08lx.%s", Outbound, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]);
  42.    }
  43.    else {
  44.       if (Addr.Point != 0)
  45.          sprintf (ArcMailName, "%s.%03x\\%04x%04x.pnt\\%08lx.%s", Outbound, Addr.Zone, Addr.Net, Addr.Node, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]);
  46.       else
  47.          sprintf (ArcMailName, "%s.%03x\\%08lx.%s", Outbound, Addr.Zone, StringCrc32 (Addr.String, 0xFFFFFFFFL), Exts[d_date.dayofweek]);
  48.    }
  49.  
  50.    Found = FALSE;
  51.    if ((p = strchr (ArcMailName, '\0')) != NULL) {
  52.       p--;
  53.       for (i = '0'; i <= '9' && Found == FALSE; i++) {
  54.          *p = (CHAR)i;
  55.          if (stat (ArcMailName, &statbuf) == 0) {
  56.             Found = TRUE;
  57.             if (statbuf.st_size == 0L) {
  58.                unlink (ArcMailName);
  59.                if (++i > '9')
  60.                   i = '0';
  61.                *p = (CHAR)i;
  62.             }
  63.          }
  64.       }
  65.       if (Found == FALSE)
  66.          *p = '0';
  67.    }
  68.  
  69.    if ((Out = new TOutbound (Cfg->Outbound)) != NULL) {
  70.       if (Cfg->MailAddress.First () == TRUE)
  71.          Out->DefaultZone = Cfg->MailAddress.Zone;
  72.       Found = FALSE;
  73.       Out->Add (Addr.Zone, Addr.Net, Addr.Node, Addr.Point, Addr.Domain);
  74.       if (Out->First () == TRUE)
  75.          do {
  76.             if (!stricmp (Out->Complete, ArcMailName)) {
  77.                Found = TRUE;
  78.                break;
  79.             }
  80.          } while (Out->Next () == TRUE);
  81.  
  82.       if (Found == FALSE) {
  83.          Out->New ();
  84.          Out->Zone = Addr.Zone;
  85.          Out->Net = Addr.Net;
  86.          Out->Node = Addr.Node;
  87.          Out->Point = Addr.Point;
  88.          strcpy (Out->Domain, Addr.Domain);
  89.          strcpy (Out->Name, &ArcMailName[strlen (ArcMailName) - 12]);
  90.          strcpy (Out->Complete, ArcMailName);
  91.          Out->Status = Flag;
  92.          Out->ArcMail = TRUE;
  93.          Out->TruncateAfter = TRUE;
  94.          Out->Add ();
  95.          Out->Update ();
  96.       }
  97.  
  98.       delete Out;
  99.    }
  100. }
  101.  
  102. VOID TRoute::SendTo (VOID)
  103. {
  104.    DIR *dir;
  105.    int fd;
  106.    USHORT Zone, Net, Node, Point, DoPack, CheckNet;
  107.    CHAR *p, Flag, Lookup[32], FlagStr[16];
  108.    class TAddress Addr;
  109.    class TPacker *Packer;
  110.    class TNodes *Nodes;
  111.    struct dirent *ent;
  112.    struct stat statbuf;
  113.  
  114.    Cfg->MailAddress.First ();
  115.    Zone = Cfg->MailAddress.Zone;
  116.    Net = Cfg->MailAddress.Net;
  117.    Node = Cfg->MailAddress.Node;
  118.    Point = 0;
  119.  
  120.    Flag = 'H';
  121.    if ((p = strtok (NULL, " ")) != NULL) {
  122.       if (!stricmp (p, "hold") || !stricmp (p, "crash") || !stricmp (p, "direct") || !stricmp (p, "normal")) {
  123.          if ((Flag = (CHAR)toupper (*p)) == 'N')
  124.             Flag = 'F';
  125.       }
  126.       strcpy (FlagStr, strupr (p));
  127.    }
  128.  
  129.    if ((p = strtok (NULL, "")) != NULL)
  130.       strcpy (Line, p);
  131.  
  132.    while ((p = strtok (Line, " ")) != NULL) {
  133.       Addr.Parse (p);
  134.       if ((p = strtok (NULL, "")) != NULL)
  135.          strcpy (Line, p);
  136.       else
  137.          Line[0] = '\0';
  138.  
  139.       if (Addr.Zone != 0)
  140.          Zone = Addr.Zone;
  141.       if (Addr.Net != 0)
  142.          Net = Addr.Net;
  143.       if (Addr.Node != 0)
  144.          Node = Addr.Node;
  145.       Point = Addr.Point;
  146.  
  147.       // Controlla se e' stato comando di compattare la posta di
  148.       // tutti i point (send-to 2:332/402.All).
  149.       if (Point == 65535U && Net != 65535U && Node != 65535U) {
  150.          if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  151.             sprintf (Temp, "%s\\%04x%04x.pnt", Outbound, Net, Node);
  152.          else
  153.             sprintf (Temp, "%s.%03x\\%04x%04x.pnt", Outbound, Zone, Net, Node);
  154.          if ((dir = opendir (Temp)) != NULL) {
  155.             while ((ent = readdir (dir)) != NULL) {
  156.                strlwr (ent->d_name);
  157.                if (strstr (ent->d_name, ".xpr") != NULL) {
  158.                   sscanf (ent->d_name, "%08hx", &Point);
  159.  
  160.                   cprintf ("SEND: %s for %u:%u/%u.%u... ", FlagStr, Zone, Net, Node, Point);
  161.                   if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  162.                      sprintf (Temp, "%s\\%04x%04x.pnt\\%08x.xpr", Outbound, Net, Node, Point);
  163.                   else
  164.                      sprintf (Temp, "%s.%03x\\%04x%04x.pnt\\%08x.xpr", Outbound, Zone, Net, Node, Point);
  165.  
  166.                   if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  167.                      close (fd);
  168.                      do {
  169.                         if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  170.                            sprintf (Name, "%s\\%04x%04x.pnt\\%08lx.pkt", Outbound, Net, Node, time (NULL));
  171.                         else
  172.                            sprintf (Name, "%s.%03x\\%04x%04x.pnt\\%08lx.pkt", Outbound, Zone, Net, Node, time (NULL));
  173.                      } while (rename (Temp, Name) != 0);
  174.  
  175.                      sprintf (Addr.String, "%u:%u/%u.%u", Zone, Net, Node, Point);
  176.                      MakeArcMailName (Addr.String, Flag);
  177.  
  178.                      if ((Packer = new TPacker (Cfg->SystemPath)) != NULL) {
  179.                         Packer->First ();
  180.                         if (Packer->CheckArc (ArcMailName) == FALSE) {
  181.                            if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  182.                               if (Nodes->Read (Addr.String) == TRUE)
  183.                                  Packer->Read (Nodes->Packer);
  184.                               delete Nodes;
  185.                            }
  186.                         }
  187.                         cprintf ("Using: '%s'\r\n", Packer->Display);
  188.                         stat (Name, &statbuf);
  189.                         if (Log != NULL)
  190.                            Log->Write ("#Packing mail for %s (%lu bytes)", Addr.String, statbuf.st_size);
  191.                         if (Log != NULL)
  192.                            Log->Write ("#Executing %s", Packer->PackCmd);
  193.                         cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  194.                         Packer->DoPack (ArcMailName, Name);
  195.                         delete Packer;
  196.                      }
  197.                   }
  198.                   cprintf ("\r\n");
  199.                }
  200.             }
  201.             closedir (dir);
  202.          }
  203.       }
  204.       // Controlla se e' stato comando di compattare la posta di
  205.       // tutta una zona (send-to all 2:All) o di un solo net (send-to 2:332/All).
  206.       else if (Net == 65535U || Node == 65535U) {
  207.          CheckNet = (Net != 65535U) ? TRUE : FALSE;
  208.          sprintf (Lookup, "%04x", Net);
  209.          if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  210.             sprintf (Temp, "%s", Outbound);
  211.          else
  212.             sprintf (Temp, "%s.%03x", Outbound, Zone);
  213.          if ((dir = opendir (Temp)) != NULL) {
  214.             while ((ent = readdir (dir)) != NULL) {
  215.                strlwr (ent->d_name);
  216.                if (strstr (ent->d_name, ".xpr") != NULL) {
  217.                   DoPack = FALSE;
  218.                   if (CheckNet == FALSE) {
  219.                      sscanf (ent->d_name, "%04hx%04hx", &Net, &Node);
  220.                      DoPack = TRUE;
  221.                   }
  222.                   else if (!strncmp (ent->d_name, Lookup, strlen (Lookup))) {
  223.                      sscanf (ent->d_name, "%04hx%04hx", &Net, &Node);
  224.                      DoPack = TRUE;
  225.                   }
  226.  
  227.                   if (DoPack == TRUE) {
  228.                      cprintf ("SEND: %s for %u:%u/%u.%u... ", FlagStr, Zone, Net, Node, Point);
  229.                      if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  230.                         sprintf (Temp, "%s\\%04x%04x.xpr", Outbound, Net, Node);
  231.                      else
  232.                         sprintf (Temp, "%s.%03x\\%04x%04x.xpr", Outbound, Zone, Net, Node);
  233.  
  234.                      if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  235.                         close (fd);
  236.                         do {
  237.                            if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  238.                               sprintf (Name, "%s\\%08lx.pkt", Outbound, time (NULL));
  239.                            else
  240.                               sprintf (Name, "%s.%03x\\%08lx.pkt", Outbound, Zone, time (NULL));
  241.                         } while (rename (Temp, Name) != 0);
  242.  
  243.                         sprintf (Addr.String, "%u:%u/%u.%u", Zone, Net, Node, Point);
  244.                         MakeArcMailName (Addr.String, Flag);
  245.  
  246.                         if ((Packer = new TPacker (Cfg->SystemPath)) != NULL) {
  247.                            Packer->First ();
  248.                            if (Packer->CheckArc (ArcMailName) == FALSE) {
  249.                               if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  250.                                  if (Nodes->Read (Addr.String) == TRUE)
  251.                                     Packer->Read (Nodes->Packer);
  252.                                  delete Nodes;
  253.                               }
  254.                            }
  255.                            cprintf ("Using: '%s'\r\n", Packer->Display);
  256.                            stat (Name, &statbuf);
  257.                            if (Log != NULL)
  258.                               Log->Write ("#Packing mail for %s (%lu bytes)", Addr.String, statbuf.st_size);
  259.                            if (Log != NULL)
  260.                               Log->Write ("#Executing %s", Packer->PackCmd);
  261.                            cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  262.                            Packer->DoPack (ArcMailName, Name);
  263.                            delete Packer;
  264.                         }
  265.                      }
  266.                      cprintf ("\r\n");
  267.                   }
  268.                }
  269.             }
  270.             closedir (dir);
  271.          }
  272.       }
  273.       else {
  274.          if (Zone == 0 || Cfg->MailAddress.Zone == Zone) {
  275.             if (Point != 0)
  276.                sprintf (Temp, "%s\\%04x%04x.pnt\\%08x.xpr", Outbound, Net, Node, Point);
  277.             else
  278.                sprintf (Temp, "%s\\%04x%04x.xpr", Outbound, Net, Node);
  279.          }
  280.          else {
  281.             if (Point != 0)
  282.                sprintf (Temp, "%s.%03x\\%04x%04x.pnt\\%08x.xpr", Outbound, Zone, Net, Node, Point);
  283.             else
  284.                sprintf (Temp, "%s.%03x\\%04x%04x.xpr", Outbound, Zone, Net, Node);
  285.          }
  286.  
  287.          if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  288.             close (fd);
  289.             cprintf ("SEND: %s for %u:%u/%u.%u... ", FlagStr, Zone, Net, Node, Point);
  290.             do {
  291.                if (Zone == 0 || Cfg->MailAddress.Zone == Zone) {
  292.                   if (Point != 0)
  293.                      sprintf (Name, "%s\\%04x%04x.pnt\\%08lx.pkt", Outbound, Net, Node, time (NULL));
  294.                   else
  295.                      sprintf (Name, "%s\\%08lx.pkt", Outbound, time (NULL));
  296.                }
  297.                else {
  298.                   if (Point != 0)
  299.                      sprintf (Name, "%s.%03x\\%04x%04x.pnt\\%08lx.pkt", Outbound, Zone, Net, Node, time (NULL));
  300.                   else
  301.                      sprintf (Name, "%s.%03x\\%08lx.pkt", Outbound, Zone, time (NULL));
  302.                }
  303.             } while (rename (Temp, Name) != 0);
  304.  
  305.             sprintf (Addr.String, "%u:%u/%u.%u", Zone, Net, Node, Point);
  306.             MakeArcMailName (Addr.String, Flag);
  307.  
  308.             if ((Packer = new TPacker (Cfg->SystemPath)) != NULL) {
  309.                Packer->First ();
  310.                if (Packer->CheckArc (ArcMailName) == FALSE) {
  311.                   if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  312.                      if (Nodes->Read (Addr.String) == TRUE)
  313.                         Packer->Read (Nodes->Packer);
  314.                      delete Nodes;
  315.                   }
  316.                }
  317.                cprintf ("Using: '%s'\r\n", Packer->Display);
  318.                stat (Name, &statbuf);
  319.                if (Log != NULL)
  320.                   Log->Write ("#Packing mail for %s (%lu bytes)", Addr.String, statbuf.st_size);
  321.                if (Log != NULL)
  322.                   Log->Write ("#Executing %s", Packer->PackCmd);
  323.                cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  324.                Packer->DoPack (ArcMailName, Name);
  325.                delete Packer;
  326.             }
  327.  
  328.             cprintf ("\r\n");
  329.          }
  330.       }
  331.    }
  332. }
  333.  
  334. VOID TRoute::RouteTo (VOID)
  335. {
  336.    DIR *dir;
  337.    int fd;
  338.    USHORT Zone, Net, Node, Point, DoPack, CheckNet;
  339.    CHAR *p, Flag, Lookup[32], DestPath[128], DestAddr[32], FlagStr[32];
  340.    ULONG TotalSize;
  341.    class TAddress Addr;
  342.    class TPacker *Packer;
  343.    class TNodes *Nodes;
  344.    struct dirent *ent;
  345.    struct stat statbuf;
  346.  
  347.    Cfg->MailAddress.First ();
  348.    Zone = Cfg->MailAddress.Zone;
  349.    Net = Cfg->MailAddress.Net;
  350.    Node = Cfg->MailAddress.Node;
  351.  
  352.    DoPack = FALSE;
  353.    DestPath[0] = '\0';
  354.    TotalSize = 0L;
  355.  
  356.    Flag = 'H';
  357.    if ((p = strtok (NULL, " ")) != NULL) {
  358.       if (!stricmp (p, "hold") || !stricmp (p, "crash") || !stricmp (p, "direct") || !stricmp (p, "normal")) {
  359.          if ((Flag = (CHAR)toupper (*p)) == 'N')
  360.             Flag = 'F';
  361.       }
  362.       strcpy (FlagStr, strupr (p));
  363.    }
  364.  
  365.    if ((p = strtok (NULL, "")) != NULL)
  366.       strcpy (Line, p);
  367.  
  368.    if ((p = strtok (Line, " ")) != NULL) {
  369.       Addr.Parse (p);
  370.       if ((p = strtok (NULL, "")) != NULL)
  371.          strcpy (Line, p);
  372.       else
  373.          Line[0] = '\0';
  374.  
  375.       Point = 0;
  376.       if (Addr.Zone != 0)
  377.          Zone = Addr.Zone;
  378.       if (Addr.Net != 0)
  379.          Net = Addr.Net;
  380.       Node = Addr.Node;
  381.       Point = Addr.Point;
  382.  
  383.       if (Zone == 0 || Cfg->MailAddress.Zone == Zone) {
  384.          if (Point != 0)
  385.             sprintf (DestPath, "%s\\%04x%04x.pnt\\", Outbound, Net, Node);
  386.          else
  387.             sprintf (DestPath, "%s\\", Outbound);
  388.       }
  389.       else {
  390.          if (Point != 0)
  391.             sprintf (DestPath, "%s.%03x\\%04x%04x.pnt\\", Outbound, Zone, Net, Node);
  392.          else
  393.             sprintf (DestPath, "%s.%03x\\", Outbound, Zone);
  394.       }
  395.  
  396.       sprintf (DestAddr, "%u:%u/%u.%u", Zone, Net, Node, Point);
  397.       MakeArcMailName (DestAddr, Flag);
  398.  
  399.       if (Point != 0)
  400.          sprintf (Temp, "%s%08x.xpr", DestPath, Point);
  401.       else
  402.          sprintf (Temp, "%s%04x%04x.xpr", DestPath, Net, Node);
  403.  
  404.       if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  405.          close (fd);
  406.          cprintf ("ROUTE: %s %u:%u/%u.%u Via %s\r\n", FlagStr, Zone, Net, Node, Point, DestAddr);
  407.          do {
  408.             sprintf (Name, "%s%08lx.pkt", DestPath, time (NULL));
  409.          } while (rename (Temp, Name) != 0);
  410.  
  411.          if (stat (Name, &statbuf) == 0)
  412.             TotalSize += statbuf.st_size;
  413.          cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  414.          DoPack = TRUE;
  415.       }
  416.    }
  417.  
  418.    while ((p = strtok (Line, " ")) != NULL) {
  419.       Addr.Parse (p);
  420.       if ((p = strtok (NULL, "")) != NULL)
  421.          strcpy (Line, p);
  422.       else
  423.          Line[0] = '\0';
  424.  
  425.       if (Addr.Zone != 0)
  426.          Zone = Addr.Zone;
  427.       if (Addr.Net != 0)
  428.          Net = Addr.Net;
  429.       Node = Addr.Node;
  430.       Point = Addr.Point;
  431.  
  432.       // Controlla se e' stato comando di compattare la posta di
  433.       // tutti i point (send-to 2:332/402.All).
  434.       if (Point == 65535U && Net != 65535U && Node != 65535U) {
  435.          if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  436.             sprintf (Temp, "%s\\%04x%04x.pnt", Outbound, Net, Node);
  437.          else
  438.             sprintf (Temp, "%s.%03x\\%04x%04x.pnt", Outbound, Zone, Net, Node);
  439.          if ((dir = opendir (Temp)) != NULL) {
  440.             while ((ent = readdir (dir)) != NULL) {
  441.                strlwr (ent->d_name);
  442.                if (strstr (ent->d_name, ".xpr") != NULL) {
  443.                   sscanf (ent->d_name, "%08hx", &Point);
  444.  
  445.                   if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  446.                      sprintf (Temp, "%s\\%04x%04x.pnt\\%08lx.xpr", Outbound, Net, Node, Point);
  447.                   else
  448.                      sprintf (Temp, "%s.%03x\\%04x%04x.pnt\\%08lx.xpr", Outbound, Zone, Net, Node, Point);
  449.  
  450.                   if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  451.                      close (fd);
  452.                      cprintf ("ROUTE: %s %u:%u/%u.%u Via %s\r\n", FlagStr, Zone, Net, Node, Point, DestAddr);
  453.                      do {
  454.                         sprintf (Name, "%s%08lx.pkt", DestPath, time (NULL));
  455.                      } while (rename (Temp, Name) != 0);
  456.  
  457.                      if (stat (Name, &statbuf) == 0)
  458.                         TotalSize += statbuf.st_size;
  459.                      cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  460.                      DoPack = TRUE;
  461.                   }
  462.                }
  463.             }
  464.             closedir (dir);
  465.          }
  466.       }
  467.       // Controlla se e' stato comando di compattare la posta di
  468.       // tutta una zona (send-to all 2:All) o di un solo net (send-to 2:332/All).
  469.       else if (Net == 65535U || Node == 65535U) {
  470.          CheckNet = (Net != 65535U) ? TRUE : FALSE;
  471.          sprintf (Lookup, "%04x", Net);
  472.          if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  473.             sprintf (Temp, "%s", Outbound);
  474.          else
  475.             sprintf (Temp, "%s.%03x", Outbound, Zone);
  476.          if ((dir = opendir (Temp)) != NULL) {
  477.             while ((ent = readdir (dir)) != NULL) {
  478.                strlwr (ent->d_name);
  479.                if (strstr (ent->d_name, ".xpr") != NULL) {
  480.                   DoPack = FALSE;
  481.                   if (CheckNet == FALSE) {
  482.                      sscanf (ent->d_name, "%04hx%04hx", &Net, &Node);
  483.                      DoPack = TRUE;
  484.                   }
  485.                   else if (!strncmp (ent->d_name, Lookup, strlen (Lookup))) {
  486.                      sscanf (ent->d_name, "%04hx%04hx", &Net, &Node);
  487.                      DoPack = TRUE;
  488.                   }
  489.  
  490.                   if (DoPack == TRUE) {
  491.                      if (Zone == 0 || Cfg->MailAddress.Zone == Zone)
  492.                         sprintf (Temp, "%s\\%04x%04x.xpr", Outbound, Net, Node);
  493.                      else
  494.                         sprintf (Temp, "%s.%03x\\%04x%04x.xpr", Outbound, Zone, Net, Node);
  495.  
  496.                      if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  497.                         close (fd);
  498.                         cprintf ("ROUTE: %s %u:%u/%u Via %s\r\n", FlagStr, Zone, Net, Node, DestAddr);
  499.                         do {
  500.                            sprintf (Name, "%s%08lx.pkt", DestPath, time (NULL));
  501.                         } while (rename (Temp, Name) != 0);
  502.  
  503.                         if (stat (Name, &statbuf) == 0)
  504.                            TotalSize += statbuf.st_size;
  505.                         cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  506.                      }
  507.                   }
  508.                }
  509.             }
  510.             closedir (dir);
  511.          }
  512.       }
  513.       else {
  514.          if (Zone == 0 || Cfg->MailAddress.Zone == Zone) {
  515.             if (Point != 0)
  516.                sprintf (Temp, "%s\\%04x%04x.pnt\\%08x.xpr", Outbound, Net, Node, Point);
  517.             else
  518.                sprintf (Temp, "%s\\%04x%04x.xpr", Outbound, Net, Node);
  519.          }
  520.          else {
  521.             if (Point != 0)
  522.                sprintf (Temp, "%s.%03x\\%04x%04x.pnt\\%08x.xpr", Outbound, Zone, Net, Node, Point);
  523.             else
  524.                sprintf (Temp, "%s.%03x\\%04x%04x.xpr", Outbound, Zone, Net, Node);
  525.          }
  526.  
  527.          if ((fd = sopen (Temp, O_RDONLY, SH_DENYNO, S_IREAD|S_IWRITE)) != -1) {
  528.             close (fd);
  529.             cprintf ("ROUTE: %s %u:%u/%u Via %s\r\n", FlagStr, Zone, Net, Node, DestAddr);
  530.             do {
  531.                sprintf (Name, "%s%08lx.pkt", DestPath, time (NULL));
  532.             } while (rename (Temp, Name) != 0);
  533.  
  534.             if (stat (Name, &statbuf) == 0)
  535.                TotalSize += statbuf.st_size;
  536.             cprintf ("Adding %s (%lub) to archive '%s'\r\n", &Name[strlen (Name) - 12], statbuf.st_size, ArcMailName);
  537.             DoPack = TRUE;
  538.          }
  539.       }
  540.    }
  541.  
  542.    if (DoPack == TRUE) {
  543.       MakeArcMailName (DestAddr, Flag);
  544.       sprintf (Name, "%s*.pkt", DestPath);
  545.  
  546.       if ((Packer = new TPacker (Cfg->SystemPath)) != NULL) {
  547.          Packer->First ();
  548.          if (Packer->CheckArc (ArcMailName) == FALSE) {
  549.             if ((Nodes = new TNodes (Cfg->NodelistPath)) != NULL) {
  550.                if (Nodes->Read (DestAddr) == TRUE)
  551.                   Packer->Read (Nodes->Packer);
  552.                delete Nodes;
  553.             }
  554.          }
  555.          if (Log != NULL) {
  556.             Log->Write ("#Packing mail for %s (%lu bytes)", DestAddr, TotalSize);
  557.             Log->Write ("#Executing %s", Packer->PackCmd);
  558.          }
  559.          Packer->DoPack (ArcMailName, Name);
  560.          delete Packer;
  561.       }
  562.    }
  563. }
  564.  
  565. VOID TRoute::Run (PSZ pszFile)
  566. {
  567.    FILE *fp;
  568.    USHORT LineNum, DoRoute;
  569.    CHAR *p;
  570.    class TPacker *Packer;
  571.  
  572.    strcpy (Outbound, Cfg->Outbound);
  573.    if (Outbound[strlen (Outbound) - 1] == '\\' || Outbound[strlen (Outbound) - 1] == '/')
  574.       Outbound[strlen (Outbound) - 1] = '\0';
  575.  
  576.    if (Log != NULL)
  577.       Log->Write (":Pack outbound mail (%s)", pszFile);
  578.  
  579.    cprintf ("Searching outbound areas...\r\n");
  580.  
  581.    DoRoute = FALSE;
  582.    if ((Packer = new TPacker (Cfg->SystemPath)) != NULL) {
  583.       if (Packer->First () == TRUE)
  584.          DoRoute = TRUE;
  585.       delete Packer;
  586.    }
  587.  
  588.    if (DoRoute == TRUE) {
  589.       if ((fp = _fsopen (pszFile, "rt", SH_DENYNO)) != NULL) {
  590.          LineNum = 1;
  591.          while (fgets (Line, sizeof (Line) - 1, fp) != NULL) {
  592.             if ((p = strchr (Line, '\n')) != NULL)
  593.                *p = '\0';
  594.             if ((p = strtok (Line, " ")) != NULL) {
  595.                if (!stricmp (p, "send-to") || !stricmp (p, "send"))
  596.                   SendTo ();
  597.                else if (!stricmp (p, "route-to") || !stricmp (p, "route"))
  598.                   RouteTo ();
  599.                else if (*p != '\0' && *p != ';' && *p != '%')
  600.                   Log->Write ("!Unknown keyword '%s' on line #%d", p, LineNum);
  601.             }
  602.  
  603.             LineNum++;
  604.          }
  605.          fclose (fp);
  606.       }
  607.    }
  608.    else {
  609.       cprintf ("No compressor(s) defined. Routing aborted.\r\n");
  610.       if (Log != NULL)
  611.          Log->Write ("!No compressor(s) defined");
  612.    }
  613. }
  614.  
  615.  
  616.