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