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