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

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <ctype.h>
  4. #include <process.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <errno.h>
  10. #include <fcntl.h>
  11. #include <io.h>
  12. #include <dos.h>
  13. #include <share.h>
  14. #include <dir.h>
  15. #include <alloc.h>
  16. #include <sys\stat.h>
  17. #include <math.h>
  18. 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 = 10000;
  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[BIGSTR], 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, 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 *) _fstrchr(fmode, 'w')) != NULL) {
  371.     share = SH_DENYRD;
  372.     md = O_RDWR | O_CREAT | O_TRUNC;
  373.   } else
  374.     if (((char *) _fstrchr(fmode, 'a')) != NULL) {
  375.     share = SH_DENYRD;
  376.     md = O_RDWR | O_CREAT;
  377.   } else {
  378.     md = O_RDONLY;
  379.   }
  380.   if (((char *) _fstrchr(fmode, 'b')) != NULL) {
  381.     md |= O_BINARY;
  382.   }
  383.   if (((char *) _fstrchr(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 *) _fstrchr(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 ((_fstrstr(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) && (_fstrchr(whitespace, s[i - 1])))
  514.     --i;
  515.   while ((i > 0) && (_fstrchr(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[181];
  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.     rename_pend(ff.ff_name);
  607.     f1 = findnext(&ff);
  608.   }
  609. }
  610.  
  611.  
  612. void write_groups(int display)
  613. {
  614.   int i;
  615.   char fn[160];
  616.   FILE *groupfp;
  617.  
  618.   sprintf(fn, "%sNEWS.RC", net_data);
  619.  
  620.   if ((groupfp = fsh_open(fn, "wt+")) == NULL) {
  621.     output("\n ■ Unable to open %s!", fn);
  622.     return;
  623.   } else {
  624.     if (display)
  625.       output("\n ■ Updating message pointers..");
  626.   }
  627.   for (i = 0; i < ngroups; i++) {
  628.     if ((*grouprec[i].groupname) && (stricmp(grouprec[i].groupname, "newsrc") != 0)) {
  629.       fprintf(groupfp, "%s %ld %s\n", grouprec[i].groupname,
  630.               grouprec[i].lastread, grouprec[i].subtype);
  631.       if ((i % 5 == 0) && (display))
  632.         output(".");
  633.     }
  634.   }
  635.   if (groupfp != NULL)
  636.     fclose(groupfp);
  637. }
  638.  
  639. void nntp_shutdown(Mail_Socket * NNTP_sock)
  640. {
  641.   if (NNTP_sock->sock != NULL) {
  642.     sock_puts(NNTP_sock->sock, "QUIT");
  643.     sock_close(NNTP_sock->sock);
  644.     sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  645.   }
  646. sock_err:
  647.   return;
  648. }
  649.  
  650. void read_groups(void)
  651. {
  652.   int i = 0, ok;
  653.   unsigned short sn;
  654.   char *ss, fn[101], fn1[160], tmp[121];
  655.   FILE *groupfp;
  656.  
  657.   sprintf(fn1, "%sNEWS.RC", net_data);
  658.   ngroups = count_lines(fn1);
  659.   if (!ngroups)
  660.     return;
  661.   if (grouprec != NULL)
  662.     farfree(grouprec);
  663.   grouprec = NULL;
  664.   grouprec = (GROUPFILEREC *) farmalloc((ngroups + 1) * sizeof(GROUPFILEREC));
  665.   if (!grouprec) {
  666.     ngroups = 0;
  667.     output("\n ■ Insufficient memory for %d groups in %s.", ngroups, fn1);
  668.     return;
  669.   }
  670.   if ((groupfp = fsh_open(fn1, "rt")) == NULL) {
  671.     if (grouprec != NULL)
  672.       farfree(grouprec);
  673.     ngroups = 0;
  674.     return;
  675.   }
  676.   while (fgets(tmp, 120, groupfp)) {
  677.     if (*tmp) {
  678.       if (strncmpi(tmp, "newsrc", 6) == 0) {
  679.         strcpy(grouprec[i].groupname, "newsrc");
  680.         ++i;
  681.       } else {
  682.         ss = strtok(tmp, " ");
  683.         strcpy(grouprec[i].groupname, ss);
  684.         ss = strtok(NULL, " ");
  685.         if (ss != NULL) {
  686.           grouprec[i].lastread = atol(ss);
  687.           ss = strtok(NULL, " \n");
  688.           if (ss != NULL) {
  689.             strcpy(grouprec[i].subtype, strupr(ss));
  690.             ++i;
  691.           }
  692.         }
  693.       }
  694.     }
  695.   }
  696.   ngroups = i;
  697.   if (groupfp != NULL)
  698.     fclose(groupfp);
  699.   for (i = 0; i < ngroups; i++) {
  700.     if ((grouprec[i].subtype) && (atoi(grouprec[i].subtype) != 0)) {
  701.       sprintf(fn, "%sN%s.NET", net_data, grouprec[i].subtype);
  702.       if (exist(fn)) {
  703.         ok = 0;
  704.         if ((groupfp = fsh_open(fn, "rt")) != NULL) {
  705.           while ((fgets(tmp, 25, groupfp)) && !ok) {
  706.             sn = atoi(tmp);
  707.             if (sn == 32767)
  708.               ok = 1;
  709.           }
  710.           fclose(groupfp);
  711.         }
  712.         if (!ok)
  713.           log_it(1, "\n ■ @32767 not listed as a subscriber in N%s.NET!",
  714.                  grouprec[i].subtype);
  715.       }
  716.     }
  717.   }
  718. }
  719.  
  720. int sendauthinfo(Mail_Socket * NNTP_sock)
  721. {
  722.   char s[MAXPATH], buf[STR];
  723.  
  724.   *_temp_buffer = 0;
  725.  
  726.   output("\n ■ Server requested authentication information.");
  727.  
  728.   while (1) {
  729.     sprintf(buf, "authinfo user %s", NEWSNAME);
  730.     sock_printf(NNTP_sock->sock, buf);
  731.     sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  732.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  733.     sscanf(_temp_buffer, "%hu %s", &reply, s);
  734.     if (reply == 381) {
  735.       sprintf(buf, "authinfo pass %s", NEWSPASS);
  736.       sock_printf(NNTP_sock->sock, buf);
  737.       sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  738.       sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  739.       sscanf(_temp_buffer, "%hu %s", &reply, s);
  740.       if (reply == 281) {
  741.         output("\n ■ Authentication accepted.  Continuing news retrieval session.");
  742.         return 1;
  743.       } else {
  744.         output("\n ■ Authentication failed.  Aborting news retrieval session.");
  745.         return 0;
  746.       }
  747.     } else {
  748.       output("\n ■ Unknown AUTHINFO response %s.", _temp_buffer);
  749.       return 0;
  750.     }
  751.   }
  752.   SOCK_READ_ERR(NNTP);
  753.   return 0;
  754. }
  755.  
  756. int cgroup(Mail_Socket * NNTP_sock, char *s)
  757. {
  758.   char junk[STRING];
  759.  
  760.   *_temp_buffer = 0;
  761.  
  762.   sock_printf(NNTP_sock->sock, "GROUP %s", s);
  763.   sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  764.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  765.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  766.   switch (reply) {
  767.     case 411:
  768.       return 0;
  769.     case 211:
  770.       sscanf(_temp_buffer, "%hu %lu %lu %lu %s",
  771.              &reply, &cur_numa, &cur_first, &cur_last, &junk);
  772.       return 1;
  773.     case 480:
  774.       return (-1);
  775.     default:
  776.       log_it(0, "\n ■ Unknown cgroup response : %s", _temp_buffer);
  777.       break;
  778.   }
  779.   SOCK_READ_ERR(NNTP);
  780.   return 0;
  781. }
  782.  
  783. void treat(char *str)
  784. {
  785.   char *obuf, *nbuf;
  786.  
  787.   if (*str) {
  788.     for (obuf = str, nbuf = str; *obuf && obuf; ++obuf) {
  789.       if (((*obuf >= 32) && (*obuf <= 126)) || (*obuf == 10) || (*obuf == 9)) {
  790.         *nbuf++ = *obuf;
  791.       }
  792.     }
  793.     *nbuf = 0;
  794.   }
  795. }
  796.  
  797. void name_packet(char *pktname)
  798. {
  799.   int ok;
  800.   struct stat info;
  801.   unsigned int i;
  802.  
  803.   ok = 0;
  804.   for (i = 0; ((i < 1000) && (!ok)); i++) {
  805.     sprintf(pktname, "%sP0-%u.%3.3d", net_data, i, instance);
  806.     if (stat(pktname, &info) == -1)
  807.       ok = 1;
  808.   }
  809. }
  810.  
  811. int savebody(Mail_Socket * NNTP_sock, char *fn, int cug, unsigned long cur_article, int *abort)
  812. {
  813.   int i, place, len, curpos, count, part;
  814.   char _big_temp_buffer[BIGSTR];
  815.   char ch, spin[26], buf[180];
  816.   unsigned long msgsize;
  817.   struct stat statbuf;
  818.   FILE *tpktfp;
  819.  
  820.   place = count = 0;
  821.   *_temp_buffer = 0;
  822.   part = 1;
  823.  
  824.   strcpy(spin, "||//--\\\\");
  825.   len = strlen(spin);
  826.  
  827.   sock_printf(NNTP_sock->sock, "BODY %ld", cur_article);
  828.   sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  829.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  830.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  831.   switch (reply) {
  832.     case 423:
  833.       return 0;
  834.     case 222:
  835.       if (!spooltodisk) {
  836.         if ((tpktfp = fsh_open(fn, "wt+")) == NULL) {
  837.           fprintf(stderr, "\n ■ Unable to create temporary packet 1 %s", fn);
  838.           sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  839.           *abort = 3;
  840.           return 0;
  841.         } else
  842.           fputs("\n", tpktfp);
  843.       } else {
  844.         if (tpktfp != NULL)
  845.           fclose(tpktfp);
  846.         if ((tpktfp = fsh_open(fn, "at+")) == NULL) {
  847.           fprintf(stderr, "\n ■ Unable to create temporary packet 2 %s", fn);
  848.           sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  849.           *abort = 3;
  850.           return 0;
  851.         } else {
  852.           fputs("\n", tpktfp);
  853.           for (i = 0; i < 79; i++)
  854.             fputs("-", tpktfp);
  855.           fputs("\n", tpktfp);
  856.           sprintf(buf, "Art  : %lu\n", cur_article);
  857.           fputs(buf, tpktfp);
  858.           if (*cur_date)
  859.             sprintf(buf, "Date : %s\n", cur_date);
  860.           else
  861.             sprintf(buf, "Date : Unknown\n");
  862.           fputs(buf, tpktfp);
  863.           if (*cur_replyto)
  864.             sprintf(buf, "From : %s\n", cur_replyto);
  865.           else
  866.             sprintf(buf, "From : Unknown\n");
  867.           fputs(buf, tpktfp);
  868.           if (*cur_subject)
  869.             sprintf(buf, "Subj : %s\n\n", cur_subject);
  870.           else
  871.             sprintf(buf, "Subj : Unknown\n");
  872.           fputs(buf, tpktfp);
  873.         }
  874.       }
  875.       if (!spooltodisk)
  876.         output("\n ■ Receiving message - [Esc] aborts - [Space] skips group [-]");
  877.       else
  878.         output("\n ■ Appending to NEWS%d.UUE - [Esc] aborts - [Space] skips group [-]", cug);
  879.       msgsize = 0L;
  880.       curpos = 0L;
  881.       if (!*abort) {
  882.         while (1) {
  883.           tcp_tick(NULL);
  884.           while (kbhit()) {
  885.             ch = (getch());
  886.             switch (ch) {
  887.               case 32:
  888.                 backline();
  889.                 output("\r ■ Skipping group... please wait until this message is completed [-]");
  890.                 *abort = 2;
  891.                 break;
  892.               case 27:
  893.                 backline();
  894.                 output("\r ■ Abort detected... please wait until this message is completed [-]");
  895.                 *abort = 1;
  896.                 break;
  897.               default:
  898.                 break;
  899.             }
  900.           }
  901.           sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  902.           sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
  903.           if (_big_temp_buffer[0] == '.' && _big_temp_buffer[1] == 0)
  904.             break;
  905.           else {
  906.             treat(_big_temp_buffer);
  907.             strcat(_big_temp_buffer, "\n");
  908.             curpos = strlen(_big_temp_buffer);
  909.             fputs(_big_temp_buffer, tpktfp);
  910.             msgsize += curpos;
  911.           }
  912.           if (count++ > 5) {
  913.             output("\b\b%c]", spin[place++]);
  914.             if (len)
  915.               place %= len;
  916.             count = 0;
  917.           }
  918.           if ((msgsize > 30000L) && (!spooltodisk)) {
  919.             strcpy(buf, "\nContinued in next message...\n");
  920.             fputs(buf, tpktfp);
  921.             if (tpktfp != NULL)
  922.               fclose(tpktfp);
  923.             sprintf(fn, "%sSPOOL\\INPUT%d.MSG", net_data, ++part);
  924.             if (stat(fn, &statbuf) == 0)
  925.               unlink(fn);
  926.             if ((tpktfp = fsh_open(fn, "wt+")) == NULL) {
  927.               fprintf(stderr, "\n ■ Unable to create temporary packet 3 %s", fn);
  928.               sock_wait_closed(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  929.               *abort = 3;
  930.               return 0;
  931.             }
  932.             backline();
  933.             output("\r ■ Breaking into %d%s part [ ]", (part), ordinal_text(part));
  934.             strcpy(buf, "\nContinued from previous message...\n");
  935.             fputs(buf, tpktfp);
  936.             msgsize = strlen(buf);
  937.           }
  938.         }
  939.         if (tpktfp != NULL)
  940.           fclose(tpktfp);
  941.         output("\b\bX]");
  942.         return 1;
  943.       }
  944.       return 1;
  945.     default:
  946.       output("\n ■ Unknown BODY error : %s", _temp_buffer);
  947.       break;
  948.   }
  949.  
  950.   SOCK_READ_ERR(NNTP);
  951.   return 0;
  952. }
  953.  
  954. int extract(char *to, char *key, char *from)
  955. {
  956.   if (!strnicmp(from, key, strlen(key))) {
  957.     from += strlen(key);
  958.     while (*from == ' ')
  959.       from++;
  960.     strcpy(to, from);
  961.     return 1;
  962.   } else
  963.     return 0;
  964. }
  965.  
  966.  
  967. int chead(Mail_Socket * NNTP_sock, unsigned long cur_article)
  968. {
  969.   char _big_temp_buffer[BIGSTR];
  970.  
  971.   *cur_path = 0;
  972.   *cur_from = 0;
  973.   *cur_replyto = 0;
  974.   *cur_subject = 0;
  975.   *cur_newsgroups = 0;
  976.   *cur_message_ID = 0;
  977.   *cur_references = 0;
  978.   *cur_date = 0;
  979.   *_temp_buffer = 0;
  980.  
  981.   sock_printf(NNTP_sock->sock, "HEAD %lu", cur_article);
  982.   sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  983.   sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
  984.   sscanf(_big_temp_buffer, "%hu %lu", &reply, &reparticle);
  985.   switch (reply) {
  986.     case 423:
  987.       output("Expired article.");
  988.       return 0;
  989.     case 221:
  990.       while (1) {
  991.         sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  992.         sock_gets(NNTP_sock->sock, _big_temp_buffer, sizeof(_big_temp_buffer));
  993.         if (_big_temp_buffer[0] == '.' && _big_temp_buffer[1] == 0) {
  994.           if (cur_replyto[0] == 0)
  995.             strcpy(cur_replyto, cur_from);
  996.           return 1;
  997.         }
  998.         if (strlen(_big_temp_buffer) > STRING)
  999.           _big_temp_buffer[STRING] = '\0';
  1000.         if (extract(cur_path, "Path:", _big_temp_buffer) ||
  1001.              extract(cur_from, "From:", _big_temp_buffer) ||
  1002.              extract(cur_subject, "Subject:", _big_temp_buffer) ||
  1003.              extract(cur_replyto, "Reply-To:", _big_temp_buffer) ||
  1004.              extract(cur_newsgroups, "Newsgroups:", _big_temp_buffer) ||
  1005.              extract(cur_organization, "Organization:", _big_temp_buffer) ||
  1006.              extract(cur_message_ID, "Message-ID:", _big_temp_buffer) ||
  1007.              extract(cur_references, "References:", _big_temp_buffer) ||
  1008.              extract(cur_lines, "Lines:", _big_temp_buffer) ||
  1009.              extract(cur_date, "Date:", _big_temp_buffer))
  1010.          continue;
  1011.       }
  1012.     default:
  1013.       log_it(0, "\n ■ Unknown chead error : %s", _big_temp_buffer);
  1014.       break;
  1015.   }
  1016.   SOCK_READ_ERR(NNTP);
  1017.   return 0;
  1018. }
  1019.  
  1020. Mail_Socket *netsocket(char *host)
  1021. {
  1022.   Mail_Socket *NNTP_sock = NULL;
  1023.   longword h;
  1024.  
  1025.   sock_init();
  1026.  
  1027.   if (!(h = resolve(host))) {
  1028.     if (!(h = resolve(host))) {
  1029.       output("\n ■ Error : Cannot resolve host %s", host);
  1030.       return NULL;
  1031.     }
  1032.   }
  1033.   if ((NNTP_sock = (Mail_Socket *) farmalloc(sizeof(Mail_Socket))) == NULL) {
  1034.     output("\n ■ Error: Insufficient memory to create socket... aborting.");
  1035.     return NULL;
  1036.   }
  1037.   if ((NNTP_sock->sock = (tcp_Socket *) farmalloc(sizeof(tcp_Socket))) == NULL) {
  1038.     output("\n ■ Error : Insufficient memory to create socket... aborting.");
  1039.     farfree(NNTP_sock);
  1040.     return NULL;
  1041.   }
  1042.   if (!tcp_open(NNTP_sock->sock, 0, h, NNTP_PORT, NULL)) {
  1043.     output("\n ■ Error : Unable to connect to to %s.", host);
  1044.     farfree(NNTP_sock);
  1045.     return NULL;
  1046.   }
  1047.   sock_mode(NNTP_sock->sock, TCP_MODE_ASCII);
  1048.   sock_wait_established(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1049.   sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1050.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1051.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1052.   switch (reply) {
  1053.     case 200:
  1054.       log_it(0, "\n ■ Connection to %s accepted...", host);
  1055.       return (NNTP_sock);
  1056.     case 502:
  1057.       output("\n ■ Connection to %s refused... try again later.", host);
  1058.       break;
  1059.     case 503:
  1060.       output("\n ■ NNTP service unavailable. Connection to %s refused.", host);
  1061.       break;
  1062.     default:
  1063.       output("\n ■ Unknown NNTP error. Connection to %s failed.", host);
  1064.       break;
  1065.   }
  1066.   SOCK_READ_ERR(NNTP);
  1067.   return 0;
  1068. }
  1069.  
  1070. int cnext(Mail_Socket * NNTP_sock)
  1071. {
  1072.   char *p, *q;
  1073.  
  1074.   *_temp_buffer = 0;
  1075.  
  1076.   sock_printf(NNTP_sock->sock, "NEXT");
  1077.   sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1078.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1079.   sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1080.   switch (reply) {
  1081.     case 421:
  1082.       return 0;
  1083.     case 223:
  1084.       p = _temp_buffer;
  1085.       q = cur_articleid;
  1086.       while ((p < _temp_buffer + STRING - 2) && (*p != '<'))
  1087.         p++;
  1088.       while ((p < _temp_buffer + STRING - 2) && (*p != '>'))
  1089.         *q++ = *p++;
  1090.       *q++ = '>';
  1091.       *q++ = '\0';
  1092.       return 1;
  1093.     default:
  1094.       log_it(0, "\n ■ Unknown cnext error : %s", _temp_buffer);
  1095.       break;
  1096.   }
  1097.   SOCK_READ_ERR(NNTP);
  1098.   return 0;
  1099. }
  1100.  
  1101. int cslave(Mail_Socket * NNTP_sock)
  1102. {
  1103.   char junk[STRING];
  1104.  
  1105.   *_temp_buffer = 0;
  1106.  
  1107.   sock_printf(NNTP_sock->sock, "SLAVE");
  1108.   sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1109.   sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1110.   sscanf(_temp_buffer, "%hu %s", &reply, &junk);
  1111.   SOCK_READ_ERR(NNTP);
  1112.   return 0;
  1113. }
  1114.  
  1115. char *stripspace(char *str)
  1116. {
  1117.   char *obuf, *nbuf;
  1118.  
  1119.   if (str) {
  1120.     for (obuf = str, nbuf = str; *obuf; ++obuf) {
  1121.       if (!isspace(*obuf))
  1122.         *nbuf++ = *obuf;
  1123.     }
  1124.     *nbuf = NULL;
  1125.   }
  1126.   return (str);
  1127. }
  1128.  
  1129.  
  1130. int saveactive(Mail_Socket * NNTP_sock, char *fn)
  1131. {
  1132.   char s[181], group[256], act;
  1133.   unsigned long to, from;
  1134.   int count, done;
  1135.   FILE *fp;
  1136.  
  1137.   *_temp_buffer = 0;
  1138.  
  1139.   if ((fp = fsh_open(fn, "w")) == NULL) {
  1140.     perror(fn);
  1141.     return 0;
  1142.   }
  1143.   done = 0;
  1144.  
  1145.   while (!done) {
  1146.     sock_printf(NNTP_sock->sock, "LIST");
  1147.     sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1148.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1149.     sscanf(_temp_buffer, "%hu %lu", &reply, &reparticle);
  1150.     if (reply == 215) {
  1151.       count = 0;
  1152.       while (1) {
  1153.         if (count++ % 25 == 0)
  1154.           output("\b\b\b\b\b\b\b%-7d", count);
  1155.         sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1156.         sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1157.         if (*_temp_buffer == '.' && _temp_buffer[1] == 0)
  1158.           break;
  1159.         sscanf(_temp_buffer, "%s %lu %lu %c", group, &to, &from, &act);
  1160.         sprintf(s, "%s %lu\n", group, to);
  1161.         fsh_write(s, sizeof(char), strlen(s), fp);
  1162.       }
  1163.       log_it(0, "\n ■ %d total newsgroups available on %s", count, serverhost);
  1164.       if (fp != NULL)
  1165.         fclose(fp);
  1166.       return 1;
  1167.     } else {
  1168.       if (reply == 480) {
  1169.         if (fp != NULL)
  1170.           fclose(fp);
  1171.         return 0;
  1172.       } else {
  1173.         log_it(0, "\n ■ Unknown saveactive error : %s", _temp_buffer);
  1174.         if (fp != NULL)
  1175.           fclose(fp);
  1176.         done = 1;
  1177.       }
  1178.     }
  1179.   }
  1180.   SOCK_READ_ERR(NNTP);
  1181.   return 0;
  1182. }
  1183.  
  1184. int checkx(int cug)
  1185. {
  1186.   char *ptr, *ptr2, *ptr3, buf[256];
  1187.   int i, max;
  1188.  
  1189.   sprintf(buf, "%s!%s", POPNAME, POPDOMAIN);
  1190.   if (_fstrstr(cur_path, buf) != 0) {
  1191.     log_it(0, "Local post \"%s\" skipped.", cur_subject);
  1192.     return 0;
  1193.   }
  1194.   if ((strlen(grouprec[cug].subtype) == 1) && (*grouprec[cug].subtype == '0'))
  1195.     return 1;
  1196.   ptr = cur_newsgroups;
  1197.  
  1198.   while (*ptr == ' ')
  1199.     ptr++;
  1200.   max = 0;
  1201.   while (1) {
  1202.     if (*ptr == 0)
  1203.       break;
  1204.     if (*ptr == ',') {
  1205.       ptr++;
  1206.       ++max;
  1207.     }
  1208.     while (*ptr == ' ')
  1209.       ptr++;
  1210.     ptr2 = ptr;
  1211.     ptr3 = buf;
  1212.     while (*ptr2 != 0 && *ptr2 != ',')
  1213.       *ptr3++ = *ptr2++;
  1214.     *ptr3 = 0;
  1215.     while (*(--ptr3) == ' ')
  1216.       *ptr3 = 0;
  1217.     ptr = ptr2;
  1218.     for (i = 0; i < cug; i++) {
  1219.       if (strcmpi(buf, grouprec[i].groupname) == 0) {
  1220.         output("Already posted in %s.", grouprec[i].groupname);
  1221.         return 0;
  1222.       }
  1223.     }
  1224.     if ((crossposts > 0) && (max > crossposts)) {
  1225.       output("Crossposted to more than %hu newsgroups.", crossposts);
  1226.       return 0;
  1227.     }
  1228.   }
  1229.   return 1;
  1230. }
  1231.  
  1232. int postnews(Mail_Socket * NNTP_sock, int cug)
  1233. {
  1234.   char s[181], s1[12], s2[5], fn[201], buf[STR], *ss;
  1235.   int f1, nlines, len, tlen;
  1236.   FILE *fp;
  1237.   struct ffblk ff;
  1238.  
  1239.   *_temp_buffer = 0;
  1240.  
  1241.   sprintf(fn, "%sOUTBOUND\\%s.*", net_data, grouprec[cug].subtype);
  1242.   f1 = findfirst(fn, &ff, 0);
  1243.   if (f1 != 0) {
  1244.     log_it(0, "\n ■ No outbound news articles to post...");
  1245.     return 1;
  1246.   }
  1247.   while (f1 == 0) {
  1248.     sock_printf(NNTP_sock->sock, "POST");
  1249.     sock_wait_input(NNTP_sock->sock, sock_delay, NULL, &NNTP_stat);
  1250.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1251.     if (*_temp_buffer != '3') {
  1252.       if (atoi(_temp_buffer) == 440)
  1253.         log_it(1, "\n ■ No posting allowed to %s!", grouprec[cug].groupname);
  1254.       else
  1255.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1256.       return 0;
  1257.     }
  1258.     output("\n ■ Posting article to %s\n", grouprec[cug].groupname);
  1259.     sprintf(s, "%sOUTBOUND\\%s", net_data, ff.ff_name);
  1260.     fp = fsh_open(s, "rb");
  1261.     nlines = 0;
  1262.     while (fgets(buf, 120, fp) != NULL) {
  1263.       if (*buf == '.' && buf[1] == 0) {
  1264.         buf[1] = '.';
  1265.         buf[2] = 0;
  1266.       }
  1267.       tlen = 0;
  1268.       len = strlen(buf);
  1269.       while (tlen < len) {
  1270.         if (!tcp_tick(NNTP_sock->sock)) {
  1271.           if (fp != NULL)
  1272.             fclose(fp);
  1273.           output("\n ■ Connection reset by host");
  1274.           return 1;
  1275.         }
  1276.         tlen += sock_fastwrite(NNTP_sock->sock, &buf[tlen], len - tlen);
  1277.       }
  1278.       backline();
  1279.       output("\r ■ Lines sent : %d", ++nlines);
  1280.     }
  1281.     if (fp != NULL)
  1282.       fclose(fp);
  1283.     sock_printf(NNTP_sock->sock, ".\n");
  1284.     output("\n ■ Awaiting acknowledgement - may take several minutes...");
  1285.     log_it(0, "\n ■ Server response : ");
  1286.     sock_wait_input(NNTP_sock->sock, 180, NULL, &NNTP_stat);
  1287.     sock_gets(NNTP_sock->sock, _temp_buffer, sizeof(_temp_buffer));
  1288.     log_it(0, "%s", _temp_buffer);
  1289.     if (*_temp_buffer != '2') {
  1290.       sscanf(_temp_buffer, "%hu %s", &reply, &buf);
  1291.       if (reply == 441) {
  1292.         ss = strtok(_temp_buffer, " ");
  1293.         ss = strtok(NULL, " ");
  1294.         if (atoi(ss) == 435)
  1295.           unlink(s);
  1296.         fnsplit(s, NULL, NULL, s1, s2);
  1297.         log_it(0, "\n ■ %s%s not accepted by server - nothing posted", s1, s2);
  1298.         if (unlink(s) == 0)
  1299.           log_it(0, "\n ■ Deleted message - %s", s);
  1300.       } else
  1301.         log_it(0, "\n ■ Remote error: %s", _temp_buffer);
  1302.     } else {
  1303.       if (unlink(s) == 0)
  1304.         log_it(0, "\n ■ Deleted sent message - %s", s);
  1305.     }
  1306.     f1 = findnext(&ff);
  1307.   }
  1308.   SOCK_READ_ERR(NNTP);
  1309.   return 0;
  1310. }
  1311.  
  1312. void get_subtype(int sub, char *where)
  1313. {
  1314.   int ok, which;
  1315.   char fn[181], s[81], net_name[21], *ss;
  1316.   FILE *fp;
  1317.  
  1318.   where[0] = 0;
  1319.   which = sub;
  1320.   sprintf(fn, "%sSUBS.XTR", syscfg.datadir);
  1321.   if ((fp = fsh_open(fn, "r")) == NULL)
  1322.     return;
  1323.   ok = 0;
  1324.   while (fgets(s, 80, fp)) {
  1325.     if (*s == '!') {
  1326.       if (which == atoi(&s[1]))
  1327.         ok = 1;
  1328.     }
  1329.     if (ok && (*s == '$')) {
  1330.       ss = strtok(s, " ");
  1331.       strcpy(net_name, &ss[1]);
  1332.       ss = strtok(NULL, " ");
  1333.       if (fp != NULL)
  1334.         fclose(fp);
  1335.       if ((stricmp(net_name, "FILENET") == 0)) {
  1336.         trimstr1(ss);
  1337.         strcpy(where, ss);
  1338.         return;
  1339.       } else
  1340.         return;
  1341.     }
  1342.   }
  1343.   if (fp != NULL)
  1344.     fclose(fp);
  1345. }
  1346.  
  1347. unsigned long max_on_sub(int cug)
  1348. {
  1349.   int i, num_subs;
  1350.   char fn[MAXPATH], subtype[12];
  1351.   unsigned long max;
  1352.   subboardrec sub;
  1353.   FILE *fp;
  1354.  
  1355.   max = 0;
  1356.   if ((strlen(grouprec[cug].subtype) == 1) && (*grouprec[cug].subtype == '0'))
  1357.     return max;
  1358.   output("\n ■ Maximum posts -     ");
  1359.   sprintf(fn, "%sSUBS.DAT", syscfg.datadir);
  1360.   if ((fp = fsh_open(fn, "rb")) == NULL) {
  1361.     output("\n ■ Unable to read %s.", fn);
  1362.     return max;
  1363.   } else {
  1364.     fseek(fp, 0L, SEEK_END);
  1365.     num_subs = (int) (ftell(fp) / sizeof(subboardrec));
  1366.     for (i = 0; i < num_subs; i++) {
  1367.       output("\b\b\b\b%-4d", i);
  1368.       fseek(fp, (long) i * sizeof(subboardrec), SEEK_SET);
  1369.       fread(&sub, sizeof(subboardrec), 1, fp);
  1370.       get_subtype(i, subtype);
  1371.       if (stricmp(subtype, grouprec[cug].subtype) == 0) {
  1372.         max = (unsigned long)sub.maxmsgs;
  1373.         output("\b\b\b\b%s (%s) - %lu posts.", sub.name, subtype, max);
  1374.         break;
  1375.       }
  1376.     }
  1377.   }
  1378.   if (fp != NULL)
  1379.     fclose(fp);
  1380.   return max;
  1381. }
  1382.  
  1383.  
  1384. int getnews(Mail_Socket * NNTP_sock)
  1385. {
  1386.   int f1, nup, nug, cug, abort, ok, done, firstrun, parts, result, bogus;
  1387.   char *p, fn[MAXPATH], mailname[121], reline[121], s[21], s1[21], pktname[121];
  1388.   char ch, orig_subj[STRING], buf[STR];
  1389.   unsigned int text_len;
  1390.   unsigned short temptype;
  1391.   unsigned long new_articles, max_articles;
  1392.   net_header_rec nh;
  1393.   struct stat statbuf;
  1394.   struct ffblk ff;
  1395.   FILE *fp;
  1396.  
  1397.   abort = cug = bogus = 0;
  1398.  
  1399.   if (stricmp(grouprec[0].groupname, "newsrc") == 0) {
  1400.     *grouprec[0].groupname = 0;
  1401.     write_groups(0);
  1402.     if (grouprec)
  1403.       farfree(grouprec);
  1404.     sprintf(fn, "%sNEWSRC", net_data);
  1405.     log_it(0, "\n ■ Creating newsgroup list : %s...         ", fn);
  1406.     if (!saveactive(NNTP_sock, fn)) {
  1407.       if (sendauthinfo(NNTP_sock))
  1408.         saveactive(NNTP_sock, fn);
  1409.     }
  1410.     return 0;
  1411.   }
  1412.   nug = nup = 1;
  1413.   cslave(NNTP_sock);
  1414.   while ((cug < ngroups) && (!abort)) {
  1415.     tcp_tick(NNTP_sock->sock);
  1416.     if (nup) {
  1417.       nup = 0;
  1418.       if (grouprec[cug].subtype) {
  1419.         if (fp != NULL)
  1420.           fclose(fp);
  1421.         name_packet(pktname);
  1422.         if ((fp = fsh_open(pktname, "wb")) == NULL) {
  1423.           log_it(0, "\n ■ Unable to create %s!", pktname);
  1424.           return 1;
  1425.         } else {
  1426.           fnsplit(pktname, NULL, NULL, s, s1);
  1427.           output("\n ■ Creating new packet : %s%s", s, s1);
  1428.         }
  1429.       } else {
  1430.         if (fp != NULL)
  1431.           fclose(fp);
  1432.       }
  1433.       write_groups(1);
  1434.     }
  1435.     if (nug) {
  1436.       nug = 0;
  1437.       while (1) {
  1438.         if (!cgroup(NNTP_sock, grouprec[cug].groupname)) {
  1439.           if (cgroup(NNTP_sock, grouprec[cug].groupname) == -1) {
  1440.             if (sendauthinfo(NNTP_sock))
  1441.               continue;
  1442.             else
  1443.               return 1;
  1444.           }
  1445.           if (++bogus > 10) {
  1446.             log_it(0, "\n ■ Too many invalid newsgroups... NEWS.RC error!");
  1447.             return 1;
  1448.           }
  1449.           log_it(1, "\n ■ Error accessing newsgroup \"%s\".", grouprec[cug].groupname);
  1450.           nug = 1;
  1451.           break;
  1452.         } else
  1453.           break;
  1454.       }
  1455.       if (!nug) {
  1456.         log_it(0, "\n ■ Requesting %s... ", grouprec[cug].groupname);
  1457.         if (grouprec[cug].lastread < cur_first)
  1458.           grouprec[cug].lastread = cur_first;
  1459.         if (grouprec[cug].lastread >= cur_last) {
  1460.           grouprec[cug].lastread = cur_last;
  1461.           log_it(0, "no new articles.");
  1462.           nug = 1;
  1463.           write_groups(0);
  1464.         } else {
  1465.           new_articles = cur_last - grouprec[cug].lastread;
  1466.           if (new_articles) {
  1467.             log_it(0, "%lu new article%s.", new_articles,
  1468.                    new_articles == 1 ? "" : "s");
  1469.           } else {
  1470.             log_it(0, "no new articles.");
  1471.             nug = 1;
  1472.             write_groups(0);
  1473.           }
  1474.           if (new_articles > 250L) {
  1475.             max_articles = max_on_sub(cug);
  1476.             if (max_articles && (new_articles > max_articles)) {
  1477.               log_it(0, "\n ■ Requesting most recent %lu articles", max_articles);
  1478.               grouprec[cug].lastread = cur_last - max_articles;
  1479.             }
  1480.           } else
  1481.             ++grouprec[cug].lastread;
  1482.         }
  1483.         postnews(NNTP_sock, cug);
  1484.         if (!nug) {
  1485.           if (cur_numa == 0) {
  1486.             log_it(0, "\n ■ No articles in %s...", grouprec[cug].groupname);
  1487.             nug = 1;
  1488.             continue;
  1489.           }
  1490.         }
  1491.       }
  1492.     } else {
  1493.       if ((!cnext(NNTP_sock)) || (grouprec[cug].lastread > cur_last)) {
  1494.         output("\n ■ End of articles in %s", grouprec[cug].groupname);
  1495.         nug = 1;
  1496.         write_groups(1);
  1497.       }
  1498.     }
  1499.     while (kbhit()) {
  1500.       ch = (getch());
  1501.       switch (ch) {
  1502.         case 27:
  1503.           log_it(0, "\n ■ Aborting news retrieval session...");
  1504.           if (fp != NULL)
  1505.             fclose(fp);
  1506.           nntp_shutdown(NNTP_sock);
  1507.           return 1;
  1508.         case 32:
  1509.           output("\n ■ Skipping group %s... ", grouprec[cug].groupname);
  1510.           write_groups(0);
  1511.           nug = 1;
  1512.           break;
  1513.         default:
  1514.           break;
  1515.       }
  1516.     }
  1517.     if (!nug) {
  1518.       output("\n ■ [%lu/%lu] : ", grouprec[cug].lastread, cur_last);
  1519.       if ((chead(NNTP_sock, grouprec[cug].lastread)) && (checkx(cug))) {
  1520.         if (*cur_subject)
  1521.           treat(cur_subject);
  1522.         else
  1523.           strcpy(cur_subject, "No subject");
  1524.         strcpy(orig_subj, cur_subject);
  1525.         if (*cur_from) {
  1526.           treat(cur_from);
  1527.           if (strlen(cur_from) > 45)
  1528.             cur_from[45] = 0;
  1529.         } else
  1530.           strcpy(cur_from, "Unknown");
  1531.         if (*cur_replyto) {
  1532.           if (strlen(cur_replyto) > 45)
  1533.             cur_replyto[45] = 0;
  1534.         } else
  1535.           strcpy(cur_replyto, "Unknown");
  1536.         output("%-55.55s", orig_subj);
  1537.         if ((strlen(grouprec[cug].subtype) == 1) && (grouprec[cug].subtype[0] == '0')) {
  1538.           spooltodisk = 1;
  1539.           sprintf(fn, "%sSPOOL\\NEWS%d.UUE", net_data, cug);
  1540.         } else {
  1541.           spooltodisk = 0;
  1542.           sprintf(fn, "%sSPOOL\\INPUT1.MSG", net_data);
  1543.           if (stat(fn, &statbuf) == 0)
  1544.             unlink(fn);
  1545.         }
  1546.         abort = 0;
  1547.         ok = (savebody(NNTP_sock, fn, cug, grouprec[cug].lastread, &abort));
  1548.         if (ok && grouprec[cug].subtype) {
  1549.           sprintf(fn, "%sSPOOL\\INPUT*.MSG", net_data);
  1550.           done = 1;
  1551.           parts = 0;
  1552.           if (findfirst(fn, &ff, 0) == 0) {
  1553.             parts = 1;
  1554.             done = 0;
  1555.           }
  1556.           firstrun = 1;
  1557.           while (!done) {
  1558.             sprintf(fn, "%sSPOOL\\%s", net_data, ff.ff_name);
  1559.             f1 = sh_open1(fn, O_RDONLY | O_BINARY);
  1560.             text_len = (unsigned int) filelength(f1);
  1561.             if (text_len > 32000L) {
  1562.               output("\n ■ Truncating %lu bytes from input file",
  1563.                      text_len - 32000L);
  1564.               text_len = 32000L;
  1565.             }
  1566.             if ((p = (char *) malloc(32767L)) == NULL) {
  1567.               log_it(0, "\n ■ Insufficient memory to read entire message");
  1568.               return 1;
  1569.             }
  1570.             sh_read(f1, (void *) p, text_len);
  1571.             sh_close(f1);
  1572.             temptype = atoi(grouprec[cug].subtype);
  1573.             nh.tosys = sy;
  1574.             nh.touser = 0;
  1575.             nh.fromsys = 32767;
  1576.             nh.fromuser = 0;
  1577.             if (!temptype) {
  1578.               nh.main_type = main_type_new_post;
  1579.               nh.minor_type = 0;
  1580.             } else {
  1581.               nh.main_type = main_type_pre_post;
  1582.               nh.minor_type = temptype;
  1583.             }
  1584.             nh.list_len = 0;
  1585.             ++cur_daten;
  1586.             nh.daten = cur_daten;
  1587.             nh.method = 0;
  1588.             if (parts > 1) {
  1589.               sprintf(buf, "%d%s ", parts, ordinal_text(parts));
  1590.               strncat(buf, orig_subj, 72);
  1591.               strcpy(cur_subject, buf);
  1592.               cur_subject[72] = '\0';
  1593.             }
  1594.             nh.length = text_len + strlen(cur_subject) + 1;
  1595.             strncpy(mailname, cur_replyto, 46);
  1596.             strcat(mailname, "\r\n");
  1597.             nh.length += strlen(mailname);
  1598.             if (nh.main_type == main_type_new_post)
  1599.               nh.length += strlen(grouprec[cug].subtype) + 1;
  1600.             if (firstrun) {
  1601.               firstrun = 0;
  1602.               if (strncmpi(cur_articleid, "re: ", 4) == 0) {
  1603.                 strncpy(reline, cur_articleid, 60);
  1604.                 sprintf(cur_articleid, "Re: %s\r\n\r\n", reline);
  1605.               }
  1606.             }
  1607.             if (!*cur_date) {
  1608.               strncpy(cur_date, ctime(&(time_t) nh.daten), 24);
  1609.               cur_date[24] = '\0';
  1610.             }
  1611.             strcat(cur_date, "\r\n");
  1612.             nh.length += strlen(cur_date);
  1613.             nh.length += strlen(cur_articleid);
  1614.             fsh_write(&nh, sizeof(net_header_rec), 1, fp);
  1615.             if (nh.main_type == main_type_new_post)
  1616.               fsh_write(grouprec[cug].subtype, sizeof(char), strlen(grouprec[cug].subtype) +1, fp);
  1617.             fsh_write(cur_subject, sizeof(char), strlen(cur_subject) +1, fp);
  1618.             fsh_write(mailname, sizeof(char), strlen(mailname), fp);
  1619.             fsh_write(cur_date, sizeof(char), strlen(cur_date), fp);
  1620.             fsh_write(cur_articleid, sizeof(char), strlen(cur_articleid), fp);
  1621.             fsh_write(p, sizeof(char), text_len, fp);
  1622.             if (p)
  1623.               free(p);
  1624.             unlink(fn);
  1625.             if (findnext(&ff) == 0) {
  1626.               done = 0;
  1627.               ++parts;
  1628.             } else
  1629.               done = 1;
  1630.           }
  1631.         }
  1632.       }
  1633.       ++grouprec[cug].lastread;
  1634.       if ((filelength(fileno(fp)) > 250000L) && grouprec[cug].subtype)
  1635.         nup = 1;
  1636.       if (abort == 2) {
  1637.         write_groups(1);
  1638.         nug = 1;
  1639.         abort = 0;
  1640.       }
  1641.       if (abort == 3) {
  1642.         output("\n ■ Disk error - exiting.");
  1643.         write_groups(1);
  1644.         return 1;
  1645.       }
  1646.     }
  1647.     if (nug) {
  1648.       ++cug;
  1649.       if (((strlen(grouprec[cug].subtype) == 1) &&
  1650.            (grouprec[cug].subtype[0] == '0')) && (grouprec[cug].subtype)) {
  1651.         nup = 1;
  1652.       } else {
  1653.         if (((strlen(grouprec[cug - 1].subtype)) > 1) &&
  1654.             ((strlen(grouprec[cug].subtype) == 1) &&
  1655.              (grouprec[cug].subtype[0] == '0'))) {
  1656.           if (fp != NULL)
  1657.             fclose(fp);
  1658.         }
  1659.       }
  1660.     }
  1661.   }
  1662.   if (fp != NULL)
  1663.     fclose(fp);
  1664.   write_groups(1);
  1665.   nntp_shutdown(NNTP_sock);
  1666.   if (abort)
  1667.     log_it(0, "\n ■ Session aborted from keyboard");
  1668.   return 0;
  1669. }
  1670.  
  1671. int copyfile(char *input, char *output)
  1672. {
  1673.   int f1, f2, i;
  1674.   char *b;
  1675.   struct ftime ft;
  1676.  
  1677.   if ((strcmp(input, output) != 0) && (exist(input)) && (!exist(output))) {
  1678.     if ((b = (char *) malloc(16400)) == NULL)
  1679.       return 0;
  1680.     f1 = sh_open1(input, O_RDONLY | O_BINARY);
  1681.     if (!f1) {
  1682.       free(b);
  1683.       b = NULL;
  1684.       return 0;
  1685.     }
  1686.     getftime(f1, &ft);
  1687.  
  1688.     f2 = sh_open(output, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  1689.     if (!f2) {
  1690.       free(b);
  1691.       b = NULL;
  1692.       f1 = sh_close(f1);
  1693.       return 0;
  1694.     }
  1695.     i = read(f1, (void *) b, 16384);
  1696.     while (i > 0) {
  1697.       sh_write(f2, (void *) b, i);
  1698.       i = read(f1, (void *) b, 16384);
  1699.     }
  1700.     f1 = sh_close(f1);
  1701.     setftime(f2, &ft);
  1702.     f2 = sh_close(f2);
  1703.     free(b);
  1704.     b = NULL;
  1705.   }
  1706.   return 1;
  1707. }
  1708.  
  1709.  
  1710.  
  1711. main(int argc, char *argv[])
  1712. {
  1713.   int ok, f, bAuth;
  1714.   char s[160], fn[MAXPATH], tempfn[MAXPATH], *ss;
  1715.   FILE *fp;
  1716.   struct tm *time_now;
  1717.   struct date dt;
  1718.   struct time tm;
  1719.   time_t some;
  1720.   Mail_Socket *nntp_sock = NULL;
  1721.  
  1722.   crossposts = 10;
  1723.   POPNAME[0] = 0;
  1724.   POPDOMAIN[0] = 0;
  1725.  
  1726.   cursor('S');
  1727.   cursor('H');
  1728.   output("\n ■ %s", version);
  1729.   if (argc != 4) {
  1730.     output("\n ■ Invalid arguments for %s\n", argv[0]);
  1731.     cursor('R');
  1732.     return EXIT_FAILURE;
  1733.   }
  1734.   strcpy(net_data, argv[1]);
  1735.   strcat(net_data, "\\");
  1736.   strcpy(serverhost, argv[2]);
  1737.   sy = atoi(argv[3]);
  1738.  
  1739.   get_dir(maindir, 0);
  1740.  
  1741.   detect_multitask();
  1742.  
  1743.   gettime(&tm);
  1744.   getdate(&dt);
  1745.   cur_daten = dostounix(&dt, &tm);
  1746.   time(&some);
  1747.   time_now = localtime(&some);
  1748.   strftime(s, 80, "\n\nNEWS session beginning on %A, %B %d, %Y at %H:%M %p",
  1749.            time_now);
  1750.   sprintf(fn, "%sNEWS.LOG", net_data);
  1751.   if ((fp = fsh_open(fn, "at")) != NULL) {
  1752.     fprintf(fp, s);
  1753.     fclose(fp);
  1754.   }
  1755.   ss = getenv("WWIV_INSTANCE");
  1756.   if (ss) {
  1757.     instance = atoi(ss);
  1758.     if ((instance <= 0) || (instance >= 1000)) {
  1759.       log_it(0, "\n ■ WWIV_INSTANCE set to %d.  Can only be 1..999!", instance);
  1760.       instance = 1;
  1761.     }
  1762.   } else
  1763.     instance = 1;
  1764.  
  1765.   sprintf(fn, "%s\\CONFIG.DAT", maindir);
  1766.   f = sh_open1(fn, O_RDONLY | O_BINARY);
  1767.   if (f < 0) {
  1768.     output("\n ■ %s NOT FOUND.", fn);
  1769.     return EXIT_FAILURE;
  1770.   }
  1771.   sh_read(f, (void *) (&syscfg), sizeof(configrec));
  1772.   sh_close(f);
  1773.  
  1774.   read_groups();
  1775.   if (ngroups == 0) {
  1776.     output("\n ■ Unable to access newsgroup file NEWS.RC!");
  1777.     return EXIT_FAILURE;
  1778.   } else {
  1779.     sprintf(fn, "%sNEWS.RC", net_data);
  1780.     sprintf(tempfn, "%sNEWS.BAK", net_data);
  1781.     if (exist(tempfn))
  1782.       unlink(tempfn);
  1783.     copyfile(fn, tempfn);
  1784.   }
  1785.  
  1786.   if (stricmp(grouprec[0].groupname, "newsrc") == 0)
  1787.     log_it(0, "\n ■ Retrieving current newsgroup listing from %s.",
  1788.            serverhost);
  1789.   else
  1790.     log_it(0, "\n ■ %u newsgroup%s defined in NEWS.RC.", ngroups,
  1791.            ngroups == 1 ? "" : "s");
  1792.  
  1793.   sprintf(fn, "%s\\NET.INI", maindir);
  1794.   if ((fp = fsh_open(fn, "rt")) == NULL)
  1795.     output("\n ■ Unable to read %s", fn);
  1796.   else {
  1797.     while (fgets(s, 100, fp)) {
  1798.       stripspace(s);
  1799.       if ((*s == ';') || (*s == '\n') || (*s == '['))
  1800.         continue;
  1801.       if (strlen(s) == 0)
  1802.         continue;
  1803.       if ((strnicmp(s, "POPNAME", 7) == 0) && (POPNAME[0] == 0)) {
  1804.         ss = strtok(s, "=");
  1805.         if (ss) {
  1806.           ss = strtok(NULL, "\n");
  1807.           trimstr1(ss);
  1808.           strcpy(POPNAME, ss);
  1809.         }
  1810.       }
  1811.       if (strnicmp(s, "FWDNAME", 7) == 0) {
  1812.         ss = strtok(s, "=");
  1813.         if (ss) {
  1814.           ss = strtok(NULL, "\n");
  1815.           trimstr1(ss);
  1816.           strcpy(POPNAME, ss);
  1817.         }
  1818.       }
  1819.       if ((strnicmp(s, "DOMAIN", 6) == 0) && (POPDOMAIN[0] == 0)) {
  1820.         ss = strtok(s, "=");
  1821.         if (ss) {
  1822.           ss = strtok(NULL, "\n");
  1823.           trimstr1(ss);
  1824.           strcpy(POPDOMAIN, ss);
  1825.         }
  1826.       }
  1827.       if (strnicmp(s, "FWDDOM", 6) == 0) {
  1828.         ss = strtok(s, "=");
  1829.         if (ss) {
  1830.           ss = strtok(NULL, "\n");
  1831.           trimstr1(ss);
  1832.           strcpy(POPDOMAIN, ss);
  1833.         }
  1834.       }
  1835.       if (strnicmp(s, "XPOSTS", 6) == 0) {
  1836.         ss = strtok(s, "=");
  1837.         if (ss) {
  1838.           ss = strtok(NULL, "\n");
  1839.           trimstr1(ss);
  1840.           crossposts = atoi(ss);
  1841.           if (crossposts > 99)
  1842.             crossposts = 10;
  1843.         }
  1844.       }
  1845.       if (strnicmp(s, "NEWSNAME", 8) == 0) {
  1846.         ss = strtok(s, "=");
  1847.         if (ss) {
  1848.           ss = strtok(NULL, "\n");
  1849.           trimstr1(ss);
  1850.           strcpy(NEWSNAME, ss);
  1851.         }
  1852.       }
  1853.       if (strnicmp(s, "NEWSPASS", 8) == 0) {
  1854.         ss = strtok(s, "=");
  1855.         if (ss) {
  1856.           ss = strtok(NULL, "\n");
  1857.           trimstr1(ss);
  1858.           strcpy(NEWSPASS, ss);
  1859.         }
  1860.       }
  1861.       ss = NULL;
  1862.     }
  1863.     if (fp != NULL)
  1864.       fclose(fp);
  1865.   }
  1866.   ok = 1;
  1867.   if ((nntp_sock = netsocket(serverhost)) != NULL) {
  1868.     bAuth = 1;
  1869.     if (NEWSNAME[0]) {
  1870.       if (!sendauthinfo(nntp_sock))
  1871.         bAuth = 0;
  1872.     }
  1873.     if (bAuth)
  1874.       ok = getnews(nntp_sock);
  1875.     if (ok)
  1876.       log_it(1, "\n ■ NEWS exited with an error.");
  1877.     else
  1878.       log_it(0, "\n ■ Normal NEWS completion.");
  1879.   }
  1880.   cd_to(maindir);
  1881.   log_it(0, "\n ■ NEWS completed processing %d newsgroups", ngroups);
  1882.   if (grouprec)
  1883.     farfree(grouprec);
  1884.   grouprec = NULL;
  1885.   check_packets();
  1886.   trim_log();
  1887.   free_Mail_Socket(nntp_sock);
  1888.   fcloseall();
  1889.   cursor('R');
  1890.   return ok;
  1891. }
  1892.