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