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