home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B95.ZIP / EXP.CPP < prev    next >
Text File  |  1998-11-11  |  68KB  |  2,383 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. void name_packet(char *pktname)
  781. {
  782.   int ok;
  783.   struct stat info;
  784.   unsigned i;
  785.  
  786.   ok = 0;
  787.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  788.     sprintf(pktname, "%sP0-%u.%3.3hu", net_data, i, instance);
  789.     if (stat(pktname, &info) == -1)
  790.       ok = 1;
  791.   }
  792. }
  793.  
  794. void name_bad(char *newfn)
  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(newfn, "%sINBOUND\\UNK-%3.3u.MSG", net_data, i);
  803.     if (stat(newfn, &info) == -1)
  804.       ok = 1;
  805.   }
  806. }
  807.  
  808. void name_check(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\\CHK-%3.3u.MSG", net_data, i);
  817.     if (stat(newfn, &info) == -1)
  818.       ok = 1;
  819.   }
  820. }
  821.  
  822. #define FROM_RETURN 0x01
  823. #define FROM_FROM   0x02
  824. #define FROM_REPLY  0x04
  825.  
  826. int import(char *fn)
  827. {
  828.   char s[513], s1[121], pktname[MAXPATH], msgdate[61], *ss, *ss1, *p, *id, *name;
  829.   char alphatype[21], recvdate[81], realfrom[205];
  830.   int i, f, from, match, subj, intext, done, tolist, mailuser, bounce;
  831.   long textlen, reallen;
  832.   struct msghdr mh;
  833.   net_header_rec nh;
  834.   FILE *fp;
  835.  
  836.   tolist = 0;
  837.   intext = 0;
  838.   mailuser = 0;
  839.   bounce = 0;
  840.   f = sh_open1(fn, O_RDONLY | O_BINARY);
  841.   if (f < 0)
  842.     return (1);
  843.   textlen = filelength(f);
  844.   if (textlen > 32767L) {
  845.     sh_close(f);
  846.     log_it(1, "\n ■ Skipping UU/Base64 %s.", fn);
  847.     return (1);
  848.   }
  849.   p = (char *) malloc((int) (textlen + 1));
  850.   if (p == NULL) {
  851.     sh_close(f);
  852.     log_it(1, "\n ■ Unable to allocate %ld bytes.", textlen);
  853.     return (1);
  854.   }
  855.   sh_read(f, (void *) p, (int) textlen);
  856.   sh_close(f);
  857.  
  858.   nh.tosys = net_sysnum;
  859.   nh.fromsys = 32767;
  860.   nh.fromuser = 0;
  861.   nh.touser = defuser;
  862.   nh.main_type = main_type_email;
  863.   nh.minor_type = 0;
  864.   nh.list_len = 0;
  865.   ++cur_daten;
  866.   nh.daten = cur_daten;
  867.   strncpy(msgdate, ctime(&(time_t) nh.daten), 24);
  868.   msgdate[24] = '\0';
  869.   sprintf(recvdate, "0RReceived: PPP Project %s on %s\r\n", VERSION, msgdate);
  870.   strcat(msgdate, "\r\n");
  871.   nh.method = 0;
  872.  
  873.   strcpy(mh.fromUserName, "Unknown");
  874.   strcpy(mh.toUserName, "Unknown");
  875.   strcpy(mh.subject, "None");
  876.   realfrom[0] = 0;
  877.  
  878.   if ((fp = fsh_open(fn, "rb")) == NULL) {
  879.     free(p);
  880.     return 1;
  881.   }
  882.   match = subj = done = from = 0;
  883.   while ((!done) && (fgets(s, 254, fp))) {
  884.     if (s[0] == 4) {
  885.       ss = strtok(s, "R");
  886.       ss = strtok(NULL, "\r\n");
  887.       if (ss == NULL)
  888.         s[0] = 0;
  889.       else
  890.         strcpy(s, ss);
  891.     } else
  892.       intext = 1;
  893.     if (!intext) {
  894.       if (stristr(s,"x-Mailer: Internet Rex") !=NULL) {
  895.         fclose(fp);
  896.         free(p);
  897.         return (1);
  898.       }
  899.       if (strncmpi(s, "x-wwiv-user", 11) == 0) {
  900.         ss1 = strtok(s, "#");
  901.         if (ss1) {
  902.           ss1 = strtok(NULL, "\r\n");
  903.           mailuser = atoi(ss1);
  904.         }
  905.       } else
  906.         if (strncmpi(s, "x-wwiv-list", 11) == 0) {
  907.         ss1 = strtok(s, "*");
  908.         if (ss1) {
  909.           ss1 = strtok(NULL, "\r\n");
  910.           strcpy(alphatype, ss1);
  911.           nh.main_type = main_type_new_post;
  912.           nh.minor_type = 0;
  913.           nh.touser = 0;
  914.           mailuser = -1;
  915.           tolist = 1;
  916.         }
  917.       } else
  918.         if (strncmpi(s, "from:", 5) == 0)
  919.         from = FROM_FROM;
  920.       else
  921.         if (strncmpi(s, "return-path:", 12) == 0)
  922.         from = FROM_RETURN;
  923.       else
  924.         if (strncmpi(s, "sender:", 7) == 0)
  925.         from = FROM_RETURN;
  926.       else
  927.         if (strncmpi(s, "x-sender:", 9) == 0)
  928.         from = FROM_RETURN;
  929.       else
  930.         if (strncmpi(s, "x-to:", 5) == 0)
  931.         from = FROM_RETURN;
  932.       else
  933.         if (strncmpi(s, "x-mailing-list:", 15) == 0)
  934.         from = FROM_RETURN;
  935.       else
  936.         if (strncmpi(s, "reply-to:", 9) == 0)
  937.         from = FROM_REPLY;
  938.       else
  939.         if (strncmpi(s, "x-reply-to:", 11) == 0)
  940.         from = FROM_REPLY;
  941.       else
  942.         if (s[0] != ' ')
  943.         from = 0;
  944.       if (from) {
  945.         if (s[0] != ' ') {
  946.           ss = strtok(s, ": ");
  947.           ss = strtok(NULL, "\r\n");
  948.         }
  949.         trimstr1(ss);
  950.       }
  951.       if (from && (strchr(ss, '@') != NULL)) {
  952.         if (from && (nh.main_type == main_type_email)) {
  953.           strcpy(s1, ss);
  954.           strlwr(s1);
  955.           for (i = 0; (i < nlists) && (nh.main_type == main_type_email); i++) {
  956.             if (stristr(s1, maillist[i].ownername) != NULL) {
  957.               if (atoi(maillist[i].subtype)) {
  958.                 nh.main_type = main_type_pre_post;
  959.                 nh.minor_type = atoi(maillist[i].subtype);
  960.               } else {
  961.                 nh.main_type = main_type_new_post;
  962.                 nh.minor_type = 0;
  963.                 strcpy(alphatype, maillist[i].subtype);
  964.               }
  965.               strcpy(alphasubtype, maillist[i].subtype);
  966.               nh.touser = 0;
  967.               from = 0;
  968.             }
  969.           }
  970.         }
  971.         if ((from > match) && ((nh.main_type == main_type_email) || (from == FROM_FROM))) {
  972.           match = from;
  973.           if (strcspn(ss, "<") != strlen(ss)) {
  974.             if ((strcspn(ss, " ")) < (strcspn(ss, "<"))) {
  975.               name = strtok(ss, "<");
  976.               trimstr1(name);
  977.               id = strtok(NULL, ">");
  978.               trimstr1(id);
  979.               sprintf(mh.fromUserName, "%s <%s>", name, id);
  980.             } else {
  981.               strncpy(mh.fromUserName, ss, 205);
  982.               trimstr1(mh.fromUserName);
  983.               if (strcspn(ss, " ") != strlen(ss))
  984.                 log_it(1, "\n ! Error parsing return address \"%s\"", mh.fromUserName);
  985.             }
  986.           } else
  987.             strncpy(mh.fromUserName, ss, 205);
  988.           mh.fromUserName[190] = 0;
  989.           strcat(mh.fromUserName, "\r\n");
  990.           if (from == FROM_FROM)
  991.             strcpy(realfrom, mh.fromUserName);
  992.         }
  993.       } else
  994.         if ((strncmpi(s, "subject:", 8) == 0) && (!subj)) {
  995.         ss = strtok(s, ": ");
  996.         ss = strtok(NULL, "\r\n");
  997.         trimstr1(ss);
  998.         strncpy(mh.subject, ss, 81);
  999.         mh.subject[72] = 0;
  1000.         subj = 1;
  1001.       } else
  1002.         if (strncmpi(s, "date:", 5) == 0) {
  1003.         ss = strtok(s, ": ");
  1004.         ss = strtok(NULL, "\r\n");
  1005.         trimstr1(ss);
  1006.         strncpy(msgdate, ss, 58);
  1007.         msgdate[58] = '\0';
  1008.         strcat(msgdate, "\r\n");
  1009.       } else
  1010.         if ((strncmpi(s, "to:", 3) == 0) || (strncmpi(s, "cc:", 3) == 0)) {
  1011.         if (mailuser == 0) {
  1012.           ss = strtok(s, ":");
  1013.           ss = strtok(NULL, "\r\n");
  1014.           strncpy(mh.toUserName, ss, 81);
  1015.           mh.toUserName[80] = 0;
  1016.           curuser = 0;
  1017.           trimstr1(mh.toUserName);
  1018.           find_name(mh.toUserName);
  1019.         } else
  1020.           if (mailuser > 0) {
  1021.           curuser = mailuser;
  1022.           if (!num_to_name(0, mh.toUserName, curuser, use_alias)) {
  1023.             curuser = 0;
  1024.             mh.toUserName[0] = 0;
  1025.           }
  1026.           }
  1027.  
  1028.         if ((stristr(mh.toUserName, "Multiple recipients of") != NULL) && (curuser != (unsigned) 65535L)) {
  1029.           for (i = 0; (i < nlists) && (nh.main_type == main_type_email); i++) {
  1030.             if (stristr(mh.toUserName, maillist[i].opttext) != NULL) {
  1031.               if (atoi(maillist[i].subtype)) {
  1032.                 nh.main_type = main_type_pre_post;
  1033.                 nh.minor_type = atoi(maillist[i].subtype);
  1034.               } else {
  1035.                 nh.main_type = main_type_new_post;
  1036.                 nh.minor_type = 0;
  1037.                 strcpy(alphatype, maillist[i].subtype);
  1038.               }
  1039.               strcpy(alphasubtype, maillist[i].subtype);
  1040.               nh.touser = 0;
  1041.             }
  1042.           }
  1043.         }
  1044.         if ((curuser == (unsigned) 65535L) && (nh.main_type == main_type_email)) {
  1045.           strcpy(alphatype, alphasubtype);
  1046.           nh.main_type = main_type_new_post;
  1047.           nh.minor_type = 0;
  1048.           nh.touser = 0;
  1049.           tolist = 1;
  1050.         } else
  1051.           if ((mh.toUserName[0] == 0) || (curuser == 0)) {
  1052.           nh.touser = defuser;
  1053.           strcpy(mh.toUserName, postmaster);
  1054.         } else {
  1055.           nh.touser = curuser;
  1056.         }
  1057.       } else
  1058.         if (strncmpi(s, "message-id:", 11) == 0) {
  1059.         sprintf(s1, "%s@wwivbbs.org", POPNAME);
  1060.         if (stristr(s, s1) != NULL)
  1061.           bounce = 1;
  1062.       } else
  1063.         if (strncmpi(s, "apparently-to:", 14) == 0) {
  1064.         ss = strtok(s, ": ");
  1065.         ss = strtok(NULL, "\r\n");
  1066.         strncpy(mh.toUserName, ss, 81);
  1067.         mh.toUserName[80] = 0;
  1068.         curuser = 0;
  1069.         trimstr1(mh.toUserName);
  1070.         if (_fstrstr(mh.toUserName, " "))
  1071.           find_name(mh.toUserName);
  1072.         else
  1073.           mh.toUserName[0] = 0;
  1074.         if ((curuser == (unsigned) 65535L) && (nh.main_type == main_type_email)) {
  1075.           strcpy(alphatype, alphasubtype);
  1076.           nh.main_type = main_type_new_post;
  1077.           nh.minor_type = 0;
  1078.           nh.touser = 0;
  1079.           tolist = 1;
  1080.         } else
  1081.           if ((mh.toUserName[0] == 0) || (curuser == 0)) {
  1082.           nh.touser = defuser;
  1083.           strcpy(mh.toUserName, postmaster);
  1084.         } else
  1085.           nh.touser = curuser;
  1086.         }
  1087.     } else
  1088.       done = 1;
  1089.   }
  1090.   if (fp != NULL)
  1091.     fclose(fp);
  1092.   if (mailuser == -1) {
  1093.     strcpy(alphasubtype, alphatype);
  1094.     curuser = (unsigned) 65535L;
  1095.   }
  1096.   trimstr1(mh.fromUserName);
  1097.   strcat(mh.fromUserName, "\r\n");
  1098.   log_it(1, "\n ■ From    : %s", mh.fromUserName);
  1099.   if ((nh.main_type == main_type_pre_post) ||
  1100.       (nh.main_type == main_type_new_post)) {
  1101.     nh.touser = 0;
  1102.     log_it(1, " ■ Post to : Sub %s", alphasubtype);
  1103.     if (bounce) {
  1104.       log_it(1, "\n ■ Return Post from Listserv - not reposted.");
  1105.       free(p);
  1106.       return (0);
  1107.     }
  1108.   } else
  1109.     log_it(1, " ■ Sent to : %s #%hd", strupr(mh.toUserName), nh.touser);
  1110.   log_it(1, "\n ■ Subject : %s", mh.subject);
  1111.  
  1112.   if (mailuser == -1) {
  1113.     sprintf(s, "%sM%s.NET", net_data, alphasubtype);
  1114.     done = 0;
  1115.     if ((fp = fsh_open(s, "rb")) == NULL)
  1116.       done = -1;
  1117.     while ((done == 0) && (fgets(s, 254, fp))) {
  1118.       if ((strcspn(s, "<")) < (strcspn(s, "@"))) {
  1119.         ss = strtok(s, "<");
  1120.         ss = strtok(NULL, ">\r\n");
  1121.       } else
  1122.         ss = strtok(s, " \r\n");
  1123.       if (stristr(realfrom, ss))
  1124.         done = 1;
  1125.     }
  1126.     if (fp != NULL)
  1127.       fclose(fp);
  1128.     if (done < 1) {
  1129.       log_it(1, "\n ■ Not a subscriber!  Message not posted.");
  1130.       name_check(pktname);
  1131.       rename(fn, pktname);
  1132.       free(p);
  1133.       return (0);
  1134.     }
  1135.   }
  1136.   name_packet(pktname);
  1137.   if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1138.     log_it(1, "\n ■ Unable to create packet %s", pktname);
  1139.     free(p);
  1140.     return (1);
  1141.   }
  1142.   nh.length = textlen + strlen(mh.fromUserName) + strlen(mh.subject)
  1143.       + strlen(msgdate) + strlen(recvdate) + 1;
  1144.   if (nh.main_type == main_type_new_post)
  1145.     nh.length += strlen(alphatype) + 1;
  1146.   while (tolist >= 0) {
  1147.     fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1148.     if (nh.main_type == main_type_new_post)
  1149.       fsh_write(alphatype, sizeof(char), strlen(alphatype) +1, fp);
  1150.     fsh_write(mh.subject, sizeof(char), strlen(mh.subject) +1, fp);
  1151.     fsh_write(mh.fromUserName, sizeof(char), strlen(mh.fromUserName), fp);
  1152.     fsh_write(msgdate, sizeof(char), strlen(msgdate), fp);
  1153.     fsh_write(recvdate, sizeof(char), strlen(recvdate), fp);
  1154.     reallen = fsh_write(p, sizeof(char), (int) textlen, fp);
  1155.     if (reallen != textlen)
  1156.       log_it(1, "\n ■ Expected %ld bytes, wrote %ld bytes.", textlen, reallen);
  1157.     nh.tosys = 32767;
  1158.     --tolist;
  1159.   }
  1160.   if (fp != NULL)
  1161.     fclose(fp);
  1162.   free(p);
  1163.   return (0);
  1164. }
  1165.  
  1166.  
  1167. char *stripcolors(char *str)
  1168. {
  1169.   char *obuf, *nbuf;
  1170.  
  1171.   if (str) {
  1172.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1173.       if (*obuf == 3)
  1174.         ++obuf;
  1175.       else
  1176.         if (((*obuf < 32) && (*obuf != 9)) || (*obuf > 126))
  1177.         continue;
  1178.       else
  1179.         *nbuf++ = *obuf;
  1180.     }
  1181.     *nbuf = NULL;
  1182.   }
  1183.   return (str);
  1184. }
  1185.  
  1186. void move_dead(net_header_rec * nh, char *text)
  1187. {
  1188.   char fn[81];
  1189.   int f;
  1190.   long l, l1;
  1191.  
  1192.   sprintf(fn, "%sDEAD.NET", net_data);
  1193.   f = sh_open(fn, O_RDWR | O_BINARY | SH_DENYRW | O_CREAT, S_IREAD | S_IWRITE);
  1194.   if (f > 0) {
  1195.     lseek(f, 0L, SEEK_END);
  1196.     l = l1 = tell(f);
  1197.     write(f, (void *) nh, sizeof(net_header_rec));
  1198.     l1 += sizeof(net_header_rec);
  1199.     write(f, (void *) text, (int) (nh->length));
  1200.     l1 += nh->length;
  1201.     if (l1 != tell(f))
  1202.       chsize(f, l);
  1203.     f = sh_close(f);
  1204.   } else
  1205.     log_it(1, "\n ! Couldn't open '%s'", fn);
  1206. }
  1207.  
  1208. void get_subtype(int sub, char *where)
  1209. {
  1210.   int ok, which;
  1211.   char fn[181], s[81], net_name[21], *ss;
  1212.   FILE *fp;
  1213.  
  1214.   where[0] = 0;
  1215.   which = sub;
  1216.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1217.   if ((fp = fsh_open(fn, "r")) == NULL)
  1218.     return;
  1219.   ok = 0;
  1220.   while (fgets(s, 80, fp)) {
  1221.     if (*s == '!') {
  1222.       if (which == atoi(&s[1]))
  1223.         ok = 1;
  1224.     }
  1225.     if (ok && (*s == '$')) {
  1226.       ss = strtok(s, " ");
  1227.       strcpy(net_name, &ss[1]);
  1228.       ss = strtok(NULL, " ");
  1229.       if (fp != NULL)
  1230.         fclose(fp);
  1231.       if ((stricmp(net_name, "FILENET") == 0)) {
  1232.         trimstr1(ss);
  1233.         strcpy(where, ss);
  1234.         return;
  1235.       } else
  1236.         return;
  1237.     }
  1238.   }
  1239.   if (fp != NULL)
  1240.     fclose(fp);
  1241. }
  1242.  
  1243. unsigned find_anony(char *stype)
  1244. {
  1245.   int i, found, anony, result, num_subs;
  1246.   char fn[MAXPATH], subtype[12];
  1247.   subboardrec sub;
  1248.   FILE *fp;
  1249.  
  1250.   result = 0;
  1251.   sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
  1252.   if ((fp = fsh_open(fn, "rb")) == NULL) {
  1253.     log_it(1, "\n ■ Unable to read %s.", fn);
  1254.     return 0;
  1255.   } else {
  1256.     fseek(fp, 0L, SEEK_END);
  1257.     num_subs = (int) (ftell(fp) / sizeof(subboardrec));
  1258.     found = 0;
  1259.     output("    ");
  1260.     for (i = 0; (i < num_subs) && (!found); i++) {
  1261.       output("\b\b\b\b%-4d", i);
  1262.       fseek(fp, (long) i * sizeof(subboardrec), SEEK_SET);
  1263.       fread(&sub, sizeof(subboardrec), 1, fp);
  1264.       get_subtype(i, subtype);
  1265.       if (stricmp(subtype, stype) == 0) {
  1266.         anony = sub.anony & 0x0f;
  1267.         output("\b\b\b\b%s - ", sub.name);
  1268.         switch (anony) {
  1269.           case anony_force_anony:
  1270.             output("forced anonymous.");
  1271.             result = 2;
  1272.             break;
  1273.           case 0:
  1274.             output("aliases.");
  1275.             result = 1;
  1276.             break;
  1277.           default:
  1278.             output("real names.");
  1279.             result = 0;
  1280.             break;
  1281.         }
  1282.         found = 1;
  1283.       }
  1284.     }
  1285.     if (!found)
  1286.       output("\b\b\b\bnot found.");
  1287.   }
  1288.   fclose(fp);
  1289.   return result;
  1290. }
  1291.  
  1292. int isleap(unsigned yr)
  1293. {
  1294.   return yr % 400 == 0 || (yr % 4 == 0 && yr % 100 != 0);
  1295. }
  1296.  
  1297. static unsigned months_to_days(unsigned month)
  1298. {
  1299.   return (month * 3057 - 3007) / 100;
  1300. }
  1301.  
  1302. int jdate(unsigned yr, unsigned mo, unsigned day)
  1303. {
  1304.   int which;
  1305.  
  1306.   which = day + months_to_days(mo);
  1307.   if (mo > 2)
  1308.     which -= isleap(yr) ? 1 : 2;
  1309.  
  1310.   return which;
  1311. }
  1312.  
  1313. int export(char *fn)
  1314. {
  1315.   char fn1[121], tagfn[121], groupname[81], outfn[121], _temp_buffer[256], acct_addr[80], list_addr[80];
  1316.   char *ss, *buffer, *text, mytype[12], alphatype[21], hold[21], tempoutfn[21], savename[81], savesubj[81];
  1317.   unsigned stype, ttype;
  1318.   int infile, outfile, inloc, outloc, term, ok, a, f, i, j, ns, i6, tolist, hdr;
  1319.   net_header_rec nhr;
  1320.   struct msghdr mh;
  1321.   struct tm *time_msg;
  1322.   FILE *fp;
  1323.   time_t some;
  1324.   char *main_type[] =
  1325.   {
  1326.     "Network Update", "email by usernum", "post from sub host", "file",
  1327.     "post to sub host", "external message", "email by name",
  1328.     "NetEdit message", "SUBS.LST", "Extra Data", "BBSLIST from GC",
  1329.     "CONNECT from GC", "Unused_1", "Info from GC", "SSM", "Sub Add Request",
  1330.     "Sub Drop Request", "Sub Add Response", "Sub Drop Response", "Sub Info",
  1331.     "Unused 1", "Unused 2", "Unused 3", "Unused 4", "Unused 5", "new post",
  1332.     "new external"
  1333.   };
  1334.  
  1335.   if ((infile = sh_open1(fn, O_RDONLY | O_BINARY)) == -1)
  1336.     return 1;
  1337.  
  1338.   if ((buffer = (char *) malloc(32 * 1024)) == NULL) {
  1339.     sh_close(infile);
  1340.     log_it(1, "\n ■ Out of memory allocating input buffer!");
  1341.     return 1;
  1342.   }
  1343.   if ((text = (char *) malloc(32 * 1024)) == NULL) {
  1344.     log_it(1, "\n ■ Out of memory allocating output buffer!");
  1345.     sh_close(infile);
  1346.     if (buffer != NULL)
  1347.       free(buffer);
  1348.     return 1;
  1349.   }
  1350.   while (sh_read(infile, &nhr, sizeof(nhr))) {
  1351.     strcpy(tagfile, deftagfile);
  1352.     *alphasubtype = 0;
  1353.     sh_read(infile, buffer, (int) nhr.length);
  1354.     if (nhr.tosys != 32767) {
  1355.       log_it(1, "\n ■ System @%hd routing through @32767... moving to DEAD.NET.",
  1356.              nhr.fromsys);
  1357.       move_dead(&nhr, buffer);
  1358.       continue;
  1359.     }
  1360.     tolist = 0;
  1361.     hdr = 1;
  1362.     if (nhr.main_type == main_type_pre_post)
  1363.       nhr.main_type = main_type_post;
  1364.     if ((nhr.main_type == main_type_post) ||
  1365.         (nhr.main_type == main_type_new_post) ||
  1366.         (nhr.main_type == main_type_email_name) ||
  1367.         (nhr.main_type == main_type_ssm)) {
  1368.       inloc = 0;
  1369.       sprintf(hold, "%hu", nhr.minor_type);
  1370.       if ((nhr.main_type == main_type_email_name) ||
  1371.           (nhr.main_type == main_type_ssm) ||
  1372.           (nhr.main_type == main_type_new_post)) {
  1373.         stype = nhr.minor_type;
  1374.         inloc = strlen(buffer) + 1;
  1375.         if ((nhr.main_type == main_type_new_post) || ((nhr.fromsys != net_sysnum) &&
  1376.                                                   (nhr.fromsys != 32767))) {
  1377.           strcpy(alphasubtype, buffer);
  1378.           strcpy(hold, alphasubtype);
  1379.         } else
  1380.           strcpy(mh.toUserName, buffer);
  1381.       } else
  1382.         if (nhr.main_type == main_type_post) {
  1383.         stype = nhr.minor_type;
  1384.       } else {
  1385.         stype = atoi(&buffer[inloc]);
  1386.         sprintf(_temp_buffer, "%u", stype);
  1387.         inloc += strlen(_temp_buffer) + 1;
  1388.       }
  1389.  
  1390.       strncpy(mh.subject, &buffer[inloc], sizeof(mh.subject));
  1391.       stripcolors(mh.subject);
  1392.       inloc += strlen(&buffer[inloc]) + 1;
  1393.  
  1394.       for (term = inloc; buffer[term] != '\r'; term++);
  1395.       buffer[term] = '\0';
  1396.  
  1397.       *acct_addr = 0;
  1398.       if ((nhr.fromsys == net_sysnum) && (nhr.fromuser)) {
  1399.         *acct_addr = 1;
  1400.         *mytype = 0;
  1401.         if (nhr.main_type == main_type_new_post)
  1402.           strcpy(mytype, hold);
  1403.         if (nhr.main_type == main_type_post)
  1404.           sprintf(mytype, "%hu", nhr.minor_type);
  1405.         if (*mytype) {
  1406.           output("\n ■ Subtype : %s - ", mytype);
  1407.           a = find_anony(mytype);
  1408.         } else
  1409.           a = use_alias;
  1410.         if (!num_to_name(acct_addr, mh.fromUserName, nhr.fromuser, a)) {
  1411.           log_it(1, "\n ■ No match for user #%hd... skipping message!",
  1412.                  nhr.fromuser);
  1413.           continue;
  1414.         }
  1415.       } else {
  1416.         strncpy(mh.fromUserName, &buffer[inloc], sizeof(mh.fromUserName));
  1417.         stripcolors(mh.fromUserName);
  1418.         strtok(mh.fromUserName, "#");
  1419.         trimstr1(mh.fromUserName);
  1420.         if (nhr.fromsys != 32767) {
  1421.           sprintf(_temp_buffer, " #%hd @%hu", nhr.fromuser, nhr.fromsys);
  1422.           strcat(mh.fromUserName, _temp_buffer);
  1423.         }
  1424.         /* Gating code will go here */
  1425.       }
  1426.  
  1427.       inloc = term + 2;
  1428.  
  1429.       while (buffer[inloc] != '\n')
  1430.         inloc++;
  1431.       inloc++;
  1432.  
  1433.       if (strnicmp(&buffer[inloc], "RE: ", 4) == 0) {
  1434.         for (term = inloc; buffer[term] != '\r'; term++);
  1435.         buffer[term] = '\0';
  1436.         strncpy(mh.subject, &buffer[inloc + 4], sizeof(mh.subject));
  1437.         if (strnicmp(mh.subject, "RE: ", 4) != 0) {
  1438.           strcpy(_temp_buffer, "Re: ");
  1439.           strcat(_temp_buffer, mh.subject);
  1440.         }
  1441.         strcpy(mh.subject, _temp_buffer);
  1442.         inloc = term + 2;
  1443.       }
  1444.       if ((strncmp(&buffer[inloc], "BY: ", 4) == 0) ||
  1445.           (strncmp(&buffer[inloc], "TO: ", 4) == 0)) {
  1446.         for (term = inloc; buffer[term] != '\r'; term++);
  1447.         buffer[term] = '\0';
  1448.         strncpy(mh.toUserName, &buffer[inloc + 4], sizeof(mh.toUserName));
  1449.         stripcolors(mh.toUserName);
  1450.         if (strcspn(mh.toUserName, "<") != strlen(mh.toUserName)) {
  1451.           if ((_fstrstr(mh.toUserName, "\"") == 0) && (_fstrstr(mh.toUserName, "(") == 0)) {
  1452.             ss = strtok(mh.toUserName, "<");
  1453.             ss = strtok(NULL, ">");
  1454.             strcpy(mh.toUserName, ss);
  1455.           }
  1456.         }
  1457.         inloc = term + 2;
  1458.       } else {
  1459.         if (nhr.main_type != main_type_email_name) {
  1460.           strcpy(mh.toUserName, "ALL");
  1461.         }
  1462.       }
  1463.       outloc = 0;
  1464.       do {
  1465.         if (buffer[inloc] == 2) {
  1466.           i = inloc + 1;
  1467.           for (j = 1; j < 255; j++) {
  1468.             if (buffer[i] == 'π')
  1469.               buffer[i] = '\r';
  1470.             if ((buffer[i] == '\r') || (i > nhr.length))
  1471.               break;
  1472.             i++;
  1473.           }
  1474.           if (j < 80) {
  1475.             i = (80 - j) / 2;
  1476.             for (j = 1; j <= i; j++)
  1477.               text[outloc++] = ' ';
  1478.           }
  1479.           inloc++;
  1480.         } else
  1481.           if (buffer[inloc] == 3)
  1482.           inloc += 2;
  1483.         else
  1484.           if ((buffer[inloc] == 124) && (isdigit(buffer[inloc + 1])) && (isdigit(buffer[inloc + 2])))
  1485.           inloc += 3;
  1486.         else
  1487.           if ((buffer[inloc] == 4) && (isdigit(buffer[inloc + 1]))) {
  1488.           i = inloc;
  1489.           for (j = 1; j < 255; j++) {
  1490.             if ((buffer[i] == '\r') || (i > nhr.length))
  1491.               break;
  1492.             i++;
  1493.             inloc++;
  1494.           }
  1495.           inloc++;
  1496.           if (buffer[inloc] == '\n')
  1497.             inloc++;
  1498.         } else
  1499.           if (buffer[inloc] >= 127)
  1500.           inloc++;
  1501.         else
  1502.           if (buffer[inloc] == 1)
  1503.           inloc++;
  1504.         else
  1505.           text[outloc++] = buffer[inloc++];
  1506.       } while (inloc < nhr.length);
  1507.  
  1508.       text[outloc] = '\0';
  1509.  
  1510.       if ((nhr.main_type == main_type_post) ||
  1511.           (nhr.main_type == main_type_pre_post) ||
  1512.           (nhr.main_type == main_type_new_post)) {
  1513.         if (nhr.main_type == main_type_new_post) {
  1514.           sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
  1515.           if (exist(fn1)) {
  1516.             tolist = 1;
  1517.             nhr.main_type = main_type_email_name;
  1518.             get_list_addr(list_addr, alphasubtype);
  1519.           }
  1520.         }
  1521.         for (i = 0; (i < nlists) && (nhr.main_type != main_type_email_name); i++) {
  1522.           if (nhr.main_type == main_type_new_post) {
  1523.             if (strcmpi(alphasubtype, maillist[i].subtype) == 0) {
  1524.               nhr.main_type = main_type_email_name;
  1525.               strcpy(mh.toUserName, maillist[i].ownername);
  1526.             }
  1527.           } else {
  1528.             ttype = atoi(maillist[i].subtype);
  1529.             if (ttype == stype) {
  1530.               nhr.main_type = main_type_email_name;
  1531.               strcpy(mh.toUserName, maillist[i].ownername);
  1532.             }
  1533.           }
  1534.         }
  1535.       }
  1536.       switch (nhr.main_type) {
  1537.         case main_type_email:
  1538.         case main_type_email_name:
  1539.         case main_type_ssm:
  1540.           i = 1;
  1541.           if ((DIGEST) && (tolist)) {
  1542.             sprintf(outfn, "%sMQUEUE\\DIGEST\\%s.%d", net_data, alphasubtype, jdater);
  1543.             if (exist(outfn))
  1544.               hdr = 0;
  1545.           } else {
  1546.             sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, i);
  1547.             while (exist(outfn))
  1548.               sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, ++i);
  1549.           }
  1550.           break;
  1551.         case main_type_new_post:
  1552.         case main_type_post:
  1553.         case main_type_pre_post:
  1554.           i = 1;
  1555.           strcpy(tempoutfn, hold);
  1556.           sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, i);
  1557.           while (exist(outfn))
  1558.             sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, ++i);
  1559.           break;
  1560.         default:
  1561.           continue;
  1562.       }
  1563.  
  1564.       log_it(1, "\n ■ Creating: %s", outfn);
  1565.       if (nhr.fromsys != net_sysnum) {
  1566.         log_it(1, "\n ■ From    : %s", mh.fromUserName);
  1567.       } else {
  1568.         if (usermail) {
  1569.           if (*acct_addr)
  1570.             log_it(1, "\n ■ From    : \"%s\" <%s>", mh.fromUserName, acct_addr);
  1571.           else
  1572.             log_it(1, "\n ■ From    : \"%s\" <%s@%s>", mh.fromUserName, POPNAME, DOMAIN);
  1573.         } else
  1574.           log_it(1, "\n ■ From    : <%s@%s>", POPNAME, DOMAIN);
  1575.       }
  1576.       if ((nhr.main_type == main_type_post) ||
  1577.           (nhr.main_type == main_type_pre_post) ||
  1578.           (nhr.main_type == main_type_new_post)) {
  1579.         sprintf(fn1, "%sNEWS.RC", net_data);
  1580.         if ((fp = fsh_open(fn1, "rt")) == NULL) {
  1581.           log_it(1, "\n ■ %s not found!", fn1);
  1582.           sh_close(infile);
  1583.           if (text)
  1584.             free(text);
  1585.           if (buffer)
  1586.             free(buffer);
  1587.           return 1;
  1588.         } else {
  1589.           ok = 0;
  1590.           while ((fgets(_temp_buffer, 80, fp) != NULL) && (!ok)) {
  1591.             groupname[0] = 0;
  1592.             ss = strtok(_temp_buffer, " ");
  1593.             if (ss) {
  1594.               strcpy(groupname, ss);
  1595.               ss = strtok(NULL, " ");
  1596.               ss = strtok(NULL, "\r");
  1597.               if (nhr.main_type == main_type_new_post) {
  1598.                 strcpy(alphatype, ss);
  1599.                 if (strncmpi(alphasubtype, alphatype, strlen(alphasubtype)) == 0)
  1600.                   ok = 1;
  1601.               } else {
  1602.                 ttype = atoi(ss);
  1603.                 if (ttype == stype)
  1604.                   ok = 1;
  1605.               }
  1606.             }
  1607.           }
  1608.           *ss = NULL;
  1609.           if (fp != NULL)
  1610.             fclose(fp);
  1611.           if (!ok) {
  1612.             if (nhr.main_type != main_type_new_post)
  1613.               sprintf(alphatype, "%u", stype);
  1614.             log_it(1, "\n ■ Subtype %s not found in NEWS.RC!", alphatype);
  1615.             sh_close(infile);
  1616.             if (text)
  1617.               free(text);
  1618.             if (buffer)
  1619.               free(buffer);
  1620.             return 1;
  1621.           }
  1622.         }
  1623.       }
  1624.       if ((nhr.main_type == main_type_email) ||
  1625.           (nhr.main_type == main_type_email_name) ||
  1626.           (nhr.main_type == main_type_ssm)) {
  1627.         if (tolist)
  1628.           log_it(1, "\n ■ Sent to : %s Mailing List", alphasubtype);
  1629.         else
  1630.           log_it(1, "\n ■ Rcpt to : %s", mh.toUserName);
  1631.       } else
  1632.         log_it(1, "\n ■ Post to : %s", groupname);
  1633.  
  1634.       strcpy(_temp_buffer, mh.subject);
  1635.       j = 0;
  1636.       for (i = 0; i < strlen(mh.subject); i++) {
  1637.         if (_temp_buffer[i] == 3)
  1638.           ++i;
  1639.         else
  1640.           mh.subject[j++] = _temp_buffer[i];
  1641.       }
  1642.       mh.subject[j] = '\0';
  1643.  
  1644.       log_it(1, "\n ■ Subject : %s", mh.subject);
  1645.  
  1646.       if ((nhr.main_type == main_type_email) ||
  1647.           (nhr.main_type == main_type_email_name) ||
  1648.           (nhr.main_type == main_type_ssm)) {
  1649.         if (tolist) {
  1650.           sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
  1651.           f = sh_open1(fn1, O_RDONLY | O_BINARY);
  1652.           if (filelength(f) <= 0) {
  1653.             log_it(1, "\n ■ Mailing list %s has no subscribers.", alphasubtype);
  1654.             sh_close(f);
  1655.             continue;
  1656.           }
  1657.           sh_close(f);
  1658.         }
  1659.       }
  1660.       outfile = sh_open(outfn, O_RDWR | O_BINARY | O_CREAT | O_APPEND, S_IWRITE);
  1661.       if (outfile == -1) {
  1662.         sh_close(infile);
  1663.         if (buffer)
  1664.           free(buffer);
  1665.         if (text)
  1666.           free(text);
  1667.         log_it(1, "\n ■ Unable to open output file %s", outfn);
  1668.         return 1;
  1669.       }
  1670.       time(&some);
  1671.       time_msg = localtime(&some);
  1672.       strftime(mh.dateTime, 80, "%a, %d %b %y %H:%M:%S (%Z)", time_msg);
  1673.       if (!hdr) {
  1674.         sprintf(_temp_buffer, "\n\n---- Next Message ----\n\n");
  1675.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1676.       }
  1677.       if (nhr.fromsys == 32767) {
  1678.         sprintf(_temp_buffer, "From: %s\n", mh.fromUserName);
  1679.       } else
  1680.         if (nhr.fromsys != net_sysnum) {
  1681.         sprintf(_temp_buffer, "From: \"%s\" <%s@%s>\n", mh.fromUserName, POPNAME, DOMAIN);
  1682.       } else {
  1683.         if ((spam) && ((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post))) {
  1684.           if (!*acct_addr) {
  1685.             if (spamname[0] == 0)
  1686.               sprintf(_temp_buffer, "From: \"%s\" <%s@dont.spam.me.%s>\n",
  1687.                       mh.fromUserName, POPNAME, DOMAIN);
  1688.             else
  1689.               sprintf(_temp_buffer, "From: \"%s\" <%s>\n", mh.fromUserName, spamname);
  1690.           } else
  1691.             sprintf(_temp_buffer, "From: \"%s\" <NOSPAM%s>\n", mh.fromUserName, acct_addr);
  1692.         } else {
  1693.           if (usermail) {
  1694.             if (*acct_addr)
  1695.               sprintf(_temp_buffer, "From: \"%s\" <%s>\n",
  1696.                       mh.fromUserName, acct_addr);
  1697.             else
  1698.               sprintf(_temp_buffer, "From: \"%s\" <%s@%s>\n",
  1699.                       mh.fromUserName, POPNAME, DOMAIN);
  1700.           } else
  1701.             sprintf(_temp_buffer, "From: <%s@%s>\n", POPNAME, DOMAIN);
  1702.         }
  1703.       }
  1704.       if ((tolist) && (DIGEST)) {
  1705.         strcpy(savename, mh.fromUserName);
  1706.         sprintf(_temp_buffer, "From: \"%s Mailing List\" <%s@%s>\n",
  1707.             alphasubtype, POPNAME, DOMAIN);
  1708.       }
  1709.       ++cur_daten;
  1710.       if (hdr) {
  1711.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1712.         sprintf(_temp_buffer, "Message-ID: <%lx-%s@wwivbbs.org>\n",
  1713.                 cur_daten, POPNAME);
  1714.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1715.       }
  1716.       if ((nhr.main_type == main_type_email) ||
  1717.           (nhr.main_type == main_type_email_name) ||
  1718.           (nhr.main_type == main_type_ssm)) {
  1719.         if (!tolist) {
  1720.           sprintf(_temp_buffer, "To: %s\n", mh.toUserName);
  1721.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1722.         } else {
  1723.           i = 0;
  1724.           if (hdr) {
  1725.             sprintf(fn1, "%sM%s.NET", net_data, alphasubtype);
  1726.             if ((fp = fsh_open(fn1, "rt")) != NULL) {
  1727.               while (fgets(_temp_buffer, 80, fp) != NULL) {
  1728.                 if (_fstrstr(_temp_buffer, "@")) {
  1729.                   strcpy(mh.toUserName, _temp_buffer);
  1730.                   sprintf(_temp_buffer, "To: %s", mh.toUserName);
  1731.                   if (_temp_buffer[strlen(_temp_buffer) - 1] != '\n')
  1732.                     strcat(_temp_buffer, "\n");
  1733.                   sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1734.                   i = 1;
  1735.                 }
  1736.               }
  1737.               if (fp != NULL)
  1738.                 fclose(fp);
  1739.             }
  1740.             if (!i) {
  1741.               sh_close(infile);
  1742.               if (buffer)
  1743.                 free(buffer);
  1744.               if (text)
  1745.                 free(text);
  1746.               log_it(1, "\n ■ Error processing mailing list %s.", alphasubtype);
  1747.               return (1);
  1748.             } else {
  1749.               if (*list_addr)
  1750.                 sprintf(_temp_buffer, "Reply-To: \"%s\" <%s>\n", alphasubtype,
  1751.                         list_addr);
  1752.               else
  1753.                 sprintf(_temp_buffer, "Reply-To: \"%s\" <%s@%s>\n", alphasubtype,
  1754.                         POPNAME, DOMAIN);
  1755.               sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1756.             }
  1757.           }
  1758.         }
  1759.       } else {
  1760.         sprintf(_temp_buffer, "Newsgroups: %s\n", groupname);
  1761.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1762.       }
  1763.       sprintf(_temp_buffer, "Subject: %s\n", mh.subject);
  1764.       if ((DIGEST) && (tolist)) {
  1765.         strcpy(savesubj, _temp_buffer);
  1766.         sprintf(_temp_buffer, "Subject: %s Daily Digest, Day %d\n", alphasubtype, jdater);
  1767.       }
  1768.       if (hdr) {
  1769.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1770.         sprintf(_temp_buffer, "MIME-Version: 1.0\n");
  1771.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1772.         sprintf(_temp_buffer, "Content-Type: text/plain; charset=us-ascii\n");
  1773.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1774.         sprintf(_temp_buffer, "Content-Transfer-Encoding: 7bit\n");
  1775.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1776.       }
  1777.       sprintf(_temp_buffer, "Date: %s\n", mh.dateTime);
  1778.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1779.       if (nhr.main_type != main_type_email_name) {
  1780.         if (hdr) {
  1781.           if (a == 2)
  1782.             sprintf(_temp_buffer, "Path: anonymous!wwivbbs.org\n");
  1783.           else
  1784.             sprintf(_temp_buffer, "Path: %s!%s\n", POPNAME, DOMAIN);
  1785.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1786.           if (a == 2)
  1787.             sprintf(_temp_buffer, "Organization: WWIV BBS\n");
  1788.           else
  1789.             sprintf(_temp_buffer, "Organization: %s * %s\n",
  1790.                     syscfg.systemname, syscfg.systemphone);
  1791.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1792.         }
  1793.       }
  1794.       if (tolist) {
  1795.         if (hdr) {
  1796.           if (*list_addr)
  1797.             sprintf(_temp_buffer, "X-Reply-To: \"%s\" <%s>\n",
  1798.                     alphasubtype, list_addr);
  1799.           else
  1800.             sprintf(_temp_buffer, "X-Reply-To: \"%s\" <%s@%s>\n",
  1801.                     alphasubtype, POPNAME, DOMAIN);
  1802.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1803.           sprintf(_temp_buffer, "Source: %s Mail List\n", alphasubtype);
  1804.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1805.         }
  1806.       }
  1807.       if (((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post)) &&
  1808.           (!tolist) && (a != 2)) {
  1809.         if (!*acct_addr) {
  1810.           if (*REPLYTO)
  1811.             sprintf(_temp_buffer, "Reply-to: \"%s\" <%s>\n", mh.fromUserName, REPLYTO);
  1812.           else
  1813.             sprintf(_temp_buffer, "Reply-to: \"%s\" <%s@%s>\n",
  1814.                     mh.fromUserName, POPNAME, DOMAIN);
  1815.         } else
  1816.           sprintf(_temp_buffer, "Reply-to: \"%s\" <%s>\n", mh.fromUserName, acct_addr);
  1817.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1818.       }
  1819.       if (hdr) {
  1820.         sprintf(_temp_buffer, "Version: WWIV PPP Project %s\n\n", VERSION);
  1821.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1822.       }
  1823.  
  1824.       if ((DIGEST) && (tolist)) {
  1825.         sprintf(_temp_buffer, "%s", savesubj);
  1826.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1827.         sprintf(_temp_buffer, "From: %s\n\n", savename);
  1828.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1829.       }
  1830.  
  1831.       if ((nhr.main_type != main_type_email) &&
  1832.           (nhr.main_type != main_type_email_name) &&
  1833.           (strncmp(mh.toUserName, "ALL", 3) != 0)) {
  1834.         sprintf(_temp_buffer, "Responding to: %s\n", mh.toUserName);
  1835.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1836.       }
  1837.       for (i = 0; i < strlen(text); i++)
  1838.         if (text[i] == 'π')
  1839.           text[i] = '\n';
  1840.  
  1841.       sh_write(outfile, text, strlen(text));
  1842.       if ((tolist) && (DIGEST)) {
  1843.         sprintf(_temp_buffer, "\n\n");
  1844.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1845.       } else {
  1846.         sprintf(tagfn, "%sI%s.TAG", syscfg.datadir, alphasubtype);
  1847.         if (exist(tagfn))
  1848.           strcpy(tagfile, tagfn);
  1849.         tagfn[0] = 0;
  1850.         ns = 0;
  1851.         for (i6 = 0; i6 < 99; i6++) {
  1852.           sprintf(tagfn, "%sI%s.T%d", syscfg.datadir, alphasubtype, i6);
  1853.           if (exist(tagfn))
  1854.             ns++;
  1855.           else
  1856.             break;
  1857.         }
  1858.         sprintf(tagfn, "%sI%s.T%d", syscfg.datadir, alphasubtype, random(ns));
  1859.         if (exist(tagfn))
  1860.           strcpy(tagfile, tagfn);
  1861.         if (tagfile[0] == 0) {
  1862.           sprintf(_temp_buffer, "\n\nOrigin: %s * %s\n\n",
  1863.                   syscfg.systemname, syscfg.systemphone);
  1864.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1865.         } else {
  1866.           if ((fp = fsh_open(tagfile, "rt")) == NULL)
  1867.             log_it(1, "\n ■ Error reading %s.", tagfile);
  1868.           else {
  1869.             sprintf(_temp_buffer, "\n\n");
  1870.             sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1871.             /* Speed this up */
  1872.             while (fgets(_temp_buffer, 120, fp)) {
  1873.               for (i = 0; ((i < strlen(_temp_buffer)) &&
  1874.                (_temp_buffer[i] != '\r') && (_temp_buffer[i] != '\n')); i++)
  1875.                 if ((_temp_buffer[i] < 32) || (_temp_buffer[i] > 126))
  1876.                   _temp_buffer[i] = 32;
  1877.               sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1878.             }
  1879.             if (fp != NULL)
  1880.               fclose(fp);
  1881.           }
  1882.           sprintf(_temp_buffer, "\n\n");
  1883.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1884.         }
  1885.       }
  1886.       sh_close(outfile);
  1887.     } else {
  1888.       if ((nhr.main_type >= 0x01) && (nhr.main_type <= 0x1b))
  1889.         log_it(1, "\n ■ %s message skipped",
  1890.                main_type[nhr.main_type - 1]);
  1891.       else
  1892.         log_it(1, "\n ■ Unknown Main_type %hd skipped", nhr.main_type);
  1893.     }
  1894.   }
  1895.   sh_close(infile);
  1896.   unlink(fn);
  1897.   if (text)
  1898.     free(text);
  1899.   if (buffer)
  1900.     free(buffer);
  1901.   return (0);
  1902. }
  1903.  
  1904. void get_dir(char *s, int be)
  1905. {
  1906.   strcpy(s, "X:\\");
  1907.   s[0] = 'A' + getdisk();
  1908.   getcurdir(0, s + 3);
  1909.   if (be) {
  1910.     if (s[strlen(s) - 1] != '\\')
  1911.       strcat(s, "\\");
  1912.   }
  1913. }
  1914.  
  1915. void ssm(char *s)
  1916. {
  1917.   int f, i, i1;
  1918.   char s1[161];
  1919.   shortmsgrec sm;
  1920.  
  1921.   sprintf(s1, "%sSMW.DAT", syscfg.datadir);
  1922.   f = sh_open(s1, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  1923.   if (f < 0)
  1924.     return;
  1925.   i = (int) (filelength(f) / sizeof(shortmsgrec));
  1926.   i1 = i - 1;
  1927.   if (i1 >= 0) {
  1928.     sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  1929.     sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  1930.     while ((sm.tosys == 0) && (sm.touser == 0) && (i1 > 0)) {
  1931.       --i1;
  1932.       sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  1933.       sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  1934.     }
  1935.     if ((sm.tosys) || (sm.touser))
  1936.       ++i1;
  1937.   } else
  1938.     i1 = 0;
  1939.   sm.tosys = 0;
  1940.   sm.touser = 1;
  1941.   strncpy(sm.message, s, 80);
  1942.   sm.message[80] = 0;
  1943.   sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  1944.   sh_write(f, (void *) &sm, sizeof(shortmsgrec));
  1945.   sh_close(f);
  1946. }
  1947.  
  1948.  
  1949. /*
  1950.   action: 1 = unsubscribed,
  1951.           2 = subscribed,
  1952.           3 = already subscribed,
  1953.           4 = not subscribed
  1954.           5 = invalid list
  1955.           6 = sending MAILLIST.TXT
  1956. */
  1957.  
  1958. void send_note(int action, char *mailname, char *listname)
  1959. {
  1960.   char s[81], fn[MAXPATH];
  1961.   int i;
  1962.   FILE *fp, *rlz;
  1963.  
  1964.   i = 1;
  1965.   sprintf(fn, "%sMQUEUE\\MSG.%d", net_data, i);
  1966.   while (exist(fn))
  1967.     sprintf(fn, "%sMQUEUE\\MSG.%d", net_data, ++i);
  1968.  
  1969.   if ((fp = fsh_open(fn, "wt+")) == NULL) {
  1970.     log_it(1, "\n ! Unable to create %s.", fn);
  1971.     return;
  1972.   }
  1973.   if (action != 5)
  1974.     fprintf(fp, "From: \"%s\" <%s@%s>\n", listname, POPNAME, DOMAIN);
  1975.   else
  1976.     fprintf(fp, "From: <%s@%s>\n", POPNAME, DOMAIN);
  1977.   fprintf(fp, "To: %s\n", mailname);
  1978.   fprintf(fp, "Subject: %s Mailing List\n\n", listname);
  1979.  
  1980.   switch (action) {
  1981.     case 1:
  1982.       sprintf(s, "%s removed from mailing list: %s", mailname, listname);
  1983.       fprintf(fp, "\n%s\n\n", s);
  1984.       log_it(1, "\n ■ %s", s);
  1985.       ssm(s);
  1986.       break;
  1987.     case 2:
  1988.       sprintf(fn, "%sR%s.RLZ", net_data, listname);
  1989.       if (!(exist(fn)))
  1990.         sprintf(fn, "%sGLOBAL.RLZ", net_data);
  1991.       if ((rlz = fsh_open(fn, "rt")) != NULL) {
  1992.         while (fgets(s, 80, rlz))
  1993.           fprintf(fp, s);
  1994.         fprintf(fp, "\n\n");
  1995.         fclose(rlz);
  1996.         sprintf(s, "%s added to mailing list: %s", mailname, listname);
  1997.         log_it(1, "\n%s", s);
  1998.         ssm(s);
  1999.       } else {
  2000.         sprintf(s, "%s added to mailing list: %s", mailname, listname);
  2001.         fprintf(fp, "\n%s\n\n", s);
  2002.         log_it(1, "\n ■ %s", s);
  2003.         ssm(s);
  2004.       }
  2005.       break;
  2006.     case 3:
  2007.       sprintf(fn, "%sR%s.RLZ", net_data, listname);
  2008.       if (!(exist(fn)))
  2009.         sprintf(fn, "%sGLOBAL.RLZ", net_data);
  2010.       if ((rlz = fsh_open(fn, "rt")) != NULL) {
  2011.         while (fgets(s, 80, rlz))
  2012.           fprintf(fp, s);
  2013.         fprintf(fp, "\n\n");
  2014.         fclose(rlz);
  2015.       } else
  2016.         fprintf(fp, "\n%s was already subscribed to mailing list:\n\n   %s\n\n",
  2017.                 mailname, listname);
  2018.       break;
  2019.     case 4:
  2020.       fprintf(fp, "\n%s not subscribed to mailing list:\n\n   %s\n\n",
  2021.               mailname, listname);
  2022.       break;
  2023.     case 5:
  2024.       sprintf(s, "%s requested an invalid mailing list: %s", mailname, listname);
  2025.       fprintf(fp, "\n%s\n\n", s);
  2026.       log_it(1, "\n ■ %s", s);
  2027.       ssm(s);
  2028.       break;
  2029.     case 6:
  2030.       sprintf(fn, "%sMAILLIST.TXT", syscfg.gfilesdir);
  2031.       if ((rlz = fsh_open(fn, "rt")) != NULL) {
  2032.         while (fgets(s, 80, rlz))
  2033.           fprintf(fp, s);
  2034.         fprintf(fp, "\n\n");
  2035.         fclose(rlz);
  2036.         sprintf(s, "Sent MAILLIST.TXT to %s.", mailname);
  2037.       } else
  2038.         sprintf(s, "No mailing list file found.  Notify system operator.");
  2039.       fprintf(fp, "\n%s\n\n", s);
  2040.       log_it(1, "\n ■ %s", s);
  2041.       ssm(s);
  2042.       break;
  2043.   }
  2044.   if (fp != NULL)
  2045.     fclose(fp);
  2046. }
  2047.  
  2048. int copyfile(char *input, char *output)
  2049. {
  2050.   int f1, f2, i;
  2051.   char *b;
  2052.   struct ftime ft;
  2053.  
  2054.   if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
  2055.     if ((b = (char *) malloc(16400)) == NULL)
  2056.       return 0;
  2057.     f1 = sh_open1(input, O_RDONLY | O_BINARY);
  2058.     if (!f1) {
  2059.       free(b);
  2060.       b = NULL;
  2061.       return 0;
  2062.     }
  2063.     getftime(f1, &ft);
  2064.  
  2065.     f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  2066.     if (!f2) {
  2067.       free(b);
  2068.       b = NULL;
  2069.       f1 = sh_close(f1);
  2070.       return 0;
  2071.     }
  2072.     i = read(f1, (void *) b, 16384);
  2073.     while (i > 0) {
  2074.       sh_write(f2, (void *) b, i);
  2075.       i = read(f1, (void *) b, 16384);
  2076.     }
  2077.     f1 = sh_close(f1);
  2078.     setftime(f2, &ft);
  2079.     f2 = sh_close(f2);
  2080.     free(b);
  2081.     b = NULL;
  2082.   }
  2083.   return 1;
  2084. }
  2085.  
  2086. char (*devices)[9];
  2087. int num_devices;
  2088.  
  2089. void finddevs(char (*devs)[9], int *count)
  2090. {
  2091.   char s[9];
  2092.   int i;
  2093.   char far *ss;
  2094.   long far *l;
  2095.   union REGS regs;
  2096.   struct SREGS sregs;
  2097.  
  2098.   *count = 0;
  2099.   regs.x.ax = 0x5200;
  2100.   int86x(INT_REAL_DOS, ®s, ®s, &sregs);
  2101.   ss = (char *) MK_FP(sregs.es, regs.x.bx);
  2102.   ss += 34;
  2103.   l = (long far *) ss;
  2104.  
  2105.   while (((unsigned short) l) != 0xffff) {
  2106.     ss = (char far *) l;
  2107.     ss += 10;
  2108.     if (*ss > 32) {
  2109.       strncpy(s, ss, 8);
  2110.       s[8] = 0;
  2111.       for (i = 7; i; i--)
  2112.         if (s[i] == ' ')
  2113.           s[i] = 0;
  2114.         else
  2115.           break;
  2116.       if (devs) {
  2117.         strcpy(devs[*count], s);
  2118.       }
  2119.       ++(*count);
  2120.     }
  2121.     l = (long far *) *l;
  2122.   }
  2123. }
  2124.  
  2125. void find_devices(void)
  2126. {
  2127.   finddevs(NULL, &num_devices);
  2128.   devices = (char (*)[9]) farmalloc((num_devices + 2) * 9);
  2129.   finddevs(devices, &num_devices);
  2130. }
  2131.  
  2132. int okfn(char *s)
  2133. {
  2134.   int i, l;
  2135.   unsigned char ch;
  2136.  
  2137.   find_devices();
  2138.   l = strlen(s);
  2139.   if ((s[0] == '-') || (s[0] == ' ') || (s[0] == '.') || (s[0] == '@'))
  2140.     return (0);
  2141.   for (i = 0; i < l; i++) {
  2142.     ch = s[i];
  2143.     if ((ch == ' ') || (ch == '/') || (ch == '\\') || (ch == ':') ||
  2144.         (ch == '>') || (ch == '<') || (ch == '|') || (ch == '+') ||
  2145.         (ch == ',') || (ch == ';') || (ch == '^') || (ch == '\"') ||
  2146.         (ch == '\'') || (ch > 126))
  2147.       return (0);
  2148.   }
  2149.  
  2150.   for (i = 0; i < num_devices; i++) {
  2151.     l = strlen(devices[i]);
  2152.     if (strncmp(devices[i], s, l) == 0) {
  2153.       if ((s[l] == 0) || (s[l] == '.') || (l == 8))
  2154.         return (0);
  2155.     }
  2156.   }
  2157.   if (devices != NULL)
  2158.     farfree(devices);
  2159.   return (1);
  2160. }
  2161.  
  2162. int subscribe(char *fn)
  2163. {
  2164.   char *ss, s[81], s1[81], mailname[81], subtype[81];
  2165.   int done, found, unsubscribe;
  2166.   FILE *fp, *oldfp, *newfp;
  2167.  
  2168.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  2169.     log_it(1, "\n ! Unable to open %s.", fn);
  2170.     return 1;
  2171.   }
  2172.   done = unsubscribe = 0;
  2173.   while ((fgets(s1, 80, fp)) && (!done)) {
  2174.     strcpy(s, &(s1[3]));
  2175.     if (strnicmp(s, "from:", 5) == 0) {
  2176.       ss = strtok(s, ":");
  2177.       if (ss) {
  2178.         ss = strtok(NULL, "\r\n");
  2179.         trimstr1(ss);
  2180.         strcpy(mailname, ss);
  2181.       }
  2182.     }
  2183.     if (strnicmp(s, "subject:", 8) == 0) {
  2184.       done = 1;
  2185.       ss = strtok(s, ":");
  2186.       if (ss) {
  2187.         ss = strtok(NULL, "\r\n");
  2188.         trimstr1(ss);
  2189.         strcpy(s1, ss);
  2190.         if (strnicmp(s1, "subscribe", 9) == 0) {
  2191.           ss = strtok(s1, " ");
  2192.           if (ss) {
  2193.             ss = strtok(NULL, "\r\n");
  2194.             trimstr1(ss);
  2195.             strcpy(subtype, ss);
  2196.           }
  2197.         }
  2198.         if (strnicmp(s1, "unsubscribe", 11) == 0) {
  2199.           unsubscribe = 1;
  2200.           ss = strtok(s1, " ");
  2201.           if (ss) {
  2202.             ss = strtok(NULL, "\r\n");
  2203.             trimstr1(ss);
  2204.             strcpy(subtype, ss);
  2205.           }
  2206.         }
  2207.       }
  2208.       ss = NULL;
  2209.     }
  2210.   }
  2211.   if (fp != NULL)
  2212.     fclose(fp);
  2213.  
  2214.   if ((!*mailname) || (!*subtype)) {
  2215.     log_it(1, "\n ! Invalid subscription request %s.", fn);
  2216.     return 1;
  2217.   }
  2218.   if ((strlen(subtype) == 1) || (strlen(subtype) > 7)) {
  2219.     log_it(1, "\n ! %s attempted to write to M%s.NET!", mailname, subtype);
  2220.     return 1;
  2221.   }
  2222.   if (strnicmp(subtype, "LISTS", 5) == 0) {
  2223.     send_note(6, mailname, subtype);
  2224.     return 1;
  2225.   }
  2226.   sprintf(s1, "M%s.NET", subtype);
  2227.   if (!okfn(s1)) {
  2228.     log_it(1, "\n ! %s attempted to create invalid filename %s!", mailname, s1);
  2229.     return 1;
  2230.   }
  2231.   sprintf(s, "%sM%s.NET", net_data, subtype);
  2232.   if (!exist(s)) {
  2233.     log_it(1, "\n ! %s subscriber list not found.", s);
  2234.     send_note(5, mailname, subtype);
  2235.     return 1;
  2236.   }
  2237.   if ((oldfp = fsh_open(s, "rt")) == NULL) {
  2238.     log_it(1, "\n ! Unable to open input file %s.", s);
  2239.     return 1;
  2240.   }
  2241.   sprintf(s1, "%sM%s.TMP", net_data, subtype);
  2242.   if (exist(s1))
  2243.     unlink(s1);
  2244.   if ((newfp = fsh_open(s1, "wt+")) == NULL) {
  2245.     log_it(1, "\n ! Unable to open output file %s.", s1);
  2246.     return 1;
  2247.   }
  2248.   found = 0;
  2249.   while (fgets(s, 80, oldfp)) {
  2250.     trimstr1(s);
  2251.     if (unsubscribe) {
  2252.       if (stricmp(s, mailname) == 0) {
  2253.         log_it(1, "\n ■ Removing %s from %s mailing list.", mailname, subtype);
  2254.         send_note(1, mailname, subtype);
  2255.         found = 1;
  2256.       } else
  2257.         fprintf(newfp, "%s\n", s);
  2258.     } else {
  2259.       if (stricmp(s, mailname) == 0) {
  2260.         log_it(1, "\n ■ %s already in %s mailing list.", mailname, subtype);
  2261.         send_note(3, mailname, subtype);
  2262.         found = 1;
  2263.       }
  2264.       fprintf(newfp, "%s\n", s);
  2265.     }
  2266.   }
  2267.   if (!found) {
  2268.     if (unsubscribe) {
  2269.       log_it(1, "\n ■ %s was not a member of %s mailing list.", mailname, subtype);
  2270.       send_note(4, mailname, subtype);
  2271.     } else {
  2272.       log_it(1, "\n ■ Adding %s to %s mailing list.", mailname, subtype);
  2273.       fprintf(newfp, "%s\n", mailname);
  2274.       send_note(2, mailname, subtype);
  2275.     }
  2276.   }
  2277.   if (oldfp != NULL)
  2278.     fclose(oldfp);
  2279.   if (newfp != NULL)
  2280.     fclose(newfp);
  2281.   sprintf(s, "%sM%s.TMP", net_data, subtype);
  2282.   sprintf(s1, "%sM%s.NET", net_data, subtype);
  2283.   if (exist(s1))
  2284.     unlink(s1);
  2285.   copyfile(s, s1);
  2286.   return 0;
  2287. }
  2288.  
  2289. int main(int argc, char *argv[])
  2290. {
  2291.   char fn[MAXPATH], newfn[MAXPATH], ext[5], *ss;
  2292.   int f, f1, i;
  2293.   struct ffblk ff;
  2294.   struct date dt;
  2295.   struct time tm;
  2296.  
  2297.   output("\n ■ PPP Import/Export %s", VERSION);
  2298.   if (argc != 7) {
  2299.     log_it(1, "\n ■ EXP <filename> <net_data> <net_sysnum> <POPNAME> <DOMAIN> <net_name>\n\n");
  2300.     if (argc > 1) {
  2301.       log_it(1, "Command line was: ");
  2302.       for (i = 0; i < argc; i++)
  2303.         log_it(1, "%s ", argv[i]);
  2304.       log_it(1, "\n\n");
  2305.     }
  2306.     return (1);
  2307.   }
  2308.   strcpy(net_data, argv[2]);
  2309.   f = sh_open1("CONFIG.DAT", O_RDONLY | O_BINARY);
  2310.   if (f < 0) {
  2311.     log_it(1, "Could not open CONFIG.DAT!\n\n");
  2312.     return 1;
  2313.   }
  2314.   sh_read(f, (void *) &syscfg, sizeof(configrec));
  2315.   sh_close(f);
  2316.  
  2317.   detect_multitask();
  2318.  
  2319.   get_dir(maindir, 1);
  2320.   sprintf(fn, "%s%s", net_data, argv[1]);
  2321.   strcpy(net_name, argv[6]);
  2322.   strcpy(POPNAME, argv[4]);
  2323.   strcpy(DOMAIN, argv[5]);
  2324.   net_sysnum = atoi(argv[3]);
  2325.   DIGEST = 0;
  2326.   tagfile[0] = 0;
  2327.   spam = 0;
  2328.  
  2329.   ss = getenv("WWIV_INSTANCE");
  2330.   if (ss) {
  2331.     instance = atoi(ss);
  2332.     if (instance >= 1000) {
  2333.       log_it(1, "\n ■ WWIV_INSTANCE set to %hd.  Can only be 1..999!",
  2334.              instance);
  2335.       instance = 1;
  2336.     }
  2337.   } else
  2338.     instance = 1;
  2339.  
  2340.   parse_net_ini();
  2341.   gettime(&tm);
  2342.   getdate(&dt);
  2343.   cur_daten = dostounix(&dt, &tm);
  2344.   jdater = jdate(dt.da_year, dt.da_mon, dt.da_day);
  2345.  
  2346.   strupr(postmaster);
  2347.   export(fn);
  2348.  
  2349.   sprintf(fn, "%sSPOOL\\UNK*.*", net_data);
  2350.   f1 = findfirst(fn, &ff, 0);
  2351.   while (f1 == 0) {
  2352.     sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
  2353.     if (!import(fn)) {
  2354.       unlink(fn);
  2355.     }
  2356.     f1 = findnext(&ff);
  2357.   }
  2358.  
  2359.   sprintf(fn, "%sINBOUND\\SUB*.*", net_data);
  2360.   f1 = findfirst(fn, &ff, 0);
  2361.   while (f1 == 0) {
  2362.     sprintf(fn, "%sINBOUND\\%s", net_data, ff.ff_name);
  2363.     fnsplit(fn, NULL, NULL, NULL, ext);
  2364.     if (strnicmp(ext, ".BAD", 4) == 0)
  2365.       log_it(1, "\n ■ Unprocessed subscriber request %s...", ff.ff_name);
  2366.     else {
  2367.       log_it(1, "\n ■ Processing subscriber request %s...", ff.ff_name);
  2368.       if (!subscribe(fn))
  2369.         unlink(fn);
  2370.       else {
  2371.         name_bad(newfn);
  2372.         rename(fn, newfn);
  2373.       }
  2374.     }
  2375.     f1 = findnext(&ff);
  2376.   }
  2377.  
  2378.   if (maillist != NULL)
  2379.     free(maillist);
  2380.  
  2381.   return 0;
  2382. }
  2383.