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

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