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

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