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