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