home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B96.ZIP / EXP.CPP < prev    next >
Text File  |  1998-11-13  |  69KB  |  2,414 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <dos.h>
  6. #include <fcntl.h>
  7. #include <sys/stat.h>
  8. #include <ctype.h>
  9. #include <mem.h>
  10. #include <conio.h>
  11. #include <io.h>
  12. #include <share.h>
  13. #include <errno.h>
  14. #include <dir.h>
  15. #include <time.h>
  16. #include <alloc.h>
  17. #include <process.h>
  18. #include <direct.h>
  19. #include "vardec.h"
  20. #include "net.h"
  21. #include "retcode.h"
  22.  
  23. #include "version.h"
  24.  
  25. #define WAIT_TIME 10
  26. #define TRIES 100
  27. #define SHARE_LEVEL 10
  28.  
  29. struct msghdr {
  30.   char fromUserName[205];
  31.   char toUserName[81];
  32.   char subject[81];
  33.   char dateTime[81];
  34. };
  35.  
  36. typedef struct {
  37.   char ownername[60];
  38.   char subtype[8];
  39.   char opttext[30];
  40. } MAILLISTREC;
  41.  
  42. MAILLISTREC *maillist;
  43. configrec syscfg;
  44.  
  45. char net_name[31], postmaster[31], net_data[MAXPATH];
  46. char POPNAME[21], REPLYTO[81], DOMAIN[81], deftagfile[MAXPATH], tagfile[MAXPATH], maindir[MAXPATH], spamname[81];
  47. unsigned short net_sysnum, defuser, use_alias, usermail, instance, spam;
  48. unsigned curuser, num_users;
  49. int nlists = 0, jdater, DIGEST;
  50. char alphasubtype[8];
  51. unsigned long cur_daten;
  52.  
  53. struct ts_os_ver {
  54.   int maj;
  55.   int min;
  56. };
  57.  
  58. #define DOS     0
  59. #define OS2     1
  60. #define DV      2
  61. #define WINS    3
  62. #define WIN3    4
  63.  
  64. #define MT_DOS  0x01
  65. #define MT_OS2  0x02
  66. #define MT_DV   0x04
  67. #define MT_WINS 0x08
  68. #define MT_WIN3 0x10
  69.  
  70. struct ts_os_ver t_os_ver[5];
  71. int t_os_type;
  72. int t_os;
  73. char t_os_name[41];
  74.  
  75. int detect_multitask(void)
  76. {
  77.   union REGS t_regs;
  78.  
  79.   t_os_type = 0;
  80.   t_os = 0;
  81.  
  82.   if (_osmajor < 10) {
  83.     t_os_ver[DOS].maj = _osmajor;
  84.     t_os_ver[DOS].min = _osminor;
  85.     t_os_type = t_os_type | MT_DOS;
  86.     strcpy(t_os_name, "DOS");
  87.   } else {
  88.     t_os_type = t_os_type | MT_OS2;
  89.     t_os_ver[OS2].maj = _osmajor / 10;
  90.     t_os_ver[OS2].min = _osminor;
  91.     if (t_os_ver[OS2].maj == 3) {
  92.       strcpy(t_os_name, "OS/2 Warp");
  93.     } else {
  94.       strcpy(t_os_name, "OS/2");
  95.     }
  96.   }
  97.  
  98.   t_regs.x.ax = 0x4680;
  99.   int86(0x2F, &t_regs, &t_regs);
  100.  
  101.   if (t_regs.x.ax == 0x0000) {
  102.     t_os_ver[WINS].maj = 3;
  103.     t_os_ver[WINS].min = 0;
  104.     t_os_type = t_os_type | MT_WINS;
  105.   } else {
  106.     t_regs.x.ax = 0x1600;
  107.     int86(0x2F, &t_regs, &t_regs);
  108.     switch (t_regs.h.al) {
  109.       case 0x00:
  110.       case 0x80:
  111.       case 0x01:
  112.       case 0xFF:
  113.         break;
  114.       default:
  115.         t_os_type = t_os_type | MT_WIN3;
  116.         t_os_ver[WIN3].maj = t_regs.h.al;
  117.         t_os_ver[WIN3].min = t_regs.h.ah;
  118.         if (t_os_ver[WIN3].maj == 4) {
  119.           strcpy(t_os_name, "Windows 95");
  120.           t_os_ver[WIN3].maj = t_os_ver[WIN3].maj - 3;
  121.         } else {
  122.           strcpy(t_os_name, "Windows");
  123.         }
  124.         break;
  125.     }
  126.   }
  127.  
  128.   t_regs.x.cx = 0x4445;
  129.   t_regs.x.dx = 0x5351;
  130.   t_regs.x.ax = 0x2B01;
  131.  
  132.   intdos(&t_regs, &t_regs);
  133.   if (t_regs.h.al != 0xFF) {
  134.     t_os_type = t_os_type | MT_DV;
  135.     t_os_ver[DV].maj = t_regs.h.bh;
  136.     t_os_ver[DV].min = t_regs.h.bl;
  137.     strcpy(t_os_name, "DESQview");
  138.   }
  139.   if (t_os_type & MT_DOS)
  140.     t_os = DOS;
  141.   if (t_os_type & MT_DV)
  142.     t_os = DV;
  143.   if (t_os_type & MT_WINS)
  144.     t_os = WINS;
  145.   if (t_os_type & MT_WIN3)
  146.     t_os = WIN3;
  147.   if (t_os_type & MT_OS2)
  148.     t_os = OS2;
  149.   return (t_os - 1);
  150. }
  151.  
  152. void giveup_timeslice(void)
  153. {
  154.   union REGS t_regs;
  155.  
  156.   switch (t_os) {
  157.     case DOS:
  158.       break;
  159.     case OS2:
  160.     case WIN3:
  161.     case WINS:
  162.       t_regs.x.ax = 0x1680;
  163.       int86(0x2f, &t_regs, &t_regs);
  164.       break;
  165.     case DV:
  166.       t_regs.x.ax = 0x1000;
  167.       int86(0x15, &t_regs, &t_regs);
  168.       break;
  169.   }
  170. }
  171.  
  172. int sh_write(int handle, void *buffer, unsigned long len)
  173. {
  174.   if (handle == -1) {
  175.     return (-1);
  176.   }
  177.   return (write(handle, buffer, (unsigned) len));
  178. }
  179.  
  180. int sh_open(char *path, int file_access, unsigned fmode)
  181. {
  182.   int handle, count, share;
  183.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  184.  
  185.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  186.     share = SH_DENYRW;
  187.   } else {
  188.     share = SH_DENYWR;
  189.   }
  190.   handle = open(path, file_access | share, fmode);
  191.   if (handle < 0) {
  192.     count = 1;
  193.     fnsplit(path, drive, dir, file, ext);
  194.     if (access(path, 0) != -1) {
  195.       delay(WAIT_TIME);
  196.       handle = open(path, file_access | share, fmode);
  197.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  198.         if (count % 2)
  199.           delay(WAIT_TIME);
  200.         else
  201.           giveup_timeslice();
  202.         count++;
  203.         handle = open(path, file_access | share, fmode);
  204.       }
  205.     }
  206.   }
  207.   return (handle);
  208. }
  209.  
  210. int sh_open1(char *path, int access)
  211. {
  212.   unsigned fmode;
  213.  
  214.   fmode = 0;
  215.   if ((access & O_RDWR) || (access & O_WRONLY))
  216.     fmode |= S_IWRITE;
  217.   if ((access & O_RDWR) || (access & O_RDONLY))
  218.     fmode |= S_IREAD;
  219.   return (sh_open(path, access, fmode));
  220. }
  221.  
  222. int sh_close(int f)
  223. {
  224.   if (f != -1)
  225.     close(f);
  226.   return (-1);
  227. }
  228.  
  229. int sh_read(int handle, void *buf, unsigned len)
  230. {
  231.   if (handle == -1) {
  232.     return (-1);
  233.   }
  234.   return (read(handle, buf, len));
  235. }
  236.  
  237. long sh_lseek(int handle, long offset, int fromwhere)
  238. {
  239.   if (handle == -1) {
  240.     return (-1L);
  241.   }
  242.   return (lseek(handle, offset, fromwhere));
  243. }
  244.  
  245. FILE *fsh_open(char *path, char *fmode)
  246. {
  247.   FILE *f;
  248.   int count, share, md, fd;
  249.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  250.  
  251.   share = SH_DENYWR;
  252.   md = 0;
  253.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  254.     share = SH_DENYRD;
  255.     md = O_RDWR | O_CREAT | O_TRUNC;
  256.   } else
  257.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  258.     share = SH_DENYRD;
  259.     md = O_RDWR | O_CREAT;
  260.   } else {
  261.     md = O_RDONLY;
  262.   }
  263.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  264.     md |= O_BINARY;
  265.   }
  266.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  267.     md &= ~O_RDONLY;
  268.     md |= O_RDWR;
  269.     share = SH_DENYRD;
  270.   }
  271.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  272.   if (fd < 0) {
  273.     count = 1;
  274.     fnsplit(path, drive, dir, file, ext);
  275.     if ((access(path, 0)) != -1) {
  276.       delay(WAIT_TIME);
  277.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  278.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  279.         delay(WAIT_TIME);
  280.         count++;
  281.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  282.       }
  283.     }
  284.   }
  285.   if (fd > 0) {
  286.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  287.       sh_lseek(fd, 0L, SEEK_END);
  288.     f = fdopen(fd, fmode);
  289.     if (!f) {
  290.       close(fd);
  291.     }
  292.   } else
  293.     f = 0;
  294.   return (f);
  295. }
  296.  
  297. size_t fsh_write(void *ptr, size_t size, size_t n, FILE * stream)
  298. {
  299.  
  300.   if (stream == NULL) {
  301.     return (0);
  302.   }
  303.   return (fwrite(ptr, size, n, stream));
  304. }
  305.  
  306.  
  307. int exist(char *s)
  308. {
  309.   int i;
  310.   struct ffblk ff;
  311.  
  312.   i = findfirst(s, &ff, 0);
  313.   if (i)
  314.     return (0);
  315.   else
  316.     return (1);
  317. }
  318.  
  319. char *stripspace(char *str)
  320. {
  321.   char *obuf, *nbuf;
  322.  
  323.   if (str) {
  324.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  325.       if (!isspace(*obuf))
  326.         *nbuf++ = *obuf;
  327.     }
  328.     *nbuf = NULL;
  329.   }
  330.   return (str);
  331. }
  332.  
  333. static unsigned char *trimstr1(unsigned char *s)
  334. {
  335.   int i;
  336.   static char *whitespace = " \r\n\t";
  337.  
  338.   i = (int) strlen(s);
  339.   while ((i > 0) && ((char *) _fstrchr(whitespace, s[i - 1]) != NULL))
  340.     --i;
  341.   while ((i > 0) && ((char *) _fstrchr(whitespace, *s) != NULL)) {
  342.     memmove(s, s + 1, --i);
  343.   }
  344.   s[i] = 0;
  345.   return (s);
  346. }
  347.  
  348. void output(char *fmt,...)
  349. {
  350.   va_list v;
  351.   char s[255];
  352.  
  353.   va_start(v, fmt);
  354.   vsprintf(s, fmt, v);
  355.   va_end(v);
  356.   fputs(s, stderr);
  357. }
  358.  
  359. int log_it(int display, char *fmt,...)
  360. {
  361.   va_list v;
  362.   char s[255], fn[MAXPATH];
  363.   FILE *fp;
  364.  
  365.   sprintf(fn, "%sNEWS.LOG", net_data);
  366.   if ((fp = fsh_open(fn, "at")) == NULL) {
  367.     output("\n ! Error accessing %s.", fn);
  368.     return 1;
  369.   }
  370.   va_start(v, fmt);
  371.   vsprintf(s, fmt, v);
  372.   va_end(v);
  373.   fputs(s, fp);
  374.   fclose(fp);
  375.   if (display)
  376.     fputs(s, stderr);
  377.   return 0;
  378. }
  379.  
  380.  
  381. void get_list_addr(char *list_addr, char *list_name)
  382. {
  383.   char *ss, fn[MAXPATH], s[101], buf[60];
  384.   int found;
  385.   FILE *fp;
  386.  
  387.   found = 0;
  388.   *list_addr = 0;
  389.   sprintf(fn, "%sACCT.INI", net_data);
  390.   if ((fp = fsh_open(fn, "rt")) != NULL) {
  391.     while ((fgets(s, 100, fp)) && (!found)) {
  392.       if (strnicmp(s, "LIST", 4) == 0) {
  393.         ss = strtok(s, "=");
  394.         if (s[4] == '-') {
  395.           strcpy(buf, &s[5]);
  396.           trimstr1(buf);
  397.           if (stricmp(buf, list_name) == 0) {
  398.             ss = strtok(NULL, "\r\n");
  399.             trimstr1(ss);
  400.             strcpy(list_addr, ss);
  401.             found = 1;
  402.           }
  403.         }
  404.       }
  405.     }
  406.     if (fp != NULL)
  407.       fclose(fp);
  408.   }
  409. }
  410.  
  411.  
  412. void properize(char *s)
  413. {
  414.   int i;
  415.  
  416.   for (i = 0; i < strlen(s); i++) {
  417.     if ((i == 0) || ((i > 0) && ((s[i - 1] == ' ') || (s[i - 1] == '.') ||
  418.            ((s[i - 1] == 'c') && (s[i - 2] == 'M')) || ((s[i - 1] == 'c') &&
  419.              (s[i - 2] == 'a') && (s[i - 3] == 'M')) || (s[i - 1] == '-') ||
  420.          (s[i - 1] == '_') || ((s[i - 1] == '\'') && (s[i - 2] == 'O'))))) {
  421.       s[i] = toupper(s[i]);
  422.     } else
  423.       s[i] = tolower(s[i]);
  424.   }
  425. }
  426.  
  427. int num_to_name(char *user_addr, char *user_name, int whichuser, int alias)
  428. {
  429.   char *ss, fn[MAXPATH], s[101], buf[60];
  430.   int i, userfile, num_users, found;
  431.   long pos;
  432.   FILE *fp;
  433.   userrec ur;
  434.  
  435.   if (alias == 2) {
  436.     strcpy(user_name, "Anonymous");
  437.     strcpy(user_addr, "user@wwivbbs.org");
  438.     return 1;
  439.   }
  440.   found = 0;
  441.   if (*user_addr) {
  442.     *user_addr = 0;
  443.     sprintf(fn, "%sACCT.INI", net_data);
  444.     if ((fp = fsh_open(fn, "rt")) != NULL) {
  445.       while ((fgets(s, 100, fp)) && (!found)) {
  446.         if (strnicmp(s, "USER", 4) == 0) {
  447.           ss = strtok(s, "=");
  448.           strcpy(buf, &s[4]);
  449.           if (isdigit(buf[0])) {
  450.             i = atoi(buf);
  451.             if (i == whichuser) {
  452.               ss = strtok(NULL, "\r\n");
  453.               if (ss) {
  454.                 trimstr1(ss);
  455.                 strcpy(user_addr, ss);
  456.                 found = 1;
  457.               }
  458.             }
  459.           }
  460.         }
  461.       }
  462.       if (fp != NULL)
  463.         fclose(fp);
  464.     }
  465.   }
  466.   found = 0;
  467.   sprintf(fn, "%sUSER.LST", syscfg.datadir);
  468.   userfile = sh_open1(fn, O_RDONLY | O_BINARY);
  469.   if (userfile < 0) {
  470.     log_it(1, "\n ■ Cannot open %s.", fn);
  471.     return (found);
  472.   }
  473.   num_users = ((int) (filelength(userfile) / sizeof(userrec)));
  474.  
  475.   if (whichuser > num_users) {
  476.     log_it(1, "\n ■ User #%d out of range.", whichuser);
  477.     return (found);
  478.   }
  479.   pos = ((long) sizeof(userrec) * ((long) whichuser));
  480.   lseek(userfile, pos, SEEK_SET);
  481.   sh_read(userfile, &ur, sizeof(userrec));
  482.   if (ur.realname[0] == 0)
  483.     log_it(1, "\n ■ User #%d has blank real name field!", whichuser);
  484.   else {
  485.     if (ur.inact == inact_deleted)
  486.       log_it(1, "\n ■ User #%d is marked as deleted!", whichuser);
  487.     else {
  488.       if (!alias)
  489.         strcpy(user_name, ur.realname);
  490.       else {
  491.         strcpy(user_name, ur.name);
  492.         properize(user_name);
  493.       }
  494.       found = 1;
  495.     }
  496.   }
  497.   sh_close(userfile);
  498.   return (found);
  499. }
  500.  
  501.  
  502. void parse_net_ini(void)
  503. {
  504.   char s[MAXPATH], origline[121], line[121], *ss, inlist = 0;
  505.   FILE *fp;
  506.   long fptr;
  507.  
  508.   defuser = 1;
  509.   use_alias = 1;
  510.   usermail = 1;
  511.   nlists = 0;
  512.   maillist = NULL;
  513.   *REPLYTO = 0;
  514.   sprintf(s, "%sNET.INI", maindir);
  515.   if ((fp = fsh_open(s, "rt")) == NULL) {
  516.     log_it(1, "\n ■ Unable to open %s.", s);
  517.     return;
  518.   }
  519.   while (fgets(line, 80, fp)) {
  520.     ss = NULL;
  521.     strcpy(origline, line);
  522.     stripspace(line);
  523.     if ((line[0] == ';') || (line[0] == '\n') || (line[0] == 0))
  524.       continue;
  525.     if (strnicmp(line, "[MAILLIST]", 10) == 0) {
  526.       fptr = ftell(fp);
  527.       while ((fgets(line, 80, fp)) && (line[0] != '[')) {
  528.         if ((line[0] != '[') && (line[0] != ';') && (line[0] != 0) &&
  529.             (strnicmp(line, "DIGEST", 6) != 0))
  530.           ++nlists;
  531.       }
  532.       fseek(fp, fptr, SEEK_SET);
  533.       maillist = (MAILLISTREC *) malloc((nlists + 1) * sizeof(MAILLISTREC));
  534.       if (maillist == NULL)
  535.         log_it(1, "\n ■ Not enough memory to process %d mailing lists.", nlists);
  536.       else
  537.         inlist = 1;
  538.       nlists = 0;
  539.       continue;
  540.     } else
  541.       if (line[0] == '[') {
  542.       inlist = 0;
  543.       continue;
  544.       }
  545.     if (inlist) {
  546.       if ((line[0] != ';') && (line[0] != 0) && (strnicmp(line, "DIGEST", 6) != 0)) {
  547.         ss = strtok(line, "\"");
  548.         trimstr1(ss);
  549.         if (*ss) {
  550.           ss = strtok(NULL, "\"");
  551.           if (*ss) {
  552.             strncpy(maillist[nlists].opttext, ss, 29);
  553.             maillist[nlists].opttext[30] = '\0';
  554.           } else
  555.             maillist[nlists].opttext[0] = '\0';
  556.         }
  557.         ss = strtok(line, "*\n");
  558.         trimstr1(ss);
  559.         strcpy(maillist[nlists].ownername, ss);
  560.         ss = strtok(NULL, "\"\n");
  561.         trimstr1(ss);
  562.         if (*ss) {
  563.           strlwr(maillist[nlists].ownername);
  564.           strcpy(maillist[nlists++].subtype, ss);
  565.         } else
  566.           log_it(1, "\n ■ Missing *subtype in maillist for %s.",
  567.                  maillist[nlists].ownername);
  568.       } else {
  569.         if (strnicmp(line, "DIGEST", 6) == 0) {
  570.           ss = strtok(line, "=");
  571.           if (*ss) {
  572.             ss = strtok(NULL, "\r\n");
  573.             trimstr1(ss);
  574.             if ((ss[0] == 'y') || (ss[0] == 'Y'))
  575.               DIGEST = 1;
  576.           }
  577.         }
  578.       }
  579.       continue;
  580.     }
  581.     if (strnicmp(line, "POSTMASTER", 10) == 0) {
  582.       ss = strtok(line, "=");
  583.       if (ss) {
  584.         ss = strtok(NULL, "\n");
  585.         if (ss)
  586.           defuser = atoi(ss);
  587.       }
  588.       continue;
  589.     }
  590.     if (strnicmp(line, "SPAMCONTROL", 11) == 0) {
  591.       ss = strtok(line, "=");
  592.       if (ss) {
  593.         ss = strtok(NULL, "\n");
  594.         if ((ss[0] == 'y') || (ss[0] == 'Y'))
  595.           spam = 1;
  596.       }
  597.       continue;
  598.     }
  599.     if (strnicmp(line, "USERMAIL", 8) == 0) {
  600.       ss = strtok(line, "=");
  601.       if (ss) {
  602.         ss = strtok(NULL, "\n");
  603.         if ((ss[0] == 'n') || (ss[0] == 'N'))
  604.           usermail = 0;
  605.       }
  606.       continue;
  607.     }
  608.     if (strnicmp(line, "SPAMADDRESS", 9) == 0) {
  609.       ss = strtok(line, "=");
  610.       if (ss) {
  611.         ss = strtok(NULL, "\n");
  612.         trimstr1(ss);
  613.         strcpy(spamname, ss);
  614.         if (stricmp(spamname, "DEFAULT") == 0)
  615.           strcpy(spamname, "WWIV_BBS@nospam.net");
  616.       }
  617.       continue;
  618.     }
  619.     if (strnicmp(line, "REPLYTO", 7) == 0) {
  620.       ss = strtok(origline, "=");
  621.       if (ss) {
  622.         ss = strtok(NULL, "\n");
  623.         trimstr1(ss);
  624.         strcpy(REPLYTO, ss);
  625.       }
  626.       continue;
  627.     }
  628.     if (strnicmp(line, "SIGNATURE", 9) == 0) {
  629.       ss = strtok(line, "=");
  630.       if (ss) {
  631.         ss = strtok(NULL, "\n");
  632.         trimstr1(ss);
  633.         strcpy(tagfile, ss);
  634.         if (!exist(tagfile)) {
  635.           log_it(1, "\n ■ Default signature file %s not found!", tagfile);
  636.           tagfile[0] = 0;
  637.         }
  638.         strcpy(deftagfile, tagfile);
  639.       }
  640.       continue;
  641.     }
  642.     if (strnicmp(line, "REALNAME", 8) == 0) {
  643.       ss = strtok(line, "=");
  644.       if (ss) {
  645.         ss = strtok(NULL, "\n");
  646.         if ((ss[0] == 'y') || (ss[0] == 'Y'))
  647.           use_alias = 0;
  648.       }
  649.     }
  650.   }
  651.   num_to_name(0, postmaster, defuser, 1);
  652.   if (fp != NULL)
  653.     fclose(fp);
  654.   return;
  655. }
  656.  
  657. unsigned char *strrep(char *str, char old, char New)
  658. {
  659.   int i;
  660.  
  661.   for (i = 0; str[i]; i++)
  662.     if (str[i] == old)
  663.       str[i] = New;
  664.   return (str);
  665. }
  666.  
  667.  
  668. char *stristr(char *String, char *Pattern)
  669. {
  670.   char *pptr, *sptr, *start;
  671.   unsigned int slen, plen;
  672.  
  673.   for (start = String, pptr = Pattern, slen = strlen(String),
  674.        plen = strlen(Pattern); slen >= plen; start++, slen--) {
  675.     while (toupper(*start) != toupper(*Pattern)) {
  676.       start++;
  677.       slen--;
  678.       if (slen < plen)
  679.         return (NULL);
  680.     }
  681.     sptr = start;
  682.     pptr = Pattern;
  683.     while (toupper(*sptr) == toupper(*pptr)) {
  684.       sptr++;
  685.       pptr++;
  686.       if ('\0' == *pptr)
  687.         return (start);
  688.     }
  689.   }
  690.   return (NULL);
  691. }
  692.  
  693. unsigned int name_to_num(char *name)
  694. {
  695.   int userfile, usernum;
  696.   userrec ur;
  697.   long pos;
  698.   char fn[MAXPATH], ur_name[60], ur_realname[60];
  699.  
  700.   if ((stristr(name, "Multiple recipients of") != NULL) || (strlen(name) == 0))
  701.     return 0;
  702.   sprintf(fn, "%sM%s.NET", net_data, name);
  703.   if (exist(fn)) {
  704.     log_it(1, "\n ■ Matched \"%s\" mailing list.", name);
  705.     strcpy(alphasubtype, name);
  706.     return (unsigned) (65535L);
  707.   }
  708.   sprintf(fn, "%sUSER.LST", syscfg.datadir);
  709.   userfile = sh_open1(fn, O_RDONLY | O_BINARY);
  710.   if (userfile < 0) {
  711.     log_it(1, "\n ■ Cannot open %s", fn);
  712.     return (0);
  713.   } else
  714.     log_it(1, "\n ■ Searching for user \"%s\"...", name);
  715.   num_users = ((int) (filelength(userfile) / sizeof(userrec)));
  716.  
  717.   for (usernum = 1; usernum < num_users; usernum++) {
  718.     pos = ((long) sizeof(userrec) * ((long) usernum));
  719.     lseek(userfile, pos, SEEK_SET);
  720.     sh_read(userfile, &ur, sizeof(userrec));
  721.     strcpy(ur_realname, ur.realname);
  722.     strrep(ur_realname, ' ', '_');
  723.     strcpy(ur_name, ur.name);
  724.     strrep(ur_name, ' ', '_');
  725.     if ((strcmpi(ur.realname, name) == 0) || (strcmpi(ur_realname, name) == 0) ||
  726.         (strcmpi(ur.name, name) == 0) || (strcmpi(ur_name, name) == 0)) {
  727.       if (ur.inact == inact_deleted) {
  728.         log_it(1, " user #%d is deleted account.", usernum);
  729.         usernum = 0;
  730.         break;
  731.       } else {
  732.         log_it(1, " matched to user #%d.", usernum);
  733.         break;
  734.       }
  735.     }
  736.   }
  737.   userfile = sh_close(userfile);
  738.  
  739.   if (usernum >= num_users) {
  740.     log_it(1, "... no match found.");
  741.     return 0;
  742.   }
  743.   return (usernum);
  744. }
  745.  
  746. char *find_name(char *name)
  747. {
  748.   char *ss, *ss1, hold[81];
  749.   int focus = 0;
  750.  
  751.   curuser = 0;
  752.   strcpy(hold, name);
  753.   ss1 = NULL;
  754.   if ((ss = _fstrchr(name, '(')) != NULL) {
  755.     ss1 = strtok(name, "(");
  756.     ss1 = strtok(NULL, ")");
  757.   } else
  758.     if ((ss = _fstrchr(name, '\"')) != NULL) {
  759.     ss1 = strtok(ss, "\"");
  760.   } else
  761.     if ((ss = _fstrchr(name, '<')) != NULL) {
  762.     ss1 = strtok(name, "<");
  763.   } else
  764.     focus = 1;
  765.   trimstr1(ss1);
  766.   if (focus) {
  767.     stripspace(hold);
  768.     curuser = name_to_num(hold);
  769.   } else
  770.     curuser = name_to_num(ss1);
  771.   if (curuser == 0)
  772.     return ('\0');
  773.   else
  774.     if (curuser == ((unsigned) 65535L))
  775.     return (alphasubtype);
  776.   else
  777.     return (ss1);
  778. }
  779.  
  780. char *find_focus(char *name)
  781. {
  782.   char *ss, focus[121];
  783.   int i;
  784.  
  785.   ss = name;
  786.   i = strcspn(ss, "<");
  787.   if (i < strlen(ss)) {
  788.     strcpy(focus, &ss[i+1]);
  789.     ss = strtok(focus, ">");
  790.   }
  791.   return (ss);
  792. }
  793.  
  794. void name_packet(char *pktname)
  795. {
  796.   int ok;
  797.   struct stat info;
  798.   unsigned i;
  799.  
  800.   ok = 0;
  801.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  802.     sprintf(pktname, "%sP0-%u.%3.3hu", net_data, i, instance);
  803.     if (stat(pktname, &info) == -1)
  804.       ok = 1;
  805.   }
  806. }
  807.  
  808. void name_bad(char *newfn)
  809. {
  810.   int ok;
  811.   struct stat info;
  812.   unsigned i;
  813.  
  814.   ok = 0;
  815.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  816.     sprintf(newfn, "%sINBOUND\\UNK-%3.3u.MSG", net_data, i);
  817.     if (stat(newfn, &info) == -1)
  818.       ok = 1;
  819.   }
  820. }
  821.  
  822. void name_check(char *newfn)
  823. {
  824.   int ok;
  825.   struct stat info;
  826.   unsigned i;
  827.  
  828.   ok = 0;
  829.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  830.     sprintf(newfn, "%sINBOUND\\CHK-%3.3u.MSG", net_data, i);
  831.     if (stat(newfn, &info) == -1)
  832.       ok = 1;
  833.   }
  834. }
  835.  
  836. #define FROM_RETURN 0x01
  837. #define FROM_FROM   0x02
  838. #define FROM_REPLY  0x04
  839.  
  840. int import(char *fn)
  841. {
  842.   char s[513], s1[121], pktname[MAXPATH], msgdate[61], *ss, *ss1, *p, *id, *name;
  843.   char alphatype[21], recvdate[81], realfrom[205];
  844.   int i, f, from, match, subj, intext, done, tolist, mailuser, bounce;
  845.   long textlen, reallen;
  846.   struct msghdr mh;
  847.   net_header_rec nh;
  848.   FILE *fp;
  849.  
  850.   tolist = 0;
  851.   intext = 0;
  852.   mailuser = 0;
  853.   bounce = 0;
  854.   f = sh_open1(fn, O_RDONLY | O_BINARY);
  855.   if (f < 0)
  856.     return (1);
  857.   textlen = filelength(f);
  858.   if (textlen > 32767L) {
  859.     sh_close(f);
  860.     log_it(1, "\n ■ Skipping UU/Base64 %s.", fn);
  861.     return (1);
  862.   }
  863.   p = (char *) malloc((int) (textlen + 1));
  864.   if (p == NULL) {
  865.     sh_close(f);
  866.     log_it(1, "\n ■ Unable to allocate %ld bytes.", textlen);
  867.     return (1);
  868.   }
  869.   sh_read(f, (void *) p, (int) textlen);
  870.   sh_close(f);
  871.  
  872.   nh.tosys = net_sysnum;
  873.   nh.fromsys = 32767;
  874.   nh.fromuser = 0;
  875.   nh.touser = defuser;
  876.   nh.main_type = main_type_email;
  877.   nh.minor_type = 0;
  878.   nh.list_len = 0;
  879.   ++cur_daten;
  880.   nh.daten = cur_daten;
  881.   strncpy(msgdate, ctime(&(time_t) nh.daten), 24);
  882.   msgdate[24] = '\0';
  883.   sprintf(recvdate, "0RReceived: PPP Project %s on %s\r\n", VERSION, msgdate);
  884.   strcat(msgdate, "\r\n");
  885.   nh.method = 0;
  886.  
  887.   strcpy(mh.fromUserName, "Unknown");
  888.   strcpy(mh.toUserName, "Unknown");
  889.   strcpy(mh.subject, "None");
  890.   realfrom[0] = 0;
  891.  
  892.   if ((fp = fsh_open(fn, "rb")) == NULL) {
  893.     free(p);
  894.     return 1;
  895.   }
  896.   match = subj = done = from = 0;
  897.   while ((!done) && (fgets(s, 254, fp))) {
  898.     if (s[0] == 4) {
  899.       ss = strtok(s, "R");
  900.       ss = strtok(NULL, "\r\n");
  901.       if (ss == NULL)
  902.         s[0] = 0;
  903.       else
  904.         strcpy(s, ss);
  905.     } else
  906.       intext = 1;
  907.     if (!intext) {
  908.       if (stristr(s,"x-Mailer: Internet Rex") !=NULL) {
  909.         fclose(fp);
  910.         free(p);
  911.         return (1);
  912.       }
  913.       if (strncmpi(s, "x-wwiv-user", 11) == 0) {
  914.         ss1 = strtok(s, "#");
  915.         if (ss1) {
  916.           ss1 = strtok(NULL, "\r\n");
  917.           mailuser = atoi(ss1);
  918.         }
  919.       } else
  920.         if (strncmpi(s, "x-wwiv-list", 11) == 0) {
  921.         ss1 = strtok(s, "*");
  922.         if (ss1) {
  923.           ss1 = strtok(NULL, "\r\n");
  924.           strcpy(alphatype, ss1);
  925.           nh.main_type = main_type_new_post;
  926.           nh.minor_type = 0;
  927.           nh.touser = 0;
  928.           mailuser = -1;
  929.           tolist = 1;
  930.         }
  931.       } else
  932.         if (strncmpi(s, "from:", 5) == 0)
  933.         from = FROM_FROM;
  934.       else
  935.         if (strncmpi(s, "return-path:", 12) == 0)
  936.         from = FROM_RETURN;
  937.       else
  938.         if (strncmpi(s, "sender:", 7) == 0)
  939.         from = FROM_RETURN;
  940.       else
  941.         if (strncmpi(s, "x-sender:", 9) == 0)
  942.         from = FROM_RETURN;
  943.       else
  944.         if (strncmpi(s, "x-to:", 5) == 0)
  945.         from = FROM_RETURN;
  946.       else
  947.         if (strncmpi(s, "x-mailing-list:", 15) == 0)
  948.         from = FROM_RETURN;
  949.       else
  950.         if (strncmpi(s, "reply-to:", 9) == 0)
  951.         from = FROM_REPLY;
  952.       else
  953.         if (strncmpi(s, "x-reply-to:", 11) == 0)
  954.         from = FROM_REPLY;
  955.       else
  956.         if (s[0] != ' ')
  957.         from = 0;
  958.       if (from) {
  959.         if (s[0] != ' ') {
  960.           ss = strtok(s, ": ");
  961.           ss = strtok(NULL, "\r\n");
  962.         }
  963.         trimstr1(ss);
  964.       }
  965.       if (from && (strchr(ss, '@') != NULL)) {
  966.         if (from && (nh.main_type == main_type_email)) {
  967.           strcpy(s1, ss);
  968.           strlwr(s1);
  969.           for (i = 0; (i < nlists) && (nh.main_type == main_type_email); i++) {
  970.             if (stristr(s1, maillist[i].ownername) != NULL) {
  971.               if (atoi(maillist[i].subtype)) {
  972.                 nh.main_type = main_type_pre_post;
  973.                 nh.minor_type = atoi(maillist[i].subtype);
  974.               } else {
  975.                 nh.main_type = main_type_new_post;
  976.                 nh.minor_type = 0;
  977.                 strcpy(alphatype, maillist[i].subtype);
  978.               }
  979.               strcpy(alphasubtype, maillist[i].subtype);
  980.               nh.touser = 0;
  981.               from = 0;
  982.             }
  983.           }
  984.         }
  985.         if ((from > match) && ((nh.main_type == main_type_email) || (from == FROM_FROM))) {
  986.           match = from;
  987.           if (strcspn(ss, "<") != strlen(ss)) {
  988.             if ((strcspn(ss, " ")) < (strcspn(ss, "<"))) {
  989.               name = strtok(ss, "<");
  990.               trimstr1(name);
  991.               id = strtok(NULL, ">");
  992.               trimstr1(id);
  993.               sprintf(mh.fromUserName, "%s <%s>", name, id);
  994.             } else {
  995.               strncpy(mh.fromUserName, ss, 205);
  996.               trimstr1(mh.fromUserName);
  997.               if (strcspn(ss, " ") != strlen(ss))
  998.                 log_it(1, "\n ! Error parsing return address \"%s\"", mh.fromUserName);
  999.             }
  1000.           } else
  1001.             strncpy(mh.fromUserName, ss, 205);
  1002.           mh.fromUserName[190] = 0;
  1003.           strcat(mh.fromUserName, "\r\n");
  1004.           if (from == FROM_FROM)
  1005.             strcpy(realfrom, mh.fromUserName);
  1006.         }
  1007.       } else
  1008.         if ((strncmpi(s, "subject:", 8) == 0) && (!subj)) {
  1009.         ss = strtok(s, ": ");
  1010.         ss = strtok(NULL, "\r\n");
  1011.         trimstr1(ss);
  1012.         strncpy(mh.subject, ss, 81);
  1013.         mh.subject[72] = 0;
  1014.         subj = 1;
  1015.       } else
  1016.         if (strncmpi(s, "date:", 5) == 0) {
  1017.         ss = strtok(s, ": ");
  1018.         ss = strtok(NULL, "\r\n");
  1019.         trimstr1(ss);
  1020.         strncpy(msgdate, ss, 58);
  1021.         msgdate[58] = '\0';
  1022.         strcat(msgdate, "\r\n");
  1023.       } else
  1024.         if ((strncmpi(s, "to:", 3) == 0) || (strncmpi(s, "cc:", 3) == 0)) {
  1025.         if (mailuser == 0) {
  1026.           ss = strtok(s, ":");
  1027.           ss = strtok(NULL, "\r\n");
  1028.           strncpy(mh.toUserName, ss, 81);
  1029.           mh.toUserName[80] = 0;
  1030.           curuser = 0;
  1031.           trimstr1(mh.toUserName);
  1032.           find_name(mh.toUserName);
  1033.         } else if (mailuser > 0) {
  1034.           curuser = mailuser;
  1035.           if (!num_to_name(0, mh.toUserName, curuser, use_alias)) {
  1036.             curuser = 0;
  1037.             mh.toUserName[0] = 0;
  1038.           }
  1039.         }
  1040.  
  1041.         if ((stristr(mh.toUserName, "Multiple recipients of") != NULL) && (curuser != (unsigned) 65535L)) {
  1042.           for (i = 0; (i < nlists) && (nh.main_type == main_type_email); i++) {
  1043.             if (stristr(mh.toUserName, maillist[i].opttext) != NULL) {
  1044.               if (atoi(maillist[i].subtype)) {
  1045.                 nh.main_type = main_type_pre_post;
  1046.                 nh.minor_type = atoi(maillist[i].subtype);
  1047.               } else {
  1048.                 nh.main_type = main_type_new_post;
  1049.                 nh.minor_type = 0;
  1050.                 strcpy(alphatype, maillist[i].subtype);
  1051.               }
  1052.               strcpy(alphasubtype, maillist[i].subtype);
  1053.               nh.touser = 0;
  1054.             }
  1055.           }
  1056.         }
  1057.         if ((curuser == (unsigned) 65535L) && (nh.main_type == main_type_email)) {
  1058.           strcpy(alphatype, alphasubtype);
  1059.           nh.main_type = main_type_new_post;
  1060.           nh.minor_type = 0;
  1061.           nh.touser = 0;
  1062.           tolist = 1;
  1063.         } else
  1064.           if ((mh.toUserName[0] == 0) || (curuser == 0)) {
  1065.           nh.touser = defuser;
  1066.           strcpy(mh.toUserName, postmaster);
  1067.         } else {
  1068.           nh.touser = curuser;
  1069.         }
  1070.       } else
  1071.         if (strncmpi(s, "message-id:", 11) == 0) {
  1072.         sprintf(s1, "%s@wwivbbs.org", POPNAME);
  1073.         if (stristr(s, s1) != NULL)
  1074.           bounce = 1;
  1075.       } else
  1076.         if (strncmpi(s, "apparently-to:", 14) == 0) {
  1077.         ss = strtok(s, ": ");
  1078.         ss = strtok(NULL, "\r\n");
  1079.         strncpy(mh.toUserName, ss, 81);
  1080.         mh.toUserName[80] = 0;
  1081.         curuser = 0;
  1082.         trimstr1(mh.toUserName);
  1083.         if (_fstrstr(mh.toUserName, " "))
  1084.           find_name(mh.toUserName);
  1085.         else
  1086.           mh.toUserName[0] = 0;
  1087.         if ((curuser == (unsigned) 65535L) && (nh.main_type == main_type_email)) {
  1088.           strcpy(alphatype, alphasubtype);
  1089.           nh.main_type = main_type_new_post;
  1090.           nh.minor_type = 0;
  1091.           nh.touser = 0;
  1092.           tolist = 1;
  1093.         } else
  1094.           if ((mh.toUserName[0] == 0) || (curuser == 0)) {
  1095.           nh.touser = defuser;
  1096.           strcpy(mh.toUserName, postmaster);
  1097.         } else
  1098.           nh.touser = curuser;
  1099.         }
  1100.     } else
  1101.       done = 1;
  1102.   }
  1103.   if (fp != NULL)
  1104.     fclose(fp);
  1105.   if (mailuser == -1) {
  1106.     strcpy(alphasubtype, alphatype);
  1107.     curuser = (unsigned) 65535L;
  1108.   }
  1109.   trimstr1(mh.fromUserName);
  1110.   strcat(mh.fromUserName, "\r\n");
  1111.   log_it(1, "\n ■ From    : %s", mh.fromUserName);
  1112.   if ((nh.main_type == main_type_pre_post) ||
  1113.       (nh.main_type == main_type_new_post)) {
  1114.     nh.touser = 0;
  1115.     log_it(1, " ■ Post to : Sub %s", alphasubtype);
  1116.     if (bounce) {
  1117.       log_it(1, "\n ■ Return Post from Listserv - not reposted.");
  1118.       free(p);
  1119.       return (0);
  1120.     }
  1121.     sprintf(s, "%sM%s.NET", net_data, alphasubtype);
  1122.     done = 0;
  1123.     if ((fp = fsh_open(s, "rb")) == NULL)
  1124.       done = -1;
  1125.     strcpy(s1, find_focus(realfrom));
  1126.     while ((done == 0) && (fgets(s, 254, fp))) {
  1127.       trimstr1(s);
  1128.       if (strcmpi(find_focus(s), s1) == 0)
  1129.         done = 1;
  1130.     }
  1131.     if (fp != NULL)
  1132.       fclose(fp);
  1133.     if (done < 1) {
  1134.       log_it(1, "\n ■ Not a subscriber!  Message not posted.");
  1135.       name_check(pktname);
  1136.       rename(fn, pktname);
  1137.       free(p);
  1138.       return (0);
  1139.     }
  1140.   } else
  1141.     log_it(1, " ■ Sent to : %s #%hd", strupr(mh.toUserName), nh.touser);
  1142.   log_it(1, "\n ■ Subject : %s", mh.subject);
  1143.  
  1144.   name_packet(pktname);
  1145.   if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1146.     log_it(1, "\n ■ Unable to create packet %s", pktname);
  1147.     free(p);
  1148.     return (1);
  1149.   }
  1150.   nh.length = textlen + strlen(mh.fromUserName) + strlen(mh.subject)
  1151.       + strlen(msgdate) + strlen(recvdate) + 1;
  1152.   if (nh.main_type == main_type_new_post)
  1153.     nh.length += strlen(alphatype) + 1;
  1154.   while (tolist >= 0) {
  1155.     fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1156.     if (nh.main_type == main_type_new_post)
  1157.       fsh_write(alphatype, sizeof(char), strlen(alphatype) +1, fp);
  1158.     fsh_write(mh.subject, sizeof(char), strlen(mh.subject) +1, fp);
  1159.     fsh_write(mh.fromUserName, sizeof(char), strlen(mh.fromUserName), fp);
  1160.     fsh_write(msgdate, sizeof(char), strlen(msgdate), fp);
  1161.     fsh_write(recvdate, sizeof(char), strlen(recvdate), fp);
  1162.     reallen = fsh_write(p, sizeof(char), (int) textlen, fp);
  1163.     if (reallen != textlen)
  1164.       log_it(1, "\n ■ Expected %ld bytes, wrote %ld bytes.", textlen, reallen);
  1165.     nh.tosys = 32767;
  1166.     --tolist;
  1167.   }
  1168.   if (fp != NULL)
  1169.     fclose(fp);
  1170.   free(p);
  1171.   return (0);
  1172. }
  1173.  
  1174.  
  1175. char *stripcolors(char *str)
  1176. {
  1177.   char *obuf, *nbuf;
  1178.  
  1179.   if (str) {
  1180.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1181.       if (*obuf == 3)
  1182.         ++obuf;
  1183.       else
  1184.         if (((*obuf < 32) && (*obuf != 9)) || (*obuf > 126))
  1185.         continue;
  1186.       else
  1187.         *nbuf++ = *obuf;
  1188.     }
  1189.     *nbuf = NULL;
  1190.   }
  1191.   return (str);
  1192. }
  1193.  
  1194. void move_dead(net_header_rec * nh, char *text)
  1195. {
  1196.   char fn[81];
  1197.   int f;
  1198.   long l, l1;
  1199.  
  1200.   sprintf(fn, "%sDEAD.NET", net_data);
  1201.   f = sh_open(fn, O_RDWR | O_BINARY | SH_DENYRW | O_CREAT, S_IREAD | S_IWRITE);
  1202.   if (f > 0) {
  1203.     lseek(f, 0L, SEEK_END);
  1204.     l = l1 = tell(f);
  1205.     write(f, (void *) nh, sizeof(net_header_rec));
  1206.     l1 += sizeof(net_header_rec);
  1207.     write(f, (void *) text, (int) (nh->length));
  1208.     l1 += nh->length;
  1209.     if (l1 != tell(f))
  1210.       chsize(f, l);
  1211.     f = sh_close(f);
  1212.   } else
  1213.     log_it(1, "\n ! Couldn't open '%s'", fn);
  1214. }
  1215.  
  1216. void get_subtype(int sub, char *where)
  1217. {
  1218.   int ok, which;
  1219.   char fn[181], s[81], net_name[21], *ss;
  1220.   FILE *fp;
  1221.  
  1222.   where[0] = 0;
  1223.   which = sub;
  1224.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1225.   if ((fp = fsh_open(fn, "r")) == NULL)
  1226.     return;
  1227.   ok = 0;
  1228.   while (fgets(s, 80, fp)) {
  1229.     if (*s == '!') {
  1230.       if (which == atoi(&s[1]))
  1231.         ok = 1;
  1232.     }
  1233.     if (ok && (*s == '$')) {
  1234.       ss = strtok(s, " ");
  1235.       strcpy(net_name, &ss[1]);
  1236.       ss = strtok(NULL, " ");
  1237.       if (fp != NULL)
  1238.         fclose(fp);
  1239.       if ((stricmp(net_name, "FILENET") == 0)) {
  1240.         trimstr1(ss);
  1241.         strcpy(where, ss);
  1242.         return;
  1243.       } else
  1244.         return;
  1245.     }
  1246.   }
  1247.   if (fp != NULL)
  1248.     fclose(fp);
  1249. }
  1250.  
  1251. unsigned find_anony(char *stype)
  1252. {
  1253.   int i, found, anony, result, num_subs;
  1254.   char fn[MAXPATH], subtype[12];
  1255.   subboardrec sub;
  1256.   FILE *fp;
  1257.  
  1258.   result = 0;
  1259.   sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
  1260.   if ((fp = fsh_open(fn, "rb")) == NULL) {
  1261.     log_it(1, "\n ■ Unable to read %s.", fn);
  1262.     return 0;
  1263.   } else {
  1264.     fseek(fp, 0L, SEEK_END);
  1265.     num_subs = (int) (ftell(fp) / sizeof(subboardrec));
  1266.     found = 0;
  1267.     output("    ");
  1268.     for (i = 0; (i < num_subs) && (!found); i++) {
  1269.       output("\b\b\b\b%-4d", i);
  1270.       fseek(fp, (long) i * sizeof(subboardrec), SEEK_SET);
  1271.       fread(&sub, sizeof(subboardrec), 1, fp);
  1272.       get_subtype(i, subtype);
  1273.       if (stricmp(subtype, stype) == 0) {
  1274.         anony = sub.anony & 0x0f;
  1275.         output("\b\b\b\b%s - ", sub.name);
  1276.         switch (anony) {
  1277.           case anony_force_anony:
  1278.             output("forced anonymous.");
  1279.             result = 2;
  1280.             break;
  1281.           case 0:
  1282.             output("aliases.");
  1283.             result = 1;
  1284.             break;
  1285.           default:
  1286.             output("real names.");
  1287.             result = 0;
  1288.             break;
  1289.         }
  1290.         found = 1;
  1291.       }
  1292.     }
  1293.     if (!found)
  1294.       output("\b\b\b\bnot found.");
  1295.   }
  1296.   fclose(fp);
  1297.   return result;
  1298. }
  1299.  
  1300. int isleap(unsigned yr)
  1301. {
  1302.   return yr % 400 == 0 || (yr % 4 == 0 && yr % 100 != 0);
  1303. }
  1304.  
  1305. static unsigned months_to_days(unsigned month)
  1306. {
  1307.   return (month * 3057 - 3007) / 100;
  1308. }
  1309.  
  1310. int jdate(unsigned yr, unsigned mo, unsigned day)
  1311. {
  1312.   int which;
  1313.  
  1314.   which = day + months_to_days(mo);
  1315.   if (mo > 2)
  1316.     which -= isleap(yr) ? 1 : 2;
  1317.  
  1318.   return which;
  1319. }
  1320.  
  1321. int export(char *fn)
  1322. {
  1323.   char fn1[121], tagfn[121], groupname[81], outfn[121], savefn[121], _temp_buffer[256], acct_addr[80], list_addr[80];
  1324.   char *ss, *buffer, *text, mytype[12], alphatype[21], hold[21], tempoutfn[21], savename[81], savesubj[81];
  1325.   unsigned stype, ttype;
  1326.   int infile, outfile, savefile, inloc, outloc, term, ok, a, f, i, j, ns, i6, tolist, hdr;
  1327.   net_header_rec nhr;
  1328.   struct msghdr mh;
  1329.   struct tm *time_msg;
  1330.   FILE *fp;
  1331.   time_t some;
  1332.   char *main_type[] =
  1333.   {
  1334.     "Network Update", "email by usernum", "post from sub host", "file",
  1335.     "post to sub host", "external message", "email by name",
  1336.     "NetEdit message", "SUBS.LST", "Extra Data", "BBSLIST from GC",
  1337.     "CONNECT from GC", "Unused_1", "Info from GC", "SSM", "Sub Add Request",
  1338.     "Sub Drop Request", "Sub Add Response", "Sub Drop Response", "Sub Info",
  1339.     "Unused 1", "Unused 2", "Unused 3", "Unused 4", "Unused 5", "new post",
  1340.     "new external"
  1341.   };
  1342.  
  1343.   if ((infile = sh_open1(fn, O_RDONLY | O_BINARY)) == -1)
  1344.     return 1;
  1345.  
  1346.   if ((buffer = (char *) malloc(32 * 1024)) == NULL) {
  1347.     sh_close(infile);
  1348.     log_it(1, "\n ■ Out of memory allocating input buffer!");
  1349.     return 1;
  1350.   }
  1351.   if ((text = (char *) malloc(32 * 1024)) == NULL) {
  1352.     log_it(1, "\n ■ Out of memory allocating output buffer!");
  1353.     sh_close(infile);
  1354.     if (buffer != NULL)
  1355.       free(buffer);
  1356.     return 1;
  1357.   }
  1358.   while (sh_read(infile, &nhr, sizeof(nhr))) {
  1359.     strcpy(tagfile, deftagfile);
  1360.     *alphasubtype = 0;
  1361.     sh_read(infile, buffer, (int) nhr.length);
  1362.     if (nhr.tosys != 32767) {
  1363.       log_it(1, "\n ■ System @%hd routing through @32767... moving to DEAD.NET.",
  1364.              nhr.fromsys);
  1365.       move_dead(&nhr, buffer);
  1366.       continue;
  1367.     }
  1368.     tolist = 0;
  1369.     hdr = 1;
  1370.     if (nhr.main_type == main_type_pre_post)
  1371.       nhr.main_type = main_type_post;
  1372.     if ((nhr.main_type == main_type_post) ||
  1373.         (nhr.main_type == main_type_new_post) ||
  1374.         (nhr.main_type == main_type_email_name) ||
  1375.         (nhr.main_type == main_type_ssm)) {
  1376.       inloc = 0;
  1377.       sprintf(hold, "%hu", nhr.minor_type);
  1378.       if ((nhr.main_type == main_type_email_name) ||
  1379.           (nhr.main_type == main_type_ssm) ||
  1380.           (nhr.main_type == main_type_new_post)) {
  1381.         stype = nhr.minor_type;
  1382.         inloc = strlen(buffer) + 1;
  1383.         if ((nhr.main_type == main_type_new_post) || ((nhr.fromsys != net_sysnum) &&
  1384.                                                   (nhr.fromsys != 32767))) {
  1385.           strcpy(alphasubtype, buffer);
  1386.           strcpy(hold, alphasubtype);
  1387.         } else
  1388.           strcpy(mh.toUserName, buffer);
  1389.       } else
  1390.         if (nhr.main_type == main_type_post) {
  1391.         stype = nhr.minor_type;
  1392.       } else {
  1393.         stype = atoi(&buffer[inloc]);
  1394.         sprintf(_temp_buffer, "%u", stype);
  1395.         inloc += strlen(_temp_buffer) + 1;
  1396.       }
  1397.  
  1398.       strncpy(mh.subject, &buffer[inloc], sizeof(mh.subject));
  1399.       stripcolors(mh.subject);
  1400.       inloc += strlen(&buffer[inloc]) + 1;
  1401.  
  1402.       for (term = inloc; buffer[term] != '\r'; term++);
  1403.       buffer[term] = '\0';
  1404.  
  1405.       *acct_addr = 0;
  1406.       if ((nhr.fromsys == net_sysnum) && (nhr.fromuser)) {
  1407.         *acct_addr = 1;
  1408.         *mytype = 0;
  1409.         if (nhr.main_type == main_type_new_post)
  1410.           strcpy(mytype, hold);
  1411.         if (nhr.main_type == main_type_post)
  1412.           sprintf(mytype, "%hu", nhr.minor_type);
  1413.         if (*mytype) {
  1414.           output("\n ■ Subtype : %s - ", mytype);
  1415.           a = find_anony(mytype);
  1416.         } else
  1417.           a = use_alias;
  1418.         if (!num_to_name(acct_addr, mh.fromUserName, nhr.fromuser, a)) {
  1419.           log_it(1, "\n ■ No match for user #%hd... skipping message!",
  1420.                  nhr.fromuser);
  1421.           continue;
  1422.         }
  1423.       } else {
  1424.         strncpy(mh.fromUserName, &buffer[inloc], sizeof(mh.fromUserName));
  1425.         stripcolors(mh.fromUserName);
  1426.         strtok(mh.fromUserName, "#");
  1427.         trimstr1(mh.fromUserName);
  1428.         if (nhr.fromsys != 32767) {
  1429.           sprintf(_temp_buffer, " #%hd @%hu", nhr.fromuser, nhr.fromsys);
  1430.           strcat(mh.fromUserName, _temp_buffer);
  1431.         }
  1432.         /* Gating code will go here */
  1433.       }
  1434.  
  1435.       inloc = term + 2;
  1436.  
  1437.       while (buffer[inloc] != '\n')
  1438.         inloc++;
  1439.       inloc++;
  1440.  
  1441.       if (strnicmp(&buffer[inloc], "RE: ", 4) == 0) {
  1442.         for (term = inloc; buffer[term] != '\r'; term++);
  1443.         buffer[term] = '\0';
  1444.         strncpy(mh.subject, &buffer[inloc + 4], sizeof(mh.subject));
  1445.         if (strnicmp(mh.subject, "RE: ", 4) != 0) {
  1446.           strcpy(_temp_buffer, "Re: ");
  1447.           strcat(_temp_buffer, mh.subject);
  1448.         }
  1449.         strcpy(mh.subject, _temp_buffer);
  1450.         inloc = term + 2;
  1451.       }
  1452.       if ((strncmp(&buffer[inloc], "BY: ", 4) == 0) ||
  1453.           (strncmp(&buffer[inloc], "TO: ", 4) == 0)) {
  1454.         for (term = inloc; buffer[term] != '\r'; term++);
  1455.         buffer[term] = '\0';
  1456.         strncpy(mh.toUserName, &buffer[inloc + 4], sizeof(mh.toUserName));
  1457.         stripcolors(mh.toUserName);
  1458.         if (strcspn(mh.toUserName, "<") != strlen(mh.toUserName)) {
  1459.           if ((_fstrstr(mh.toUserName, "\"") == 0) && (_fstrstr(mh.toUserName, "(") == 0)) {
  1460.             ss = strtok(mh.toUserName, "<");
  1461.             ss = strtok(NULL, ">");
  1462.             strcpy(mh.toUserName, ss);
  1463.           }
  1464.         }
  1465.         inloc = term + 2;
  1466.       } else {
  1467.         if (nhr.main_type != main_type_email_name) {
  1468.           strcpy(mh.toUserName, "ALL");
  1469.         }
  1470.       }
  1471.       outloc = 0;
  1472.       do {
  1473.         if (buffer[inloc] == 2) {
  1474.           i = inloc + 1;
  1475.           for (j = 1; j < 255; j++) {
  1476.             if (buffer[i] == 'π')
  1477.               buffer[i] = '\r';
  1478.             if ((buffer[i] == '\r') || (i > nhr.length))
  1479.               break;
  1480.             i++;
  1481.           }
  1482.           if (j < 80) {
  1483.             i = (80 - j) / 2;
  1484.             for (j = 1; j <= i; j++)
  1485.               text[outloc++] = ' ';
  1486.           }
  1487.           inloc++;
  1488.         } else
  1489.           if (buffer[inloc] == 3)
  1490.           inloc += 2;
  1491.         else
  1492.           if ((buffer[inloc] == 124) && (isdigit(buffer[inloc + 1])) && (isdigit(buffer[inloc + 2])))
  1493.           inloc += 3;
  1494.         else
  1495.           if ((buffer[inloc] == 4) && (isdigit(buffer[inloc + 1]))) {
  1496.           i = inloc;
  1497.           for (j = 1; j < 255; j++) {
  1498.             if ((buffer[i] == '\r') || (i > nhr.length))
  1499.               break;
  1500.             i++;
  1501.             inloc++;
  1502.           }
  1503.           inloc++;
  1504.           if (buffer[inloc] == '\n')
  1505.             inloc++;
  1506.         } else
  1507.           if (buffer[inloc] >= 127)
  1508.           inloc++;
  1509.         else
  1510.           if (buffer[inloc] == 1)
  1511.           inloc++;
  1512.         else
  1513.           text[outloc++] = buffer[inloc++];
  1514.       } while (inloc < nhr.length);
  1515.  
  1516.       text[outloc] = '\0';
  1517.  
  1518.       if ((nhr.main_type == main_type_post) ||
  1519.           (nhr.main_type == main_type_pre_post) ||
  1520.           (nhr.main_type == main_type_new_post)) {
  1521.         if (nhr.main_type == main_type_new_post) {
  1522.           sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
  1523.           if (exist(fn1)) {
  1524.             tolist = 1;
  1525.             nhr.main_type = main_type_email_name;
  1526.             get_list_addr(list_addr, alphasubtype);
  1527.           }
  1528.         }
  1529.         for (i = 0; (i < nlists) && (nhr.main_type != main_type_email_name); i++) {
  1530.           if (nhr.main_type == main_type_new_post) {
  1531.             if (strcmpi(alphasubtype, maillist[i].subtype) == 0) {
  1532.               nhr.main_type = main_type_email_name;
  1533.               strcpy(mh.toUserName, maillist[i].ownername);
  1534.             }
  1535.           } else {
  1536.             ttype = atoi(maillist[i].subtype);
  1537.             if (ttype == stype) {
  1538.               nhr.main_type = main_type_email_name;
  1539.               strcpy(mh.toUserName, maillist[i].ownername);
  1540.             }
  1541.           }
  1542.         }
  1543.       }
  1544.       switch (nhr.main_type) {
  1545.         case main_type_email:
  1546.         case main_type_email_name:
  1547.         case main_type_ssm:
  1548.           i = 1;
  1549.           if ((DIGEST) && (tolist)) {
  1550.             sprintf(outfn, "%sMQUEUE\\DIGEST\\%s.%d", net_data, alphasubtype, jdater);
  1551.             if (exist(outfn))
  1552.               hdr = 0;
  1553.           } else {
  1554.             sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, i);
  1555.             while (exist(outfn))
  1556.               sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, ++i);
  1557.             i = 1;
  1558.             sprintf(savefn, "%sSENT\\MSG%04d.SNT", net_data, i);
  1559.             while (exist(savefn))
  1560.               sprintf(savefn, "%sSENT\\MSG%04d.SNT", net_data, ++i);
  1561.           }
  1562.           break;
  1563.         case main_type_new_post:
  1564.         case main_type_post:
  1565.         case main_type_pre_post:
  1566.           i = 1;
  1567.           strcpy(tempoutfn, hold);
  1568.           sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, i);
  1569.           while (exist(outfn))
  1570.             sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, ++i);
  1571.           break;
  1572.         default:
  1573.           continue;
  1574.       }
  1575.  
  1576.       log_it(1, "\n ■ Creating: %s", outfn);
  1577.       if (nhr.fromsys != net_sysnum) {
  1578.         log_it(1, "\n ■ From    : %s", mh.fromUserName);
  1579.       } else {
  1580.         if (usermail) {
  1581.           if (*acct_addr)
  1582.             log_it(1, "\n ■ From    : \"%s\" <%s>", mh.fromUserName, acct_addr);
  1583.           else
  1584.             log_it(1, "\n ■ From    : \"%s\" <%s@%s>", mh.fromUserName, POPNAME, DOMAIN);
  1585.         } else
  1586.           log_it(1, "\n ■ From    : <%s@%s>", POPNAME, DOMAIN);
  1587.       }
  1588.       if ((nhr.main_type == main_type_post) ||
  1589.           (nhr.main_type == main_type_pre_post) ||
  1590.           (nhr.main_type == main_type_new_post)) {
  1591.         sprintf(fn1, "%sNEWS.RC", net_data);
  1592.         if ((fp = fsh_open(fn1, "rt")) == NULL) {
  1593.           log_it(1, "\n ■ %s not found!", fn1);
  1594.           sh_close(infile);
  1595.           if (text)
  1596.             free(text);
  1597.           if (buffer)
  1598.             free(buffer);
  1599.           return 1;
  1600.         } else {
  1601.           ok = 0;
  1602.           while ((fgets(_temp_buffer, 80, fp) != NULL) && (!ok)) {
  1603.             groupname[0] = 0;
  1604.             ss = strtok(_temp_buffer, " ");
  1605.             if (ss) {
  1606.               strcpy(groupname, ss);
  1607.               ss = strtok(NULL, " ");
  1608.               ss = strtok(NULL, "\r");
  1609.               if (nhr.main_type == main_type_new_post) {
  1610.                 strcpy(alphatype, ss);
  1611.                 if (strncmpi(alphasubtype, alphatype, strlen(alphasubtype)) == 0)
  1612.                   ok = 1;
  1613.               } else {
  1614.                 ttype = atoi(ss);
  1615.                 if (ttype == stype)
  1616.                   ok = 1;
  1617.               }
  1618.             }
  1619.           }
  1620.           *ss = NULL;
  1621.           if (fp != NULL)
  1622.             fclose(fp);
  1623.           if (!ok) {
  1624.             if (nhr.main_type != main_type_new_post)
  1625.               sprintf(alphatype, "%u", stype);
  1626.             log_it(1, "\n ■ Subtype %s not found in NEWS.RC!", alphatype);
  1627.             sh_close(infile);
  1628.             if (text)
  1629.               free(text);
  1630.             if (buffer)
  1631.               free(buffer);
  1632.             return 1;
  1633.           }
  1634.         }
  1635.       }
  1636.       if ((nhr.main_type == main_type_email) ||
  1637.           (nhr.main_type == main_type_email_name) ||
  1638.           (nhr.main_type == main_type_ssm)) {
  1639.         if (tolist)
  1640.           log_it(1, "\n ■ Sent to : %s Mailing List", alphasubtype);
  1641.         else
  1642.           log_it(1, "\n ■ Rcpt to : %s", mh.toUserName);
  1643.       } else
  1644.         log_it(1, "\n ■ Post to : %s", groupname);
  1645.  
  1646.       strcpy(_temp_buffer, mh.subject);
  1647.       j = 0;
  1648.       for (i = 0; i < strlen(mh.subject); i++) {
  1649.         if (_temp_buffer[i] == 3)
  1650.           ++i;
  1651.         else
  1652.           mh.subject[j++] = _temp_buffer[i];
  1653.       }
  1654.       mh.subject[j] = '\0';
  1655.  
  1656.       log_it(1, "\n ■ Subject : %s", mh.subject);
  1657.  
  1658.       if ((nhr.main_type == main_type_email) ||
  1659.           (nhr.main_type == main_type_email_name) ||
  1660.           (nhr.main_type == main_type_ssm)) {
  1661.         if (tolist) {
  1662.           sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
  1663.           f = sh_open1(fn1, O_RDONLY | O_BINARY);
  1664.           if (filelength(f) <= 0) {
  1665.             log_it(1, "\n ■ Mailing list %s has no subscribers.", alphasubtype);
  1666.             sh_close(f);
  1667.             continue;
  1668.           }
  1669.           sh_close(f);
  1670.         }
  1671.       }
  1672.       outfile = sh_open(outfn, O_RDWR | O_BINARY | O_CREAT | O_APPEND, S_IWRITE);
  1673.       if (outfile == -1) {
  1674.         sh_close(infile);
  1675.         if (buffer)
  1676.           free(buffer);
  1677.         if (text)
  1678.           free(text);
  1679.         log_it(1, "\n ■ Unable to open output file %s", outfn);
  1680.         return 1;
  1681.       }
  1682.       if (!tolist) {
  1683.         savefile = sh_open(savefn, O_RDWR | O_BINARY | O_CREAT | O_APPEND, S_IWRITE);
  1684.         if (savefile == -1)
  1685.           log_it(1, "\n ■ Unable to open output file %s", savefn);
  1686.       }
  1687.       time(&some);
  1688.       time_msg = localtime(&some);
  1689.       strftime(mh.dateTime, 80, "%a, %d %b %y %H:%M:%S (%Z)", time_msg);
  1690.       if (!hdr) {
  1691.         sprintf(_temp_buffer, "\n\n---- Next Message ----\n\n");
  1692.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1693.       }
  1694.       if (nhr.fromsys == 32767) {
  1695.         sprintf(_temp_buffer, "From: %s\n", mh.fromUserName);
  1696.       } else
  1697.         if (nhr.fromsys != net_sysnum) {
  1698.         sprintf(_temp_buffer, "From: \"%s\" <%s@%s>\n", mh.fromUserName, POPNAME, DOMAIN);
  1699.       } else {
  1700.         if ((spam) && ((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post))) {
  1701.           if (!*acct_addr) {
  1702.             if (spamname[0] == 0)
  1703.               sprintf(_temp_buffer, "From: \"%s\" <%s@dont.spam.me.%s>\n",
  1704.                       mh.fromUserName, POPNAME, DOMAIN);
  1705.             else
  1706.               sprintf(_temp_buffer, "From: \"%s\" <%s>\n", mh.fromUserName, spamname);
  1707.           } else
  1708.             sprintf(_temp_buffer, "From: \"%s\" <NOSPAM%s>\n", mh.fromUserName, acct_addr);
  1709.         } else {
  1710.           if (usermail) {
  1711.             if (*acct_addr)
  1712.               sprintf(_temp_buffer, "From: \"%s\" <%s>\n",
  1713.                       mh.fromUserName, acct_addr);
  1714.             else
  1715.               sprintf(_temp_buffer, "From: \"%s\" <%s@%s>\n",
  1716.                       mh.fromUserName, POPNAME, DOMAIN);
  1717.           } else
  1718.             sprintf(_temp_buffer, "From: <%s@%s>\n", POPNAME, DOMAIN);
  1719.         }
  1720.       }
  1721.       if ((tolist) && (DIGEST)) {
  1722.         strcpy(savename, mh.fromUserName);
  1723.         sprintf(_temp_buffer, "From: \"%s Mailing List\" <%s@%s>\n",
  1724.             alphasubtype, POPNAME, DOMAIN);
  1725.       }
  1726.       ++cur_daten;
  1727.       if (hdr) {
  1728.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1729.         if ((!tolist) && (savefile != -1))
  1730.           sh_write(savefile, _temp_buffer, strlen(_temp_buffer));
  1731.         sprintf(_temp_buffer, "Message-ID: <%lx-%s@wwivbbs.org>\n",
  1732.                 cur_daten, POPNAME);
  1733.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1734.       }
  1735.       if ((nhr.main_type == main_type_email) ||
  1736.           (nhr.main_type == main_type_email_name) ||
  1737.           (nhr.main_type == main_type_ssm)) {
  1738.         if (!tolist) {
  1739.           sprintf(_temp_buffer, "To: %s\n", mh.toUserName);
  1740.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1741.           if ((!tolist) && (savefile != -1))
  1742.             sh_write(savefile, _temp_buffer, strlen(_temp_buffer));
  1743.         } else {
  1744.           i = 0;
  1745.           if (hdr) {
  1746.             sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
  1747.             if ((fp = fsh_open(fn1, "rt")) != NULL) {
  1748.               while (fgets(_temp_buffer, 80, fp) != NULL) {
  1749.                 if (_fstrstr(_temp_buffer, "@")) {
  1750.                   strcpy(mh.toUserName, _temp_buffer);
  1751.                   sprintf(_temp_buffer, "To: %s", mh.toUserName);
  1752.                   if (_temp_buffer[strlen(_temp_buffer) - 1] != '\n')
  1753.                     strcat(_temp_buffer, "\n");
  1754.                   sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1755.                   i = 1;
  1756.                 }
  1757.               }
  1758.               if (fp != NULL)
  1759.                 fclose(fp);
  1760.             }
  1761.             if (!i) {
  1762.               sh_close(infile);
  1763.               if (buffer)
  1764.                 free(buffer);
  1765.               if (text)
  1766.                 free(text);
  1767.               log_it(1, "\n ■ Error processing mailing list %s.", alphasubtype);
  1768.               return (1);
  1769.             } else {
  1770.               if (*list_addr)
  1771.                 sprintf(_temp_buffer, "Reply-To: \"%s\" <%s>\n", alphasubtype,
  1772.                         list_addr);
  1773.               else
  1774.                 sprintf(_temp_buffer, "Reply-To: \"%s\" <%s@%s>\n", alphasubtype,
  1775.                         POPNAME, DOMAIN);
  1776.               sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1777.             }
  1778.           }
  1779.         }
  1780.       } else {
  1781.         sprintf(_temp_buffer, "Newsgroups: %s\n", groupname);
  1782.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1783.       }
  1784.       sprintf(_temp_buffer, "Subject: %s\n", mh.subject);
  1785.       if ((DIGEST) && (tolist)) {
  1786.         strcpy(savesubj, _temp_buffer);
  1787.         sprintf(_temp_buffer, "Subject: %s Daily Digest, Day %d\n", alphasubtype, jdater);
  1788.       }
  1789.       if (hdr) {
  1790.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1791.         if ((!tolist) && (savefile != -1))
  1792.           sh_write(savefile, _temp_buffer, strlen(_temp_buffer));
  1793.         sprintf(_temp_buffer, "MIME-Version: 1.0\n");
  1794.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1795.         sprintf(_temp_buffer, "Content-Type: text/plain; charset=us-ascii\n");
  1796.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1797.         sprintf(_temp_buffer, "Content-Transfer-Encoding: 7bit\n");
  1798.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1799.       }
  1800.       sprintf(_temp_buffer, "Date: %s\n", mh.dateTime);
  1801.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1802.       if ((!tolist) && (savefile != -1))
  1803.         sh_write(savefile, _temp_buffer, strlen(_temp_buffer));
  1804.       if (nhr.main_type != main_type_email_name) {
  1805.         if (hdr) {
  1806.           if (a == 2)
  1807.             sprintf(_temp_buffer, "Path: anonymous!wwivbbs.org\n");
  1808.           else
  1809.             sprintf(_temp_buffer, "Path: %s!%s\n", POPNAME, DOMAIN);
  1810.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1811.           if (a == 2)
  1812.             sprintf(_temp_buffer, "Organization: WWIV BBS\n");
  1813.           else
  1814.             sprintf(_temp_buffer, "Organization: %s * %s\n",
  1815.                     syscfg.systemname, syscfg.systemphone);
  1816.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1817.         }
  1818.       }
  1819.       if (tolist) {
  1820.         if (hdr) {
  1821.           if (*list_addr)
  1822.             sprintf(_temp_buffer, "X-Reply-To: \"%s\" <%s>\n",
  1823.                     alphasubtype, list_addr);
  1824.           else
  1825.             sprintf(_temp_buffer, "X-Reply-To: \"%s\" <%s@%s>\n",
  1826.                     alphasubtype, POPNAME, DOMAIN);
  1827.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1828.           sprintf(_temp_buffer, "Source: %s Mail List\n", alphasubtype);
  1829.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1830.         }
  1831.       }
  1832.       if (((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post)) &&
  1833.           (!tolist) && (a != 2)) {
  1834.         if (!*acct_addr) {
  1835.           if (*REPLYTO)
  1836.             sprintf(_temp_buffer, "Reply-to: \"%s\" <%s>\n", mh.fromUserName, REPLYTO);
  1837.           else
  1838.             sprintf(_temp_buffer, "Reply-to: \"%s\" <%s@%s>\n",
  1839.                     mh.fromUserName, POPNAME, DOMAIN);
  1840.         } else
  1841.           sprintf(_temp_buffer, "Reply-to: \"%s\" <%s>\n", mh.fromUserName, acct_addr);
  1842.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1843.       }
  1844.       if (hdr) {
  1845.         sprintf(_temp_buffer, "Version: WWIV PPP Project %s\n\n", VERSION);
  1846.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1847.       }
  1848.  
  1849.       if ((DIGEST) && (tolist)) {
  1850.         sprintf(_temp_buffer, "%s", savesubj);
  1851.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1852.         sprintf(_temp_buffer, "From: %s\n\n", savename);
  1853.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1854.       }
  1855.  
  1856.       if ((nhr.main_type != main_type_email) &&
  1857.           (nhr.main_type != main_type_email_name) &&
  1858.           (strncmp(mh.toUserName, "ALL", 3) != 0)) {
  1859.         sprintf(_temp_buffer, "Responding to: %s\n", mh.toUserName);
  1860.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1861.         if ((!tolist) && (savefile != -1))
  1862.           sh_write(savefile, _temp_buffer, strlen(_temp_buffer));
  1863.       }
  1864.       for (i = 0; i < strlen(text); i++)
  1865.         if (text[i] == 'π')
  1866.           text[i] = '\n';
  1867.  
  1868.       sh_write(outfile, text, strlen(text));
  1869.       if ((!tolist) && (savefile != -1))
  1870.         sh_write(savefile, text, strlen(text));
  1871.       if ((tolist) && (DIGEST)) {
  1872.         sprintf(_temp_buffer, "\n\n");
  1873.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1874.       } else {
  1875.         sprintf(tagfn, "%sI%s.TAG", syscfg.datadir, alphasubtype);
  1876.         if (exist(tagfn))
  1877.           strcpy(tagfile, tagfn);
  1878.         tagfn[0] = 0;
  1879.         ns = 0;
  1880.         for (i6 = 0; i6 < 99; i6++) {
  1881.           sprintf(tagfn, "%sI%s.T%d", syscfg.datadir, alphasubtype, i6);
  1882.           if (exist(tagfn))
  1883.             ns++;
  1884.           else
  1885.             break;
  1886.         }
  1887.         sprintf(tagfn, "%sI%s.T%d", syscfg.datadir, alphasubtype, random(ns));
  1888.         if (exist(tagfn))
  1889.           strcpy(tagfile, tagfn);
  1890.         if (tagfile[0] == 0) {
  1891.           sprintf(_temp_buffer, "\n\nOrigin: %s * %s\n\n",
  1892.                   syscfg.systemname, syscfg.systemphone);
  1893.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1894.         } else {
  1895.           if ((fp = fsh_open(tagfile, "rt")) == NULL)
  1896.             log_it(1, "\n ■ Error reading %s.", tagfile);
  1897.           else {
  1898.             sprintf(_temp_buffer, "\n\n");
  1899.             sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1900.             /* Speed this up */
  1901.             while (fgets(_temp_buffer, 120, fp)) {
  1902.               for (i = 0; ((i < strlen(_temp_buffer)) &&
  1903.                (_temp_buffer[i] != '\r') && (_temp_buffer[i] != '\n')); i++)
  1904.                 if ((_temp_buffer[i] < 32) || (_temp_buffer[i] > 126))
  1905.                   _temp_buffer[i] = 32;
  1906.               sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1907.             }
  1908.             if (fp != NULL)
  1909.               fclose(fp);
  1910.           }
  1911.           sprintf(_temp_buffer, "\n\n");
  1912.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1913.         }
  1914.       }
  1915.       sh_close(outfile);
  1916.       if (savefile != -1)
  1917.         sh_close(savefile);
  1918.     } else {
  1919.       if ((nhr.main_type >= 0x01) && (nhr.main_type <= 0x1b))
  1920.         log_it(1, "\n ■ %s message skipped",
  1921.                main_type[nhr.main_type - 1]);
  1922.       else
  1923.         log_it(1, "\n ■ Unknown Main_type %hd skipped", nhr.main_type);
  1924.     }
  1925.   }
  1926.   sh_close(infile);
  1927.   unlink(fn);
  1928.   if (text)
  1929.     free(text);
  1930.   if (buffer)
  1931.     free(buffer);
  1932.   return (0);
  1933. }
  1934.  
  1935. void get_dir(char *s, int be)
  1936. {
  1937.   strcpy(s, "X:\\");
  1938.   s[0] = 'A' + getdisk();
  1939.   getcurdir(0, s + 3);
  1940.   if (be) {
  1941.     if (s[strlen(s) - 1] != '\\')
  1942.       strcat(s, "\\");
  1943.   }
  1944. }
  1945.  
  1946. void ssm(char *s)
  1947. {
  1948.   int f, i, i1;
  1949.   char s1[161];
  1950.   shortmsgrec sm;
  1951.  
  1952.   sprintf(s1, "%sSMW.DAT", syscfg.datadir);
  1953.   f = sh_open(s1, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  1954.   if (f < 0)
  1955.     return;
  1956.   i = (int) (filelength(f) / sizeof(shortmsgrec));
  1957.   i1 = i - 1;
  1958.   if (i1 >= 0) {
  1959.     sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  1960.     sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  1961.     while ((sm.tosys == 0) && (sm.touser == 0) && (i1 > 0)) {
  1962.       --i1;
  1963.       sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  1964.       sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  1965.     }
  1966.     if ((sm.tosys) || (sm.touser))
  1967.       ++i1;
  1968.   } else
  1969.     i1 = 0;
  1970.   sm.tosys = 0;
  1971.   sm.touser = 1;
  1972.   strncpy(sm.message, s, 80);
  1973.   sm.message[80] = 0;
  1974.   sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  1975.   sh_write(f, (void *) &sm, sizeof(shortmsgrec));
  1976.   sh_close(f);
  1977. }
  1978.  
  1979.  
  1980. /*
  1981.   action: 1 = unsubscribed,
  1982.           2 = subscribed,
  1983.           3 = already subscribed,
  1984.           4 = not subscribed
  1985.           5 = invalid list
  1986.           6 = sending MAILLIST.TXT
  1987. */
  1988.  
  1989. void send_note(int action, char *mailname, char *listname)
  1990. {
  1991.   char s[81], fn[MAXPATH];
  1992.   int i;
  1993.   FILE *fp, *rlz;
  1994.  
  1995.   i = 1;
  1996.   sprintf(fn, "%sMQUEUE\\MSG.%d", net_data, i);
  1997.   while (exist(fn))
  1998.     sprintf(fn, "%sMQUEUE\\MSG.%d", net_data, ++i);
  1999.  
  2000.   if ((fp = fsh_open(fn, "wt+")) == NULL) {
  2001.     log_it(1, "\n ! Unable to create %s.", fn);
  2002.     return;
  2003.   }
  2004.   if (action != 5)
  2005.     fprintf(fp, "From: \"%s\" <%s@%s>\n", listname, POPNAME, DOMAIN);
  2006.   else
  2007.     fprintf(fp, "From: <%s@%s>\n", POPNAME, DOMAIN);
  2008.   fprintf(fp, "To: %s\n", mailname);
  2009.   fprintf(fp, "Subject: %s Mailing List\n\n", listname);
  2010.  
  2011.   switch (action) {
  2012.     case 1:
  2013.       sprintf(s, "%s removed from mailing list: %s", mailname, listname);
  2014.       fprintf(fp, "\n%s\n\n", s);
  2015.       log_it(1, "\n ■ %s", s);
  2016.       ssm(s);
  2017.       break;
  2018.     case 2:
  2019.       sprintf(fn, "%sR%s.RLZ", net_data, listname);
  2020.       if (!(exist(fn)))
  2021.         sprintf(fn, "%sGLOBAL.RLZ", net_data);
  2022.       if ((rlz = fsh_open(fn, "rt")) != NULL) {
  2023.         while (fgets(s, 80, rlz))
  2024.           fprintf(fp, s);
  2025.         fprintf(fp, "\n\n");
  2026.         fclose(rlz);
  2027.         sprintf(s, "%s added to mailing list: %s", mailname, listname);
  2028.         log_it(1, "\n%s", s);
  2029.         ssm(s);
  2030.       } else {
  2031.         sprintf(s, "%s added to mailing list: %s", mailname, listname);
  2032.         fprintf(fp, "\n%s\n\n", s);
  2033.         log_it(1, "\n ■ %s", s);
  2034.         ssm(s);
  2035.       }
  2036.       break;
  2037.     case 3:
  2038.       sprintf(fn, "%sR%s.RLZ", net_data, listname);
  2039.       if (!(exist(fn)))
  2040.         sprintf(fn, "%sGLOBAL.RLZ", net_data);
  2041.       if ((rlz = fsh_open(fn, "rt")) != NULL) {
  2042.         while (fgets(s, 80, rlz))
  2043.           fprintf(fp, s);
  2044.         fprintf(fp, "\n\n");
  2045.         fclose(rlz);
  2046.       } else
  2047.         fprintf(fp, "\n%s was already subscribed to mailing list:\n\n   %s\n\n",
  2048.                 mailname, listname);
  2049.       break;
  2050.     case 4:
  2051.       fprintf(fp, "\n%s not subscribed to mailing list:\n\n   %s\n\n",
  2052.               mailname, listname);
  2053.       break;
  2054.     case 5:
  2055.       sprintf(s, "%s requested an invalid mailing list: %s", mailname, listname);
  2056.       fprintf(fp, "\n%s\n\n", s);
  2057.       log_it(1, "\n ■ %s", s);
  2058.       ssm(s);
  2059.       break;
  2060.     case 6:
  2061.       sprintf(fn, "%sMAILLIST.TXT", syscfg.gfilesdir);
  2062.       if ((rlz = fsh_open(fn, "rt")) != NULL) {
  2063.         while (fgets(s, 80, rlz))
  2064.           fprintf(fp, s);
  2065.         fprintf(fp, "\n\n");
  2066.         fclose(rlz);
  2067.         sprintf(s, "Sent MAILLIST.TXT to %s.", mailname);
  2068.       } else
  2069.         sprintf(s, "No mailing list file found.  Notify system operator.");
  2070.       fprintf(fp, "\n%s\n\n", s);
  2071.       log_it(1, "\n ■ %s", s);
  2072.       ssm(s);
  2073.       break;
  2074.   }
  2075.   if (fp != NULL)
  2076.     fclose(fp);
  2077. }
  2078.  
  2079. int copyfile(char *input, char *output)
  2080. {
  2081.   int f1, f2, i;
  2082.   char *b;
  2083.   struct ftime ft;
  2084.  
  2085.   if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
  2086.     if ((b = (char *) malloc(16400)) == NULL)
  2087.       return 0;
  2088.     f1 = sh_open1(input, O_RDONLY | O_BINARY);
  2089.     if (!f1) {
  2090.       free(b);
  2091.       b = NULL;
  2092.       return 0;
  2093.     }
  2094.     getftime(f1, &ft);
  2095.  
  2096.     f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  2097.     if (!f2) {
  2098.       free(b);
  2099.       b = NULL;
  2100.       f1 = sh_close(f1);
  2101.       return 0;
  2102.     }
  2103.     i = read(f1, (void *) b, 16384);
  2104.     while (i > 0) {
  2105.       sh_write(f2, (void *) b, i);
  2106.       i = read(f1, (void *) b, 16384);
  2107.     }
  2108.     f1 = sh_close(f1);
  2109.     setftime(f2, &ft);
  2110.     f2 = sh_close(f2);
  2111.     free(b);
  2112.     b = NULL;
  2113.   }
  2114.   return 1;
  2115. }
  2116.  
  2117. char (*devices)[9];
  2118. int num_devices;
  2119.  
  2120. void finddevs(char (*devs)[9], int *count)
  2121. {
  2122.   char s[9];
  2123.   int i;
  2124.   char far *ss;
  2125.   long far *l;
  2126.   union REGS regs;
  2127.   struct SREGS sregs;
  2128.  
  2129.   *count = 0;
  2130.   regs.x.ax = 0x5200;
  2131.   int86x(INT_REAL_DOS, ®s, ®s, &sregs);
  2132.   ss = (char *) MK_FP(sregs.es, regs.x.bx);
  2133.   ss += 34;
  2134.   l = (long far *) ss;
  2135.  
  2136.   while (((unsigned short) l) != 0xffff) {
  2137.     ss = (char far *) l;
  2138.     ss += 10;
  2139.     if (*ss > 32) {
  2140.       strncpy(s, ss, 8);
  2141.       s[8] = 0;
  2142.       for (i = 7; i; i--)
  2143.         if (s[i] == ' ')
  2144.           s[i] = 0;
  2145.         else
  2146.           break;
  2147.       if (devs) {
  2148.         strcpy(devs[*count], s);
  2149.       }
  2150.       ++(*count);
  2151.     }
  2152.     l = (long far *) *l;
  2153.   }
  2154. }
  2155.  
  2156. void find_devices(void)
  2157. {
  2158.   finddevs(NULL, &num_devices);
  2159.   devices = (char (*)[9]) farmalloc((num_devices + 2) * 9);
  2160.   finddevs(devices, &num_devices);
  2161. }
  2162.  
  2163. int okfn(char *s)
  2164. {
  2165.   int i, l;
  2166.   unsigned char ch;
  2167.  
  2168.   find_devices();
  2169.   l = strlen(s);
  2170.   if ((s[0] == '-') || (s[0] == ' ') || (s[0] == '.') || (s[0] == '@'))
  2171.     return (0);
  2172.   for (i = 0; i < l; i++) {
  2173.     ch = s[i];
  2174.     if ((ch == ' ') || (ch == '/') || (ch == '\\') || (ch == ':') ||
  2175.         (ch == '>') || (ch == '<') || (ch == '|') || (ch == '+') ||
  2176.         (ch == ',') || (ch == ';') || (ch == '^') || (ch == '\"') ||
  2177.         (ch == '\'') || (ch > 126))
  2178.       return (0);
  2179.   }
  2180.  
  2181.   for (i = 0; i < num_devices; i++) {
  2182.     l = strlen(devices[i]);
  2183.     if (strncmp(devices[i], s, l) == 0) {
  2184.       if ((s[l] == 0) || (s[l] == '.') || (l == 8))
  2185.         return (0);
  2186.     }
  2187.   }
  2188.   if (devices != NULL)
  2189.     farfree(devices);
  2190.   return (1);
  2191. }
  2192.  
  2193. int subscribe(char *fn)
  2194. {
  2195.   char *ss, s[81], s1[81], mailname[81], subtype[81];
  2196.   int done, found, unsubscribe;
  2197.   FILE *fp, *oldfp, *newfp;
  2198.  
  2199.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  2200.     log_it(1, "\n ! Unable to open %s.", fn);
  2201.     return 1;
  2202.   }
  2203.   done = unsubscribe = 0;
  2204.   while ((fgets(s1, 80, fp)) && (!done)) {
  2205.     strcpy(s, &(s1[3]));
  2206.     if (strnicmp(s, "from:", 5) == 0) {
  2207.       ss = strtok(s, ":");
  2208.       if (ss) {
  2209.         ss = strtok(NULL, "\r\n");
  2210.         trimstr1(ss);
  2211.         strcpy(mailname, ss);
  2212.       }
  2213.     }
  2214.     if (strnicmp(s, "subject:", 8) == 0) {
  2215.       done = 1;
  2216.       ss = strtok(s, ":");
  2217.       if (ss) {
  2218.         ss = strtok(NULL, "\r\n");
  2219.         trimstr1(ss);
  2220.         strcpy(s1, ss);
  2221.         if (strnicmp(s1, "subscribe", 9) == 0) {
  2222.           ss = strtok(s1, " ");
  2223.           if (ss) {
  2224.             ss = strtok(NULL, "\r\n");
  2225.             trimstr1(ss);
  2226.             strcpy(subtype, ss);
  2227.           }
  2228.         }
  2229.         if (strnicmp(s1, "unsubscribe", 11) == 0) {
  2230.           unsubscribe = 1;
  2231.           ss = strtok(s1, " ");
  2232.           if (ss) {
  2233.             ss = strtok(NULL, "\r\n");
  2234.             trimstr1(ss);
  2235.             strcpy(subtype, ss);
  2236.           }
  2237.         }
  2238.       }
  2239.       ss = NULL;
  2240.     }
  2241.   }
  2242.   if (fp != NULL)
  2243.     fclose(fp);
  2244.  
  2245.   if ((!*mailname) || (!*subtype)) {
  2246.     log_it(1, "\n ! Invalid subscription request %s.", fn);
  2247.     return 1;
  2248.   }
  2249.   if ((strlen(subtype) == 1) || (strlen(subtype) > 7)) {
  2250.     log_it(1, "\n ! %s attempted to write to M%s.NET!", mailname, subtype);
  2251.     return 1;
  2252.   }
  2253.   if (strnicmp(subtype, "LISTS", 5) == 0) {
  2254.     send_note(6, mailname, subtype);
  2255.     return 1;
  2256.   }
  2257.   sprintf(s1, "M%s.NET", subtype);
  2258.   if (!okfn(s1)) {
  2259.     log_it(1, "\n ! %s attempted to create invalid filename %s!", mailname, s1);
  2260.     return 1;
  2261.   }
  2262.   sprintf(s, "%sM%s.NET", net_data, subtype);
  2263.   if (!exist(s)) {
  2264.     log_it(1, "\n ! %s subscriber list not found.", s);
  2265.     send_note(5, mailname, subtype);
  2266.     return 1;
  2267.   }
  2268.   if ((oldfp = fsh_open(s, "rt")) == NULL) {
  2269.     log_it(1, "\n ! Unable to open input file %s.", s);
  2270.     return 1;
  2271.   }
  2272.   sprintf(s1, "%sM%s.TMP", net_data, subtype);
  2273.   if (exist(s1))
  2274.     unlink(s1);
  2275.   if ((newfp = fsh_open(s1, "wt+")) == NULL) {
  2276.     log_it(1, "\n ! Unable to open output file %s.", s1);
  2277.     return 1;
  2278.   }
  2279.   found = 0;
  2280.   while (fgets(s, 80, oldfp)) {
  2281.     trimstr1(s);
  2282.     if (unsubscribe) {
  2283.       if (stricmp(s, mailname) == 0) {
  2284.         log_it(1, "\n ■ Removing %s from %s mailing list.", mailname, subtype);
  2285.         send_note(1, mailname, subtype);
  2286.         found = 1;
  2287.       } else
  2288.         fprintf(newfp, "%s\n", s);
  2289.     } else {
  2290.       if (stricmp(s, mailname) == 0) {
  2291.         log_it(1, "\n ■ %s already in %s mailing list.", mailname, subtype);
  2292.         send_note(3, mailname, subtype);
  2293.         found = 1;
  2294.       }
  2295.       fprintf(newfp, "%s\n", s);
  2296.     }
  2297.   }
  2298.   if (!found) {
  2299.     if (unsubscribe) {
  2300.       log_it(1, "\n ■ %s was not a member of %s mailing list.", mailname, subtype);
  2301.       send_note(4, mailname, subtype);
  2302.     } else {
  2303.       log_it(1, "\n ■ Adding %s to %s mailing list.", mailname, subtype);
  2304.       fprintf(newfp, "%s\n", mailname);
  2305.       send_note(2, mailname, subtype);
  2306.     }
  2307.   }
  2308.   if (oldfp != NULL)
  2309.     fclose(oldfp);
  2310.   if (newfp != NULL)
  2311.     fclose(newfp);
  2312.   sprintf(s, "%sM%s.TMP", net_data, subtype);
  2313.   sprintf(s1, "%sM%s.NET", net_data, subtype);
  2314.   if (exist(s1))
  2315.     unlink(s1);
  2316.   copyfile(s, s1);
  2317.   return 0;
  2318. }
  2319.  
  2320. int main(int argc, char *argv[])
  2321. {
  2322.   char fn[MAXPATH], newfn[MAXPATH], ext[5], *ss;
  2323.   int f, f1, i;
  2324.   struct ffblk ff;
  2325.   struct date dt;
  2326.   struct time tm;
  2327.  
  2328.   output("\n ■ PPP Import/Export %s", VERSION);
  2329.   if (argc != 7) {
  2330.     log_it(1, "\n ■ EXP <filename> <net_data> <net_sysnum> <POPNAME> <DOMAIN> <net_name>\n\n");
  2331.     if (argc > 1) {
  2332.       log_it(1, "Command line was: ");
  2333.       for (i = 0; i < argc; i++)
  2334.         log_it(1, "%s ", argv[i]);
  2335.       log_it(1, "\n\n");
  2336.     }
  2337.     return (1);
  2338.   }
  2339.   strcpy(net_data, argv[2]);
  2340.   f = sh_open1("CONFIG.DAT", O_RDONLY | O_BINARY);
  2341.   if (f < 0) {
  2342.     log_it(1, "Could not open CONFIG.DAT!\n\n");
  2343.     return 1;
  2344.   }
  2345.   sh_read(f, (void *) &syscfg, sizeof(configrec));
  2346.   sh_close(f);
  2347.  
  2348.   detect_multitask();
  2349.  
  2350.   get_dir(maindir, 1);
  2351.   sprintf(fn, "%s%s", net_data, argv[1]);
  2352.   strcpy(net_name, argv[6]);
  2353.   strcpy(POPNAME, argv[4]);
  2354.   strcpy(DOMAIN, argv[5]);
  2355.   net_sysnum = atoi(argv[3]);
  2356.   DIGEST = 0;
  2357.   tagfile[0] = 0;
  2358.   spam = 0;
  2359.  
  2360.   ss = getenv("WWIV_INSTANCE");
  2361.   if (ss) {
  2362.     instance = atoi(ss);
  2363.     if (instance >= 1000) {
  2364.       log_it(1, "\n ■ WWIV_INSTANCE set to %hd.  Can only be 1..999!",
  2365.              instance);
  2366.       instance = 1;
  2367.     }
  2368.   } else
  2369.     instance = 1;
  2370.  
  2371.   parse_net_ini();
  2372.   gettime(&tm);
  2373.   getdate(&dt);
  2374.   cur_daten = dostounix(&dt, &tm);
  2375.   jdater = jdate(dt.da_year, dt.da_mon, dt.da_day);
  2376.  
  2377.   strupr(postmaster);
  2378.   export(fn);
  2379.  
  2380.   sprintf(fn, "%sSPOOL\\UNK*.*", net_data);
  2381.   f1 = findfirst(fn, &ff, 0);
  2382.   while (f1 == 0) {
  2383.     sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
  2384.     if (!import(fn)) {
  2385.       unlink(fn);
  2386.     }
  2387.     f1 = findnext(&ff);
  2388.   }
  2389.  
  2390.   sprintf(fn, "%sINBOUND\\SUB*.*", net_data);
  2391.   f1 = findfirst(fn, &ff, 0);
  2392.   while (f1 == 0) {
  2393.     sprintf(fn, "%sINBOUND\\%s", net_data, ff.ff_name);
  2394.     fnsplit(fn, NULL, NULL, NULL, ext);
  2395.     if (strnicmp(ext, ".BAD", 4) == 0)
  2396.       log_it(1, "\n ■ Unprocessed subscriber request %s...", ff.ff_name);
  2397.     else {
  2398.       log_it(1, "\n ■ Processing subscriber request %s...", ff.ff_name);
  2399.       if (!subscribe(fn))
  2400.         unlink(fn);
  2401.       else {
  2402.         name_bad(newfn);
  2403.         rename(fn, newfn);
  2404.       }
  2405.     }
  2406.     f1 = findnext(&ff);
  2407.   }
  2408.  
  2409.   if (maillist != NULL)
  2410.     free(maillist);
  2411.  
  2412.   return 0;
  2413. }
  2414.