home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B32.ZIP / EXP.C < prev    next >
Text File  |  1997-07-05  |  36KB  |  1,265 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 <malloc.h>
  17. #include <process.h>
  18. #include <direct.h>
  19. #include "vardec.h"
  20. #include "net.h"
  21.  
  22. #include "version.h"
  23.  
  24. #define WAIT_TIME 10
  25. #define TRIES 100
  26. #define SHARE_LEVEL 10
  27. #define MT_DESQVIEW 0x01
  28. #define MT_WINDOWS  0x02
  29. #define MT_OS2      0x04
  30. #define MT_NB       0x40
  31.  
  32.  
  33. struct msghdr {
  34.   char fromUserName[205];
  35.   char toUserName[81];
  36.   char subject[81];
  37.   char dateTime[81];
  38. };
  39.  
  40. typedef struct {
  41.   char ownername[60];
  42.   char subtype[8];
  43. } MAILLISTREC;
  44.  
  45. MAILLISTREC *maillist;
  46. configrec syscfg;
  47.  
  48. char *net_name, postmaster[31], net_data[MAXPATH], POPNAME[21], DOMAIN[81], tagfile[MAXPATH], maindir[MAXPATH], spamname[81];
  49. unsigned short net_sysnum, defuser, num_users, use_alias, instance, curuser, spam;
  50. int multitasker = 0;
  51. int nlists = 0;
  52. char alphasubtype[8];
  53.  
  54. void dv_pause(void)
  55. {
  56.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  57.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  58.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  59. }
  60.  
  61. void win_pause(void)
  62. {
  63.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  64. }
  65.  
  66. int get_dos_version(void)
  67. {
  68.   _AX = 0x3000;
  69.   geninterrupt(0x21);
  70.   if (_AX % 256 >= 10) {
  71.     multitasker |= MT_OS2;
  72.   }
  73.   return (_AX);
  74. }
  75.  
  76. int get_dv_version(void)
  77. {
  78.   int v;
  79.  
  80.   if (multitasker & MT_OS2)
  81.     return 0;
  82.   _AX = 0x2b01;
  83.   _CX = 0x4445;
  84.   _DX = 0x5351;
  85.   geninterrupt(0x21);
  86.   if (_AL == 0xff) {
  87.     return 0;
  88.   } else {
  89.     v = _BX;
  90.     multitasker |= MT_DESQVIEW;
  91.     return v;
  92.   }
  93. }
  94.  
  95. int get_win_version(void)
  96. {
  97.   int v = 0;
  98.  
  99.   __emit__(0x55, 0x06, 0x53);
  100.   _AX = 0x352f;
  101.   geninterrupt(0x21);
  102.   _AX = _ES;
  103.   if (_AX | _BX) {
  104.     _AX = 0x1600;
  105.     geninterrupt(0x2f);
  106.     v = _AX;
  107.     if (v % 256 <= 1)
  108.       v = 0;
  109.   }
  110.   __emit__(0x5b, 0x07, 0x5d);
  111.   if (v != 0)
  112.     multitasker |= MT_WINDOWS;
  113.   return (v);
  114. }
  115.  
  116. int get_nb_version(void)
  117. {
  118.   _AX = 0;
  119.   geninterrupt(0x2A);
  120.   return (_AH);
  121. }
  122.  
  123. void detect_multitask(void)
  124. {
  125.   get_dos_version();
  126.   get_win_version();
  127.   get_dv_version();
  128.   if (multitasker < 2)
  129.     if (get_nb_version())
  130.       multitasker = MT_NB;
  131. }
  132.  
  133. void giveup_timeslice(void)
  134. {
  135.   if (multitasker) {
  136.     switch (multitasker) {
  137.  case 1:
  138.  case 3:
  139.         dv_pause();
  140.         break;
  141.       case 2:
  142.       case 4:
  143.       case 5:
  144.       case 6:
  145.       case 7:
  146.         win_pause();
  147.         break;
  148.       default:
  149.         break;
  150.     }
  151.   }
  152. }
  153.  
  154. int sh_write(int handle, void *buffer, unsigned long len)
  155. {
  156.   if (handle == -1) {
  157.     return (-1);
  158.   }
  159.   return (write(handle, buffer, (unsigned) len));
  160. }
  161.  
  162. int sh_open(char *path, int file_access, unsigned fmode)
  163. {
  164.   int handle, count, share;
  165.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  166.  
  167.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  168.     share = SH_DENYRW;
  169.   } else {
  170.     share = SH_DENYWR;
  171.   }
  172.   handle = open(path, file_access | share, fmode);
  173.   if (handle < 0) {
  174.     count = 1;
  175.     fnsplit(path, drive, dir, file, ext);
  176.     if (access(path, 0) != -1) {
  177.       delay(WAIT_TIME);
  178.       handle = open(path, file_access | share, fmode);
  179.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  180.         if (count % 2)
  181.           delay(WAIT_TIME);
  182.         else
  183.           giveup_timeslice();
  184.         count++;
  185.         handle = open(path, file_access | share, fmode);
  186.       }
  187.     }
  188.   }
  189.   return (handle);
  190. }
  191.  
  192. int sh_open1(char *path, int access)
  193. {
  194.   unsigned fmode;
  195.  
  196.   fmode = 0;
  197.   if ((access & O_RDWR) || (access & O_WRONLY))
  198.     fmode |= S_IWRITE;
  199.   if ((access & O_RDWR) || (access & O_RDONLY))
  200.     fmode |= S_IREAD;
  201.   return (sh_open(path, access, fmode));
  202. }
  203.  
  204. int sh_close(int f)
  205. {
  206.   if (f != -1)
  207.     close(f);
  208.   return (-1);
  209. }
  210.  
  211. int sh_read(int handle, void *buf, unsigned len)
  212. {
  213.   if (handle == -1) {
  214.     return (-1);
  215.   }
  216.   return (read(handle, buf, len));
  217. }
  218.  
  219. long sh_lseek(int handle, long offset, int fromwhere)
  220. {
  221.   if (handle == -1) {
  222.     return (-1L);
  223.   }
  224.   return (lseek(handle, offset, fromwhere));
  225. }
  226.  
  227. FILE *fsh_open(char *path, char *fmode)
  228. {
  229.   FILE *f;
  230.   int count, share, md, fd;
  231.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  232.  
  233.   share = SH_DENYWR;
  234.   md = 0;
  235.   if (((char *) _fstrchr(fmode, 'w')) != NULL) {
  236.     share = SH_DENYRD;
  237.     md = O_RDWR | O_CREAT | O_TRUNC;
  238.   } else
  239.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  240.     share = SH_DENYRD;
  241.     md = O_RDWR | O_CREAT;
  242.   } else {
  243.     md = O_RDONLY;
  244.   }
  245.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  246.     md |= O_BINARY;
  247.   }
  248.   if (((char *) _fstrchr(fmode, '+')) != NULL) {
  249.     md &= ~O_RDONLY;
  250.     md |= O_RDWR;
  251.     share = SH_DENYRD;
  252.   }
  253.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  254.   if (fd < 0) {
  255.     count = 1;
  256.     fnsplit(path, drive, dir, file, ext);
  257.     if ((access(path, 0)) != -1) {
  258.       delay(WAIT_TIME);
  259.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  260.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  261.         delay(WAIT_TIME);
  262.         count++;
  263.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  264.       }
  265.     }
  266.   }
  267.   if (fd > 0) {
  268.     if (((char *) _fstrchr(fmode, 'a')) != NULL)
  269.       sh_lseek(fd, 0L, SEEK_END);
  270.     f = fdopen(fd, fmode);
  271.     if (!f) {
  272.       close(fd);
  273.     }
  274.   } else
  275.     f = 0;
  276.   return (f);
  277. }
  278.  
  279. size_t fsh_write(void *ptr, size_t size, size_t n, FILE * stream)
  280. {
  281.  
  282.   if (stream == NULL) {
  283.     return (0);
  284.   }
  285.   return (fwrite(ptr, size, n, stream));
  286. }
  287.  
  288.  
  289. int exist(char *s)
  290. {
  291.   int i;
  292.   struct ffblk ff;
  293.  
  294.   i = findfirst(s, &ff, 0);
  295.   if (i)
  296.     return (0);
  297.   else
  298.     return (1);
  299. }
  300.  
  301. char *stripspace(char *str)
  302. {
  303.   char *obuf, *nbuf;
  304.  
  305.   if (str) {
  306.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  307.       if (!isspace(*obuf))
  308.         *nbuf++ = *obuf;
  309.     }
  310.     *nbuf = NULL;
  311.   }
  312.   return (str);
  313. }
  314.  
  315. static unsigned char *trimstr1(unsigned char *s)
  316. {
  317.   int i;
  318.   static char *whitespace = " \r\n\t\"";
  319.  
  320.   i = (int) strlen(s);
  321.   while ((i > 0) && ((char *) _fstrchr(whitespace, s[i - 1]) != NULL))
  322.     --i;
  323.   while ((i > 0) && ((char *) _fstrchr(whitespace, *s) != NULL)) {
  324.     memmove(s, s + 1, --i);
  325.   }
  326.   s[i] = 0;
  327.   return (s);
  328. }
  329.  
  330. void output(char *fmt, ...)
  331. {
  332.   va_list v;
  333.   char s[255];
  334.  
  335.   va_start(v, fmt);
  336.   vsprintf(s, fmt, v);
  337.   va_end(v);
  338.   fputs(s, stderr);
  339. }
  340.  
  341. int num_to_name(char *where, int whichuser, int alias)
  342. {
  343.   int userfile, num_users, found;
  344.   userrec ur;
  345.   long pos;
  346.   char fn[MAXPATH];
  347.  
  348.   found = 0;
  349.   sprintf(fn, "%sUSER.LST", syscfg.datadir);
  350.   userfile = sh_open1(fn, O_RDONLY | O_BINARY);
  351.   if (userfile < 0) {
  352.     output("\n ■ Cannot open %s.", fn);
  353.     return (found);
  354.   }
  355.   num_users = ((int) (filelength(userfile) / sizeof(userrec)));
  356.  
  357.   if (whichuser > num_users) {
  358.     output("\n ■ User #%d out of range.", whichuser);
  359.     return (found);
  360.   }
  361.   pos = ((long) sizeof(userrec) * ((long) whichuser));
  362.   lseek(userfile, pos, SEEK_SET);
  363.   sh_read(userfile, &ur, sizeof(userrec));
  364.   if (ur.realname[0] == 0)
  365.     output("\n ■ User #%d has blank real name field!", whichuser);
  366.   else {
  367.     if (ur.inact == inact_deleted)
  368.       output("\n ■ User #%d is marked as deleted!", whichuser);
  369.     else {
  370.       if (!alias)
  371.         strcpy(where, ur.realname);
  372.       else {
  373.         strlwr(ur.name);
  374.         strcpy(where, ur.name);
  375.       }
  376.       found = 1;
  377.     }
  378.   }
  379.   sh_close(userfile);
  380.   return (found);
  381. }
  382.  
  383.  
  384. void parse_net_ini(void)
  385. {
  386.   char s[MAXPATH], line[121], *ss, inlist = 0;
  387.   FILE *fp;
  388.   long fptr;
  389.  
  390.   defuser = 1;
  391.   use_alias = 1;
  392.   nlists = 0;
  393.   maillist = NULL;
  394.   sprintf(s, "%sNET.INI", maindir);
  395.   fp = fsh_open(s, "rt");
  396.   if (!fp) {
  397.     output("\n ■ Unable to open %s.", s);
  398.     return;
  399.   }
  400.   while (fgets(line, 80, fp)) {
  401.     ss = NULL;
  402.     stripspace(line);
  403.     if ((line[0] == ';') || (line[0] == '\n') || (line[0] == 0))
  404.       continue;
  405.     if (strnicmp(line, "[MAILLIST]", 10) == 0) {
  406.       fptr = ftell(fp);
  407.       while ((fgets(line, 80, fp)) && (line[0] != '[')) {
  408.         if ((line[0] != '[') && (line[0] != ';') && (line[0] != 0))
  409.           ++nlists;
  410.       }
  411.       fseek(fp, fptr, SEEK_SET);
  412.       maillist = (MAILLISTREC *) malloc((nlists + 1) * sizeof(MAILLISTREC));
  413.       if (maillist == NULL) {
  414.         output("\n ■ Not enough memory to process mail lists.");
  415.       } else
  416.         inlist = 1;
  417.       nlists = 0;
  418.       continue;
  419.     } else if (line[0] == '[') {
  420.       inlist = 0;
  421.       continue;
  422.     }
  423.     if (inlist) {
  424.       if ((line[0] != ';') && (line[0] != 0)) {
  425.         ss = strtok(line, "*\n");
  426.         trimstr1(ss);
  427.         strcpy(maillist[nlists].ownername, ss);
  428.         ss = strtok(NULL, "\n");
  429.         trimstr1(ss);
  430.         if (ss[0])
  431.           strcpy(maillist[nlists++].subtype, ss);
  432.         else
  433.           output("\n ■ Missing *subtype in maillist for %s.",
  434.                   maillist[nlists].ownername);
  435.       }
  436.       continue;
  437.     }
  438.     if (strnicmp(line, "POSTMASTER", 10) == 0) {
  439.       ss = strtok(line, "=");
  440.       if (ss) {
  441.         ss = strtok(NULL, "\n");
  442.         if (ss)
  443.           defuser = atoi(ss);
  444.       }
  445.       continue;
  446.     }
  447.     if (strnicmp(line, "SPAMCONTROL", 11) == 0) {
  448.       ss = strtok(line, "=");
  449.       if (ss) {
  450.         ss = strtok(NULL, "\n");
  451.         if ((ss[0] == 'y') || (ss[0] == 'Y'))
  452.           spam = 1;
  453.       }
  454.       continue;
  455.     }
  456.     if (strnicmp(line, "SPAMADDRESS", 9) == 0) {
  457.       ss = strtok(line, "=");
  458.       if (ss) {
  459.         ss = strtok(NULL, "\n");
  460.         trimstr1(ss);
  461.         strcpy(spamname, ss);
  462.         if (stricmp(spamname, "DEFAULT") == 0)
  463.           strcpy(spamname, "wwiv_bbs_ppp_project@nospam.net");
  464.       }
  465.       continue;
  466.     }
  467.     if (strnicmp(line, "SIGNATURE", 9) == 0) {
  468.       ss = strtok(line, "=");
  469.       if (ss) {
  470.         ss = strtok(NULL, "\n");
  471.         trimstr1(ss);
  472.         strcpy(tagfile, ss);
  473.         if (!exist(tagfile)) {
  474.           output("\n ■ Default signature file %s not found!", tagfile);
  475.           tagfile[0] = 0;
  476.         }
  477.       }
  478.       continue;
  479.     }
  480.     if (strnicmp(line, "REALNAME", 8) == 0) {
  481.       ss = strtok(line, "=");
  482.       if (ss) {
  483.         ss = strtok(NULL, "\n");
  484.         if ((ss[0] == 'y') || (ss[0] == 'Y'))
  485.           use_alias = 0;
  486.       }
  487.     }
  488.   }
  489.   num_to_name(postmaster, defuser, 1);
  490.   fclose(fp);
  491.   return;
  492. }
  493.  
  494. unsigned char *strrep(char *str, char old, char New)
  495. {
  496.   int i;
  497.  
  498.   for (i = 0; str[i]; i++)
  499.     if (str[i] == old)
  500.       str[i] = New;
  501.   return (str);
  502. }
  503.  
  504.  
  505. int name_to_num(char *name)
  506. {
  507.   int userfile, usernum;
  508.   userrec ur;
  509.   long pos;
  510.   char fn[MAXPATH], ur_name[60], ur_realname[60];
  511.  
  512.   sprintf(fn, "%sUSER.LST", syscfg.datadir);
  513.   userfile = sh_open1(fn, O_RDONLY | O_BINARY);
  514.   if (userfile < 0) {
  515.     output("\n ■ Cannot open %s", fn);
  516.     return (0);
  517.   } else
  518.     output("\n ■ Searching for user \"%s\"...", name);
  519.   num_users = ((int) (filelength(userfile) / sizeof(userrec)));
  520.  
  521.   for (usernum = 1; usernum < num_users; usernum++) {
  522.     pos = ((long) sizeof(userrec) * ((long) usernum));
  523.     lseek(userfile, pos, SEEK_SET);
  524.     sh_read(userfile, &ur, sizeof(userrec));
  525.     strcpy(ur_realname, ur.realname);
  526.     strrep(ur_realname, ' ', '_');
  527.     strcpy(ur_name, ur.name);
  528.     strrep(ur_name, ' ', '_');
  529.     if ((strcmpi(ur.realname, name) == 0) || (strcmpi(ur_realname, name) == 0) ||
  530.         (strcmpi(ur.name, name) == 0) || (strcmpi(ur_name, name) == 0)) {
  531.       if (ur.inact == inact_deleted) {
  532.         output(" user #%d is deleted account.", usernum);
  533.         usernum = 0;
  534.         break;
  535.       } else {
  536.         output(" matched user #%d.", usernum);
  537.         break;
  538.       }
  539.     }
  540.   }
  541.   userfile = sh_close(userfile);
  542.  
  543.   if (usernum >= num_users) {
  544.     output("... no match found.");
  545.     return (0);
  546.   }
  547.   return (usernum);
  548. }
  549.  
  550. char *find_name(char *name)
  551. {
  552.   char *ss;
  553.  
  554.   curuser = 0;
  555.   if (strcspn(name, "(") != strlen(name)) {
  556.     ss = strtok(name, "(");
  557.     ss = strtok(NULL, ")");
  558.     strcpy(name, ss);
  559.     curuser = name_to_num(name);
  560.   } else if (strcspn(name, "\"") != strlen(name)) {
  561.     ss = strtok(name, "\"");
  562.     ss = strtok(NULL, "\"");
  563.     strcpy(name, ss);
  564.     curuser = name_to_num(name);
  565.   } else if (strcspn(name, "<") != strlen(name)) {
  566.     ss = strtok(name, "<");
  567.     trimstr1(ss);
  568.     strcpy(name, ss);
  569.     curuser = name_to_num(name);
  570.   }
  571.   if (curuser == 0)
  572.     return ('\0');
  573.   else
  574.     return (ss);
  575. }
  576.  
  577. void name_packet(char *pktname)
  578. {
  579.   int ok;
  580.   struct stat info;
  581.   unsigned i;
  582.  
  583.   ok = 0;
  584.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  585.     sprintf(pktname, "%sP0-%u.%3.3hu", net_data, i, instance);
  586.     if (stat(pktname, &info) == -1)
  587.       ok = 1;
  588.   }
  589. }
  590.  
  591.  
  592.  
  593. int import(char *fn)
  594. {
  595.   char s[513], pktname[MAXPATH], msgdate[31], *ss, *p, *id, *name;
  596.   char alphatype[21];
  597.   int i, f, from, subj, intext, done;
  598.   long textlen, reallen;
  599.   struct msghdr mh;
  600.   net_header_rec nh;
  601.   struct date dt;
  602.   struct time tm;
  603.   FILE *fp;
  604.  
  605.   intext = 0;
  606.   f = sh_open1(fn, O_RDONLY | O_BINARY);
  607.   if (f < 0)
  608.     return (1);
  609.   textlen = filelength(f);
  610.   if (textlen > 32767L) {
  611.     output("\n ■ Skipping %s - greater than 32K.", fn);
  612.     return (1);
  613.   }
  614.   p = (char *) malloc((int) (textlen + 1));
  615.   if (p == NULL) {
  616.     output("\n ■ Unable to allocate %ld bytes.", textlen);
  617.     return (1);
  618.   }
  619.   sh_read(f, (void *) p, (int) textlen);
  620.   sh_close(f);
  621.  
  622.   nh.tosys = net_sysnum;
  623.   nh.fromsys = 32767;
  624.   nh.fromuser = 0;
  625.   nh.touser = defuser;
  626.   nh.main_type = main_type_email;
  627.   nh.minor_type = 0;
  628.   nh.list_len = 0;
  629.   gettime(&tm);
  630.   getdate(&dt);
  631.   nh.daten = dostounix(&dt, &tm);
  632.   nh.method = 0;
  633.  
  634.   fp = fsh_open(fn, "rb");
  635.   if (!fp) {
  636.     free(p);
  637.     return (1);
  638.   }
  639.  
  640.   from = subj = done = 0;
  641.   while ((fgets(s, 254, fp)) && !done) {
  642.     if (s[0] == 4) {
  643.       ss = strtok(s, "R");
  644.       ss = strtok(NULL, "\r\n");
  645.       strcpy(s, ss);
  646.     } else
  647.       intext = 1;
  648.     if (!intext) {
  649.       if ((strncmpi(s, "reply-to:", 9) == 0) ||
  650.           ((strncmpi(s, "from:", 5) == 0) && (!from)) ||
  651.           ((strncmpi(s, "return-path:", 12) == 0) && (!from))) {
  652.         if ((strncmpi(s, "return-path:", 12) != 0) && (!from))
  653.           from = 1;
  654.         ss = strtok(s, ": ");
  655.         ss = strtok(NULL, "\r\n");
  656.         trimstr1(ss);
  657.         if (strncmpi(s, "reply-to", 8) == 0) {
  658.           for (i = 0; (i < nlists) && (nh.main_type == main_type_email); i++) {
  659.             if (strstr(ss, maillist[i].ownername) != NULL) {
  660.               if (atoi(maillist[i].subtype)) {
  661.                 nh.main_type = main_type_pre_post;
  662.                 nh.minor_type = atoi(maillist[i].subtype);
  663.               } else {
  664.                 nh.main_type = main_type_new_post;
  665.                 nh.minor_type = 0;
  666.                 strcpy(alphatype, maillist[i].subtype);
  667.               }
  668.               strcpy(alphasubtype, maillist[i].subtype);
  669.               nh.touser = 0;
  670.             }
  671.           }
  672.         } else {
  673.           if (strcspn(ss, "<") != strlen(ss)) {
  674.             if ((strcspn(ss, " ")) < (strcspn(ss, "<"))) {
  675.               name = strtok(ss, "<");
  676.               trimstr1(name);
  677.               id = strtok(NULL, ">");
  678.               trimstr1(id);
  679.               sprintf(mh.fromUserName, "%s (%s)", id, name);
  680.             } else {
  681.               strncpy(mh.fromUserName, ss, 205);
  682.               trimstr1(mh.fromUserName);
  683.               if (strcspn(ss, " ") != strlen(ss))
  684.                 output("\nName is *after* host in \"%s\"", name);
  685.             }
  686.           } else
  687.             strncpy(mh.fromUserName, ss, 205);
  688.           mh.fromUserName[190] = 0;
  689.           strcat(mh.fromUserName, "\r\n");
  690.         }
  691.       } else
  692.         if ((strncmpi(s, "subject:", 8) == 0) && (!subj)) {
  693.         ss = strtok(s, ": ");
  694.         ss = strtok(NULL, "\r\n");
  695.         trimstr1(ss);
  696.         strncpy(mh.subject, ss, 81);
  697.         mh.subject[72] = 0;
  698.       } else
  699.         if ((strncmpi(s, "to:", 3) == 0) || (strncmpi(s, "cc:", 3) == 0)) {
  700.         ss = strtok(s, ": ");
  701.         ss = strtok(NULL, "\r\n");
  702.         strncpy(mh.toUserName, ss, 81);
  703.         mh.toUserName[81] = 0;
  704.         trimstr1(mh.toUserName);
  705.         if (_fstrstr(mh.toUserName, " "))
  706.           find_name(mh.toUserName);
  707.         else
  708.           mh.toUserName[0] = 0;
  709.         if ((mh.toUserName[0] == 0) || (curuser == 0)) {
  710.           nh.touser = defuser;
  711.           strcpy(mh.toUserName, postmaster);
  712.         } else
  713.           nh.touser = curuser;
  714.         }
  715.     } else
  716.       done = 1;
  717.   }
  718.   fclose(fp);
  719.   output("\n ■ From    : %s", mh.fromUserName);
  720.   if ((nh.main_type == main_type_pre_post) ||
  721.       (nh.main_type == main_type_new_post))
  722.     output(" ■ Post to : Sub %s", alphasubtype);
  723.   else
  724.     output(" ■ Sent to : %s #%hd", strupr(mh.toUserName), nh.touser);
  725.   output("\n ■ Subject : %s", mh.subject);
  726.   name_packet(pktname);
  727.   fp = fsh_open(pktname, "wb");
  728.   if (fp < 0) {
  729.     output("\n ■ Unable to create packet %s", pktname);
  730.     free(p);
  731.     return (1);
  732.   }
  733.   strncpy(msgdate, ctime(&(time_t) nh.daten), 24);
  734.   msgdate[24] = '\0';
  735.   strcat(msgdate, "\r\n");
  736.   nh.length = textlen + strlen(mh.fromUserName) + strlen(mh.subject) + strlen(msgdate) + 1;
  737.   if (nh.main_type == main_type_new_post)
  738.     nh.length += strlen(alphatype) + 1;
  739.   fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  740.   if (nh.main_type == main_type_new_post)
  741.     fsh_write(alphatype, sizeof(char), strlen(alphatype) +1, fp);
  742.   fsh_write(mh.subject, sizeof(char), strlen(mh.subject) +1, fp);
  743.   fsh_write(mh.fromUserName, sizeof(char), strlen(mh.fromUserName), fp);
  744.   fsh_write(msgdate, sizeof(char), strlen(msgdate), fp);
  745.   reallen = fsh_write(p, sizeof(char), (int) textlen, fp);
  746.   if (reallen != textlen)
  747.     output("\n ■ Expected %ld bytes, wrote %ld bytes.", textlen, reallen);
  748.   fclose(fp);
  749.   free(p);
  750.   return (0);
  751. }
  752.  
  753. unsigned char *stripcolors(unsigned char *text)
  754. {
  755.   static unsigned char s[161];
  756.   int i, i1;
  757.  
  758.   if (strlen(text) == 0)
  759.     return ("");
  760.  
  761.   i = 0;
  762.   i1 = 0;
  763.   do {
  764.     if (text[i] == 3)
  765.       i++;
  766.     else {
  767.       if ((text[i] > 32) && (text[i] < 128) || (text[i] == 9))
  768.         s[i1++] = text[i];
  769.     }
  770.     i++;
  771.   } while (i < strlen(text));
  772.   s[i1] = 0;
  773.   return (s);
  774. }
  775.  
  776. int export(char *fn)
  777. {
  778.   char fn1[121], tagfn[121], groupname[81], outfn[121], _temp_buffer[256];
  779.   char *ss, *buffer, *text, alphatype[21], hold[21], tempoutfn[21];
  780.   unsigned stype, ttype;
  781.   int infile, outfile, inloc, outloc, term, ok, i, j, ns, i6;
  782.   net_header_rec nhr;
  783.   struct msghdr mh;
  784.   struct tm *time_msg;
  785.   FILE *fp;
  786.   time_t some;
  787.   char *main_type[] =
  788.   {
  789.     "Network Update", "email by usernum", "post from sub host", "file",
  790.     "post to sub host", "external message", "email by name",
  791.     "NetEdit message", "SUBS.LST", "Extra Data", "BBSLIST from GC",
  792.     "CONNECT from GC", "Unused_1", "Info from GC", "SSM", "Sub Add Request",
  793.     "Sub Drop Request", "Sub Add Response", "Sub Drop Response", "Sub Info",
  794.     "Unused 1", "Unused 2", "Unused 3", "Unused 4", "Unused 5", "new post",
  795.     "new external"
  796.   };
  797.  
  798.   if ((infile = sh_open1(fn, O_RDONLY | O_BINARY)) == -1)
  799.     return (1);
  800.  
  801.   if ((buffer = (char *) malloc(32 * 1024)) == NULL) {
  802.     output("\n ■ Out of memory allocating input buffer!");
  803.     return (1);
  804.   }
  805.   if ((text = (char *) malloc(32 * 1024)) == NULL) {
  806.     output("\n ■ Out of memory allocating output buffer!");
  807.     if (buffer)
  808.       free(buffer);
  809.     buffer = NULL;
  810.     return (1);
  811.   }
  812.   while (sh_read(infile, &nhr, sizeof(nhr))) {
  813.     sh_read(infile, buffer, (int) nhr.length);
  814.     if (nhr.tosys != 32767) {
  815.       output("\n ■ Non-Internet system routing via @32767... aborting export.");
  816.       return (1);
  817.     }
  818.     if (nhr.main_type == main_type_pre_post)
  819.       nhr.main_type = main_type_post;
  820.     if ((nhr.main_type == main_type_post) ||
  821.         (nhr.main_type == main_type_new_post) ||
  822.         (nhr.main_type == main_type_email_name) ||
  823.         (nhr.main_type == main_type_ssm)) {
  824.       inloc = 0;
  825.       sprintf(hold, "%hu", nhr.minor_type);
  826.       if ((nhr.main_type == main_type_email_name) ||
  827.           (nhr.main_type == main_type_ssm) ||
  828.           (nhr.main_type == main_type_new_post)) {
  829.         stype = nhr.minor_type;
  830.         inloc = strlen(buffer) + 1;
  831.         if (nhr.main_type == main_type_new_post) {
  832.           strcpy(alphasubtype, buffer);
  833.           strcpy(hold, alphasubtype);
  834.         } else
  835.           strcpy(mh.toUserName, buffer);
  836.         if (nhr.fromsys != net_sysnum) {
  837.           output("\n ■ Gate from #%hd@%hd to %s not yet supported",
  838.                   nhr.fromuser, nhr.fromsys, mh.toUserName);
  839.           continue;
  840.         }
  841.       } else
  842.         if (nhr.main_type == main_type_post)
  843.         stype = nhr.minor_type;
  844.       else {
  845.         stype = atoi(&buffer[inloc]);
  846.         sprintf(_temp_buffer, "%u", stype);
  847.         inloc += strlen(_temp_buffer) + 1;
  848.       }
  849.       strncpy(mh.subject, &buffer[inloc], sizeof(mh.subject));
  850.       stripcolors(mh.subject);
  851.       inloc += strlen(&buffer[inloc]) + 1;
  852.  
  853.       for (term = inloc; buffer[term] != '\r'; term++);
  854.       buffer[term] = '\0';
  855.  
  856.       if ((nhr.fromsys == net_sysnum) && (nhr.fromuser)) {
  857.         if ((nhr.main_type != main_type_post) &&
  858.             (nhr.main_type != main_type_new_post)) {
  859.           if (!num_to_name(mh.fromUserName, nhr.fromuser, use_alias)) {
  860.             output("\n ■ No match for user #%hd... skipping message!",
  861.                     nhr.fromuser);
  862.             continue;
  863.           }
  864.         } else {
  865.           if (!num_to_name(mh.fromUserName, nhr.fromuser, use_alias)) {
  866.             output("\n ■ No match for user #%hd... skipping message!",
  867.                     nhr.fromuser);
  868.             continue;
  869.           }
  870.         }
  871.       } else {
  872.         strncpy(mh.fromUserName, &buffer[inloc], sizeof(mh.fromUserName));
  873.         stripcolors(mh.fromUserName);
  874.         strtok(mh.fromUserName, "#");
  875.         if ((nhr.main_type == main_type_post) &&
  876.             (nhr.main_type == main_type_new_post) &&
  877.             (nhr.fromsys != net_sysnum)) {
  878.           sprintf(_temp_buffer, " #%hd @%hu", nhr.fromuser, nhr.fromsys);
  879.           strcat(mh.fromUserName, _temp_buffer);
  880.         }
  881.       }
  882.  
  883.       inloc = term + 2;
  884.  
  885.       while (buffer[inloc] != '\n')
  886.         inloc++;
  887.       inloc++;
  888.  
  889.       if (strncmp(&buffer[inloc], "0R", 3) == 0) {
  890.         while (buffer[inloc] != '\n')
  891.           ++inloc;
  892.         inloc++;
  893.       }
  894.       if (strnicmp(&buffer[inloc], "RE: ", 4) == 0) {
  895.         for (term = inloc; buffer[term] != '\r'; term++);
  896.         buffer[term] = '\0';
  897.         strncpy(mh.subject, &buffer[inloc + 4], sizeof(mh.subject));
  898.         inloc = term + 2;
  899.       }
  900.       if ((strncmp(&buffer[inloc], "BY: ", 4) == 0) ||
  901.           (strncmp(&buffer[inloc], "TO: ", 4) == 0)) {
  902.         for (term = inloc; buffer[term] != '\r'; term++);
  903.         buffer[term] = '\0';
  904.         strncpy(mh.toUserName, &buffer[inloc + 4], sizeof(mh.toUserName));
  905.         stripcolors(mh.toUserName);
  906.         if (strcspn(mh.toUserName, "<") != strlen(mh.toUserName)) {
  907.           if ((strstr(mh.toUserName, "\"") == 0) && (strstr(mh.toUserName, "(") == 0)) {
  908.             ss = strtok(mh.toUserName, "<");
  909.             ss = strtok(NULL, ">");
  910.             strcpy(mh.toUserName, ss);
  911.           }
  912.         }
  913.         inloc = term + 2;
  914.       } else {
  915.         if (nhr.main_type != main_type_email_name) {
  916.           strcpy(mh.toUserName, "ALL\n");
  917.         }
  918.       }
  919.  
  920.       outloc = 0;
  921.       do {
  922.         if (buffer[inloc] == 2) {
  923.           i = inloc + 1;
  924.           for (j = 1; j < 80; j++) {
  925.             if ((buffer[i] == '\r') ||
  926.                 (i > nhr.length))
  927.               break;
  928.             i++;
  929.           }
  930.           if (j < 80) {
  931.             i = (80 - j) / 2;
  932.             for (j = 1; j <= i; j++)
  933.               text[outloc++] = ' ';
  934.           }
  935.           inloc++;
  936.         } else
  937.           if (buffer[inloc] == 3)
  938.           inloc += 2;
  939.         else
  940.           if ((buffer[inloc] == 4) && ((buffer[inloc + 1] >= 48) && (buffer[inloc + 1] <= 57)))
  941.           inloc += 2;
  942.         else
  943.           if (buffer[inloc] >= 127) {
  944.           inloc++;
  945.         } else
  946.           if (buffer[inloc] == 1)
  947.           inloc++;
  948.         else
  949.           text[outloc++] = buffer[inloc++];
  950.       } while (inloc < nhr.length);
  951.  
  952.       text[outloc] = '\0';
  953.  
  954.       if ((nhr.main_type == main_type_post) ||
  955.           (nhr.main_type == main_type_pre_post) ||
  956.           (nhr.main_type == main_type_new_post)) {
  957.         for (i = 0; (i < nlists) && (nhr.main_type != main_type_email_name); i++) {
  958.           if (nhr.main_type == main_type_new_post) {
  959.             if (strcmpi(alphasubtype, maillist[i].subtype) == 0) {
  960.               nhr.main_type = main_type_email_name;
  961.               strcpy(mh.toUserName, maillist[i].ownername);
  962.             }
  963.           } else {
  964.             ttype = atoi(maillist[i].subtype);
  965.             if (ttype == stype) {
  966.               nhr.main_type = main_type_email_name;
  967.               strcpy(mh.toUserName, maillist[i].ownername);
  968.             }
  969.           }
  970.         }
  971.       }
  972.       switch (nhr.main_type) {
  973.         case main_type_email:
  974.         case main_type_email_name:
  975.         case main_type_ssm:
  976.           i = 1;
  977.           sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, i);
  978.           while (exist(outfn))
  979.             sprintf(outfn, "%sMQUEUE\\MSG.%d", net_data, ++i);
  980.           break;
  981.         case main_type_new_post:
  982.         case main_type_post:
  983.         case main_type_pre_post:
  984.           i = 1;
  985.           strcpy(tempoutfn, hold);
  986.           sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, i);
  987.           while (exist(outfn))
  988.             sprintf(outfn, "%sOUTBOUND\\%s.%d", net_data, tempoutfn, ++i);
  989.           break;
  990.         default:
  991.           continue;
  992.       }
  993.  
  994.       output("\n ■ Creating: %s", outfn);
  995.       output("\n ■ From    : %s", mh.fromUserName);
  996.       if ((nhr.main_type == main_type_post) ||
  997.           (nhr.main_type == main_type_pre_post) ||
  998.           (nhr.main_type == main_type_new_post)) {
  999.         sprintf(fn1, "%sNEWS.RC", net_data);
  1000.         fp = fsh_open(fn1, "rt");
  1001.         if (!fp) {
  1002.           output("\n ■ %s not found!", fn1);
  1003.           return 1;
  1004.         } else {
  1005.           ok = 0;
  1006.           while ((fgets(_temp_buffer, 80, fp) != NULL) && (!ok)) {
  1007.             groupname[0] = 0;
  1008.             ss = strtok(_temp_buffer, " ");
  1009.             if (ss) {
  1010.               strcpy(groupname, ss);
  1011.               ss = strtok(NULL, " ");
  1012.               ss = strtok(NULL, "\r");
  1013.               if (nhr.main_type == main_type_new_post) {
  1014.                 strcpy(alphatype, ss);
  1015.                 if (strncmpi(alphasubtype, alphatype, strlen(alphasubtype)) == 0)
  1016.                   ok = 1;
  1017.               } else {
  1018.                 ttype = atoi(ss);
  1019.                 if (ttype == stype)
  1020.                   ok = 1;
  1021.               }
  1022.             }
  1023.           }
  1024.           *ss = NULL;
  1025.           fclose(fp);
  1026.           if (!ok) {
  1027.             output("\n ■ Group not found in NEWS.RC!");
  1028.             return 1;
  1029.           }
  1030.         }
  1031.       }
  1032.       if ((nhr.main_type == main_type_email) ||
  1033.           (nhr.main_type == main_type_email_name) ||
  1034.           (nhr.main_type == main_type_ssm)) {
  1035.         output("\n ■ To      : %s", strlwr(mh.toUserName));
  1036.       } else {
  1037.         if (groupname[0] == 0)
  1038.           output("\n ■ No match for subtype %u in NEWS.RC", stype);
  1039.         else
  1040.           output("\n ■ Post to : %s", groupname);
  1041.       }
  1042.  
  1043.       output("\n ■ Subject : %s", mh.subject);
  1044.  
  1045.       outfile = sh_open(outfn, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC | O_EXCL, S_IWRITE);
  1046.       if (outfile == -1) {
  1047.         if (buffer)
  1048.           free(buffer);
  1049.         if (text)
  1050.           free(text);
  1051.         output("\n ■ Unable to open output file %s", outfn);
  1052.         return (1);
  1053.       }
  1054.       time(&some);
  1055.       time_msg = localtime(&some);
  1056.       strftime(mh.dateTime, 80, "%a, %d %b %y %H:%M:%S (%Z)", time_msg);
  1057.       for (j = 0; j < strlen(mh.fromUserName); j++)
  1058.         if (mh.fromUserName[j] == ' ')
  1059.           mh.fromUserName[j] = '_';
  1060.       if ((spam) && ((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post)))
  1061.         if (spamname[0] == 0)
  1062.           sprintf(_temp_buffer, "From: %s@dont.spam.me.%s (%s)\n",
  1063.                   POPNAME, DOMAIN,
  1064.                   mh.fromUserName);
  1065.         else
  1066.           sprintf(_temp_buffer, "From: %s (%s)\n",
  1067.                   spamname,
  1068.                   mh.fromUserName);
  1069.       else
  1070.         sprintf(_temp_buffer, "From: %s@%s (%s)\n",
  1071.                 POPNAME, DOMAIN, mh.fromUserName);
  1072.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1073.       delay(2000);
  1074.       sprintf(_temp_buffer, "Message-ID: <%lx-%s@%s>\n",
  1075.               time(NULL), POPNAME, DOMAIN);
  1076.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1077.       if ((nhr.main_type == main_type_email) ||
  1078.           (nhr.main_type == main_type_email_name) ||
  1079.           (nhr.main_type == main_type_ssm)) {
  1080.         sprintf(_temp_buffer, "To: %s\n",
  1081.                 mh.toUserName);
  1082.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1083.       } else {
  1084.         sprintf(_temp_buffer, "Newsgroups: %s\n", groupname);
  1085.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1086.       }
  1087.       sprintf(_temp_buffer, "Subject: %s\n", mh.subject);
  1088.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1089.       sprintf(_temp_buffer, "Date: %s\n", mh.dateTime);
  1090.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1091.       sprintf(_temp_buffer, "Organization: %s * @%hu.%s * %s\n",
  1092.               syscfg.systemname, net_sysnum, net_name, syscfg.systemphone);
  1093.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1094.       if ((!spam) && ((nhr.main_type != main_type_post) || (nhr.main_type != main_type_new_post))) {
  1095.         sprintf(_temp_buffer, "Reply-To: %s@%s (%s)\n",
  1096.                 POPNAME, DOMAIN, mh.fromUserName);
  1097.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1098.       }
  1099.       sprintf(_temp_buffer, "Version: WWIV PPP Project %s\n\n", VERSION);
  1100.       sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1101.  
  1102.       if ((spam) && ((nhr.main_type == main_type_post) || (nhr.main_type == main_type_new_post))) {
  1103.         sprintf(_temp_buffer, "Reply to: %s@%s (%s)\n\n",
  1104.                 POPNAME, DOMAIN, mh.fromUserName);
  1105.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1106.       }
  1107.       if ((nhr.main_type != main_type_email) &&
  1108.           (nhr.main_type != main_type_email_name) &&
  1109.           (strncmp(mh.toUserName, "ALL", 3) != 0)) {
  1110.         sprintf(_temp_buffer, "Responding to: %s\n", mh.toUserName);
  1111.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1112.       }
  1113.       sh_write(outfile, text, strlen(text));
  1114.  
  1115.       sprintf(tagfn, "%sI%u.TAG", syscfg.datadir, stype);
  1116.       if (exist(tagfn))
  1117.         strcpy(tagfile, tagfn);
  1118.       tagfn[0] = 0;
  1119.       ns = 0;
  1120.       for (i6 = 0; i6 < 99; i6++) {
  1121.         sprintf(tagfn, "%sI%u.T%d", syscfg.datadir, i6);
  1122.         if (exist(tagfn))
  1123.           ns++;
  1124.         else
  1125.           break;
  1126.       }
  1127.       sprintf(tagfn, "%sI%u.T%d", syscfg.datadir, random(ns));
  1128.       if (exist(tagfn))
  1129.         strcpy(tagfile, tagfn);
  1130.       if (tagfile[0] == 0) {
  1131.         sprintf(_temp_buffer, "\n\nOrigin: %s * %s * @%hu.FILEnet\n\n",
  1132.                 syscfg.systemname, syscfg.systemphone, net_sysnum);
  1133.         sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1134.       } else {
  1135.         fp = fsh_open(tagfile, "rt");
  1136.         if (!fp)
  1137.           output("\n ■ Error reading %s.", tagfile);
  1138.         else {
  1139.           sprintf(_temp_buffer, "\n\n");
  1140.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1141.           while (fgets(_temp_buffer, 120, fp)) {
  1142.             for (i = 0; ((i < strlen(_temp_buffer)) &&
  1143.                (_temp_buffer[i] != '\r') && (_temp_buffer[i] != '\n')); i++)
  1144.               if ((_temp_buffer[i] < 32) || (_temp_buffer[i] > 126))
  1145.                 _temp_buffer[i] = 32;
  1146.             sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1147.           }
  1148.           fclose(fp);
  1149.           sprintf(_temp_buffer, "\n\n");
  1150.           sh_write(outfile, _temp_buffer, strlen(_temp_buffer));
  1151.         }
  1152.       }
  1153.       sh_close(outfile);
  1154.     } else {
  1155.       if ((nhr.main_type >= 0x01) && (nhr.main_type <= 0x1b))
  1156.         output("\n ■ %s message skipped",
  1157.                 main_type[nhr.main_type - 1]);
  1158.       else
  1159.         output("\n ■ Unknown Main_type %hd skipped", nhr.main_type);
  1160.     }
  1161.   }
  1162.   sh_close(infile);
  1163.   unlink(fn);
  1164.   if (text)
  1165.     free(text);
  1166.   if (buffer)
  1167.     free(buffer);
  1168.   return (0);
  1169. }
  1170.  
  1171. void get_dir(char *s, int be)
  1172. {
  1173.   strcpy(s, "X:\\");
  1174.   s[0] = 'A' + getdisk();
  1175.   getcurdir(0, s + 3);
  1176.   if (be) {
  1177.     if (s[strlen(s) - 1] != '\\')
  1178.       strcat(s, "\\");
  1179.   }
  1180. }
  1181.  
  1182. int main(int argc, char *argv[])
  1183. {
  1184.   char fn[MAXPATH], *ss;
  1185.   int f, f1, maxmail, i;
  1186.   struct ffblk ff;
  1187.  
  1188.   /* 0      1               2          3          4       5        6       */
  1189.   /* exp s32767.net,      net_data, net_sysnum, popname, domain, net_name  */
  1190.   /* exp netlog/contact,  net_data,   sysnum,     sent    recd   totaltime */
  1191.  
  1192.   output("\n ■ PPP Import/Export %s", VERSION);
  1193.   if (argc != 7) {
  1194.     output("\n ■ EXP <filename> <net_data> <net_sysnum> <POPNAME> <DOMAIN> <net_name>\n\n");
  1195.     if (argc > 1) {
  1196.       output("Command line was: ");
  1197.       for (i = 0; i < argc; i++)
  1198.         output("%s ", argv[i]);
  1199.       output("\n\n");
  1200.     }
  1201.     return (1);
  1202.   }
  1203.   detect_multitask();
  1204.  
  1205.   get_dir(maindir, 1);
  1206.   strcpy(net_data, argv[2]);
  1207.   sprintf(fn, "%s%s", net_data, argv[1]);
  1208.   net_name = argv[6];
  1209.   strcpy(POPNAME, argv[4]);
  1210.   strcpy(DOMAIN, argv[5]);
  1211.   net_sysnum = atoi(argv[3]);
  1212.   tagfile[0] = 0;
  1213.   spam = 0;
  1214.  
  1215.   f = sh_open1("CONFIG.DAT", O_RDONLY | O_BINARY);
  1216.   if (f < 0) {
  1217.     output("Could not open CONFIG.DAT!\n\n");
  1218.     return (1);
  1219.   }
  1220.   sh_read(f, (void *) &syscfg, sizeof(configrec));
  1221.   sh_close(f);
  1222.  
  1223.   ss = getenv("WWIV_INSTANCE");
  1224.   if (ss) {
  1225.     instance = atoi(ss);
  1226.     if (instance >= 1000) {
  1227.       output("\n ■ WWIV_INSTANCE set to %hd.  Can only be 1..999!",
  1228.               instance);
  1229.       instance = 1;
  1230.     }
  1231.   } else
  1232.     instance = 1;
  1233.  
  1234.   parse_net_ini();
  1235.  
  1236. /*
  1237.   output("\n ■ Postmaster default account set to %s #%hd.",
  1238.           strupr(postmaster), defuser);
  1239.   output("\n ■ Using user %s on outbound Internet mail.",
  1240.           use_alias ? "aliases" : "real names");
  1241.   if (spam)
  1242.     output("\n ■ Using bogus originating address on newsgroup posts.");
  1243.   if (tagfile[0] != 0)
  1244.     output("\n ■ Using signature file : %s", tagfile);
  1245. */
  1246.   strupr(postmaster);
  1247.  
  1248.   export(fn);
  1249.  
  1250.   sprintf(fn, "%sSPOOL\\UNK*.*", net_data);
  1251.   f1 = findfirst(fn, &ff, 0);
  1252.   maxmail = 14;
  1253.   while ((f1 == 0) && maxmail) {
  1254.     sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
  1255.     if (!import(fn)) {
  1256.       unlink(fn);
  1257.       --maxmail;
  1258.     }
  1259.     f1 = findnext(&ff);
  1260.   }
  1261.   if (maillist != NULL)
  1262.     free(maillist);
  1263.   return 0;
  1264. }
  1265.