home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B42.ZIP / NEWS.C < prev    next >
C/C++ Source or Header  |  1997-09-27  |  52KB  |  1,892 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <ctype.h>
  4. #include <process.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <errno.h>
  10. #include <fcntl.h>
  11. #include <io.h>
  12. #include <dos.h>
  13. #include <share.h>
  14. #include <dir.h>
  15. #include <alloc.h>
  16. #include <sys\stat.h>
  17. #include <math.h>
  18. #include "tcp.h"
  19. #include "pop.h"
  20. #include "net.h"
  21. #include "vardec.h"
  22. #include "version.h"
  23. #include "retcode.h"
  24.  
  25. extern unsigned _stklen = 10240;
  26.  
  27. #define SHARE_LEVEL 10
  28. #define WAIT_TIME 10
  29. #define TRIES 100
  30.  
  31. #define MT_DESQVIEW 0x01
  32. #define MT_WINDOWS  0x02
  33. #define MT_OS2      0x04
  34. #define MT_NB       0x40
  35.  
  36. #define BIGSTR 4096
  37. #define STRING 512
  38. #define STR 129
  39. #define WAIT_TIME 10
  40. #define TRIES 100
  41. #define NUL '\0'
  42. #define LAST(s) s[strlen(s)-1]
  43. #define NNTP_PORT 119
  44. #define MAX_LOG 800
  45.  
  46. #define free_Mail_Socket(SOCK) if (SOCK!=NULL) {     \
  47.   farfree(SOCK->sock); farfree(SOCK); SOCK=NULL; }
  48.  
  49. configrec syscfg;
  50.  
  51. static int NNTP_stat;
  52.  
  53. unsigned short reply;
  54. unsigned long reparticle;
  55. unsigned long cur_daten;
  56.  
  57. char serverhost[81], newsrc[81];
  58. char maindir[181], tmpdir[201], net_data[181];
  59. char *version = "Freeware PPP News Retrieval " VERSION;
  60.  
  61. char cur_gname[STRING], tpktname[121];
  62. char POPNAME[STR], POPDOMAIN[STR];
  63. char msgto[STRING], msgarea[STRING];
  64. long cur_numa, cur_first, cur_last;
  65.  
  66. long cur_article;
  67. char cur_articleid[STRING];
  68. char cur_path[STRING], cur_from[STRING], cur_subject[STRING], cur_replyto[STRING];
  69. char cur_newsgroups[STRING], cur_message_ID[STRING], cur_organization[STRING], cur_references[STRING], cur_lines[STR], cur_date[STRING];
  70. int instance, crossposts, multitasker = 0, SOCK_DELAY;
  71. unsigned short sy;
  72.  
  73. typedef struct {
  74.   char groupname[60];
  75.   long lastread;
  76.   char subtype[8];
  77. } GROUPFILEREC;
  78.  
  79. GROUPFILEREC *grouprec;
  80. int ngroups;
  81.  
  82. int bogus = 0;
  83.  
  84. #define SOCK_READ_ERR(SOCK) sock_err:                                     \
  85.   switch (NNTP_stat) {                                                    \
  86.     case 1 :                                                              \
  87.       write_groups(1);                                                    \
  88.       log_it(0, "\n ! Connection closed : %s", sockerr(NNTP_sock->sock)); \
  89.       free_Mail_Socket(SOCK);                                             \
  90.       fcloseall();                                                        \
  91.       cursor('R');                                                        \
  92.       exit(EXIT_FAILURE);                                                 \
  93.     case -1:                                                              \
  94.       write_groups(1);                                                    \
  95.       log_it(0, "\n ! Session error: %s", sockerr(NNTP_sock->sock));      \
  96.       free_Mail_Socket(SOCK);                                             \
  97.       fcloseall();                                                        \
  98.       cursor('R');                                                        \
  99.       exit(EXIT_FAILURE);                                                 \
  100.   }                                                                       \
  101.  
  102. char *texth[] = {"th", "st", "nd", "rd"};
  103.  
  104. char *ordinal_text(int number)
  105. {
  106.   if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
  107.     number = 0;
  108.   return texth[number];
  109. }
  110.  
  111. static unsigned cursize;
  112.  
  113. void cursor(int tmp)
  114. {
  115.   union REGS inregs, outregs;
  116.  
  117.   switch (toupper(tmp)) {
  118.     case 'S':                               /* Save */
  119.       inregs.h.ah = 3;
  120.       inregs.h.bh = 0;
  121.       int86(0x10, &inregs, &outregs);
  122.       cursize = outregs.x.cx;
  123.       break;
  124.     case 'R':                               /* Restore */
  125.       inregs.h.ah = 1;
  126.       inregs.x.cx = cursize;
  127.       int86(0x10, &inregs, &outregs);
  128.       break;
  129.     case 'H':                               /* Hide */
  130.       inregs.h.ah = 1;
  131.       inregs.h.ch = 0x20;
  132.       int86(0x10, &inregs, &outregs);
  133.       break;
  134.     case 'N':                               /* Normal */
  135.       inregs.h.ah = 1;
  136.       inregs.h.ch = 6;
  137.       inregs.h.cl = 7;
  138.       int86(0x10, &inregs, &outregs);
  139.       break;
  140.   }
  141. }
  142.  
  143. void dv_pause(void)
  144. {
  145.   __emit__(0xb8, 0x1a, 0x10, 0xcd, 0x15);
  146.   __emit__(0xb8, 0x00, 0x10, 0xcd, 0x15);
  147.   __emit__(0xb8, 0x25, 0x10, 0xcd, 0x15);
  148. }
  149.  
  150. void win_pause(void)
  151. {
  152.   __emit__(0x55, 0xb8, 0x80, 0x16, 0xcd, 0x2f, 0x5d);
  153. }
  154.  
  155. int get_dos_version(void)
  156. {
  157.   _AX = 0x3000;
  158.   geninterrupt(0x21);
  159.   if (_AX % 256 >= 10) {
  160.     multitasker |= MT_OS2;
  161.   }
  162.   return (_AX);
  163. }
  164.  
  165. int get_dv_version(void)
  166. {
  167.   int v;
  168.  
  169.   if (multitasker & MT_OS2)
  170.     return 0;
  171.   _AX = 0x2b01;
  172.   _CX = 0x4445;
  173.   _DX = 0x5351;
  174.   geninterrupt(0x21);
  175.   if (_AL == 0xff) {
  176.     return 0;
  177.   } else {
  178.     v = _BX;
  179.     multitasker |= MT_DESQVIEW;
  180.     return v;
  181.   }
  182. }
  183.  
  184. int get_win_version(void)
  185. {
  186.   int v = 0;
  187.  
  188.   __emit__(0x55, 0x06, 0x53);
  189.   _AX = 0x352f;
  190.   geninterrupt(0x21);
  191.   _AX = _ES;
  192.   if (_AX | _BX) {
  193.     _AX = 0x1600;
  194.     geninterrupt(0x2f);
  195.     v = _AX;
  196.     if (v % 256 <= 1)
  197.       v = 0;
  198.   }
  199.   __emit__(0x5b, 0x07, 0x5d);
  200.   if (v != 0)
  201.     multitasker |= MT_WINDOWS;
  202.   return (v);
  203. }
  204.  
  205. int get_nb_version(void)
  206. {
  207.   _AX = 0;
  208.   geninterrupt(0x2A);
  209.   return (_AH);
  210. }
  211.  
  212. void detect_multitask(void)
  213. {
  214.   get_dos_version();
  215.   get_win_version();
  216.   get_dv_version();
  217.   if (multitasker < 2)
  218.     if (get_nb_version())
  219.       multitasker = MT_NB;
  220. }
  221.  
  222. void giveup_timeslice(void)
  223. {
  224.   if (multitasker) {
  225.     switch (multitasker) {
  226.  case 1:
  227.  case 3:
  228.         dv_pause();
  229.         break;
  230.       case 2:
  231.       case 4:
  232.       case 5:
  233.       case 6:
  234.       case 7:
  235.         win_pause();
  236.         break;
  237.       default:
  238.         break;
  239.     }
  240.   }
  241. }
  242.  
  243. void output(char *fmt, ...)
  244. {
  245.   va_list v;
  246.   char s[512];
  247.  
  248.   va_start(v, fmt);
  249.   vsprintf(s, fmt, v);
  250.   va_end(v);
  251.   fputs(s, stderr);
  252. }
  253.  
  254. void backline(void)
  255. {
  256.   int i;
  257.  
  258.   output(" ");
  259.   for (i = wherex(); i > 0; i--)
  260.     output("\b \b");
  261. }
  262.  
  263. void cd_to(char *s)
  264. {
  265.   char *s1;
  266.   int i, db;
  267.  
  268.   s1 = s;
  269.   i = strlen(s1) - 1;
  270.   db = (s1[i] == '\\');
  271.   if (i == 0)
  272.     db = 0;
  273.   if ((i == 2) && (s1[1] == ':'))
  274.     db = 0;
  275.   if (db)
  276.     s1[i] = 0;
  277.   chdir(s1);
  278.   if (s[1] == ':')
  279.     setdisk(s[0] - 'A');
  280. }
  281.  
  282. void get_dir(char *s, int be)
  283. {
  284.   strcpy(s, "X:\\");
  285.   s[0] = 'A' + getdisk();
  286.   getcurdir(0, s + 3);
  287.   if (be) {
  288.     if (s[strlen(s) - 1] != '\\')
  289.       strcat(s, "\\");
  290.   }
  291. }
  292.  
  293. int sh_write(int handle, void *buffer, unsigned long len)
  294. {
  295.   if (handle == -1) {
  296.     return (-1);
  297.   }
  298.   return (write(handle, buffer, (unsigned) len));
  299. }
  300.  
  301. int sh_open(char *path, int file_access, unsigned fmode)
  302. {
  303.   int handle, count, share;
  304.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  305.  
  306.   if ((file_access & O_RDWR) || (file_access & O_WRONLY) || (fmode & S_IWRITE)) {
  307.     share = SH_DENYRW;
  308.   } else {
  309.     share = SH_DENYWR;
  310.   }
  311.   handle = open(path, file_access | share, fmode);
  312.   if (handle < 0) {
  313.     count = 1;
  314.     fnsplit(path, drive, dir, file, ext);
  315.     if (access(path, 0) != -1) {
  316.       delay(WAIT_TIME);
  317.       handle = open(path, file_access | share, fmode);
  318.       while (((handle < 0) && (errno == EACCES)) && (count < TRIES)) {
  319.         if (count % 2)
  320.           delay(WAIT_TIME);
  321.         else
  322.           giveup_timeslice();
  323.         count++;
  324.         handle = open(path, file_access | share, fmode);
  325.       }
  326.     }
  327.   }
  328.   return (handle);
  329. }
  330.  
  331. int sh_open1(char *path, int access)
  332. {
  333.   unsigned fmode;
  334.  
  335.   fmode = 0;
  336.   if ((access & O_RDWR) || (access & O_WRONLY))
  337.     fmode |= S_IWRITE;
  338.   if ((access & O_RDWR) || (access & O_RDONLY))
  339.     fmode |= S_IREAD;
  340.   return (sh_open(path, access, fmode));
  341. }
  342.  
  343. int sh_close(int f)
  344. {
  345.   if (f != -1)
  346.     close(f);
  347.   return (-1);
  348. }
  349.  
  350. int sh_read(int handle, void *buf, unsigned len)
  351. {
  352.   if (handle == -1) {
  353.     return (-1);
  354.   }
  355.   return (read(handle, buf, len));
  356. }
  357.  
  358. long sh_lseek(int handle, long offset, int fromwhere)
  359. {
  360.   if (handle == -1) {
  361.     return (-1L);
  362.   }
  363.   return (lseek(handle, offset, fromwhere));
  364. }
  365.  
  366. FILE *fsh_open(char *path, char *fmode)
  367. {
  368.   FILE *f;
  369.   int count, share, md, fd;
  370.   char drive[MAXDRIVE], dir[MAXDIR], file[MAXFILE], ext[MAXEXT];
  371.  
  372.   share = SH_DENYWR;
  373.   md = 0;
  374.   if (((char *) strchr(fmode, 'w')) != NULL) {
  375.     share = SH_DENYRD;
  376.     md = O_RDWR | O_CREAT | O_TRUNC;
  377.   } else
  378.     if (((char *) strchr(fmode, 'a')) != NULL) {
  379.     share = SH_DENYRD;
  380.     md = O_RDWR | O_CREAT;
  381.   } else {
  382.     md = O_RDONLY;
  383.   }
  384.   if (((char *) strchr(fmode, 'b')) != NULL) {
  385.     md |= O_BINARY;
  386.   }
  387.   if (((char *) strchr(fmode, '+')) != NULL) {
  388.     md &= ~O_RDONLY;
  389.     md |= O_RDWR;
  390.     share = SH_DENYRD;
  391.   }
  392.   fd = open(path, md | share, S_IREAD | S_IWRITE);
  393.   if (fd < 0) {
  394.     count = 1;
  395.     fnsplit(path, drive, dir, file, ext);
  396.     if ((access(path, 0)) != -1) {
  397.       delay(WAIT_TIME);
  398.       fd = open(path, md | share, S_IREAD | S_IWRITE);
  399.       while (((fd < 0) && (errno == EACCES)) && (count < TRIES)) {
  400.         delay(WAIT_TIME);
  401.         count++;
  402.         fd = open(path, md | share, S_IREAD | S_IWRITE);
  403.       }
  404.     }
  405.   }
  406.   if (fd > 0) {
  407.     if (((char *) strchr(fmode, 'a')) != NULL)
  408.       sh_lseek(fd, 0L, SEEK_END);
  409.     f = fdopen(fd, fmode);
  410.     if (!f) {
  411.       close(fd);
  412.     }
  413.   } else
  414.     f = 0;
  415.   return (f);
  416. }
  417.  
  418. size_t fsh_write(void *ptr, size_t size, size_t n, FILE * stream)
  419. {
  420.  
  421.   if (stream == NULL) {
  422.     return (0);
  423.   }
  424.   return (fwrite(ptr, size, n, stream));
  425. }
  426.  
  427. void trim_log(void)
  428. {
  429.   int num_lines, total_lines, kill_lines;
  430.   FILE *old_log, *new_log;
  431.   char ol[101], nl[101], s[121];
  432.  
  433.   sprintf(ol, "%s\\NEWS.LOG", net_data);
  434.   sprintf(nl, "%s\\NEWS.ZZZ", net_data);
  435.  
  436.   old_log = fopen(ol, "r");
  437.   new_log = fopen(nl, "a");
  438.  
  439.   total_lines = 0;
  440.   if (old_log != NULL) {
  441.     while (!(fgets(s, 100, old_log) == NULL))
  442.       ++total_lines;
  443.     rewind(old_log);
  444.     if (total_lines < MAX_LOG) {
  445.       if (old_log != NULL)
  446.         fclose(old_log);
  447.       if (new_log != NULL)
  448.         fclose(new_log);
  449.       unlink(nl);
  450.       return;
  451.     }
  452.     kill_lines = total_lines - MAX_LOG;
  453.     num_lines = 0;
  454.     while (!(fgets(s, 100, old_log) == NULL) && (num_lines < kill_lines))
  455.       num_lines++;
  456.     while ((strstr(s, "NEWS session") == NULL) && (num_lines < total_lines)) {
  457.       fgets(s, 81, old_log);
  458.       num_lines++;
  459.     }
  460.     fputs(s, new_log);
  461.     while ((!(fgets(s, 100, old_log) == NULL)))
  462.       fputs(s, new_log);
  463.   }
  464.   if (old_log != NULL)
  465.     fclose(old_log);
  466.   if (new_log != NULL)
  467.     fclose(new_log);
  468.   unlink(ol);
  469.   rename(nl, ol);
  470. }
  471.  
  472. void ssm(char *s)
  473. {
  474.   int f, i, i1;
  475.   char s1[161];
  476.   shortmsgrec sm;
  477.   configrec syscfg;
  478.  
  479.   sprintf(s1, "CONFIG.DAT");
  480.   f = sh_open1(s1, O_RDONLY | O_BINARY);
  481.   if (f < 0)
  482.     return;
  483.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  484.   sh_close(f);
  485.   sprintf(s1, "%sSMW.DAT", syscfg.datadir);
  486.   f = sh_open(s1, O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  487.   if (f < 0)
  488.     return;
  489.   i = (int) (filelength(f) / sizeof(shortmsgrec));
  490.   i1 = i - 1;
  491.   if (i1 >= 0) {
  492.     sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  493.     sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  494.     while ((sm.tosys == 0) && (sm.touser == 0) && (i1 > 0)) {
  495.       --i1;
  496.       sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  497.       sh_read(f, (void *) &sm, sizeof(shortmsgrec));
  498.     }
  499.     if ((sm.tosys) || (sm.touser))
  500.       ++i1;
  501.   } else
  502.     i1 = 0;
  503.   sm.tosys = 0;
  504.   sm.touser = 1;
  505.   strncpy(sm.message, s, 80);
  506.   sm.message[80] = 0;
  507.   sh_lseek(f, ((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  508.   sh_write(f, (void *) &sm, sizeof(shortmsgrec));
  509.   sh_close(f);
  510. }
  511.  
  512. static unsigned char *trimstr1(unsigned char *s)
  513. {
  514.   int i;
  515.   static char *whitespace = " \r\n\t";
  516.  
  517.   i = strlen(s);
  518.   while ((i > 0) && (strchr(whitespace, s[i - 1])))
  519.     --i;
  520.   while ((i > 0) && (strchr(whitespace, *s))) {
  521.     memmove(s, s + 1, --i);
  522.   }
  523.   s[i] = 0;
  524.   return (s);
  525. }
  526.  
  527.  
  528.  
  529. int log_it(int send_ssm, char *fmt,...)
  530. {
  531.   va_list v;
  532.   char s[512];
  533.   FILE *fp;
  534.  
  535.   sprintf(s, "%s\\NEWS.LOG", net_data);
  536.   if ((fp = fsh_open(s, "at")) == NULL)
  537.     return 1;
  538.   va_start(v, fmt);
  539.   vsprintf(s, fmt, v);
  540.   va_end(v);
  541.   fputs(s, fp);
  542.   fputs(s, stderr);
  543.   if (fp != NULL)
  544.     fclose(fp);
  545.   trimstr1(s);
  546.   if (send_ssm)
  547.     ssm(s);
  548.   return 0;
  549. }
  550.  
  551.  
  552. int count_lines(char *s)
  553. {
  554.   FILE *fp;
  555.   char fn[201];
  556.   unsigned int nl = 0;
  557.   const int NEWLINE = '\n';
  558.   int c;
  559.  
  560.   strcpy(fn, s);
  561.   if ((fp = fsh_open(fn, "rt")) == NULL) {
  562.     output("\n ■ Cannot open %s", fn);
  563.     return 0;
  564.   }
  565.   while ((c = getc(fp)) != EOF) {
  566.     if (c == NEWLINE)
  567.       ++nl;
  568.   }
  569.   if (fp != NULL)
  570.     fclose(fp);
  571.   return nl;
  572. }
  573.  
  574. int exist(char *s)
  575. {
  576.   int i;
  577.   struct ffblk ff;
  578.  
  579.   i = findfirst(s, &ff, 0);
  580.   if (i)
  581.     return (0);
  582.   else
  583.     return (1);
  584. }
  585.  
  586. void rename_pend(char *dir, char *file)
  587. {
  588.   char s[181], s1[181];
  589.   int i, ok;
  590.  
  591.   sprintf(s, "%s\\%s", dir, file);
  592.   ok = 0;
  593.   for (i = 0; i < 1000 && !ok; i++) {
  594.     sprintf(s1, "%s\\P0-%u.NET", dir, i);
  595.     if (!exist(s1)) {
  596.       rename(s, s1);
  597.       ok = 1;
  598.     }
  599.   }
  600. }
  601.  
  602. void check_packets(void)
  603. {
  604.   char s[181];
  605.   int f1;
  606.   struct ffblk ff;
  607.  
  608.   sprintf(s, "%s\\P0-*.%3.3d", net_data, instance);
  609.   f1 = findfirst(s, &ff, 0);
  610.   while (f1 == 0) {
  611.     rename_pend(net_data, ff.ff_name);
  612.     f1 = findnext(&ff);
  613.   }
  614. }
  615.  
  616.  
  617. void err_exit(int exitlevel, char *fmt,...)
  618. {
  619.   va_list v;
  620.   char s[255];
  621.  
  622.   va_start(v, fmt);
  623.   vsprintf(s, fmt, v);
  624.   va_end(v);
  625.   fputs(s, stderr);
  626.   check_packets();
  627.   cursor('R');
  628.   exit(exitlevel);
  629. }
  630.  
  631. void write_groups(int display)
  632. {
  633.   int i;
  634.   FILE *groupfp;
  635.  
  636.   if ((groupfp = fsh_open(newsrc, "wt")) == NULL) {
  637.     output("\n ■ Unable to open %s!", newsrc);
  638.     return;
  639.   } else {
  640.     if (display)
  641.       output("\n ■ Updating pointers in %s...", newsrc);
  642.   }
  643.   for (i = 0; i < ngroups; i++) {
  644.     if ((grouprec[i].groupname[0]) && (stricmp(grouprec[i].groupname, "newsrc") != 0)) {
  645.       fprintf(groupfp, "%s %ld %s\n", grouprec[i].groupname,
  646.               grouprec[i].lastread, grouprec[i].subtype);
  647.     }
  648.   }
  649.   if (groupfp != NULL)
  650.     fclose(groupfp);
  651. }
  652.  
  653. void far *mallocx(unsigned long l)
  654. {
  655.   void *x;
  656.   char huge *xx;
  657.  
  658.   if (!l)
  659.     l = 1;
  660.   x = farmalloc(l);
  661.   if (!x) {
  662.     output("\n ■ Unable to allocate %lu bytes of memory", l);
  663.     cursor('R');
  664.     exit(EXIT_FAILURE);
  665.   }
  666.   xx = (char huge *) x;
  667.   while (l) {
  668.     if (l > 32768L) {
  669.       memset((void *) xx, 0, (size_t) 32768L);
  670.       l -= 32768L;
  671.       xx += 32768L;
  672.     } else {
  673.       memset((void *) xx, 0, (size_t) l);
  674.       break;
  675.     }
  676.   }
  677.   return (x);
  678. }
  679.  
  680.  
  681. void nntp_shutdown(Mail_Socket * NNTP_sock)
  682. {
  683.   sock_printf(NNTP_sock->sock, "QUIT");
  684.   sock_close(NNTP_sock->sock);
  685.   sock_wait_closed(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  686. sock_err:
  687.   return;
  688. }
  689.  
  690.  
  691. void read_groups(void)
  692. {
  693.   int i = 0, ok;
  694.   unsigned short sn;
  695.   char *ss, fn[101], tmp[101];
  696.   FILE *groupfp;
  697.  
  698.   ngroups = count_lines(newsrc);
  699.   if (!ngroups)
  700.     return;
  701.   grouprec = (GROUPFILEREC *) mallocx((ngroups + 1) * sizeof(GROUPFILEREC));
  702.   if (!grouprec) {
  703.     ngroups = 0;
  704.     output("\n ■ Unable to allocate memory reading NEWS.RC!");
  705.     return;
  706.   }
  707.   if ((groupfp = fsh_open(newsrc, "rt")) == NULL) {
  708.     farfree(grouprec);
  709.     ngroups = 0;
  710.     return;
  711.   }
  712.   while (fgets(tmp, 120, groupfp)) {
  713.     if (tmp[0]) {
  714.       if (strncmpi(tmp, "newsrc", 6) == 0) {
  715.         strcpy(grouprec[i].groupname, "newsrc");
  716.         ++i;
  717.       } else {
  718.         ss = strtok(tmp, " ");
  719.         strcpy(grouprec[i].groupname, ss);
  720.         ss = strtok(NULL, " ");
  721.         if (ss != NULL) {
  722.           grouprec[i].lastread = atol(ss);
  723.           ss = strtok(NULL, " \n");
  724.           if (ss != NULL) {
  725.             strcpy(grouprec[i].subtype, strupr(ss));
  726.             ++i;
  727.           }
  728.         }
  729.       }
  730.     }
  731.   }
  732.   ngroups = i;
  733.   if (groupfp != NULL)
  734.     fclose(groupfp);
  735.   for (i = 0; i < ngroups; i++) {
  736.     if ((grouprec[i].subtype) && (atoi(grouprec[i].subtype) != 0)) {
  737.       sprintf(fn, "%s\\N%s.NET", net_data, grouprec[i].subtype);
  738.       if (exist(fn)) {
  739.         groupfp = fsh_open(fn, "rt");
  740.         ok = 0;
  741.         while ((fgets(tmp, 25, groupfp)) && !ok) {
  742.           sn = atoi(tmp);
  743.           if (sn == 32767)
  744.             ok = 1;
  745.         }
  746.         if (groupfp != NULL)
  747.           fclose(groupfp);
  748.         if (!ok)
  749.           log_it(1, "\n ■ @32767 not listed as a subscriber in N%s.NET!",
  750.                  grouprec[i].subtype);
  751.       }
  752.     }
  753.   }
  754. }
  755.  
  756. int cgroup(Mail_Socket * NNTP_sock, char *s)
  757. {
  758.   static char _temp_buffer[STRING];
  759.  
  760.   sock_printf(NNTP_sock->sock, "GROUP %s", s);
  761.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  762.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  763.   sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  764.   if (reply == 411)
  765.     return 1;
  766.   else {
  767.     if (reply == 211) {
  768.       sscanf(_temp_buffer, "%hu %ld %ld %ld %s",
  769.              &reply, &cur_numa, &cur_first, &cur_last, &cur_gname);
  770.       return 0;
  771.     } else {
  772.       if (reply == 480)
  773.         return 2;
  774.       else
  775.         log_it(0, "\n ■ Unknown cgroup response : %s", _temp_buffer);
  776.       return 1;
  777.     }
  778.   }
  779.   SOCK_READ_ERR(NNTP_sock);
  780.   return -1;
  781. }
  782.  
  783. int cstat(Mail_Socket * NNTP_sock, long l)
  784. {
  785.   char *p, *q;
  786.   static char _temp_buffer[STRING];
  787.  
  788.   sock_printf(NNTP_sock->sock, "STAT %ld", l);
  789.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  790.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  791.   sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  792.   if (reply == 423)
  793.     return -1;
  794.   else if (reply == 223) {
  795.     cur_article = reparticle;
  796.     p = _temp_buffer;
  797.     q = cur_articleid;
  798.     while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  799.       p++;
  800.     while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  801.       *q++ = *p++;
  802.     *q++ = '>';
  803.     *q++ = '\0';
  804.     return 0;
  805.     }
  806.   else
  807.     log_it(0, "\n ■ Unknown cstat error : %s", _temp_buffer);
  808.   SOCK_READ_ERR(NNTP_sock);
  809.   return -1;
  810. }
  811.  
  812. void qexit(Mail_Socket * NNTP_sock, int n)
  813. {
  814.   static char _temp_buffer[STR];
  815.  
  816.   if (n >= 10)
  817.     log_it(0, "\n ! Fatal NEWS error: check configuration!");
  818.   fflush(stdout);
  819.   sock_printf(NNTP_sock->sock, "QUIT");
  820.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  821.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  822.   if (*_temp_buffer != '2')
  823.     log_it(0, "\n ■ Tried to quit host but failed");
  824. sock_err:
  825.   cursor('R');
  826.   check_packets();
  827.   fcloseall();
  828.   free_Mail_Socket(NNTP_sock);
  829.   exit(n);
  830. }
  831.  
  832. void treat(char *str)
  833. {
  834.   char *obuf, *nbuf;
  835.  
  836.   if (*str) {
  837.     for (obuf = str, nbuf = str; *obuf && obuf; ++obuf) {
  838.       if (((*obuf >= 32) && (*obuf <= 126)) || (*obuf == 10) || (*obuf == 9)) {
  839.         *nbuf++ = *obuf;
  840.       }
  841.     }
  842.   }
  843.   *nbuf = 0;
  844. }
  845.  
  846. void name_packet(char *pktname)
  847. {
  848.   int ok;
  849.   struct stat info;
  850.   unsigned int i;
  851.  
  852.   ok = 0;
  853.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  854.     sprintf(pktname, "%s\\P0-%u.%3.3d", net_data, i, instance);
  855.     if (stat(pktname, &info) == -1)
  856.       ok = 1;
  857.   }
  858. }
  859.  
  860. int savebody(Mail_Socket * NNTP_sock, int cug, int *abort)
  861. {
  862.   char s1[21], s2[21], ch;
  863.   unsigned int curpos, count, part;
  864.   char spin[26];
  865.   int i, place, len, spooltodisk;
  866.   unsigned long msgsize;
  867.   struct stat statbuf;
  868.   FILE *tpktfp = NULL;
  869.   static char _temp_buffer[BIGSTR];
  870.  
  871.   strcpy(spin, "||//--\\\\");
  872.   place = count = spooltodisk = 0;
  873.   len = strlen(spin);
  874.  
  875.   if ((strlen(grouprec[cug].subtype) == 1) &&
  876.       (grouprec[cug].subtype[0] == '0'))
  877.     spooltodisk = 1;
  878.   part = 1;
  879.   if (spooltodisk)
  880.     sprintf(tpktname, "%s\\NEWS%d.UUE", tmpdir, cug);
  881.   else {
  882.     sprintf(tpktname, "%s\\INPUT%d.MSG", tmpdir, part++);
  883.     if (stat(tpktname, &statbuf) == 0)
  884.       unlink(tpktname);
  885.   }
  886.   sock_printf(NNTP_sock->sock, "BODY %ld", cur_article);
  887.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  888.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  889.   sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  890.   if (reply == 423)
  891.     return -1;
  892.   else {
  893.     if (reply == 222) {
  894.       if (!spooltodisk) {
  895.         if ((tpktfp = fsh_open(tpktname, "wt+")) == NULL) {
  896.           fprintf(stderr, "\n ■ Unable to create temporary packet %s", tpktname);
  897.           return -1;
  898.         } else {
  899.           strcpy(_temp_buffer, "\n");
  900.           fputs(_temp_buffer, tpktfp);
  901.         }
  902.       } else {
  903.         if (tpktfp != NULL)
  904.           fclose(tpktfp);
  905.         if ((tpktfp = fsh_open(tpktname, "at+")) == NULL) {
  906.           log_it(0, "\n ■ Unable to create temporary packet %s", tpktname);
  907.           qexit(NNTP_sock, 1);
  908.         } else {
  909.           fputs("\n", tpktfp);
  910.           for (i = 0; i < 79; i++)
  911.             fputs("-", tpktfp);
  912.           fputs("\n", tpktfp);
  913.           sprintf(_temp_buffer, "Art  : %ld\n", cur_article);
  914.           fputs(_temp_buffer, tpktfp);
  915.           sprintf(_temp_buffer, "Date : %s\n", cur_date);
  916.           fputs(_temp_buffer, tpktfp);
  917.           sprintf(_temp_buffer, "From : %s\n", cur_replyto);
  918.           fputs(_temp_buffer, tpktfp);
  919.           sprintf(_temp_buffer, "Subj : %s\n\n", cur_subject);
  920.           fputs(_temp_buffer, tpktfp);
  921.         }
  922.       }
  923.       fnsplit(tpktname, NULL, NULL, s1, s2);
  924.       if (!spooltodisk)
  925.         output("\n ■ Receiving message - <Esc> aborts - <Space> skips group [-]");
  926.       else
  927.         output("\n ■ Appending to %s%s - <Esc> aborts - <Space> skips group [-]", s1, s2);
  928.       msgsize = 0L;
  929.       curpos = 0L;
  930.       while (1) {
  931.         if (kbhit()) {
  932.           ch = (getch());
  933.           switch (ch) {
  934.             case 27:
  935.               output("\r ■ Abort detected... please wait until message is completed [-]");
  936.               *abort = 1;
  937.               break;
  938.             case 32:
  939.               output("\r ■ Skipping group... please wait until message is completed [-]");
  940.               *abort = 2;
  941.               break;
  942.             default:
  943.               break;
  944.           }
  945.         }
  946.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  947.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  948.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  949.           break;
  950.         } else {
  951.           treat(_temp_buffer);
  952.           strcat(_temp_buffer, "\n");
  953.           curpos = strlen(_temp_buffer);
  954.           fputs(_temp_buffer, tpktfp);
  955.           msgsize += curpos;
  956.         }
  957.         if (count++ > 5) {
  958.           output("\b\b%c]", spin[place++]);
  959.           place %= len;
  960.           count = 0;
  961.         }
  962.         if ((msgsize > 30000L) && (!spooltodisk)) {
  963.           strcpy(_temp_buffer, "\nContinued in next message...\n");
  964.           fputs(_temp_buffer, tpktfp);
  965.           if (tpktfp != NULL)
  966.             fclose(tpktfp);
  967.           sprintf(tpktname, "%s\\INPUT%d.MSG", tmpdir, part++);
  968.           if (stat(tpktname, &statbuf) == 0)
  969.             unlink(tpktname);
  970.           if ((tpktfp = fsh_open(tpktname, "wt+")) == NULL) {
  971.             fprintf(stderr, "\n ■ Unable to create temporary packet %s", tpktname);
  972.             return -1;
  973.           }
  974.           backline();
  975.           output("\r ■ Breaking into %d%s part [ ]", (
  976.                                          part - 1), ordinal_text(part - 1));
  977.           strcpy(_temp_buffer, "\nContinued from previous message...\n");
  978.           fputs(_temp_buffer, tpktfp);
  979.           msgsize = strlen(_temp_buffer);
  980.         }
  981.       }
  982.       if (tpktfp != NULL)
  983.         fclose(tpktfp);
  984.       output("\b\bX]");
  985.       return 1;
  986.     }
  987.   }
  988.   if (tpktfp != NULL)
  989.     fclose(tpktfp);
  990.   SOCK_READ_ERR(NNTP_sock);
  991.   return 0;
  992. }
  993.  
  994. int extract(char *to, char *key, char *from)
  995. {
  996.   if (!strnicmp(from, key, strlen(key))) {
  997.     from += strlen(key);
  998.     while (*from == ' ')
  999.       from++;
  1000.     strcpy(to, from);
  1001.     return 1;
  1002.   } else
  1003.     return 0;
  1004. }
  1005.  
  1006.  
  1007. int chead(Mail_Socket * NNTP_sock)
  1008. {
  1009.   static char _temp_buffer[BIGSTR];
  1010.  
  1011.   *cur_path = 0;
  1012.   *cur_from = 0;
  1013.   *cur_replyto = 0;
  1014.   *cur_subject = 0;
  1015.   *cur_newsgroups = 0;
  1016.   *cur_message_ID = 0;
  1017.   *cur_references = 0;
  1018.   *cur_date = 0;
  1019.  
  1020.   sock_printf(NNTP_sock->sock, "HEAD %ld", cur_article);
  1021.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1022.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1023.   sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  1024.   if (reply == 423)
  1025.     return 0;
  1026.   else
  1027.     if (reply == 221)
  1028.     while (1) {
  1029.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1030.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1031.       if (strlen(_temp_buffer) > 1024)
  1032.         _temp_buffer[1024] = 0;
  1033.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  1034.         if (cur_replyto[0] == 0)
  1035.           strcpy(cur_replyto, cur_from);
  1036.         return 1;
  1037.       }
  1038.       extract(cur_path, "Path:", _temp_buffer) ||
  1039.           extract(cur_from, "From:", _temp_buffer) ||
  1040.           extract(cur_subject, "Subject:", _temp_buffer) ||
  1041.           extract(cur_replyto, "Reply-To:", _temp_buffer) ||
  1042.           extract(cur_newsgroups, "Newsgroups:", _temp_buffer) ||
  1043.           extract(cur_organization, "Organization:", _temp_buffer) ||
  1044.           extract(cur_message_ID, "Message-ID:", _temp_buffer) ||
  1045.           extract(cur_references, "References:", _temp_buffer) ||
  1046.           extract(cur_lines, "Lines:", _temp_buffer) ||
  1047.           extract(cur_date, "Date:", _temp_buffer);
  1048.     }
  1049.   else {
  1050.     log_it(0, "\n ■ Unknown chead error : %s", _temp_buffer);
  1051.   }
  1052.   SOCK_READ_ERR(NNTP_sock);
  1053.   return 0;
  1054. }
  1055.  
  1056. Mail_Socket *netsocket(char *host)
  1057. {
  1058.   Mail_Socket *NNTP_sock = NULL;
  1059.   longword h;
  1060.   static char _temp_buffer[STR];
  1061.  
  1062.   if (!(h = resolve(host)))
  1063.     err_exit(EXIT_FAILURE, "\n ■ Could not resolve %s... aborting", host);
  1064.   if ((NNTP_sock = (Mail_Socket *) farmalloc(sizeof(Mail_Socket))) == NULL)
  1065.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1066.   if ((NNTP_sock->sock = (tcp_Socket *) farmalloc(sizeof(tcp_Socket))) == NULL) {
  1067.     farfree(NNTP_sock);
  1068.     err_exit(EXIT_FAILURE, "\n ■ Insufficient memory for socket... aborting.");
  1069.   }
  1070.   if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
  1071.     free_Mail_Socket(NNTP_sock);
  1072.     err_exit(EXIT_FAILURE, "\n ■ TCP socket open failed... aborting");
  1073.   }
  1074.   sock_mode(NNTP_sock->sock, TCP_MODE_ASCII);
  1075.   sock_wait_established(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1076.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1077.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1078.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1079.   switch (reply) {
  1080.     case 200:
  1081.       log_it(0, "\n ■ Connection to %s accepted...", host);
  1082.       break;
  1083.     case 502:
  1084.       free_Mail_Socket(NNTP_sock);
  1085.       err_exit(EXIT_FAILURE, "\n ■ Connection to %s refused... try again later.", host);
  1086.       break;
  1087.     case 503:
  1088.       free_Mail_Socket(NNTP_sock);
  1089.       err_exit(EXIT_FAILURE, "\n ■ NNTP service unavailable. Connection to %s refused.", host);
  1090.       break;
  1091.     default:
  1092.       free_Mail_Socket(NNTP_sock);
  1093.       err_exit(EXIT_FAILURE, "\n ■ Unknown NNTP error. Connection to %s failed.", host);
  1094.       break;
  1095.   }
  1096.   SOCK_READ_ERR(NNTP_sock);
  1097.   return (NNTP_sock);
  1098. }
  1099.  
  1100. int cnext(Mail_Socket * NNTP_sock)
  1101. {
  1102.   char *p, *q;
  1103.   static char _temp_buffer[STRING];
  1104.  
  1105.   sock_printf(NNTP_sock->sock, "NEXT");
  1106.   sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1107.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1108.   sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  1109.   if (reply == 421)
  1110.     return -1;
  1111.   else if (reply == 223) {
  1112.     cur_article = reparticle;
  1113.     p = _temp_buffer;
  1114.     q = cur_articleid;
  1115.     while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  1116.       p++;
  1117.     while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  1118.       *q++ = *p++;
  1119.     *q++ = '>';
  1120.     *q++ = '\0';
  1121.     return 0;
  1122.   } else
  1123.     log_it(0, "\n ■ Unknown cnext error : %s", _temp_buffer);
  1124.   SOCK_READ_ERR(NNTP_sock);
  1125.   return -1;
  1126. }
  1127.  
  1128. char *stripspace(char *str)
  1129. {
  1130.   char *obuf, *nbuf;
  1131.  
  1132.   if (str) {
  1133.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1134.       if (!isspace(*obuf))
  1135.         *nbuf++ = *obuf;
  1136.     }
  1137.     *nbuf = NULL;
  1138.   }
  1139.   return (str);
  1140. }
  1141.  
  1142.  
  1143. int sendauthinfo(Mail_Socket * NNTP_sock)
  1144. {
  1145.   char s[MAXPATH], line[121], name[21], pass[31], *ss;
  1146.   static char _temp_buffer[BIGSTR];
  1147.   FILE *fp;
  1148.  
  1149.   output("\n ■ Server requested authentication information.");
  1150.   sprintf(s, "%s\\NET.INI", maindir);
  1151.   if ((fp = fsh_open(s, "rt")) == NULL) {
  1152.     output("\n ■ Unable to open %s.", s);
  1153.     return 1;
  1154.   }
  1155.   while (fgets(line, 80, fp)) {
  1156.     ss = NULL;
  1157.     stripspace(line);
  1158.     if ((line[0] == ';') || (line[0] == '\n') || (line[0] == '['))
  1159.       continue;
  1160.     if (strlen(line) == 0)
  1161.       continue;
  1162.     if (strnicmp(line, "NEWSNAME", 8) == 0) {
  1163.       ss = strtok(line, "=");
  1164.       if (ss) {
  1165.         ss = strtok(NULL, "\n");
  1166.         trimstr1(ss);
  1167.         name[0] = 0;
  1168.         strcpy(name, ss);
  1169.       }
  1170.     }
  1171.     if (strnicmp(line, "NEWSPASS", 8) == 0) {
  1172.       ss = strtok(line, "=");
  1173.       if (ss) {
  1174.         ss = strtok(NULL, "\n");
  1175.         trimstr1(ss);
  1176.         pass[0] = 0;
  1177.         strcpy(pass, ss);
  1178.       }
  1179.     }
  1180.   }
  1181.   if (fp != NULL)
  1182.     fclose(fp);
  1183.   if ((name[0] == 0) || (pass[0] == 0)) {
  1184.     output("\n ■ NEWSNAME or NEWSPASS not properly defined!");
  1185.     return 1;
  1186.   }
  1187.   while (1) {
  1188.     sprintf(_temp_buffer, "authinfo user %s", name);
  1189.     sock_printf(NNTP_sock->sock, _temp_buffer);
  1190.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1191.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1192.     sscanf(_temp_buffer, "%hu %s", &reply, s);
  1193.     if (reply == 381) {
  1194.       sprintf(_temp_buffer, "authinfo pass %s", pass);
  1195.       sock_printf(NNTP_sock->sock, _temp_buffer);
  1196.       sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1197.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1198.       sscanf(_temp_buffer, "%hu %s", &reply, s);
  1199.       if (reply == 281) {
  1200.         output("\n ■ Authentication accepted.  Continuing news retrieval session.");
  1201.         return 0;
  1202.       } else {
  1203.         output("\n ■ Authentication failed.  Aborting news retrieval session.");
  1204.         return 1;
  1205.       }
  1206.     } else {
  1207.       output("\n ■ Unknown response \"%hu\" from server.", reply);
  1208.       return 1;
  1209.     }
  1210.   }
  1211.   SOCK_READ_ERR(NNTP_sock);
  1212.   return -1;
  1213. }
  1214.  
  1215. int saveactive(Mail_Socket * NNTP_sock, char *fn)
  1216. {
  1217.   char s[181], group[256], act;
  1218.   long to, from;
  1219.   int count, done;
  1220.   FILE *fp;
  1221.   static char _temp_buffer[BIGSTR];
  1222.  
  1223.   if ((fp = fsh_open(fn, "w")) == NULL) {
  1224.     perror(fn);
  1225.     return -1;
  1226.   }
  1227.   done = 0;
  1228.   while (!done) {
  1229.     sock_printf(NNTP_sock->sock, "LIST");
  1230.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1231.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1232.     sscanf(_temp_buffer, "%hu %ld", &reply, &reparticle);
  1233.     if (reply == 215) {
  1234.       count = 0;
  1235.       while (1) {
  1236.         if (count++ % 25 == 0)
  1237.           output("\b\b\b\b\b\b\b%-7d", count);
  1238.         sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1239.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1240.         if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0)
  1241.           break;
  1242.         sscanf(_temp_buffer, "%s %ld %ld %c", group, &to, &from, &act);
  1243.         sprintf(s, "%s %ld\n", group, to);
  1244.         fsh_write(s, sizeof(char), strlen(s), fp);
  1245.       }
  1246.       log_it(0, "\n ■ %d total newsgroups available on %s", count, serverhost);
  1247.       if (fp != NULL)
  1248.         fclose(fp);
  1249.       return 0;
  1250.     } else {
  1251.       if (reply == 480) {
  1252.         if (fp != NULL)
  1253.           fclose(fp);
  1254.         return 1;
  1255.       } else {
  1256.         log_it(0, "\n ■ Unknown saveactive error : %s", _temp_buffer);
  1257.         if (fp != NULL)
  1258.           fclose(fp);
  1259.         done = 1;
  1260.       }
  1261.     }
  1262.   }
  1263.   SOCK_READ_ERR(NNTP_sock);
  1264.   return -1;
  1265. }
  1266.  
  1267. int checkx(int cug)
  1268. {
  1269.   char *ptr, *ptr2, *ptr3, buf[256];
  1270.   int i, max;
  1271.  
  1272. /*
  1273.   ptr = strtok(cur_organization, "*");
  1274.   trimstr1(ptr);
  1275.   if (strncmpi(ptr, syscfg.systemname, strlen(syscfg.systemname)) == 0) {
  1276.     log_it(0, "\n ■ Skipping message - originally posted on %s.", syscfg.systemname);
  1277.     return 0;
  1278.   }
  1279. */
  1280.   sprintf(buf, "%s!%s", POPNAME, POPDOMAIN);
  1281.   if (strstr(cur_path, buf) != 0) {
  1282.     log_it(0, "\n ■ Local post \"%s\" skipped.", cur_subject);
  1283.     return 0;
  1284.   }
  1285.  
  1286.   ptr = cur_newsgroups;
  1287.   while (*ptr == ' ')
  1288.     ptr++;
  1289.   max = 0;
  1290.   while (1) {
  1291.     if (*ptr == 0)
  1292.       break;
  1293.     if (*ptr == ',') {
  1294.       ptr++;
  1295.       ++max;
  1296.     }
  1297.     while (*ptr == ' ')
  1298.       ptr++;
  1299.     ptr2 = ptr;
  1300.     ptr3 = buf;
  1301.     while (*ptr2 != 0 && *ptr2 != ',')
  1302.       *ptr3++ = *ptr2++;
  1303.     *ptr3 = 0;
  1304.     while (*(--ptr3) == ' ')
  1305.       *ptr3 = 0;
  1306.     ptr = ptr2;
  1307.     for (i = 0; i < cug; i++) {
  1308.       if (strcmpi(buf, grouprec[i].groupname) == 0) {
  1309.         output("\n ■ Skipping message - already posted in %s.",
  1310.                 grouprec[i].groupname);
  1311.         return 0;
  1312.       }
  1313.     }
  1314.     if ((crossposts > 0) && (max > crossposts)) {
  1315.       output("\n ■ Skipping message - crossposted to more than %hu newsgroups.",
  1316.           crossposts);
  1317.       return 0;
  1318.     }
  1319.   }
  1320.   return 1;
  1321. }
  1322.  
  1323. int postnews(Mail_Socket * NNTP_sock, int cug)
  1324. {
  1325.   char s[181], s1[12], s2[5], fn[201], *ss;
  1326.   int f1, nlines, len, tlen;
  1327.   FILE *fp;
  1328.   static char _temp_buffer[STR];
  1329.   struct ffblk ff;
  1330.  
  1331.   sprintf(fn, "%s\\OUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
  1332.   f1 = findfirst(fn, &ff, 0);
  1333.   if (f1 != 0) {
  1334.     log_it(0, "\n ■ No outbound news articles to post...");
  1335.     return 1;
  1336.   }
  1337.   while (f1 == 0) {
  1338.     sock_printf(NNTP_sock->sock, "POST");
  1339.     sock_wait_input(NNTP_sock->sock, SOCK_DELAY, NULL, &NNTP_stat);
  1340.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1341.     if (*_temp_buffer != '3') {
  1342.       if (atoi(_temp_buffer) == 440)
  1343.         log_it(1, "\n ■ No posting allowed to %s!", grouprec[cug].groupname);
  1344.       else
  1345.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1346.       return 0;
  1347.     }
  1348.     output("\n ■ Posting article to %s\n", grouprec[cug].groupname);
  1349.     sprintf(s, "%s\\OUTBOUND\\%s", net_data, ff.ff_name);
  1350.     fp = fsh_open(s, "rb");
  1351.     nlines = 0;
  1352.     while (fgets(_temp_buffer, 120, fp) != NULL) {
  1353.       if (_temp_buffer[0] == '.' && _temp_buffer[1] == 0) {
  1354.         _temp_buffer[1] = '.';
  1355.         _temp_buffer[2] = 0;
  1356.       }
  1357.       tlen = 0;
  1358.       len = strlen(_temp_buffer);
  1359.       while (tlen < len) {
  1360.         if (!tcp_tick(NNTP_sock->sock)) {
  1361.           if (fp != NULL)
  1362.             fclose(fp);
  1363.           output("\n ■ Connection reset by host");
  1364.           return 1;
  1365.         }
  1366.         tlen += sock_fastwrite(NNTP_sock->sock, &_temp_buffer[tlen], len - tlen);
  1367.       }
  1368.       backline();
  1369.       output("\r ■ Lines sent : %d", ++nlines);
  1370.     }
  1371.     if (fp != NULL)
  1372.       fclose(fp);
  1373.     sock_printf(NNTP_sock->sock, ".\n");
  1374.     output("\n ■ Awaiting acknowledgement - may take several minutes...");
  1375.     log_it(0, "\n ■ Server response : ");
  1376.     sock_wait_input(NNTP_sock->sock, 180, NULL, &NNTP_stat);
  1377.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1378.     log_it(0, "%s", _temp_buffer);
  1379.     if (*_temp_buffer != '2') {
  1380.       if (atoi(_temp_buffer) == 441) {
  1381.         ss = strtok(_temp_buffer, " ");
  1382.         ss = strtok(NULL, " ");
  1383.         if (atoi(ss) == 435)
  1384.           unlink(s);
  1385.         fnsplit(s, NULL, NULL, s1, s2);
  1386.         log_it(0, "\n ■ %s%s not accepted by server - nothing posted", s1, s2);
  1387.       } else
  1388.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1389.     } else {
  1390.       if (unlink(s) == 0)
  1391.         log_it(0, "\n ■ Deleted sent message - %s", s);
  1392.     }
  1393.     f1 = findnext(&ff);
  1394.   }
  1395.   SOCK_READ_ERR(NNTP_sock);
  1396.   return 0;
  1397. }
  1398.  
  1399. void get_subtype(int sub, char *where)
  1400. {
  1401.   int ok, which;
  1402.   char fn[181], s[81], net_name[21], *ss;
  1403.   FILE *fp;
  1404.  
  1405.   where[0] = 0;
  1406.   which = sub;
  1407.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1408.   if ((fp = fsh_open(fn, "r")) == NULL)
  1409.     return;
  1410.   ok = 0;
  1411.   while (fgets(s, 80, fp)) {
  1412.     if (s[0] == '!') {
  1413.       if (which == atoi(&s[1]))
  1414.         ok = 1;
  1415.     }
  1416.     if (ok && (s[0] == '$')) {
  1417.       ss = strtok(s, " ");
  1418.       strcpy(net_name, &ss[1]);
  1419.       ss = strtok(NULL, " ");
  1420.       if (fp != NULL)
  1421.         fclose(fp);
  1422.       if ((stricmp(net_name, "FILENET") == 0)) {
  1423.         trimstr1(ss);
  1424.         strcpy(where, ss);
  1425.         return;
  1426.       } else
  1427.         return;
  1428.     }
  1429.   }
  1430.   if (fp != NULL)
  1431.     fclose(fp);
  1432. }
  1433.  
  1434. unsigned short max_on_sub(int cug)
  1435. {
  1436.   int i, num_subs;
  1437.   char fn[MAXPATH], subtype[12];
  1438.   unsigned short max;
  1439.   subboardrec sub;
  1440.   FILE *fp;
  1441.  
  1442.   if ((strlen(grouprec[cug].subtype) == 1) && (grouprec[cug].subtype[0] == '0'))
  1443.     return 0;
  1444.   sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
  1445.   if ((fp = fsh_open(fn, "rb")) != NULL) {
  1446.     fseek(fp, 0L, SEEK_END);
  1447.     num_subs = (int) (ftell(fp) / sizeof(subboardrec));
  1448.     for (i = 0; i < num_subs; i++) {
  1449.       output("\b\b\b\b%-4d", i);
  1450.       fseek(fp, (long) i * sizeof(subboardrec), SEEK_SET);
  1451.       fread(&sub, sizeof(subboardrec), 1, fp);
  1452.       get_subtype(i, subtype);
  1453.       if (stricmp(subtype, grouprec[cug].subtype) == 0) {
  1454.         max = sub.maxmsgs;
  1455.         output("\b\b\b\b%s (%s) - %hu posts.", sub.name, subtype, max);
  1456.         fclose(fp);
  1457.         return max;
  1458.       }
  1459.     }
  1460.     fclose(fp);
  1461.   } else
  1462.     output("\n ■ Unable to read %s!", fn);
  1463.   return 0;
  1464. }
  1465.  
  1466.  
  1467. int getnews(char *hostname)
  1468. {
  1469.   int f1, nup, nug, cug, abort, ok, done, firstrun, parts;
  1470.   char *p, fn[201], mailname[121], reline[121], s[21], s1[21], pktname[121];
  1471.   char ch, orig_subj[STRING];
  1472.   unsigned int text_len;
  1473.   unsigned short temptype;
  1474.   long new_articles, max_articles;
  1475.   net_header_rec nh;
  1476.   struct ffblk ff;
  1477.   static FILE *fp;
  1478.   Mail_Socket *nntp_sock;
  1479.   static char _temp_buffer[STR];
  1480.  
  1481.   abort = cug = 0;
  1482.   sock_init();
  1483.   nntp_sock = netsocket(hostname);
  1484.  
  1485.   if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
  1486.     grouprec[0].groupname[0] = 0;
  1487.     write_groups(0);
  1488.     if (grouprec)
  1489.       farfree(grouprec);
  1490.     sprintf(fn, "%s\\NEWSRC", net_data);
  1491.     log_it(0, "\n ■ Creating newsgroup list : %s...         ", fn);
  1492.     if (saveactive(nntp_sock, fn) == 1) {
  1493.       if (sendauthinfo(nntp_sock) == 0)
  1494.         saveactive(nntp_sock, fn);
  1495.     }
  1496.     nntp_shutdown(nntp_sock);
  1497.     free_Mail_Socket(nntp_sock);
  1498.     return 0;
  1499.   }
  1500.   nug = nup = 1;
  1501.   while ((cug < ngroups) && (!abort)) {
  1502.     if (nup) {
  1503.       nup = 0;
  1504.       if (grouprec[cug].subtype) {
  1505.         if (fp != NULL)
  1506.           fclose(fp);
  1507.         write_groups(0);
  1508.         name_packet(pktname);
  1509.         if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1510.           log_it(0, "\n ■ Unable to create %s!", pktname);
  1511.           qexit(nntp_sock, 1);
  1512.         } else {
  1513.           fnsplit(pktname, NULL, NULL, s, s1);
  1514.           output("\n ■ Creating new packet : %s%s", s, s1);
  1515.         }
  1516.       } else {
  1517.         if (fp != NULL)
  1518.           fclose(fp);
  1519.       }
  1520.     }
  1521.     if (nug) {
  1522.       nug = 0;
  1523.       cur_article = ++grouprec[cug].lastread;
  1524.       while (1) {
  1525.         if (cgroup(nntp_sock, grouprec[cug].groupname)) {
  1526.           if (cgroup(nntp_sock, grouprec[cug].groupname) == 2) {
  1527.             if (sendauthinfo(nntp_sock) == 0)
  1528.               continue;
  1529.             else
  1530.               return 1;
  1531.           }
  1532.           log_it(1, "\n ■ Error accessing newsgroup \"%s\".",
  1533.                  grouprec[cug].groupname);
  1534.           if (++bogus >= 10) {
  1535.             log_it(0, "\n ■ Too many invalid newsgroups... NEWS.RC error!");
  1536.             qexit(nntp_sock, 10);
  1537.           }
  1538.           nug = 1;
  1539.           break;
  1540.         } else
  1541.           break;
  1542.       }
  1543.       if (!nug) {
  1544.         log_it(0, "\n ■ Requesting %s... ", grouprec[cug].groupname);
  1545.         if (grouprec[cug].lastread < cur_first)
  1546.           grouprec[cug].lastread = cur_first;
  1547.         if (grouprec[cug].lastread > cur_last) {
  1548.           grouprec[cug].lastread = cur_last;
  1549.           log_it(0, "no new articles.");
  1550.           nug = 1;
  1551.         } else {
  1552.           new_articles = cur_last - grouprec[cug].lastread;
  1553.           if (new_articles)
  1554.             log_it(0, "%ld new article%s.", new_articles + 1,
  1555.                  new_articles == 1L ? "" : "s");
  1556.           else {
  1557.             log_it(0, "no new articles.");
  1558.             nug = 1;
  1559.           }
  1560.           if (new_articles > 250L) {
  1561.             max_articles = 0L;
  1562.             output("\n ■ Maximum posts -     ");
  1563.             max_articles = (long) max_on_sub(cug);
  1564.             if (max_articles && (new_articles > max_articles)) {
  1565.               log_it(0, "\n ■ Requesting most recent %ld articles", max_articles);
  1566.               grouprec[cug].lastread = cur_last - max_articles;
  1567.             }
  1568.           }
  1569.         }
  1570.         postnews(nntp_sock, cug);
  1571.         if (!nug) {
  1572.           if (cur_numa == 0) {
  1573.             log_it(0, "\n ■ No articles available in %s...",
  1574.                    grouprec[cug].groupname);
  1575.             nug = 1;
  1576.             continue;
  1577.           } else {
  1578.             if (cstat(nntp_sock, grouprec[cug].lastread) &&
  1579.                 cstat(nntp_sock, cur_last))
  1580.               nug = 1;
  1581.           }
  1582.         }
  1583.       }
  1584.     } else {
  1585.       if (cnext(nntp_sock) == -1) {
  1586.         output("\n ■ End of new articles in %s",
  1587.                 grouprec[cug].groupname);
  1588.         nug = 1;
  1589.         write_groups(1);
  1590.       }
  1591.     }
  1592.     while (kbhit()) {
  1593.       ch = (getch());
  1594.       switch (ch) {
  1595.         case 27:
  1596.           log_it(0, "\n ■ Aborting news retrieval session...");
  1597.           if (fp != NULL)
  1598.             fclose(fp);
  1599.           nntp_shutdown(nntp_sock);
  1600.           free_Mail_Socket(nntp_sock);
  1601.           return 1;
  1602.         case 32:
  1603.           output("\n ■ Skipping group %s... ", grouprec[cug].groupname);
  1604.           write_groups(1);
  1605.           nug = 1;
  1606.           break;
  1607.         default:
  1608.           break;
  1609.       }
  1610.     }
  1611.     if (!nug) {
  1612.       if ((chead(nntp_sock)) && (checkx(cug))) {
  1613.         if (cur_subject[0]) {
  1614.           treat(cur_subject);
  1615.           if (strlen(cur_subject) > 65)
  1616.             cur_subject[65] = '\0';
  1617.         } else
  1618.           strcpy(cur_subject, "No subject");
  1619.         strcpy(orig_subj, cur_subject);
  1620.         if (cur_from[0]) {
  1621.           treat(cur_from);
  1622.           if (strlen(cur_from) > 45)
  1623.             cur_from[45] = 0;
  1624.         } else
  1625.           strcpy(cur_from, "Unknown");
  1626.         if (cur_replyto[0]) {
  1627.           if (strlen(cur_replyto) > 45)
  1628.             cur_replyto[45] = 0;
  1629.         }
  1630.         strncpy(_temp_buffer, orig_subj, 56);
  1631.         _temp_buffer[56] = '\0';
  1632.         output("\n ■ [%ld/%ld] : %s ", grouprec[cug].lastread,
  1633.                 cur_last, _temp_buffer);
  1634.         abort = 0;
  1635.         ok = savebody(nntp_sock, cug, &abort);
  1636.         if (ok && grouprec[cug].subtype) {
  1637.           strcpy(msgarea, grouprec[cug].groupname);
  1638.           sprintf(msgto, "All");
  1639.           sprintf(fn, "%s\\INPUT*.MSG", tmpdir);
  1640.           done = 1;
  1641.           parts = 0;
  1642.           if (findfirst(fn, &ff, 0) == 0) {
  1643.             parts = 1;
  1644.             done = 0;
  1645.           }
  1646.           firstrun = 1;
  1647.           while (!done) {
  1648.             sprintf(fn, "%s\\%s", tmpdir, ff.ff_name);
  1649.             f1 = sh_open1(fn, O_RDONLY | O_BINARY);
  1650.             text_len = (unsigned int) filelength(f1);
  1651.             if (text_len > 32000L) {
  1652.               output("\n ■ Truncating %lu bytes from input file",
  1653.                       text_len - 32000L);
  1654.               text_len = 32000;
  1655.             }
  1656.             if ((p = (char *) malloc(32767L)) == NULL) {
  1657.               log_it(0, "\n ■ Insufficient memory to read entire message");
  1658.               qexit(nntp_sock, 1);
  1659.             }
  1660.             sh_read(f1, (void *) p, text_len);
  1661.             sh_close(f1);
  1662.             temptype = atoi(grouprec[cug].subtype);
  1663.             nh.tosys = sy;
  1664.             nh.touser = 0;
  1665.             nh.fromsys = 32767;
  1666.             nh.fromuser = 0;
  1667.             if (!temptype) {
  1668.               nh.main_type = main_type_new_post;
  1669.               nh.minor_type = 0;
  1670.             } else {
  1671.               nh.main_type = main_type_pre_post;
  1672.               nh.minor_type = temptype;
  1673.             }
  1674.             nh.list_len = 0;
  1675.             ++cur_daten;
  1676.             nh.daten = cur_daten;
  1677.             nh.method = 0;
  1678.             if (parts > 1) {
  1679.               sprintf(_temp_buffer, "%d%s ", parts, ordinal_text(parts));
  1680.               strcat(_temp_buffer, orig_subj);
  1681.               strcpy(cur_subject, _temp_buffer);
  1682.               if (strlen(cur_subject) > 72)
  1683.                 cur_subject[72] = '\0';
  1684.               else
  1685.                 cur_subject[strlen(cur_subject)] = '\0';
  1686.             }
  1687.             nh.length = text_len + strlen(cur_subject) + 1;
  1688.             strncpy(mailname, cur_replyto, 46);
  1689.             strcat(mailname, "\r\n");
  1690.             nh.length += strlen(mailname);
  1691.             if (nh.main_type == main_type_new_post)
  1692.               nh.length += strlen(grouprec[cug].subtype) + 1;
  1693.             if (firstrun) {
  1694.               firstrun = 0;
  1695.               if (strncmpi(cur_articleid, "re: ", 4) == 0) {
  1696.                 strncpy(reline, cur_articleid, 60);
  1697.                 sprintf(cur_articleid, "Re: %s\r\n\r\n", reline);
  1698.               }
  1699.             }
  1700.             if (!cur_date[0]) {
  1701.               strncpy(cur_date, ctime(&(time_t) nh.daten), 24);
  1702.               cur_date[24] = '\0';
  1703.             }
  1704.             strcat(cur_date, "\r\n");
  1705.             nh.length += strlen(cur_date);
  1706.             nh.length += strlen(cur_articleid);
  1707.             fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1708.             if (nh.main_type == main_type_new_post)
  1709.               fsh_write(grouprec[cug].subtype, sizeof(char), strlen(grouprec[cug].subtype) +1, fp);
  1710.             fsh_write(cur_subject, sizeof(char), strlen(cur_subject) +1, fp);
  1711.             fsh_write(mailname, sizeof(char), strlen(mailname), fp);
  1712.             fsh_write(cur_date, sizeof(char), strlen(cur_date), fp);
  1713.             fsh_write(cur_articleid, sizeof(char), strlen(cur_articleid), fp);
  1714.             fsh_write(p, sizeof(char), text_len, fp);
  1715.             if (p)
  1716.               free(p);
  1717.             unlink(fn);
  1718.             if (findnext(&ff) == 0) {
  1719.               done = 0;
  1720.               ++parts;
  1721.             } else
  1722.               done = 1;
  1723.           }
  1724.         }
  1725. //        grouprec[cug].lastread = cur_article;
  1726. //      } else
  1727. //        grouprec[cug].lastread = cur_article + 1;
  1728.       }
  1729.       cur_article = ++grouprec[cug].lastread;
  1730.       if ((filelength(fileno(fp)) > 250000L) && grouprec[cug].subtype)
  1731.         nup = 1;
  1732.       if (abort == 2) {
  1733.         write_groups(1);
  1734.         nug = 1;
  1735.         abort = 0;
  1736.       }
  1737.     }
  1738.     if (nug) {
  1739.       ++cug;
  1740.       if (((strlen(grouprec[cug].subtype) == 1) &&
  1741.            (grouprec[cug].subtype[0] == '0')) && (grouprec[cug].subtype)) {
  1742.         nup = 1;
  1743.       } else {
  1744.         if ((grouprec[cug - 1].subtype) &&
  1745.             ((strlen(grouprec[cug].subtype) == 1) &&
  1746.              (grouprec[cug].subtype[0] == '0'))) {
  1747.           if (fp != NULL)
  1748.             fclose(fp);
  1749.         }
  1750.       }
  1751.     }
  1752.   }
  1753.   if (fp != NULL)
  1754.     fclose(fp);
  1755.   if (abort)
  1756.     log_it(0, "\n ■ Session aborted from keyboard");
  1757.   write_groups(1);
  1758.   nntp_shutdown(nntp_sock);
  1759.   free_Mail_Socket(nntp_sock);
  1760.   return 0;
  1761. }
  1762.  
  1763. void main(int argc, char *argv[])
  1764. {
  1765.   int f;
  1766.   char s[201], fn[MAXPATH], *ss;
  1767.   FILE *fp;
  1768.   struct tm *time_now;
  1769.   struct date dt;
  1770.   struct time tm;
  1771.   time_t some;
  1772.  
  1773.   cursor('S');
  1774.   cursor('H');
  1775.   output("\n ■ %s", version);
  1776.   if (argc != 4)
  1777.     err_exit(EXIT_FAILURE, "\n ■ Invalid arguments for %s", argv[0]);
  1778.   ss = getenv("WWIV_INSTANCE");
  1779.   if (ss) {
  1780.     instance = atoi(ss);
  1781.     if ((instance <= 0) || (instance >= 1000)) {
  1782.       log_it(0, "\n ■ WWIV_INSTANCE set to %d.  Can only be 1..999!", instance);
  1783.       instance = 1;
  1784.     }
  1785.   } else
  1786.     instance = 1;
  1787.   gettime(&tm);
  1788.   getdate(&dt);
  1789.   cur_daten = dostounix(&dt, &tm);
  1790.   SOCK_DELAY = 120;
  1791.   get_dir(maindir, 0);
  1792.   strcpy(net_data, argv[1]);
  1793.   strcpy(serverhost, argv[2]);
  1794.   detect_multitask();
  1795.   time(&some);
  1796.   time_now = localtime(&some);
  1797.   strftime(s, 80, "\n\nNEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1798.            time_now);
  1799.   sprintf(fn, "%s\\NEWS.LOG", net_data);
  1800.   if ((fp = fsh_open(fn, "at")) != NULL) {
  1801.     fprintf(fp, s);
  1802.     fclose(fp);
  1803.   }
  1804.   sprintf(tmpdir, "%s\\SPOOL", net_data);
  1805.   sy = atoi(argv[3]);
  1806.   sprintf(s, "%s\\CONFIG.DAT", maindir);
  1807.   f = sh_open1(s, O_RDONLY | O_BINARY);
  1808.   if (f < 0)
  1809.     err_exit(EXIT_FAILURE, "\n ■ %s NOT FOUND.", s);
  1810.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1811.   sh_close(f);
  1812.   sprintf(newsrc, "%s\\NEWS.RC", net_data);
  1813.   read_groups();
  1814.   if (ngroups == 0)
  1815.     err_exit(EXIT_FAILURE, "\n ■ Unable to access newsgroup file: %s!", newsrc);
  1816.   if (stricmp(grouprec[0].groupname, "newsrc") == 0)
  1817.     log_it(0, "\n ■ Retrieving current newsgroup listing from %s",
  1818.            serverhost);
  1819.   else
  1820.     log_it(0, "\n ■ %u newsgroup%s defined in %s", ngroups,
  1821.            ngroups == 1 ? "" : "s", strlwr(newsrc));
  1822.   crossposts = 10;
  1823.   POPNAME[0] = 0;
  1824.   POPDOMAIN[0] = 0;
  1825.   sprintf(fn, "%s\\NET.INI", maindir);
  1826.   if ((fp = fsh_open(fn, "rt")) == NULL)
  1827.     output("\n ■ Unable to read %s", fn);
  1828.   else {
  1829.     while (fgets(s, 80, fp)) {
  1830.       ss = NULL;
  1831.       stripspace(s);
  1832.       if ((s[0] == ';') || (s[0] == '\n') || (s[0]== '['))
  1833.         continue;
  1834.       if (strlen(s) == 0)
  1835.         continue;
  1836.       if ((strnicmp(s, "POPNAME", 7) == 0) && (POPNAME[0] == 0)) {
  1837.         ss = strtok(s, "=");
  1838.         if (ss) {
  1839.           ss = strtok(NULL, "\n");
  1840.           trimstr1(ss);
  1841.           strcpy(POPNAME, ss);
  1842.         }
  1843.       }
  1844.       if (strnicmp(s, "FWDNAME", 7) == 0) {
  1845.         ss = strtok(s, "=");
  1846.         if (ss) {
  1847.           ss = strtok(NULL, "\n");
  1848.           trimstr1(ss);
  1849.           strcpy(POPNAME, ss);
  1850.         }
  1851.       }
  1852.       if ((strnicmp(s, "DOMAIN", 6) == 0) && (POPDOMAIN[0] == 0)) {
  1853.         ss = strtok(s, "=");
  1854.         if (ss) {
  1855.           ss = strtok(NULL, "\n");
  1856.           trimstr1(ss);
  1857.           strcpy(POPDOMAIN, ss);
  1858.         }
  1859.       }
  1860.       if (strnicmp(s, "FWDDOM", 6) == 0) {
  1861.         ss = strtok(s, "=");
  1862.         if (ss) {
  1863.           ss = strtok(NULL, "\n");
  1864.           trimstr1(ss);
  1865.           strcpy(POPDOMAIN, ss);
  1866.         }
  1867.       }
  1868.       if (strnicmp(s, "XPOSTS", 6) == 0) {
  1869.         ss = strtok(s, "=");
  1870.         if (ss) {
  1871.           ss = strtok(NULL, "\n");
  1872.           trimstr1(ss);
  1873.           crossposts = atoi(ss);
  1874.           if (crossposts > 99)
  1875.             crossposts = 10;
  1876.         }
  1877.       }
  1878.     }
  1879.     if (fp != NULL)
  1880.       fclose(fp);
  1881.   }
  1882.   if (getnews(serverhost))
  1883.     err_exit(EXIT_FAILURE, "\n ■ Exiting program.");
  1884.   if (grouprec)
  1885.     farfree(grouprec);
  1886.   grouprec = NULL;
  1887.   cd_to(maindir);
  1888.   log_it(0, "\n ■ NEWS succesfully completed processing %d newsgroups", ngroups);
  1889.   trim_log();
  1890.   err_exit(EXIT_SUCCESS, "\n ■ Normal program termination");
  1891. }
  1892.