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