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

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