C
C  BULLETIN10.FOR, Version 4/26/91
C  Purpose: Bulletin board utility program.
C  Environment: VAX/VMS
C  Usage: Invoked by the BULLETIN command.
C  Programmer: Mark R. London
C
C  Copyright (c) 1990
C  Property of Massachusetts Institute of Technology, Cambridge MA 02139.
C  This program cannot be copied or distributed in any form for non-MIT
C  use without specific written approval of MIT Plasma Fusion Center
C  Management.
C
	INTEGER FUNCTION NEWS_READ()
 
	IMPLICIT INTEGER (A-Z)
 
	COMMON /BUFFER/ BUFFER,SB,EB
	CHARACTER BUFFER*1280
 
	PARAMETER CR = CHAR(13), LF = CHAR(10)
 
	COMMON /NEWS_INIT/ END_READ
 
	NEWS_READ = 1
 
	IF (END_READ.EQ.0) THEN
	   IER = NEWS_READ_PACKET(BUFFER(:1024))
	   IF (IER.LE.0) THEN
	      CALL NEWS_LOGOUT
	      NEWS_READ = 0
	      RETURN
	   END IF
	   START_READ = 1
	   END_READ = IER
	END IF
 
	IF (END_READ.EQ.0) THEN
	   NEWS_READ = 0
	   RETURN
	END IF
 
	DO WHILE (1)
	   END_LINE = INDEX(BUFFER(START_READ:END_READ),LF)
	   IF (END_LINE.GT.0) THEN
	      SB = START_READ
	      IF (END_LINE-2.LE.255) THEN
	         END_LINE = END_LINE + SB - 1
	         EB = END_LINE - 2
	      ELSE
		 EB = SB + 254
		 IF (INDEX(BUFFER(SB:EB),' ').GT.0) THEN
		    DO WHILE (BUFFER(EB:EB).NE.' ')
		       EB = EB - 1
		    END DO
		 END IF
		 END_LINE = EB
	      END IF
	      IF (END_LINE.LT.END_READ) THEN
	         START_READ = END_LINE + 1
	      ELSE
	         END_READ = 0
	      END IF
	      RETURN
	   ELSE IF (END_READ-START_READ.EQ.1023) THEN
	      NEWS_READ = 0
	      RETURN
	   ELSE
	      BUFFER = BUFFER(START_READ:END_READ)
	      END_READ = END_READ - START_READ + 1
	      IER = NEWS_READ_PACKET(BUFFER(END_READ+1:END_READ+1024))
	      IF (IER.LE.0) THEN
	         NEWS_READ = 0
	         RETURN
	      ELSE
	         START_READ = 1
		 END_READ = END_READ + IER
	      END IF
	   END IF
	END DO
 
	RETURN
	END
 
 
 
 
	INTEGER FUNCTION NEWS_WRITE(WRITE)
 
	IMPLICIT INTEGER (A-Z)
 
	PARAMETER CR = CHAR(13), LF = CHAR(10)
 
	COMMON /NEWS_INIT/ END_READ
 
	CHARACTER*(*) WRITE
 
	LOGICAL TRY_RECONNECT/.FALSE./
 
	END_READ = 0
 
	IF (WRITE.EQ.' ') THEN
	   NEWS_WRITE = NEWS_WRITE_PACKET(CR//LF)
	ELSE
	   NEWS_WRITE = NEWS_WRITE_PACKET(WRITE//CR//LF)
	END IF
 
	IF (.NOT.NEWS_WRITE.AND..NOT.TRY_RECONNECT) THEN
	   TRY_RECONNECT = .TRUE.
	   CALL NEWS_RECONNECT(WRITE)
	   TRY_RECONNECT = .FALSE.
	END IF
 
	RETURN
	END
 
 
 
 
	SUBROUTINE NEWS_RECONNECT(WRITE)
 
	IMPLICIT INTEGER (A-Z)
 
	INCLUDE 'BULLFOLDER.INC'
 
	COMMON /POINT/ BULL_POINT
 
	CHARACTER*(*) WRITE
 
	CHARACTER*6 NUMBER
 
	CHARACTER*(FOLDER_RECORD) FOLDER2_COM
 
	CALL NEWS_LOGOUT
 
        IF (.NOT.NEWS_LOGIN()) RETURN
	
	IF (FOLDER(:1).GE.'a'.AND.FOLDER(:1).LE.'z') THEN
	   FOLDER2_COM = FOLDER1_COM
	   FOLDER1 = FOLDER
	   FOLDER1_DESCRIP = FOLDER_DESCRIP
	   CALL NEWS_GROUP(IER)
	   IF (IER.NE.0) RETURN
	   FOLDER1_COM = FOLDER2_COM
 
	   IF (.NOT.OTS$CVT_L_TI(BULL_POINT+1,NUMBER,,,)) RETURN
	   IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURN
           IF (.NOT.NEWS_READ()) RETURN
	END IF
	
	IF (.NOT.NEWS_WRITE(WRITE)) RETURN
 
	RETURN
	END
 
 
 
	SUBROUTINE NEWS_LOGOUT
 
        IMPLICIT INTEGER (A-Z)
 
	COMMON /NEWS_CONNECTED/ NEWS_CONNECTED
 
	CALL NEWS_DISCONNECT
	NEWS_CONNECTED = .FALSE.
	
	RETURN
	END
 
 
 
	SUBROUTINE REMOTE_DELETE(SBULL,IMMEDIATE,SUBJ,I,FOLDER1_COM,IER)
 
	IMPLICIT INTEGER (A-Z)
 
	INCLUDE 'BULLDIR.INC'
 
	INCLUDE 'BULLUSER.INC'
 
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 
	COMMON /PATH/ PATHNAME,LPATH
	CHARACTER*132 PATHNAME
 
	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*255 MESSAGE_ID
 
	CHARACTER*12 HIGHFROM
 
	CHARACTER*(*) SUBJ,FOLDER1_COM
 
	IF (REMOTE_SET.EQ.1) THEN
	   WRITE(REMOTE_UNIT,'(4A)',IOSTAT=IER)
     &			 4,SBULL,IMMEDIATE,SUBJ
	   IF (IER.EQ.0) THEN
	      READ(REMOTE_UNIT,'(Q,A)',IOSTAT=IER) I,FOLDER1_COM
	   END IF
	ELSE IF (REMOTE_SET.EQ.3) THEN
	   CALL STR$UPCASE(HIGHFROM,FROM)
	   IF (LPATH.EQ.0) CALL GET_PATHNAME
	   IF (HIGHFROM.EQ.USERNAME.AND.MESSAGE_ID(INDEX(MESSAGE_ID,'@')+1:
     &		TRIM(MESSAGE_ID)-1).EQ.PATHNAME(:INDEX(PATHNAME,'!')-1))
     &		THEN
	      CALL NEWS_POST('cancel',0,IER,'Delete news item.')
	   ELSE
	      WRITE (6,'('' ERROR: Not owner of message.'')')
	   END IF
	   IER = 0
	END IF
 
	RETURN
	END
 
 
 
 
	SUBROUTINE REMOTE_DIRECTORY_COMMAND(START,END,REVERSE,ALL_DIR,IER)
 
	IMPLICIT INTEGER (A-Z)
 
	INCLUDE 'BULLDIR.INC'
 
	INCLUDE 'BULLFOLDER.INC'
 
	COMMON /BUFFER/ BUFFER,SB,EB
	CHARACTER BUFFER*1280
 
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 
        COMMON /XHDR/ XHDR
        LOGICAL XHDR /.FALSE./
 
	COMMON /POINT/ BULL_POINT
 
	CHARACTER*6 NUMBER,NUMBER1
 
	CHARACTER*1024 TEMP
 
	DATA QXHDR1 /0/
 
	IF (XHDR) THEN
	   IF (QXHDR1.NE.0) THEN		! Is queue empty?
	      QXHDR = QXHDR1		! No, set queue pointer to head
	   ELSE				! Else if queue is empty
	      CALL INIT_QUEUE(QXHDR,TEMP)
	      QXHDR1 = QXHDR		! Init header pointer
	   END IF
	END IF
 
	SYSTEM = 0
 
	IF (REMOTE_SET.EQ.1) THEN
	   IF (REVERSE) THEN
	      WRITE(REMOTE_UNIT,'(3A)',IOSTAT=IER) 13,END,START
	   ELSE
	      WRITE(REMOTE_UNIT,'(3A)',IOSTAT=IER) 13,START,END
	   END IF
	ELSE
	   IER = 2
	   NUMDIR = END - START + 1
	   IF (START.LT.F_START) THEN
	      START = F_START
	      END = START + NUMDIR - 1 
	   END IF
	END IF
 
	IF (REMOTE_SET.EQ.3.AND.XHDR) THEN
	   IF (.NOT.OTS$CVT_L_TI(START,NUMBER,,,)) RETURN
	   IF (.NOT.OTS$CVT_L_TI(END,NUMBER1,,,)) RETURN
	   DO WHILE (NUMBER1(1:1).EQ.' ')
	      NUMBER1 = NUMBER1(2:)
	   END DO
	   NUMDIR1 = 0
	   DO WHILE (NUMDIR1.LT.NUMDIR)
              IF (.NOT.NEWS_WRITE('XHDR DATE '//NUMBER//'-'//NUMBER1)) 
     &								RETURN
	      IF (.NOT.NEWS_READ()) RETURN
	      IF (BUFFER(:2).NE.'22') THEN
		 IF (NUMDIR1.EQ.0) THEN
	            IER = 0
	            END = START - 1
	            RETURN
	         ELSE
		    NUMDIR = NUMDIR1
		 END IF
	      ELSE
		 IF (.NOT.NEWS_READ()) RETURN
		 IF (NUMDIR1.EQ.0.AND.BUFFER(SB:EB).NE.'.'.AND..NOT.
     &		    OTS$CVT_TI_L(BUFFER(SB:INDEX(BUFFER(SB:EB),' ')+SB-2)
     &		    ,START,,%VAL(1))) RETURN
	         DO WHILE (BUFFER(SB:EB).NE.'.')
		    IF (NUMDIR1.LT.NUMDIR) THEN
	               NUMDIR1 = NUMDIR1 + 1
		       TEMP = BUFFER(SB:EB)
	               CALL WRITE_QUEUE(%VAL(QXHDR),QXHDR,TEMP)
	            END IF
		    IF (.NOT.NEWS_READ()) RETURN
	         END DO
		 IF (NUMDIR1.EQ.0) THEN
		    IF (START.LE.F_START) RETURN
		    START = MAX(F_START,START-NUMDIR)
		    END = START + NUMDIR - 1
		    IF (.NOT.OTS$CVT_L_TI(START,NUMBER,,,)) RETURN
		    IF (.NOT.OTS$CVT_L_TI(END,NUMBER1,,,)) RETURN
		    DO WHILE (NUMBER1(1:1).EQ.' ')
		       NUMBER1 = NUMBER1(2:)
	 	    END DO
	         ELSE IF (NUMDIR1.LT.NUMDIR) THEN
		    IF (.NOT.NEWS_WRITE('STAT '//TEMP(:INDEX(TEMP,' ')-1)))
     &								 RETURN
		    IF (.NOT.NEWS_READ()) RETURN
		    IF (.NOT.NEWS_WRITE('NEXT')) RETURN
		    IF (.NOT.NEWS_READ()) RETURN
	            IF (BUFFER(:2).NE.'22') THEN
	               NUMDIR = NUMDIR1
		    ELSE
		       NUMBER = BUFFER(SB+4:INDEX(BUFFER(SB+4:),' ')+SB+2)
                       IF (.NOT.OTS$CVT_TI_L(NUMBER,
     &						MSG_NUM,,%VAL(1))) RETURN
		       DO WHILE (NUMBER(LEN(NUMBER):).EQ.' ')
		          NUMBER = ' '//NUMBER(1:)
		       END DO
		       MSG_NUM = MSG_NUM + (NUMDIR - NUMDIR1) - 1
		       IF (.NOT.OTS$CVT_L_TI(MSG_NUM,NUMBER1,,,)) RETURN
		       DO WHILE (NUMBER1(1:1).EQ.' ')
		          NUMBER1 = NUMBER1(2:)
		       END DO
	            END IF
	         END IF
	      END IF
	   END DO
	   CALL OTS$CVT_L_TI(START,NUMBER,,,)
	   NUMBER1 = TEMP(:INDEX(TEMP,' ')-1)
	   END = START + NUMDIR - 1
	   DO I=1,2
	      IF (I.EQ.1.AND..NOT.NEWS_WRITE
     &		('XHDR SUBJECT '//NUMBER//'-'//NUMBER1)) RETURN
	      IF (I.EQ.2.AND..NOT.NEWS_WRITEr
     &		('XHDR FROM '//NUMBER//'-'//NUMBER1)) RETURN
	      IF (.NOT.NEWS_READ()) RETURNM
	      IF (BUFFER(:2).EQ.'22') THEN1
	         QXHDR = QXHDR1
		 IF (.NOT.NEWS_READ()) RETURN 
		 NUMDIR1 = 0
	         DO WHILE (BUFFER(SB:EB).NE.'.'.AND.NUMDIR1.LT.NUMDIR) 
		    NUMDIR1 = NUMDIR1 + 1s
	            CALL READ_QUEUE(%VAL(QXHDR),DUMMY,TEMP)
		    DO J=SB+INDEX(BUFFER(SB:EB),' '),EBR
		       IF (ICHAR(BUFFER(J:J)).LT.32) BUFFER(J:J) = ' '
		    END DO
		    TEMP(I*256+1:) = BUFFER(SB+INDEX(BUFFER(SB:EB),' '):EB)A
	            CALL WRITE_QUEUE(%VAL(QXHDR),QXHDR,TEMP)D
		    IF (.NOT.NEWS_READ()) RETURN
		 END DOE
	      END IFB
	   END DO
	   QXHDR = QXHDR1
	   IER = 0 
	ELSE IF (REMOTE_SET.EQ.3.AND..NOT.XHDR) THEN 
	   IF (.NOT.OTS$CVT_L_TI(START,NUMBER,,,)) RETURN
	   IF (.NOT.NEWS_WRITE('HEAD '//NUMBER)) RETURN
	   IF (.NOT.NEWS_READ()) RETURN
	   IF (BUFFER(:2).NE.'22') THEN
	      IF (.NOT.NEWS_WRITE('NEXT')) RETURN
	      IF (.NOT.NEWS_READ()) RETURN 
              IF (.NOT.OTS$CVT_TI_L(BUFFER(SB+4:
     &		  INDEX(BUFFER(SB+4:),' ')+SB+2),I,,%VAL(1))) RETURN
	      IF (BUFFER(:2).NE.'22'.OR.I.LT.START) THEN 
		 BUFFER(:3) = '500''
		 DO WHILE (START.LE.F_NBULL.AND.BUFFER(:2).NE.'22')	
		    START = START + 1 
		    IF (.NOT.OTS$CVT_L_TI(START,NUMBER,,,)) RETURN
		    IF (.NOT.NEWS_WRITE('HEAD '//NUMBER)) RETURN
		    IF (.NOT.NEWS_READ()) RETURN
		 END DO 
	         IF (BUFFER(:2).NE.'22') THEN
		    IER = 0E
		    END = START - 1D
		    RETURN
	         END IF
	      END IFT
	      IF (.NOT.NEWS_WRITE('HEAD')) RETURN
	      IF (.NOT.NEWS_READ()) RETURNN
              IER = OTS$CVT_TI_L(BUFFER(SB+4:D
     &			INDEX(BUFFER(SB+4:),' ')+SB+2),START,,%VAL(1))R
	      END = START + NUMDIR - 1 
	   END IF
	   IER = 0 
	END IF
  
	IF (IER.EQ.0) THEN1
	   I = START 
	   DO WHILE (IER.EQ.0.AND.I.LE.END)
	      IF (REMOTE_SET.EQ.1) THEN
	         READ(REMOTE_UNIT,'(A)',IOSTAT=IER) BULLDIR_ENTRY
	      ELSE IF (XHDR) THEN
		 CALL READ_QUEUE(%VAL(QXHDR),QXHDR,TEMP)
		 LTEMP = INDEX(TEMP,' ')
	         CALL OTS$CVT_TI_L(TEMP(:LTEMP-1),MSG_NUM,,%VAL(1))
		 CALL NEWS_TIME(TEMP(LTEMP+1:TRIM(TEMP(:256))),MSG_BTIM)
		 DESCRIP = TEMP(257:512)
		 CALL GET_FROM(TEMP(512:768),TRIM(TEMP(512:768)))K
	      ELSE/
	         IER = OTS$CVT_TI_L(BUFFER(SB+4:D
     &			INDEX(BUFFER(SB+4:),' ')+SB+2),MSG_NUM,,%VAL(1)) 
		 CALL NEWS_HEADER(IER)
		 IF (IER.NE.0) RETURNL
	      END IF
	      CALL WRITE_QUEUE(%VAL(ALL_DIR),ALL_DIR,BULLDIR_ENTRY)
	      I = I + 1
	      IF (REMOTE_SET.EQ.3.AND..NOT.XHDR.AND.I.LE.END) THENM
		 IER = 2
	         IF (.NOT.NEWS_WRITE('NEXT')) RETURNA
		 IF (.NOT.NEWS_READ()) RETURNO
	         IF (BUFFER(:3).NE.'223') THENL
		    END = I - 1 
		    IER = 0O
		    RETURN
		 END IFF
	         IF (.NOT.NEWS_WRITE('HEAD')) RETURN 
		 IF (.NOT.NEWS_READ()) RETURN 
		 IER = 0
	      END IFR
	   END DO
	END IFS
 P
	IF (REMOTE_SET.EQ.3) THEN
	   IER = 1E
	   IF (.NOT.OTS$CVT_L_TI(BULL_POINT,NUMBER,,,)) RETURNN
	   IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURN
           IF (.NOT.NEWS_READ()) RETURN 
	   IER = 0 
	END IF.
 .
	RETURN(
	END
 
 E
 I
	INTEGER FUNCTION NEWS_LOGIN
 E
	IMPLICIT INTEGER (A-Z)
 D
	COMMON /NEWS_CONNECTED/ NEWS_CONNECTED
	LOGICAL NEWS_CONNECTED /.FALSE./
 C
        COMMON /XHDR/ XHDR
        LOGICAL XHDR /.FALSE./
 C
	COMMON /BUFFER/ BUFFER,SB,EB
	CHARACTER BUFFER*1280
 
        IF (.NOT.NEWS_CONNECTED) THENE
	   NEWS_LOGIN = .FALSE.
           NEWS_CONNECTED = NEWS_CONNECT()
           IF (.NOT.NEWS_CONNECTED) RETURN
           IF (.NOT.NEWS_READ()) RETURNS
           IF (.NOT.NEWS_WRITE('XHDR')) RETURN
           IF (.NOT.NEWS_READ()) RETURN 
	   XHDR = BUFFER(:3).NE.'500'
	END IFE
 
	NEWS_LOGIN = .TRUE.
 R
	RETURNC
	END
 (
 S
 ,
 D
	SUBROUTINE NEWS_HEADER(IER)
 1
	IMPLICIT INTEGER (A-Z)U
 ,
	INCLUDE 'BULLDIR.INC'
 	
	COMMON /BUFFER/ BUFFER,SB,EBF
	CHARACTER BUFFER*1280
 A
	EX_BTIM(1) = 0,
	EX_BTIM(2) = 0,
 D
	DESCRIP = ' '
	FROM = ' 'F
 E
	DO WHILE (BUFFER(SB:EB).NE.'.')
	   IER = NEWS_READ()
	   IF (.NOT.IER) RETURN
	   IF (BUFFER(SB:EB).NE.'.') THEN
	      IF (BUFFER(SB:SB+7).EQ.'Subject:'.AND.EB.GE.SB+9) THENS
		 DO I=SB+9,EBT
		    IF (ICHAR(BUFFER(I:I)).LT.32) BUFFER(I:I) = ' 'L
		 END DO(
		 DESCRIP = BUFFER(SB+9:EB)
	      ELSE IF (BUFFER(SB:SB+4).EQ.'Date:'.AND.EB.GE.SB+6) THENe
		 CALL NEWS_TIME(BUFFER(SB+6:EB),MSG_BTIM)
	      ELSE IF (BUFFER(SB:SB+7).EQ.'Expires:'.AND.EB.GE.SB+9) THEN
		 CALL NEWS_TIME(BUFFER(SB+9:EB),EX_BTIM)
	      ELSE IF (BUFFER(SB:SB+4).EQ.'From:'.AND.EB.GE.SB+6) THENU
		 CALL GET_FROM(BUFFER(SB+6:EB),EB-SB+1),
	      END IFT
	   END IF
	END DOC
 O
	IER = 0
 D
	RETURNE
	END
 T
 N
 
 
	SUBROUTINE REMOTE_READ_MESSAGE(BULL_SEARCH,IER)
 L
	IMPLICIT INTEGER (A-Z) 
 L
	INCLUDE 'BULLFOLDER.INC'M
 ,
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 1
	COMMON /BUFFER/ BUFFER,SB,EB 
	CHARACTER BUFFER*1280
  
	CHARACTER*6 NUMBERQ
 R
	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 5,BULL_SEARCH 
	ELSE 
	   IER = 2H
	   IF (BULL_SEARCH.LT.F_START) BULL_SEARCH = F_START
	   IF (.NOT.OTS$CVT_L_TI(BULL_SEARCH,NUMBER,,,)) RETURN
	   IF (.NOT.NEWS_WRITE('HEAD '//NUMBER)) RETURN
	   IF (.NOT.NEWS_READ()) RETURN
	   IF (BUFFER(:2).NE.'22') RETURN
	   IER = 03
	END IFT
 R
	RETURNT
	END
  
  
 
	SUBROUTINE REMOTE_GET_NEWEST_MSG(IN_BTIM,START)
  
	IMPLICIT INTEGER (A-Z)H
 
	INCLUDE 'BULLFOLDER.INC' 
 E
	INCLUDE 'BULLUSER.INC'
  
	COMMON /READIT/ READIT 
 M
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 L
	COMMON /BUFFER/ BUFFER,SB,EB 
	CHARACTER BUFFER*1280
 ,
	DIMENSION IN_BTIM(2) 
 O
	CHARACTER TIME*20,FIRST*80
  
	CHARACTER*6 NUMBER2
 
	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(3A)',IOSTAT=IER) 12,IN_BTIM(1),IN_BTIM(2)
	   IF (IER.EQ.0) THEN
	      READ (REMOTE_UNIT,'(A)',IOSTAT=IER) START
	   END IF
	ELSE IF (READIT.EQ.1) THENF
	   I = NEWS_FIND_SUBSCRIBE()N
	   START = (LAST_NEWS_READ2(2,I).AND.'3FFF'X) +  
     &			LAST_NEWS_READ(2,I) + 1
	   IF (START.GT.F_NBULL) THEN
	      START = -1E
	   ELSE
	      LAST_NEWS_READ2(2,I) = MIN(8191,F_NBULL-LAST_NEWS_READ(2,I)).
     &			.OR.(LAST_NEWS_READ2(2,I).AND.'C000'X)V
	   END IF
	ELSED
	   START = -1
	   IER = SYS$ASCTIM(,TIME,IN_BTIM,)
	   CALL DATE_TIME(TIME)
	   SKIP = 0
	   DO WHILE (1)
	      IF (.NOT.NEWS_WRITE('NEWNEWS '//FOLDER_NAME(:TRIM( 
     &		  FOLDER_NAME))//' '//TIME)) RETURN
	      IF (.NOT.NEWS_READ()) RETURNA
	      IF (BUFFER(:2).EQ.'23') THEND
 	         IF (.NOT.NEWS_READ()) CALL EXIT
		 DO I=1,SKIP
		    IF (.NOT.NEWS_READ()) CALL EXITT
		 END DOA
		 FIRST = BUFFER(SB:EB)
		 IF (FIRST.EQ.'.') RETURN	
		 DO WHILE (BUFFER(SB:EB).NE.'.')
		    IF (.NOT.NEWS_READ()) CALL EXIT 
		 END DO 
	         IF (.NOT.NEWS_WRITE('STAT '//FIRST(:TRIM(FIRST))))
     &					  CALL EXIT
                 IF (.NOT.NEWS_READ()) CALL EXIT
	         IF (BUFFER(:2).EQ.'22') THEN
		    IF (BUFFER(5:INDEX(BUFFER(5:),' ')+3).EQ.'0') THEN
		       I = F_NBULL + 1
		       DO WHILE (I.GE.F_START.AND.(FIRST(:TRIM(FIRST)).NE.
     &			   BUFFER(INDEX(BUFFER,'<'):INDEX(BUFFER,'>'))U
     &			   .OR.I.GT.F_NBULL))
		          I = I - 1 
			  IF (.NOT.OTS$CVT_L_TI(I,NUMBER,,,)) RETURNM
			  IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURN 
			  IF (.NOT.NEWS_READ()) RETURNV
		       END DO 
		       IF (I.GE.F_START) START = I
		    ELSE
		       IER = OTS$CVT_TI_L(BUFFER(SB+4:
     &		          INDEX(BUFFER(SB+4:),' ')+SB+2),START,,%VAL(1))
		    END IF
		    RETURN
		 END IF
	      END IFO
	      SKIP = SKIP + 1
	   END DO
	END IF	
  
	RETURNL
	END
 1
 1
 Q
	SUBROUTINE REMOTE_COPY_BULL(IER)R
 :
	IMPLICIT INTEGER (A-Z) 
  
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
  
	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(A)',IOSTAT=IER) 2
	ELSE'
	END IF 
 N
	RETURN 
	END
 -
 
  
	SUBROUTINE REMOTE_WRITE_BULL_FILE(OUTPUT)
 
	IMPLICIT INTEGER (A-Z)'
 U
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 .
	CHARACTER*(*) OUTPUT&
 '
	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 6,OUTPUT
	ELSE 
	END IFE
 2
	RETURN)
	END
  
  
  
 	SUBROUTINE GET_REMOTE_MESSAGE(IER)
CR
C  SUBROUTINE GET_REMOTE_MESSAGE
CW
C  FUNCTION:
C	Gets remote message.
C.
 D
	IMPLICIT INTEGER (A-Z)D
  
	INCLUDE 'BULLDIR.INC'
 D
	INCLUDE '($RMSDEF)'
 T
	COMMON /BUFFER/ BUFFER,SB,EBR
	CHARACTER BUFFER*1280
 I
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
  
	COMMON /REMOTE_READ_MESSAGE/ SCRATCH_R1
	DATA SCRATCH_R1 /0/
 :
	COMMON /REF/ REFERENCES,LREFU
	CHARACTER*255 REFERENCESD
 	
	COMMON /NEWSGROUPS/ NEWSGROUPS
	CHARACTER*255 NEWSGROUPS
  
	CHARACTER*255 TEMP,FROM_LINE,SUBJECT_LINE
  
	CHARACTER*10 MSGNUM
 N
	IF (SCRATCH_R1.NE.0) THEN		! Is queue empty?,
	   SCRATCH_R = SCRATCH_R1		! No, set queue pointer to head 
	ELSE					! Else if queue is empty
	   CALL INIT_QUEUE(SCRATCH_R,INPUT)
	   SCRATCH_R1 = SCRATCH_R		! Init header pointer 
	END IF.
 S
	IF (REMOTE_SET.EQ.3) THEN
	   MSGNUM = BUFFER(5:INDEX(BUFFER(5:),' ')-1+4)
 E
	   SUBJECT_LINE = ' '
	   FROM_LINE = ' 'N
	   NEWSGROUPS = ' '
	   LREF = 0
	   DO WHILE (BUFFER(SB:EB).NE.'.')0
	      IER = NEWS_READ()
	      IF (.NOT.IER) RETURN'
	      IF (BUFFER(SB:EB).NE.'.') THEN(
	         IF (BUFFER(SB:SB+4).EQ.'From:'.AND.EB.GT.SB+5) THEN_
		    FROM_LINE = 'From: '//BUFFER(SB+6:EB)T
	         ELSE IF (BUFFER(SB:SB+7).EQ.'Subject:'.AND.:
     &						    EB.GT.SB+8) THEN
		    DO I=SB+9,EB
		       IF (ICHAR(BUFFER(I:I)).LT.32) BUFFER(I:I) = ' '
		    END DO
		    SUBJECT_LINE = 'Subj: '//BUFFER(SB+9:EB)
	         ELSE IF (BUFFER(SB:SB+10).EQ.'Newsgroups:'.AND.D
     &						    EB.GT.SB+11) THEN+
		    NEWSGROUPS = BUFFER(SB+12:EB)S
	         ELSE IF (BUFFER(SB:SB+10).EQ.'References:'.AND.
     &						    EB.GT.SB+11) THEN 
		    IF (LREF.EQ.0) THEND
		       REFERENCES = BUFFER(SB+12:EB)
		    ELSE
		       REFERENCES = BUFFER(SB+12:EB)//' '//E
     &				REFERENCES(:LREF)H
	            END IFE
		    LREF = TRIM(REFERENCES)E
	         ELSE IF (BUFFER(SB:SB+10).EQ.'Message-ID:'.AND.M
     &						    EB.GT.SB+11) THENS
		    IF (LREF.EQ.0) THENP
		       REFERENCES = BUFFER(SB+12:EB)
		    ELSE
		       REFERENCES = REFERENCES(:LREF)//' '//
     &				BUFFER(SB+12:EB)
	            END IFE
		    LREF = TRIM(REFERENCES)(
	         END IF
	      END IF)
	   END DO
 S
	   LSUB = TRIM(SUBJECT_LINE)R
	   LFRO = TRIM(FROM_LINE)
	END IFR
 _
	ILEN = 128L
	IER = 0
	LENGTH = 0N
	LTEMP = 0
 =
	DO WHILE (ILEN.GT.0.AND.IER.EQ.0)
	   IF (REMOTE_SET.EQ.1) THENM
	      READ (REMOTE_UNIT,'(Q,A)',IOSTAT=IER) ILEN,INPUTR
	   ELSE
	      IF (ILEN.EQ.128) ILEN = 0
	      IF (LTEMP.GT.0) THENT
		 ILEN = MIN(128,LTEMP)
		 INPUT = TEMP(:ILEN)
		 LTEMP = LTEMP - ILEN 
	      END IF_
	      IF (ILEN.LT.128) THEN
		 IF (LFRO.GT.0) THEN
		    BUFFER = FROM_LINE
		    SB = 1
		    EB = LFRO
		    LFRO = 0
		    IER = 1 
		 ELSE IF (LSUB.GT.0) THENT
		    BUFFER = SUBJECT_LINER
		    SB = 1
		    EB = LSUB(
		    LSUB = 0
		    IER = 1 
		 ELSE.
		    IF (LSUB.EQ.0) THEN 
		       IF (.NOT.NEWS_WRITE('ARTICLE '//MSGNUM)) RETURN
		       IF (.NOT.NEWS_READ()) RETURN 
		       IF (BUFFER(:2).NE.'22') THENC
			  IER = 0
			  RETURNC
		       END IF 
		       LSUB = -1
		    END IF
		    IER = NEWS_READ() 
		 END IFE
		 IF (IER.AND.BUFFER(SB:EB).NE.'.') THENA
		    IER = 02
		    LTEMP = MIN(255,EB-SB+1)
		    IF (LTEMP.GT.0) THEN
		       TEMP = CHAR(LTEMP)//BUFFER(SB:SB+LTEMP-1)
		    ELSE
		       TEMP = CHAR(1)//' '
		       LTEMP = 1
		    END IF
		    LTEMP = LTEMP + 1 
		    LINP = MIN(LTEMP,128-ILEN)
		    INPUT = INPUT(:ILEN)//TEMP(:LINP)R
		    ILEN = ILEN + LINP
		    LTEMP = LTEMP - LINP
		    TEMP = TEMP(LINP+1:)
		 ELSE IF (IER) THEND
		    IER = 0E
		    INPUT = INPUT(:ILEN)//CHAR(0) 
		    ILEN = -128E
		 ELSE.
		    ILEN = 128
		 END IFF
	      ELSEC
		 TEMP = TEMP(129:)
	      END IF 
	   END IF
	   IF (IER.NE.0.AND.ILEN.GT.0) THEN
	      CALL ERRSNS(IDUMMY,IER1)E
	      IF (IER1.EQ.RMS$_RER) THEN	! Ignore this errorE
		 IER = 0
		 ILEN = 0B
	      ELSEN
		 CALL SYS_GETMSG(IER1)
	         LENGTH = 0
	         IER1 = IER
	         CALL DISCONNECT_REMOTE
	         IER = IER1	! IER is set to 0 by DISCONNECT_REMOTEB
	      END IF
	   ELSE IF (ABS(ILEN).EQ.128) THENa
	      CALL WRITE_QUEUE(%VAL(SCRATCH_R),SCRATCH_R,INPUT)
	      LENGTH = LENGTH + 1
	   END IF
	END DOQ
 x
	RETURNN
	END
 B
  
 N
 	
	SUBROUTINE REMOTE_REMOVE_FOLDER(IER))
  
	IMPLICIT INTEGER (A-Z)B
 .
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 B
	RETURN6
	END
 B
 ,
  
	SUBROUTINE CONNECT_REMOTE_FOLDER(READ_ONLY,IER)
C
C  SUBROUTINE CONNECT_REMOTE_FOLDERO
CN
C  FUNCTION: Connects to folder that is located on other DECNET node.L
CI
	IMPLICIT INTEGER (A-Z)
 
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
	DATA REMOTE_UNIT /15/
 ,
	COMMON /COMMAND_SWITCHES/ LOGIN_SWITCH,SYSTEM_SWITCHQ
	COMMON /COMMAND_SWITCHES/ SYSTEM_LOGIN_BTIM(2)T
	COMMON /COMMAND_SWITCHES/ REVERSE_SWITCH,SEPARATE
	CHARACTER*1 SEPARATEL
 A
	COMMON /READIT/ READITC
  
	COMMON /NEWS_INIT/ END_READ
 T
	INCLUDE 'BULLUSER.INC' 
 U
	INCLUDE 'BULLFOLDER.INC'(
 A
	INCLUDE 'BULLDIR.INC'
 F
	INCLUDE 'BULLFILES.INC'
  
	CHARACTER*12 FOLDER_BBOARD_SAVE,FOLDER_OWNER_SAVE
	CHARACTER*25 FOLDER_SAVE 
  
	DIMENSION DUMMY(4)O
 G
	IF (FOLDER1(:1).GE.'a'.AND.FOLDER1(:1).LE.'z') THEN
	   END_READ = 0
	   IF (.NOT.NEWS_LOGIN()) THEN'
	      IER = 2
	      RETURNA
	   END IF
	   CALL NEWS_GROUP(IER)
	   IF (IER.NE.0) RETURN
	   IF (REMOTE_SET.EQ.1) CLOSE(UNIT=REMOTE_UNIT)
	   RETURN
	END IFN
 N
	REMOTE_UNIT = 31 - REMOTE_UNIT*
 F
	SAME = .TRUE.
	LEN_BBOARD = TRIM(FOLDER1_BBOARD)
	IF (INDEX(FOLDER1_BBOARD,'*').GT.0) THEN  ! Remote folder name differentB
	   SAME = .FALSE.			  ! from local?  Yes.
	   LEN_BBOARD = LEN_BBOARD - 1A
	END IFN
 F
	OPEN (UNIT=REMOTE_UNIT,STATUS='UNKNOWN',IOSTAT=IER,RECL=256,
     &		FILE=FOLDER1_BBOARD(3:LEN_BBOARD)//'::"TASK=BULLETIN1"')
 S
	IF (IER.EQ.0) THENF
	   IF (.NOT.SAME) THEN
	      FOLDER1_FILE = FOLDER_FILE 
	      FOLDER_FILE = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))
     &		//FOLDER1N
	      REMOTE_SET_SAVE = REMOTE_SET 
	      REMOTE_SET = .FALSE. 
	      CALL OPEN_BULLDIR
	      CALL READDIR(0,IER)
	      CALL CLOSE_BULLDIRO
	      REMOTE_SET = REMOTE_SET_SAVEE
	      FOLDER_FILE = FOLDER1_FILE 
	      FOLDER_SAVE = FOLDER1
	      FOLDER1 = BULLDIR_HEADER(13:)
	   END IF
	   SYSLOG = .FALSE.
	   IF (READIT.EQ.1) THEN 
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,'SYSTEM?'
	      READ(REMOTE_UNIT,'(A)',IOSTAT=IER) IER1
	      IF (IER1) THEN	
	         WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,FOLDER1//'+'
		 SYSLOG = .TRUE.
	      END IFI
	   END IF
	   IF (.NOT.SYSLOG) THEN_
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,FOLDER1
	   END IF
	   FOLDER_OWNER_SAVE = FOLDER1_OWNERX
	   FOLDER_BBOARD_SAVE = FOLDER1_BBOARDN
	   FOLDER_NUMBER_SAVE = FOLDER1_NUMBER)
	   IF (IER.EQ.0) THEN
	      IF (SYSLOG) THEN 
	         READ(REMOTE_UNIT,'(7A)',IOSTAT=IER)IER1,READ_ONLY,
     &		   DUMMY(1),DUMMY(2),DUMMY(3),DUMMY(4),FOLDER1_COM
	      ELSEF
	         READ(REMOTE_UNIT,'(5A)',IOSTAT=IER)IER1,READ_ONLY,
     &		   DUMMY(1),DUMMY(2),FOLDER1_COM
	      END IFU
	   END IF
	   IF (.NOT.SAME) FOLDER1 = FOLDER_SAVE
	   FOLDER1_BBOARD = FOLDER_BBOARD_SAVE)
	   FOLDER1_NUMBER = FOLDER_NUMBER_SAVES
	   FOLDER1_OWNER = FOLDER_OWNER_SAVE 
	END IFU
 R
	IF (IER.NE.0.OR..NOT.IER1) THEN
	   CLOSE (UNIT=REMOTE_UNIT)
	   REMOTE_UNIT = 31 - REMOTE_UNIT
	   IF (IER.EQ.0.AND.FOLDER_NUMBER_SAVE.GE.0.AND.
     &	       TEST_BULLCP().NE.2) THEN			! Not BULLCP processI
	      IF (TEST2(BRIEF_FLAG,FOLDER_NUMBER_SAVE)E
     &		  .OR.TEST2(SET_FLAG,FOLDER_NUMBER_SAVE)) THEN
	         CALL OPEN_BULLUSER_SHARED)
	         CALL READ_USER_FILE_KEYNAME(USERNAME,IER)
	         CALL CLR2(BRIEF_FLAG,FOLDER_NUMBER_SAVE)
	         CALL CLR2(SET_FLAG,FOLDER_NUMBER_SAVE)
	         IF (IER.EQ.0) REWRITE (4) USER_ENTRY
	         CALL CLOSE_BULLUSERH
	      END IFR
	   END IF
	   IER = 2I
	ELSEU
	   CLOSE (UNIT=31-REMOTE_UNIT)R
C
C  If remote folder has returned a last read time for the folder,O
C  and if in /LOGIN mode, or last selected folder was a different
C  folder, or folder specified with "::", then update last read time.U
C'
	   IF (((FOLDER_NUMBER.NE.FOLDER1_NUMBER.OR.READIT.EQ.1)B
     &		.AND.(DUMMY(1).NE.0.OR.DUMMY(2).NE.0))
     &		.OR.FOLDER1_NUMBER.EQ.-1) THEN
	      LAST_READ_BTIM(1,FOLDER1_NUMBER+1) = DUMMY(1)
	      LAST_READ_BTIM(2,FOLDER1_NUMBER+1) = DUMMY(2)
	      IF (SYSLOG) THENN
	         LAST_SYS_BTIM(1,FOLDER1_NUMBER+1) = DUMMY(3)
	         LAST_SYS_BTIM(2,FOLDER1_NUMBER+1) = DUMMY(4)
	      END IFT
	   END IF
	   IER = 0e
	END IF,
  
	RETURN_
	END
 C
 1
  
	SUBROUTINE REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)
 s
	IMPLICIT INTEGER (A-Z)U
 C
	INCLUDE 'BULLDIR.INC'
 _
	INCLUDE 'BULLFOLDER.INC'e
 o
	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD
 S
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
  
	COMMON /BUFFER/ BUFFER,SB,EBN
	CHARACTER BUFFER*1280
 '
	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*255 MESSAGE_ID
  
	COMMON /NEXT/ NEXT
	LOGICAL NEXT /.FALSE./R
 
	COMMON /NEWGROUP/ NEWGROUP.
 T
	CHARACTER*6 NUMBERU
 R
	CHARACTER IN_BTIM(2)D
 .
	IF (REMOTE_SET.EQ.1) THEN
	   IF (ICOUNT.GE.0) THEN:
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 8,ICOUNTA
	   ELSE
	      WRITE (REMOTE_UNIT,'(3A)',IOSTAT=IER) 8,-1,MSG_KEYI
	   END IF
	   IF (IER.EQ.0) THEN
	      IF (ICOUNT.EQ.0) THEN
	         READ (REMOTE_UNIT,'(2A)',IOSTAT=IER) ICOUNT,BULLDIR_HEADER
	      ELSE IF (ICOUNT.EQ.-1) THEN
                 READ (REMOTE_UNIT,'(2A)',IOSTAT=IER1) IER,BULLDIR_ENTRY
	         IF (IER1.GT.0) THEN0
	            CALL ERROR_AND_EXIT
	         ELSE IF (IER.NE.0) THENF
	            CALL CONVERT_ENTRY_FROMBIN 
	         END IF
	         RETURN
	      ELSE 
	         READ (REMOTE_UNIT,'(2A)',IOSTAT=IER) ICOUNT,BULLDIR_ENTRY 
	      END IF 
	   END IF
	   IF (IER.GT.0) THEN
	      CALL ERROR_AND_EXIT
	   ELSE IF (ICOUNT.EQ.1) THEN
	      CALL CONVERT_HEADER_FROMBIN
	   ELSE
	      CALL CONVERT_ENTRY_FROMBINR
	   END IF
	ELSE IF (REMOTE_SET.EQ.3) THEN 
	   IF (ICOUNT.EQ.0) THEN 
	      NBULL = F_NBULL
	      ICOUNT = 1I
	      RETURN=
	   ELSE IF (ICOUNT.EQ.-1) THEN 
	      IER = 2
	      CALL GET_MSGBTIM(MSG_KEY,IN_BTIM)
	      CALL REMOTE_GET_NEWEST_MSG(IN_BTIM,START)
	      IF (START.EQ.-1) RETURN
              IF (.NOT.NEWS_WRITE('HEAD')) CALL ERROR_AND_EXIT
              IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXITA
	   ELSE
	      IER = 2
	      IF (NEXT.AND..NOT.NEWGROUP) THEN=
	         IF (.NOT.NEWS_WRITE('NEXT')) CALL ERROR_AND_EXIT
		 IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	         IF (BUFFER(:3).NE.'223') RETURN 
	         IF (.NOT.NEWS_WRITE('HEAD')) CALL ERROR_AND_EXIT
		 IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	      ELSE
		 IF (ICOUNT.LT.F_START) ICOUNT = F_START
		 IF (ICOUNT.GT.F_NBULL) ICOUNT = F_NBULL
	         IF (.NOT.OTS$CVT_L_TI(ICOUNT,NUMBER,,,)) RETURNB
	         IF (.NOT.NEWS_WRITE('HEAD '//NUMBER))L
     &						CALL ERROR_AND_EXIT 
	         IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXITE
	      END IF	
	      IF (BUFFER(:2).NE.'22') THEND
	         DO WHILE (NEXT.AND.NEWGROUP.AND.ICOUNT.GT.F_START)
		    ICOUNT = ICOUNT - 1A
	            IF (.NOT.OTS$CVT_L_TI(ICOUNT,NUMBER,,,)) RETURN
	            IF (.NOT.NEWS_WRITE('HEAD '//NUMBER))
     &						CALL ERROR_AND_EXITS
	            IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
		    IF (BUFFER(:2).EQ.'22') NEXT = .FALSE.
	         END DO
	         IF (INCMD(:4).EQ.'BACK'.AND.ICOUNT.GE.F_START) THENI
	            IF (.NOT.NEWS_WRITE('LAST')) CALL ERROR_AND_EXIT 
		    IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT	
	            IF (BUFFER(:3).NE.'223') RETURN
	            IF (.NOT.NEWS_WRITE('HEAD')) CALL ERROR_AND_EXITF
	            IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
		 ELSE IF (INCMD(:4).NE.'READ'.AND..NOT.NEXT) THEN 
                    IF (.NOT.NEWS_WRITE('NEXT')) CALL ERROR_AND_EXIT
                    IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXITY
                    IF (BUFFER(:3).NE.'223') RETURN=
                    IF (.NOT.NEWS_WRITE('HEAD')) CALL ERROR_AND_EXIT
                    IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXITS
	         END IF
	      END IF 
	      IF (BUFFER(:2).NE.'22') RETURNN
	      IER = OTS$CVT_TI_L(BUFFER(5:INDEX(BUFFER(5:),' ')+3),
     &							ICOUNT,,%VAL(1))S
	      IF (.NOT.IER) RETURNR
	      START = ICOUNTN
	      BULLETIN_NUM = STARTM
	   END IF
	   NEWGROUP = .FALSE.
	   MESSAGE_ID = BUFFER(INDEX(BUFFER,'<'):INDEX(BUFFER,'>'))
	   IER = 0,
	   CALL NEWS_HEADER(IER)N
	   IF (IER.GT.0) THEN
	      CALL ERROR_AND_EXIT
	   ELSE
	      CALL CONVERT_ENTRY_FROMBINI
	   END IF
	   BLOCK = START
	   MSG_NUM = STARTR
	   SYSTEM = 0
	   IF (ICOUNT.NE.-1) THEN
	      ICOUNT = ICOUNT + 1
	   ELSE
	      IER = START
	   END IF
	END IFA
 S
	RETURNS
	END
 I
 T
 2
 
 M
        SUBROUTINE GET_MSGBTIM(MSG_KEY,BTIM)
 C
        IMPLICIT INTEGER (A-Z)
 R
        INTEGER BTIM(2)O
 N
        CHARACTER*8 MSG_KEY,INPUTU
 S
	INPUT = MSG_KEY
 E
        DO I=1,8
           INPUT(9-I:9-I) = MSG_KEY(I:I)
        END DO
  
        CALL LIB$MOVC3(8,%REF(INPUT),BTIM(1))_
 E
        RETURN
	END
 V
 
 
	SUBROUTINE NEWS_GROUP(IER) 
 L
	IMPLICIT INTEGER (A-Z)R
 1
	INCLUDE 'BULLFOLDER.INC'D
 0
	COMMON /BUFFER/ BUFFER,SB,EBE
	CHARACTER BUFFER*1280
 R
	COMMON /NEWGROUP/ NEWGROUPN
 _
	IER = NEWS_WRITE('GROUP '//FOLDER1_DESCRIP(:TRIM(FOLDER1_DESCRIP)))
	IF (.NOT.IER) RETURNE
 N
	IER = NEWS_READ()
	IF (.NOT.IER) RETURNU
 *
	IF (BUFFER(:3).EQ.'411') THEN
	   CALL OPEN_BULLNEWS_SHAREDI
	   CALL READ_FOLDER_FILE_KEYNAME_TEMP(FOLDER1,IER1)
	   IF (IER1.EQ.0) DELETE (7)S
	   CALL CLOSE_BULLFOLDER
           RETURNN
	END IF 
 
	NEWGROUP = .TRUE.
 I
	BUFFER = BUFFER(5:)
 N
	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_END,,%VAL(1))D
	IF (.NOT.IER) RETURN)
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)
	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_START,,%VAL(1))=
	IF (.NOT.IER) RETURN(
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)
	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_NBULL,,%VAL(1)) 
	IF (.NOT.IER) RETURN
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)
 S
	IER = 0
  
	RETURNT
	END
 E
 E
 T
	SUBROUTINE NEWS_TIME(INTIME,BTIM)
 L
	IMPLICIT INTEGER (A-Z)F
 E
	CHARACTER*(*) INTIMEL
 R
	CHARACTER*20 TIME
 F
	I = 1
	LTIME = TRIM(INTIME)(
	DO WHILE (I.LE.LTIME.AND.(ICHAR(INTIME(I:I)).LT.ICHAR('0').OR.1
     &		  ICHAR(INTIME(I:I)).GT.ICHAR('9')))
	   I = I + 1 
	END DOI
 )
	IF (I.GT.LTIME) THEN 
	   CALL SYS_BINTIM('-',BTIM) 
	   RETURN
	END IFS
  
	CALL STR$UPCASE(TIME,INTIME(I:))F
  
	DO J = 1,2S
	   I = 1
	   DO WHILE (TIME(I:I).NE.' '.AND.I.LT.LEN(TIME))
	      I = I + 1
	   END DO
	   TIME(I:I) = '-'E
	END DOO
 R
	IF (I.EQ.LEN(TIME)) RETURNN
  
	IF (TIME(I+3:I+3).EQ.' ') THENM
	   IF (TIME(I+1:I+1).EQ.'9'.OR.TIME(I+1:I+1).EQ.'8') THEN
	      TIME = TIME(:I)//'19'//TIME(I+1:)
	   ELSE
	      TIME = TIME(:I)//'20'//TIME(I+1:)
	   END IF
	END IFM
  
	I = 1
	DO J = 1,2 
	   DO WHILE (TIME(I:I).NE.' '.AND.I.LE.LEN(TIME))
	      I = I + 1
	   END DO
	   I = I + 1 
	END DOU
  
	IF (I-2.GT.LEN(TIME).OR.I-2.LE.0) RETURNE
	CALL SYS_BINTIM(TIME(:I-2),BTIM)_
 A
	RETURN
        ENDU
 R
 F
 E
	SUBROUTINE NEWS_LISTD
 _
	IMPLICIT INTEGER (A-Z) 
 E
	INCLUDE 'BULLFOLDER.INC'R
 O
	COMMON /BUFFER/ BUFFER,SB,EBE
	CHARACTER BUFFER*1280
  
	IF (.NOT.NEWS_LOGIN()) RETURN
 0
	IF (.NOT.NEWS_WRITE('LIST')) RETURN
	IF (.NOT.NEWS_READ()) RETURN 
	IF (BUFFER(:3).NE.'215') RETURN
 I
	CALL OPEN_BULLNEWS_SHARED	! Open folder file&
  
	NEWS_FOLDER1_BBOARD = '::'B
 S
	CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER1))
	IF (IER1.NE.0) THEN
	   NEWS_FOLDER1 = 'a'
	   NEWS_FOLDER1_NUMBER = 1000
	   NEWS_F1_END = 1001
	   WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COMU
	END IF)
	IF (NEWS_F1_END.LT.1001) NEWS_F1_END = 1001
	NEWS_F_END = NEWS_F1_ENDL
	LAST_READ = NEWS_FOLDER1_NUMBER
	DO WHILE (NEWS_READ().AND.BUFFER(SB:EB).NE.'.')
	   FLEN = INDEX(BUFFER(SB:),' ') - 1u
	   NEWS_FOLDER1 = BUFFER(SB:MIN(25,FLEN)+SB-1) 
	   IF (IER1.EQ.0) THENe
	      CALL READ_FOLDER_FILE_KEYNAME_TEMP(NEWS_FOLDER1,IER)d
	   END IF
	   SP = FLEN+SB+1
	   EP = INDEX(BUFFER(SP:),' ')+SP-2
	   IER2 = OTS$CVT_TI_L(BUFFER(SP:EP),NEWS_F1_NBULL,,%VAL(1)).
	   SP = EP + 2)
	   EP = INDEX(BUFFER(SP:),' ')+SP-2
	   IER2 = OTS$CVT_TI_L(BUFFER(SP:EP),NEWS_F1_START,,%VAL(1)) 
	   CALL SYS_BINTIM('-',NEWS_F1_NEWEST_BTIM)
	   IF (IER.NE.0.OR.IER1.NE.0) THEN 
	      IF (FLEN.GT.25) THENR
	         NEWS_FOLDER1_DESCRIP = BUFFER(SB+25:FLEN+SB-1)
	      ELSE
	         NEWS_FOLDER1_DESCRIP = ' '
	      END IF 
	      IER = 0
	      DO WHILE (IER.EQ.0.AND.IER1.EQ.0)
		 DO WHILE (REC_LOCK(IER))s
	            READ (7,KEY=NEWS_F_END,KEYID=1,IOSTAT=IER)_
	         END DO
		 IF (IER.EQ.0) NEWS_F_END = NEWS_F_END + 1
	      END DOI
	      NEWS_FOLDER1_NUMBER = NEWS_F_ENDS
	      WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM
	      IF (IER.EQ.0) NEWS_F_END = NEWS_F_END + 1
	   ELSE IF (F1_START.NE.NEWS_F1_START.OR.
     &		    F1_NBULL.NE.NEWS_F1_NBULL) THENR
	      REWRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM
	      DO I = LAST_READ+1,NEXT_READ-1D
		 DO WHILE (REC_LOCK(IER))		! Delete non-existant
	            READ (7,KEY=I,KEYID=1,IOSTAT=IER)	! newsgroupsN
	         END DO
		 IF (IER.EQ.0) DELETE (UNIT=7)		  
	      END DOI
	      LAST_READ = NEXT_READ
	   END IF
	END DOO
 .
	CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER1)I
	NEWS_F1_END = NEWS_F_ENDE
	REWRITE (7) NEWS_FOLDER1_COM.
  
	CALL CLOSE_BULLNEWS
 A
	RETURN_
        ENDO
 T
 R
	SUBROUTINE LOWERCASE(INPUT)
 F
	CHARACTER*(*) INPUT
  
	DO I=1,LEN(INPUT)
	   IF (INPUT(I:I).GE.'A'.AND.INPUT(I:I).LE.'Z') THEN 
	      INPUT(I:I) = CHAR(ICHAR(INPUT(I:I)) - ICHAR('A') + ICHAR('a')) 
	   END IF
	END DOD
 E
	RETURN,
	END
 S
 =
 )
	SUBROUTINE NEWS_POST(FILENAME,FILEOPEN,IER,SUBJECT)
 F
	IMPLICIT INTEGER (A-Z)C
  
	INCLUDE 'BULLNEWS.INC'I
 I
	INCLUDE 'BULLFOLDER.INC'L
 O
	INCLUDE 'BULLUSER.INC' 
 E
	COMMON /BUFFER/ BUFFER,SB,EBM
	CHARACTER BUFFER*1280
 (
	COMMON /REF/ REFERENCES,LREF(
	CHARACTER*255 REFERENCESN
 L
	COMMON /PATH/ PATHNAME,LPATH
	CHARACTER*132 PATHNAMEI
 I
	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD
 B
	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*255 MESSAGE_ID(
 B
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
  
	COMMON /NEWSGROUPS/ NEWSGROUPS)
	CHARACTER*255 NEWSGROUPS 
  
	CHARACTER*(*) FILENAME,SUBJECTR
 A
	CHARACTER TODAY*23,MSGID*23,ZONE*5,GROUPS*255
 .
	DIMENSION NOW(2),GMT(2)
  
	IER = 1
 T
	IF (FILENAME.NE.'cancel') THENN
	   IF (.NOT.FILEOPEN) THEN(
	      OPEN (UNIT=3,FILE=FILENAME,STATUS='OLD',IOSTAT=IER1)T
	      IF (IER1.NE.0) RETURN
	   END IF
 C
	   IER1 = 0
	   DO WHILE (IER1.EQ.0)
	      READ (3,'(A)',IOSTAT=IER1) BUFFER
	      IF (IER1.NE.0) GO TO 900F
	      IF (TRIM(BUFFER).GT.0) IER1 = 1
	   END DO
  
	   REWIND (UNIT=3)T
	END IFU
 N
	IF (.NOT.NEWS_LOGIN()) GO TO 900N
 N
	IF (LPATH.EQ.0) CALL GET_PATHNAME
 	
	IF (.NOT.NEWS_WRITE('POST')) GO TO 900T
	IF (.NOT.NEWS_READ()) GO TO 900
	IF (BUFFER(:3).NE.'340') THEN
	   WRITE (6,'('' ERROR: Posting not allowed.'')')
	   GO TO 900C
	END IF_
 R
	IF (REMOTE_SET.GE.3) THEN
	   IF (TRIM(NEWSGROUPS).GT.0.AND.INCMD(:2).EQ.'RE') THENE
	      GROUPS = 'Newsgroups: '//NEWSGROUPS
	   ELSE IF (REMOTE_SET.EQ.4) THEN
	      GROUPS = 'Newsgroups: '//FOLDER1_DESCRIPL
	   ELSE
	      GROUPS = 'Newsgroups: '//FOLDER_DESCRIP
	   END IF
	   IF (FILENAME.NE.'cancel') THEN
	      IF (CLI$PRESENT('GROUPS')) THEN
		 CALL OPEN_BULLNEWS_SHARED
		 FLEN = 0A
		 DO WHILE (CLI$GET_VALUE('GROUPS',FOLDER1_NAME,FLEN)
     &			.AND.TRIM(GROUPS)+FLEN+1.LE.LEN(GROUPS)) 
		    CALL LOWERCASE(FOLDER1_NAME)
		    CALL READ_FOLDER_FILE_KEYNAME_TEMP
     &			(FOLDER1_NAME(:FLEN),IER1)O
		    IF (IER1.EQ.0) GROUPS = GROUPS(:TRIM(GROUPS))//X
     &			','//FOLDER1_NAME(:TRIM(FOLDER1_NAME))(
		 END DOL
		 CALL CLOSE_BULLNEWS
	      END IFF
	   END IF
	   IF (.NOT.NEWS_WRITE(GROUPS(:TRIM(GROUPS)))) GO TO 900R
	END IF2
	IF (.NOT.NEWS_WRITE('Path: '//PATHNAME(:LPATH))) GO TO 900)
	IF (.NOT.NEWS_WRITE('From: '//PATHNAME(INDEX(PATHNAME,'!')+1:
     &	   TRIM(PATHNAME))//'@'//PATHNAME(:INDEX(PATHNAME,'!')-1)))
     &	   GO TO 900T
	IF (.NOT.NEWS_WRITE('Subject: '//SUBJECT(:TRIM(SUBJECT)))))
     &	   GO TO 900O
 ,
	IF (INCMD(:2).EQ.'RE') THEN
	   IF (.NOT.NEWS_WRITE('References: '//REFERENCES(:LREF)))R
     &	      GO TO 900
	END IFA
 .
	CALL SYS$ASCTIM(,TODAY(:23),,)U
 R
	IF (LZONE.EQ.0) THEN)
	   IF (SYS_TRNLNM_SYSTEM('LISP$TIME_ZONE',ZONE)) THEN
	      IER = OTS$CVT_TI_L(ZONE(:TRIM(ZONE)),DIFF,,%VAL(1))
	      IF (DIFF.LT.0) THEN
		 PAST = .TRUE.
	         ZONE = ZONE(2:)T
	      ELSE IF (DIFF.GT.12) THEN
		 PAST = .TRUE.
		 DIFF = 24 - DIFF+
	         IER = OTS$CVT_L_TI(DIFF,ZONE(1:2),,,)D
		 IF (ZONE(1:1).EQ.' ') ZONE = ZONE(2:)
	      ELSEU
	         PAST = .FALSE.
	      END IF 
	      IER = SYS_BINTIM('0 '//ZONE(:TRIM(ZONE))//':00',GMT)N
	      IER = SYS$GETTIM(NOW)
	      IF (PAST) THENG
	         IER = LIB$ADDX(NOW,GMT,GMT)I
	      ELSE 
	         IER = LIB$SUBX(NOW,GMT,GMT) 
	      END IFV
	      IER = SYS$ASCTIM(,TODAY,GMT,)
	      ZONE = 'GMT'
	   ELSE IF (.NOT.SYS_TRNLNM_SYSTEM('MULTINET_TIMEZONE',ZONE)R
     &         .AND..NOT.SYS_TRNLNM_SYSTEM('PMDF_TIMEZONE',ZONE)) THEN
	      ZONE = 'GMT'
	   END IF
	   LZONE = TRIM(ZONE)
	END IFN
 _
	MSGID = TODAY(:2)//TODAY(4:6)//TODAY(10:11)//'.'//)
     &		TODAY(13:14)//TODAY(16:17)//TODAY(19:20)//TODAY(22:23)
	IF (MSGID(1:1).EQ.' ') MSGID = MSGID(2:)H
	IF (.NOT.NEWS_WRITE('Message-ID: <'//MSGID(:TRIM(MSGID))//_
     &	    '@'//PATHNAME(:INDEX(PATHNAME,'!')-1)//'>')) GO TO 900L
 O
	TODAY = TODAY(:2)//' '//TODAY(4:6)//' '//TODAY(10:20)
	IF (TODAY(1:1).EQ.' ') TODAY = TODAY(2:)
 R
	IF (LORGAN.EQ.0) THEN
	   IF (SYS_TRNLNM('BULL_NEWS_ORGANIZATION','DEFINED')) THEN
	      IER1 = SYS_TRNLNM('BULL_NEWS_ORGANIZATION',ORGANIZATION)F
	   END IF
	   LORGAN = TRIM(ORGANIZATION)
	END IF.
 )
	IF (LORGAN.GT.0) THEN
	   IF (.NOT.NEWS_WRITE('Organization: '//ORGANIZATION(:LORGAN)))'
     &		GO TO 900A
	END IFI
 .
	IF (.NOT.NEWS_WRITE('Date: '//TODAY(:TRIM(TODAY))//' '//S
     &		ZONE(:LZONE))) GO TO 900
 E
	IF (FILENAME.EQ.'cancel') THENE
	   IF (.NOT.NEWS_WRITE('Control: cancel '
     &		//MESSAGE_ID(:TRIM(MESSAGE_ID)))) RETURN
	   IF (.NOT.NEWS_WRITE('.')) RETURN
	   IF (.NOT.NEWS_READ()) RETURN
	   IF (BUFFER(:3).EQ.'240') IER = 0
	   RETURN
	END IFC
 (
	IF (.NOT.NEWS_WRITE(' ')) GO TO 900
  
	IER1 = 0)
	DO WHILE (IER1.EQ.0)N
	   READ (3,'(Q,A)',IOSTAT=IER1) ILEN,BUFFER
	   IF (BUFFER(:ILEN).EQ.'.') THEN
	      BUFFER = '..'
	      ILEN = 2(
	   END IF
	   IF (IER1.EQ.0.AND..NOT.NEWS_WRITE(BUFFER(:ILEN))) GO TO 900I
	END DOE
 E
	IF (.NOT.NEWS_WRITE('.')) GO TO 900
	IF (.NOT.NEWS_READ()) GO TO 900
	IF (BUFFER(:3).EQ.'240') IER = 0'
 .
900	IF (FILENAME.NE.'cancel'.AND..NOT.FILEOPEN) CLOSE (UNIT=3)
 )
	RETURNE
	END
 T
  
 I
	SUBROUTINE GET_PATHNAME
  
	IMPLICIT INTEGER (A-Z)=
 
	INCLUDE 'BULLUSER.INC'E
 I
	COMMON /PATH/ PATHNAME,LPATHE
	CHARACTER*132 PATHNAME 
  
	IF (NEWS_GETHOSTNAME(PATHNAME).EQ.-1) THEN.
	   IF (.NOT.SYS_TRNLNM_SYSTEM('ARPANET_HOST_NAME',PATHNAME).AND.
     &	    .NOT.SYS_TRNLNM_SYSTEM('INTERNET_HOST_NAME',PATHNAME).AND.P
     &	    .NOT.SYS_TRNLNM_SYSTEM('MX_NODE_NAME',PATHNAME)) THEN
	      WRITE (6,'('' ERROR: Cannot find local host name.'')')E
	      RETURNU
	   END IF
	END IFS
	   
	PATHNAME = PATHNAME(:TRIM(PATHNAME))//'!'
     &			//USERNAME(:TRIM(USERNAME))
	CALL LOWERCASE(PATHNAME)H
	LPATH = TRIM(PATHNAME)
 
	RETURND
	END
 D
 '
 B
 S
	SUBROUTINE NEWS2BULLE
 Y
	IMPLICIT INTEGER (A-Z) 
 R
	INCLUDE 'BULLFOLDER.INC'E
 =
	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD
  
	COMMON /BUFFER/ BUFFER,SB,EBN
	CHARACTER BUFFER*1280
 
	EXTERNAL BULLETIN_SUBCOMMANDS
 N
	CHARACTER TIME*20,FIRST*80,FOLDER_SAVE*25
 D
	CHARACTER*6 NUMBERR
 D
	DIMENSION SAVE_F_NEWEST_BTIM(2)
 )
	CALL ALLPRIVL
 =
	CALL NEWS_LIST)
 '
	CALL INIT_QUEUE(FOLDER_Q1,FOLDER_COM)
 ,
	FOLDER_Q = FOLDER_Q1E
 E
	CALL OPEN_BULLFOLDER_SHARED		! Get folder fileT
 (
	NUM_FOLDERS = 0
	IER = 0
	DO WHILE (IER.EQ.0)			! Find folders with news feed
	   CALL READ_FOLDER_FILE(IER)
	   IF (IER.EQ.0) THEN
	      SLIST = INDEX(FOLDER_DESCRIP,'<')
	      IF (SLIST.GT.0) THEN
		 IF ((INDEX(FOLDER_DESCRIP,'@').LE.SLIST.OR.
     &		      FOLDER_DESCRIP(SLIST+1:SLIST+1).EQ.'@').AND.
     &		     INDEX(FOLDER_DESCRIP,'.').GT.SLIST) THEN.
		    NUM_FOLDERS = NUM_FOLDERS + 1D
	   	    CALL WRITE_QUEUE(%VAL(FOLDER_Q),FOLDER_Q,FOLDER_COM)F
	         END IF
	      END IFI
	   END IF
	END DO 
  
	CALL CLOSE_BULLFOLDER			! We don't need file anymoreC
 E
	IF (NUM_FOLDERS.EQ.0.OR..NOT.NEWS_LOGIN()) CALL EXITT
 R
	FOLDER_Q = FOLDER_Q1	
	POINT_FOLDER = 0_
	FILEOPEN = .FALSE.1
	DO WHILE (POINT_FOLDER.LT.NUM_FOLDERS)B
	   IF (.NOT.FILEOPEN) THENE
	      POINT_FOLDER = POINT_FOLDER + 1
	      CALL READ_QUEUE(%VAL(FOLDER_Q),FOLDER_Q,FOLDER_COM)
	      CALL SELECT_FOLDER(.FALSE.,IER)
	      SAVE_F_NEWEST_BTIM(1) = F_NEWEST_BTIM(1)(
	      SAVE_F_NEWEST_BTIM(2) = F_NEWEST_BTIM(2)T
	      FOLDER_SAVE = FOLDERH
	      FOLDER_DESCRIP = FOLDER_DESCRIP(INDEX(FOLDER_DESCRIP,'<')+1:)
	      FOLDER_DESCRIP = FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,'>')-1)
	      IF (FOLDER_DESCRIP(1:1).EQ.'@'.AND.IER) THEND
	         OPEN (UNIT=3,FILE=FOLDER_DESCRIP(2:TRIM(FOLDER_DESCRIP))
     &			,STATUS='OLD',IOSTAT=IER1)W
		 IF (IER1.EQ.0) THEN
	            READ (3,'(A)',IOSTAT=IER1) FOLDER_DESCRIP
		    IF (IER1.NE.0) CLOSE (UNIT=3)O
	            IF (IER1.EQ.0) FILEOPEN = .TRUE.D
		 END IFN
	      ELSE(
	         IER1 = 0
	      END IF.
	   END IF
	   IF (IER.AND.IER1.EQ.0) THENP
	      FOLDER_NUMBER = -1A
	      FOLDER1 = FOLDER_DESCRIP(:TRIM(FOLDER_DESCRIP))
	      CALL SELECT_FOLDER(.FALSE.,IER)
	      IF (IER) THEN
	         CALL REMOTE_GET_NEWEST_MSG(SAVE_F_NEWEST_BTIM,START)
		 IF (START.GE.F_START) THEN
	            CALL OTS$CVT_L_TI(START,NUMBER,,,)F
	            INCMD = 'COPY/ORIGINAL '//FOLDER_SAVE(:TRIM(E
     &			FOLDER_SAVE))//' '//NUMBER//'-LAST'
	            CALL CLI$DCL_PARSE(INCMD,BULLETIN_SUBCOMMANDS)C
		    CALL MOVE(.FALSE.)
	         END IF
	      END IFO
	      IF (FILEOPEN) THENA
	         READ (3,'(A)',IOSTAT=IER1) FOLDER_DESCRIPO
		 IF (IER1.NE.0) CLOSE (UNIT=3)
	         IF (IER1.NE.0) FILEOPEN = .FALSE.O
	      END IFA
	   END IF
	END DOJ
 R
	CALL EXIT
	END
 Y
 ,
 I
	SUBROUTINE DATE_TIME(TIME)D
 N
	IMPLICIT INTEGER (A-Z)I
 =
	CHARACTER*36 MONTH.
	DATA MONTH/'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'/ 
 O
	CHARACTER*(*) TIMEN
 ,
	NMONTH = (INDEX(MONTH,TIME(4:6))+2)/3
 .
	IF (TIME(1:1).EQ.' ') TIME(1:1) = '0'
 
	TIME = TIME(10:11)//CHAR(ICHAR('0')+NMONTH/10)//CHAR(ICHAR('0')+
     &		 MOD(NMONTH,10))//TIME(1:2)//' '//TIME(13:14)//.
     &		 TIME(16:17)//TIME(19:20) 
 I
	RETURN3
	END
 I
 
 
	SUBROUTINE ALLPRIV)
 O
        IMPLICIT INTEGER (A-Z)
  
	COMMON /PRIVILEGES/ PROCPRIV(2),NEEDPRIV(2)
 O
	PROCPRIV(1) = -1.
	PROCPRIV(2) = -19
	NEEDPRIV(1) = -1.
	NEEDPRIV(2) = -1 
 T
	RETURN 
	END
 s
 g
 t
	SUBROUTINE NEWS_NEW_FOLDERC
 E
	IMPLICIT INTEGER (A-Z)E
 E
	INCLUDE 'BULLFOLDER.INC'G
 P
	READ (7,IOSTAT=IER,KEYEQ=1000,KEYID=1) NEWS_FOLDER_COMw
 o
	NEWS_FOLDER1 = FOLDER1L
	NEWS_FOLDER1_DESCRIP = FOLDER1_DESCRIP(26:)
 w
        DO WHILE (IER.EQ.0)
	   READ (7,IOSTAT=IER,KEYEQ=NEWS_F_END,KEYID=1)
	   IF (IER.EQ.0) NEWS_F_END = NEWS_F_END + 1'
        END DO
 C
        NEWS_FOLDER1_NUMBER = NEWS_F_END
	CALL SYS_BINTIM('-',NEWS_F1_NEWEST_BTIM)C
        WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM&
 .
	READ (7,KEYEQ=1000,KEYID=1) NEWS_FOLDER1_COM 
	NEWS_F1_END = NEWS_F_END)
	REWRITE (7) NEWS_FOLDER1_COME
 M
	RETURN 
	END
 O
 R
 A
	SUBROUTINE SUBSCRIBE 
 (
	IMPLICIT INTEGER (A-Z)S
 R
	INCLUDE 'BULLUSER.INC''
 /
	INCLUDE 'BULLFOLDER.INC'N
 )
	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 I
	IF (REMOTE_SET.NE.3) THEN
	   WRITE (6,'('' ERROR: Selected folder is not a news folder.'')')E
	   RETURN
	END IFT
 M
	I = 1
	DO WHILE (LAST_NEWS_READ2(1,I).NE.NEWS_FOLDER_NUMBER.AND.
     &		LAST_NEWS_READ2(1,I).NE.0.AND.I.LE.FOLDER_MAX)
	   I = I + 1H
	END DO-
 )
	IF (I.GT.FOLDER_MAX) THEN
	   WRITE (6,'('' ERROR: Cannot subscribe.  You have '',
     &		    '' reached the news folder limit of '',I,''.'')') 
     &		    FOLDER_MAX
	   RETURN
	ELSE IF (LAST_NEWS_READ2(1,I).EQ.NEWS_FOLDER_NUMBER) THEN
	   WRITE (6,'('' You are already subscribed to '',A,''.'')')F
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	   RETURN
	ELSE=
	   WRITE (6,'('' You are now subscribed to '',A,''.'')')D
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	END IFZ
 (
	LAST_NEWS_READ2(1,I) = NEWS_FOLDER_NUMBER
	IF (F_START.LE.F_NBULL) THENF
	   LAST_NEWS_READ2(2,I) = MIN(8191,F_NBULL-(F_START-1))
	   LAST_NEWS_READ(2,I) = F_START - 1 
	ELSES
	   LAST_NEWS_READ2(2,I) = 0
	   LAST_NEWS_READ(2,I) = F_NBULLN
	END IF/
 E
	RETURNN
	END
 '
 T
 
	SUBROUTINE UNSUBSCRIBEO
 
	IMPLICIT INTEGER (A-Z) 
  
	INCLUDE 'BULLUSER.INC'T
 T
	INCLUDE 'BULLFOLDER.INC' 
  
	I = NEWS_FIND_SUBSCRIBE()
  
	IF (I.GT.FOLDER_MAX) THEN
	   WRITE (6,'('' ERROR: You are not subscribed to '',A,''.'')')
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	   RETURN
	ELSEN
	   WRITE (6,'('' You are now no longer subscribed to '',A,''.'')')
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	END IF
 G
	DO J=I,FOLDER_MAX-1
	   LAST_NEWS_READ(1,J) = LAST_NEWS_READ(1,J+1)/
	   LAST_NEWS_READ(2,J) = LAST_NEWS_READ(2,J+1)G
	END DOQ
 '
	LAST_NEWS_READ(1,FOLDER_MAX) = 0S
	LAST_NEWS_READ(2,FOLDER_MAX) = 0(
 I
	RETURN 
	END
 '
 /
 H
	SUBROUTINE NEWS_GET_NEWEST_MESSAGE(IER)
 L
	IMPLICIT INTEGER (A-Z)/
 /
	INCLUDE 'BULLUSER.INC'0
 )
	INCLUDE 'BULLFOLDER.INC'O
  
	I = NEWS_FIND_SUBSCRIBE()
 Q
	IER = LAST_NEWS_READ(2,I) + 1
 N
	IF (I.GT.FOLDER_MAX.OR.IER.GT.F_NBULL) THEN
	   IER = 0M
	   RETURN
	END IFI
 ,
	RETURNI
	END
  
  
 
	SUBROUTINE NEWS_UPDATE_NEWEST_MESSAGE(NUMBER)
  
	IMPLICIT INTEGER (A-Z)F
 N
	INCLUDE 'BULLUSER.INC'o
 '
	INCLUDE 'BULLFOLDER.INC'
  
	I = NEWS_FIND_SUBSCRIBE()
 I
	IF (I.GT.FOLDER_MAX) RETURN
 Y
	IF (NUMBER.GT.LAST_NEWS_READ(2,I)) THEN
	   LAST_NEWS_READ(2,I) = NUMBER
	   LAST_NEWS_READ2(2,I) = MIN(8191,F_NBULL-NUMBER) 
     &			.OR.(LAST_NEWS_READ2(2,I).AND.'C000'X))
	END IF
  
	RETURNN
	END
 (
 )
 E
 N
  
	SUBROUTINE NEWS_GET_SUBSCRIBE(SUBNUM,SUBMSG):
 E
	IMPLICIT INTEGER (A-Z)U
 
	INCLUDE 'BULLUSER.INC'E
 W
	IF (SUBNUM.EQ.0) THEN
	   COUNT = 0D
	   SUBMSG = LAST_NEWS_READ(2,1)
	   RETURN
	ELSE IF (SUBNUM.EQ.-1) THEN
	   DO J=COUNT,FOLDER_MAX-1 
	      LAST_NEWS_READ(1,J) = LAST_NEWS_READ(1,J+1)
	      LAST_NEWS_READ(2,J) = LAST_NEWS_READ(2,J+1)
	   END DO
 D
	   LAST_NEWS_READ(1,FOLDER_MAX) = 0
	   LAST_NEWS_READ(2,FOLDER_MAX) = 0
	ELSEI
	   COUNT = COUNT + 1 
	END IF
 
	IF (COUNT.LE.FOLDER_MAX) THEN
	   SUBNUM = LAST_NEWS_READ2(1,COUNT)T
	   SUBMSG = LAST_NEWS_READ(2,COUNT)
	ELSEA
	   SUBNUM = 0
	END IF 
 Z
	RETURNI
	END
 U
 S
 I
 E
	SUBROUTINE NEWS_NEW_NOTIFICATION(MESSAGES)T
C1
C  SUBROUTINE NEW_NOTIFICATION
CN
 (
	IMPLICIT INTEGER (A-Z) 
 F
	INCLUDE 'BULLFOLDER.INC'R
 E
	INCLUDE 'BULLUSER.INC'D
 
	COMMON /READIT/ READITM
 S
	COMMON /POINT/ BULL_POINT
 M
	COMMON /LOGIN_BTIM/ LOGIN_BTIM_SAVE(2)E
 M
	MESSAGES = .FALSE.)
 H
	IF (.NOT.SYS_TRNLNM('BULL_NEWS_SERVER','DEFINED')) RETURN
 '
	CALL NEWS_GET_SUBSCRIBE(0,MSGNUM)
	IF (MSGNUM.EQ.0) RETURN
 A
	CALL OPEN_BULLNEWS_SHARED
	SUBNUM = 1N
 (
	DO WHILE (SUBNUM.GT.0)O
	   IER = 1A
	   DO WHILE (SUBNUM.NE.0.AND.IER.NE.0)R
	      CALL NEWS_GET_SUBSCRIBE(SUBNUM,MSGNUM)E
	      IF (SUBNUM.NE.0) THEN
	         CALL READ_FOLDER_FILE_KEYNUM(SUBNUM,IER)
		 IF (IER.EQ.0.AND.
     &			MSGNUM.GT.F_NBULL.AND.F_START.LE.F_NBULL) THENA
		    CALL NEWS_UPDATE_NEWEST_MESSAGE(F_START)
	         ELSE IF (IER.NE.0) THEN8
		    SUBNUM = -1D
		 ELSE IF (MSGNUM.GE.F_NBULL.OR.F_NBULL.EQ.0) THENB
		    IER = 1L
		 END IF
	      END IFL
	      IF (IER.EQ.0.AND.SUBNUM.GT.0) THEN_
		 IF (READIT.EQ.1) THEN
		    IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER).AND.l
     &		        .NOT.TEST_SET_FLAG(NEWS_FOLDER_NUMBER)) THEN
		       IER = 1
		    ELSE IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER).OR.H
     &			.NOT.TEST_SET_FLAG(NEWS_FOLDER_NUMBER).OR.I
     &			NEW_FLAG(2).NE.-1) THEN
	               DIFF = COMPARE_BTIM(LOGIN_BTIM_SAVE,F_NEWEST_BTIM)
		       IF (DIFF.GT.0) IER = 1&
		    END IF
		 END IFI
	      END IF)
	   END DO
	   IF (READIT.EQ.0.AND.SUBNUM.GT.0) THENC
	      WRITE (6,'('' There are new messages in folder '', 
     &		     A,''.'',$)') FOLDER_DESCRIP(1:TRIM(FOLDER_DESCRIP))
	      MESSAGES = .TRUE.
	   ELSE IF (SUBNUM.GT.0) THEN
	      IF (TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER)
     &		  .AND.TEST_SET_FLAG(NEWS_FOLDER_NUMBER)) THEN
		 WRITE (6,'('' There are new messages in folder ''
     &		     A,''.'',$)') FOLDER_DESCRIP(1:TRIM(FOLDER_DESCRIP))
	      ELSEL
		 CALL CLOSE_BULLNEWS
	         CALL SELECT_FOLDER(.FALSE.,IER1)
		 IF (IER1) THEN)
		    CALL LOGIN_FOLDERI
	            IF (BULL_POINT.NE.-1) THENE
		     IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER)) THENE
		       SAVE_BULL_POINT = BULL_POINTR
		       REDO = .TRUE.
		       DO WHILE (REDO)
		          REDO = .FALSE.
		          CALL READNEW(REDO)
			  IF (REDO) CALL REDISPLAY_DIRECTORYT
			  BULL_POINT = SAVE_BULL_POINTO
		       END DOI
		     END IFP
		    END IF
		 END IF'
		 CALL OPEN_BULLNEWS_SHARED
	      END IF 
	   END IF
	END DOI
 A
	CALL CLOSE_BULLNEWS
 	
	RETURNE
	END
 C
 E
 N
	LOGICAL FUNCTION TEST_SET_FLAG(NUMBER)P
 =
	IMPLICIT INTEGER (A-Z) 
 E
	INCLUDE 'BULLUSER.INC'
  
	IF (NUMBER.GE.0.AND.NUMBER.LE.FOLDER_MAX) THEN)
	   TEST_SET_FLAG = TEST2(SET_FLAG,NUMBER)
	   RETURN
	END IFI
 T
	I = NEWS_FIND_SUBSCRIBE()
 L
	TEST_SET_FLAG = BTEST(LAST_NEWS_READ2(2,I),14)N
  
	RETURNA
	END
 _
 _
 E
 M
	LOGICAL FUNCTION TEST_BRIEF_FLAG(NUMBER)G
 _
	IMPLICIT INTEGER (A-Z) 
 L
	INCLUDE 'BULLUSER.INC'E
 ,
	IF (NUMBER.GE.0.AND.NUMBER.LE.FOLDER_MAX) THEN_
	   TEST_BRIEF_FLAG = TEST2(BRIEF_FLAG,NUMBER)
	   RETURN
	END IF 
 C
	I = NEWS_FIND_SUBSCRIBE()
 N
	TEST_BRIEF_FLAG = BTEST(LAST_NEWS_READ2(2,I),15) 
  
	RETURN 
	END
 
  
 I
	INTEGER FUNCTION NEWS_FIND_SUBSCRIBE())
 O
	IMPLICIT INTEGER (A-Z)O
 	
	INCLUDE 'BULLUSER.INC'I
 )
	INCLUDE 'BULLFOLDER.INC'F
 O
	I = 1
	DO WHILE (LAST_NEWS_READ2(1,I).NE.NEWS_FOLDER_NUMBER 
     &					.AND.I.LE.FOLDER_MAX)
	   I = I + 1E
	END DOI
 I
	NEWS_FIND_SUBSCRIBE = I
 A
	RETURNO
	END
 T
 O
 /
 N
	SUBROUTINE NEWS_SET_USER_FLAG(NOTIFY,READNEW,BRIEF)
 T
	IMPLICIT INTEGER (A-Z)X
 N
	INCLUDE 'BULLUSER.INC'I
 T
	I = NEWS_FIND_SUBSCRIBE()
 '
	IF (I.GT.FOLDER_MAX) THEN
	   WRITE (6,'('' ERROR: NEWS FOLDER is not subscribed.'')')
	   RETURN
	END IF'
 /
	IF (NOTIFY.EQ.1) THEN
	   WRITE (6,'('' ERROR: NOTIFY cannot be set for news folder.'')')N
	   RETURN
	END IF 
 M
	IF (READNEW.EQ.1) LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),14)
	IF (READNEW.EQ.0) LAST_NEWS_READ2(2,I) = IBCLR(LAST_NEWS_READ2(2,I),14)
	IF (BRIEF.EQ.1) LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),15)
	IF (BRIEF.EQ.0) LAST_NEWS_READ2(2,I) = IBCLR(LAST_NEWS_READ2(2,I),15)
	S
	RETURNE
	END
