C
C  BULLETIN10.FOR, Version 12/28/92
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
C  Programmer: Mark R. London
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.257.OR.
     &	       (END_LINE.EQ.0.AND.END_READ-START_READ.GE.254)) THEN
	      END_LINE = 255
	   END IF
	   IF (END_LINE.GT.0) THEN
	      SB = START_READ
	      END_LINE = END_LINE + SB - 1
	      EB = END_LINE - 2
	      IF (BUFFER(EB+2:EB+2).NE.LF) EB = EB + 2
	      IF (END_LINE.LT.END_READ) THEN
		 START_READ = END_LINE + 1
	      ELSE
		 END_READ = 0
	      END IF
	      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)

	INCLUDE 'BULLDIR.INC'

	PARAMETER CR = CHAR(13), LF = CHAR(10)

	COMMON /NEWS_INIT/ END_READ

        COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
 
        COMMON /LOCALPOST/ LOCAL_POST

	CHARACTER*(*) WRITE

	LOGICAL TRY_RECONNECT/.FALSE./

	IF (LOCAL_POST) THEN
	   WRITE (8,'(A)') WRITE
	   DO I=1,LEN(INPUT),255
	      CALL COMPRESS(WRITE,INPUT,L)
	      LENGTH = LENGTH + MAX(1,L) + 1
	   END DO
	   NEWS_WRITE = .TRUE.
	   RETURN
	END IF

	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*8 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 'BULLUSER.INC'

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	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.GE.3) THEN
	   IF (TEST_NEWS_OWNER()) THEN
	      CALL NEWS_POST('cancel',0,IER,'Delete news item.')
	   ELSE IF (REMOTE_SET.EQ.3) THEN
	      WRITE (6,'('' ERROR: Not owner of message.'')')
	   END IF
	   IER = 0
	END IF

	RETURN
	END




	LOGICAL FUNCTION TEST_NEWS_OWNER()

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'

	COMMON /PATH/ PATHNAME,LPATH
	CHARACTER*132 PATHNAME

	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*256 MESSAGE_ID

	CHARACTER*12 HIGHFROM

	CALL STR$UPCASE(HIGHFROM,FROM)
	IF (LPATH.EQ.0) CALL GET_PATHNAME
	TEST_NEWS_OWNER = FROM.EQ.USERNAME.OR.
     &	    (HIGHFROM.EQ.USERNAME.AND.
     &	    MESSAGE_ID(FIRST_INDEX(MESSAGE_ID,'@%'):
     &	    TRIM(MESSAGE_ID)).EQ.
     &	    PATHNAME(FIRST_INDEX(PATHNAME,'@%'):LPATH))

	RETURN
	END


	INTEGER FUNCTION FIRST_INDEX(INPUT,FIND)

	IMPLICIT INTEGER (A-Z)

	CHARACTER*(*) INPUT,FIND

	FIRST_INDEX = 0

	DO I=1,LEN(FIND)
	   J = INDEX(INPUT,FIND(I:I))
	   IF (J.GT.0.AND.(FIRST_INDEX.EQ.0.OR.J.LT.FIRST_INDEX))
     &		FIRST_INDEX = J
	END DO

	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*8 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_WRITEt
     &		('XHDR SUBJECT '//NUMBER//'-'//NUMBER1)) RETURNM
	      IF (I.EQ.2.AND..NOT.NEWS_WRITEE
     &		('XHDR FROM '//NUMBER//'-'//NUMBER1)) RETURN
	      IF (.NOT.NEWS_READ()) RETURN*
	      IF (BUFFER(:2).EQ.'22') THEN=
		 QXHDR = QXHDR1O
		 IF (.NOT.NEWS_READ()) RETURNE
		 NUMDIR1 = 0
		 DO WHILE (BUFFER(SB:EB).NE.'.'.AND.NUMDIR1.LT.NUMDIR)
		    NUMDIR1 = NUMDIR1 + 1
		    CALL READ_QUEUE(%VAL(QXHDR),DUMMY,TEMP)
		    SB1 = INDEX(BUFFER(SB:EB),' ')+SB-1=
		    SB1 = FIRST_ALPHA(BUFFER(SB1:EB))+SB1-1A
		    TEMP(I*256+1:) = BUFFER(SB1:EB)E
		    CALL WRITE_QUEUE(%VAL(QXHDR),QXHDR,TEMP)
		    IF (.NOT.NEWS_READ()) RETURN
		 END DO(
	      END IF.
	   END DO
	   QXHDR = QXHDR1
	   IER = 0A
	ELSE IF (REMOTE_SET.EQ.3.AND..NOT.XHDR) THEN5
	   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()) RETURN1
	      IF (.NOT.OTS$CVT_TI_L(BUFFER(SB+4:D
     &		  INDEX(BUFFER(SB+4:),' ')+SB+2),I,,%VAL(1))) RETURN
	      IF (BUFFER(:2).NE.'22'.OR.I.LT.START) THENR
		 BUFFER(:3) = '500'N
		 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') THENI
		    IER = 0I
		    END = START - 1C
		    RETURN
		 END IFR
	      END IFR
	      IF (.NOT.NEWS_WRITE('HEAD')) RETURN
	      IF (.NOT.NEWS_READ()) RETURNL
	      IER = OTS$CVT_TI_L(BUFFER(SB+4:
     &			INDEX(BUFFER(SB+4:),' ')+SB+2),START,,%VAL(1))
	      END = START + NUMDIR - 1
	   END IF
	   IER = 0
	END IFT

	IF (IER.EQ.0) THEN 
	   I = STARTT
	   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))I
		 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))) 
	      ELSE 
		 IER = OTS$CVT_TI_L(BUFFER(SB+4:
     &			INDEX(BUFFER(SB+4:),' ')+SB+2),MSG_NUM,,%VAL(1)) 
		 CALL NEWS_HEADER(IER)
		 IF (IER.NE.0) RETURNM
	      END IFL
	      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) THENN
		 IER = 2
		 IF (.NOT.NEWS_WRITE('NEXT')) RETURN
		 IF (.NOT.NEWS_READ()) RETURNO
		 IF (BUFFER(:3).NE.'223') THEN
		    END = I - 1 
		    IER = 0P
		    RETURN
		 END IF)
		 IF (.NOT.NEWS_WRITE('HEAD')) RETURN
		 IF (.NOT.NEWS_READ()) RETURNT
		 IER = 0
	      END IFN
	   END DO
	END IF 

	IF (REMOTE_SET.EQ.3) THEN
	   IER = 1U
	   IF (.NOT.OTS$CVT_L_TI(BULL_POINT,NUMBER,,,)) RETURNO
	   IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURN
	   IF (.NOT.NEWS_READ()) RETURN
	   IER = 0E
	END IF

	RETURNN
	END



	INTEGER FUNCTION NEWS_LOGIN

	IMPLICIT INTEGER (A-Z)C

	COMMON /NEWS_CONNECTED/ NEWS_CONNECTEDB
	LOGICAL NEWS_CONNECTED /.FALSE./T

	COMMON /XHDR/ XHDRR
	LOGICAL XHDR /.FALSE./A

	COMMON /BUFFER/ BUFFER,SB,EB
	CHARACTER BUFFER*1280

	IF (.NOT.NEWS_CONNECTED) THEN
	   NEWS_LOGIN = .FALSE.
	   CALL START_NEWS_TIMER()N
	   NEWS_CONNECTED = NEWS_CONNECT()=
	   CALL CANCEL_NEWS_TIMER()
	   IF (.NOT.NEWS_CONNECTED) RETURN 
	   IF (.NOT.NEWS_READ()) RETURN
	   IF (.NOT.NEWS_WRITE('XHDR')) RETURNF
	   IF (.NOT.NEWS_READ()) RETURN
	   XHDR = BUFFER(:3).NE.'500'
	END IFS

	NEWS_LOGIN = .TRUE.

	RETURNt
	END


	SUBROUTINE CONVERT_TO_GMT(BTIM)

	IMPLICIT INTEGER (A-Z) 

	DIMENSION GMT_DIFF(2),BTIM(2)

	CHARACTER HOUR*4E
	DATA HOUR /' '/

	PARAMETER NZONES = 4F

	COMMON /ZONE/ ZONE,LZONE

	CHARACTER ZONES*(NZONES*4)C
	CHARACTER*4 HOURS(NZONES),ZONEU
	DATA ZONES /'EST CST MST PST '/
	DATA HOURS /'5','6','7','8'/T

	TO_GMT = .TRUE.

	ENTRY CONVERT_FROM_GMT(BTIM)M

	IF (HOUR.EQ.' ') THEN
	   IF (SYS_TRNLNM_SYSTEM('LISP$TIME_ZONE',HOUR)) THEN
	      ZONE = 'GMT'H
	   ELSE IF (SYS_TRNLNM_SYSTEM('MULTINET_TIMEZONE',ZONE)
     &	       .OR.SYS_TRNLNM_SYSTEM('PMDF_TIMEZONE',ZONE)) THENE
	      HOUR = HOURS((INDEX(ZONES,ZONE)+3)/4)
	   ELSE
	      ZONE = 'GMT'_
	      HOUR = '00'
	   END IF
	   IER = OTS$CVT_TI_L(HOUR(:TRIM(HOUR)),DIFF,,%VAL(1))I
	   IF (DIFF.LT.0) THEN 
	      PAST = .TRUE.
	      HOUR = HOUR(2:)
	   ELSE IF (DIFF.GT.12) THEN
	      PAST = .TRUE.
	      DIFF = 24 - DIFF0
	      IER = OTS$CVT_L_TI(DIFF,HOUR(:2),,,)
	      IF (HOUR(:1).EQ.' ') HOUR = HOUR(2:)
	   ELSE
	      PAST = .FALSE.D
	   END IF
	   LZONE = TRIM(ZONE)
	   IER = SYS_BINTIM('0 '//HOUR(:TRIM(HOUR))//':00',GMT_DIFF)N
	END IFC

	IF ((PAST.AND..NOT.TO_GMT).OR.(.NOT.PAST.AND.TO_GMT)) THENA
	   IER = LIB$SUBX(BTIM,GMT_DIFF,BTIM)
	ELSEO
	   IER = LIB$ADDX(BTIM,GMT_DIFF,BTIM)
	END IFC

	TO_GMT = .FALSE.

	RETURNI
	END




	SUBROUTINE START_NEWS_TIMER()

	IMPLICIT INTEGER (A-Z)

	INTEGER TIMADR(2)			! Buffer containing timeD
						! in desired system format. 
	CHARACTER TIMBUF*16,SEC*4
	DATA TIMBUF/'0 00:00:00.00'/L

	EXTERNAL KILL_NEWS_CONNECT

	IF (TIMBUF(9:10).EQ.'00') THEN
	   CALL LIB$GET_EF(WAITEFN)
	   TIMBUF(9:10) = '30'F
	   IF (SYS_TRNLNM('BULL_NEWS_TIMER',SEC)) THEN1
	      IER = OTS$CVT_TI_L(SEC(:TRIM(SEC)),I,,%VAL(1))T
	      IF (IER.AND.I.GT.0) THEN
		 IF (TRIM(SEC).EQ.1) THEN_
		    TIMBUF(9:10) = '0'//SEC(:1)D
		 ELSE 
		    TIMBUF(9:10) = SEC
		 END IF=
	      END IF1
	   END IF
	   IER = SYS$BINTIM(TIMBUF(:13),TIMADR)
	END IF 

	IER = SYS$SETIMR(%VAL(WAITEFN),TIMADR,KILL_NEWS_CONNECT,)

	RETURNA

	ENTRY CANCEL_NEWS_TIMER()

	IER = SYS$CANCEL(%VAL(WAITEFN))

	RETURNN
	END


	SUBROUTINE KILL_NEWS_CONNECT() 

	IMPLICIT INTEGER (A-Z).

	COMMON /NEWS_CONNECTED/ NEWS_CONNECTED 

	IF (NEWS_CONNECTED) RETURNI

	NLUN = NEWS_GET_CHAN() 

	IER = SYS$CANCEL(%VAL(NLUN)) 

	CALL NEWS_DISCONNECT()

	RETURN	
	END



	SUBROUTINE NEWS_HEADER(IER)

	IMPLICIT INTEGER (A-Z).

	INCLUDE 'BULLDIR.INC'

	COMMON /BUFFER/ BUFFER,SB,EB
	CHARACTER BUFFER*1280

	COMMON /REF/ REFERENCES,LREFD
	CHARACTER*256 REFERENCES 

	COMMON /NEWSGROUPS/ NEWSGROUPS)
	CHARACTER*256 NEWSGROUPS.

	COMMON /HEADER_INFO/ MSGNUM,SUBJECT_LINE,FROM_LINEV
	CHARACTER*256 FROM_LINE,SUBJECT_LINE'
	CHARACTER*12 MSGNUM

	EX_BTIM(1) = 0E
	EX_BTIM(2) = 0 

	DESCRIP = ' '
	FROM = ' 'F
	SUBJECT_LINE = ' 'T
	FROM_LINE = ' '
	NEWSGROUPS = ' '
	LREF = 0M

	MSGNUM = BUFFER(5:INDEX(BUFFER(5:),' ')-1+4)L

	DO WHILE (BUFFER(SB:EB).NE.'.')
	   IER = NEWS_READ()D
	   IF (.NOT.IER) RETURN
	   IF (BUFFER(SB:EB).NE.'.') THEN
	      IF (BUFFER(SB:SB+7).EQ.'Subject:'.AND.EB.GE.SB+9) THENR
		 SB1 = FIRST_ALPHA(BUFFER(SB+9:EB))+SB+8
		 SUBJECT_LINE = 'Subj: '//BUFFER(SB1:EB)
		 DESCRIP = BUFFER(SB1:EB)(
	      ELSE IF (BUFFER(SB:SB+4).EQ.'Date:'.AND.EB.GE.SB+6) THEN	
		 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) THENW
		 SB1 = FIRST_ALPHA(BUFFER(SB+6:EB))+SB+5
		 FROM_LINE = 'From: '//BUFFER(SB1:EB).
		 CALL GET_FROM(BUFFER(SB1:EB),EB-SB1+1) 
              ELSE IF (BUFFER(SB:SB+10).EQ.'Message-ID:'.AND.S
     &                                              EB.GT.SB+11) THEN(
                 NEWS_MSGID = BUFFER(SB+13:EB-1)
		 IF (LREF.EQ.0) THEN
		    REFERENCES = BUFFER(SB+12:EB)
		 ELSE 
		    REFERENCES = REFERENCES(:LREF)//' '//
     &				BUFFER(SB+12:EB)
		 END IFN
		 LREF = TRIM(REFERENCES)
	      ELSE IF (BUFFER(SB:SB+10).EQ.'Newsgroups:'.AND.
     &						    EB.GT.SB+11) THENF
		 SB1 = FIRST_ALPHA(BUFFER(SB+12:EB))+SB+11
		 NEWSGROUPS = BUFFER(SB1:EB)
	      ELSE IF (BUFFER(SB:SB+10).EQ.'References:'.AND.
     &						    EB.GT.SB+11) THEN 
		 IF (LREF.EQ.0) THEN
		    REFERENCES = BUFFER(SB+12:EB)/
		 ELSE-
	            REFERENCES = BUFFER(SB+12:EB)//' '//W
     &				REFERENCES(:LREF) 
	   	 END IF
	         LREF = TRIM(REFERENCES).
	      END IFT
	   END IF
	END DOE

	IER = 0

	RETURN	
	END



	INTEGER FUNCTION FIRST_ALPHA(INPUT)

	CHARACTER*(*) INPUT

	DO I=1,LEN(INPUT)
	   IF (ICHAR(INPUT(I:I)).LT.32) INPUT(I:I) = ' 'R
	END DO	

	DO FIRST_ALPHA=1,LEN(INPUT)
	   IF (ICHAR(INPUT(FIRST_ALPHA:FIRST_ALPHA)).GT.32) RETURN 
	END DOI

	RETURNU
	END




	SUBROUTINE REMOTE_READ_MESSAGE(BULL_SEARCH,IER)

	IMPLICIT INTEGER (A-Z)X

	INCLUDE 'BULLFOLDER.INC'N

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /BUFFER/ BUFFER,SB,EB
	CHARACTER BUFFER*1280

	CHARACTER*8 NUMBERT

	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 5,BULL_SEARCHT
	ELSE 
	   IER = 2E
	   IF (BULL_SEARCH.LT.F_START) BULL_SEARCH = F_START:
	   IF (.NOT.OTS$CVT_L_TI(BULL_SEARCH,NUMBER,,,)) RETURN
	   IF (.NOT.NEWS_WRITE('ARTICLE '//NUMBER)) RETURN.
	   IF (.NOT.NEWS_READ()) RETURN
	   IF (BUFFER(:2).NE.'22') RETURN
	   IER = 0)
	END IF

	RETURNB
	END



	SUBROUTINE REMOTE_GET_NEWEST_MSG(IN_BTIM,START)

	IMPLICIT INTEGER (A-Z)B

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'	

	COMMON /READIT/ READITT

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /BUFFER/ BUFFER,SB,EBF
	CHARACTER BUFFER*1280

	DIMENSION IN_BTIM(2)F

	CHARACTER TIME*20,FIRST*80E

	CHARACTER*8 NUMBERR

	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) THENT
	   I = NEWS_FIND_SUBSCRIBE()A
	   START = (LAST_NEWS_READ2(2,I).AND.'3FFF'X) +
     &			LAST_NEWS_READ(2,I) + 1
	   IF (START.GT.F_NBULL) THEN
	      START = -1 
	   ELSE
	      LAST_NEWS_READ2(2,I) = MIN(8191,F_NBULL-LAST_NEWS_READ(2,I))R
     &			.OR.(LAST_NEWS_READ2(2,I).AND.'C000'X)E
	   END IF
	ELSET
	   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)) RETURNP
	      IF (.NOT.NEWS_READ()) RETURNO
	      IF (BUFFER(:2).EQ.'23') THEND
		 IF (.NOT.NEWS_READ()) CALL EXIT
		 DO I=1,SKIP
		    IF (.NOT.NEWS_READ()) CALL EXITR
		 END DO 
		 FIRST = BUFFER(SB:EB)
		 IF (FIRST.EQ.'.') RETURNI
		 DO WHILE (BUFFER(SB:EB).NE.'.')
		    IF (.NOT.NEWS_READ()) CALL EXITR
		 END DON
		 IF (.NOT.NEWS_WRITE('STAT '//FIRST(:TRIM(FIRST))))E
     &					  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,'>')) 
     &			   .OR.I.GT.F_NBULL))
			  I = I - 1
			  IF (.NOT.OTS$CVT_L_TI(I,NUMBER,,,)) RETURNN
			  IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURN 
			  IF (.NOT.NEWS_READ()) RETURNE
		       END DOR
		       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))R
		    END IF
		    RETURN
		 END IFB
	      END IFB
	      SKIP = SKIP + 1
	   END DO
	END IFS

	RETURN 
	END



	SUBROUTINE REMOTE_COPY_BULL(IER)N

	IMPLICIT INTEGER (A-Z)E

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(A)',IOSTAT=IER) 2
	ELSEF
	END IFW

	RETURND
	END



	SUBROUTINE REMOTE_WRITE_BULL_FILE(OUTPUT)

	IMPLICIT INTEGER (A-Z)D

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	CHARACTER*(*) OUTPUTG

	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 6,OUTPUT
	ELSE*
	END IF 

	RETURN
	END



	SUBROUTINE GET_REMOTE_MESSAGE(IER)Z
C
C  SUBROUTINE GET_REMOTE_MESSAGE
CA
C  FUNCTION:
C	Gets remote message.
C 

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLDIR.INC'

	INCLUDE '($RMSDEF)'

	COMMON /BUFFER/ BUFFER,SB,EBI
	CHARACTER BUFFER*1280

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /REMOTE_READ_MESSAGE/ SCRATCH_R1
	DATA SCRATCH_R1 /0/

	COMMON /REF/ REFERENCES,LREFO
	CHARACTER*256 REFERENCESI

	COMMON /NEWSGROUPS/ NEWSGROUPS 
	CHARACTER*256 NEWSGROUPS/

	COMMON /HEADER_INFO/ MSGNUM,SUBJECT_LINE,FROM_LINE
	CHARACTER*256 FROM_LINE,SUBJECT_LINE(
	CHARACTER*12 MSGNUM

	COMMON /LOCAL_UPDATE/ LOCAL_UPDATE1

	CHARACTER*256 TEMP,TEMP1 

	IF (SCRATCH_R1.NE.0) THEN		! Is queue empty?P
	   SCRATCH_R = SCRATCH_R1		! No, set queue pointer to headL
	ELSE					! Else if queue is empty
	   CALL INIT_QUEUE(SCRATCH_R,INPUT)
	   SCRATCH_R1 = SCRATCH_R		! Init header pointer 
	END IFN

	ILEN = 128Y
	IER = 0
	LENGTH = 0I
	LTEMP = 0
	HEADER_SEEN = .FALSE.

        IF (REMOTE_SET.EQ.3) THENN
	   LSUB = TRIM(SUBJECT_LINE) 
	   LFRO = TRIM(FROM_LINE)
	   IF (LOCAL_UPDATE1.NE.0) THEN
              ILEN = 1
	      INPUT(:1) = CHAR(0)
           END IF
	END IFS

	DO WHILE (ILEN.GT.0.AND.IER.EQ.0)
	   IF (REMOTE_SET.EQ.1) THENT
	      READ (REMOTE_UNIT,'(Q,A)',IOSTAT=IER) ILEN,INPUTs
	   ELSE
	      IF (ILEN.EQ.128) ILEN = 0
	      IF (LTEMP.GT.0) THENL
		 ILEN = MIN(128,LTEMP)
		 INPUT = TEMP(:ILEN)
		 LTEMP = LTEMP - ILENA
	      END IFA
	      IF (ILEN.LT.128) THEN
		 IF (LFRO.GT.0) THEN
                    IF (LOCAL_UPDATE1.NE.0) THEN
	               CALL COMPRESS(FROM_LINE(:LFRO),FROM_LINE,LFRO)
	            END IF)
		    LTEMP = LFRO
		    LFRO = 0
		    IER = 0	
		    TEMP = CHAR(LTEMP)//FROM_LINEE
		    LTEMP = LTEMP + 1 
		    LINP = MIN(LTEMP,128-ILEN)
		    INPUT = INPUT(:ILEN)//TEMP(:LINP)S
		    ILEN = ILEN + LINP
		    LTEMP = LTEMP - LINP
		    TEMP = TEMP(LINP+1:)
		 ELSE IF (LSUB.GT.0) THENV
                    IF (LOCAL_UPDATE1.NE.0) THEN
	               CALL COMPRESS(SUBJECT_LINE(:LSUB),SUBJECT_LINE,LSUB)
	            END IF
		    LTEMP = LSUB
		    LSUB = 0
		    IER = 0C
		    TEMP = CHAR(LTEMP)//SUBJECT_LINE
		    LTEMP = LTEMP + 1(
		    LINP = MIN(LTEMP,128-ILEN)
		    INPUT = INPUT(:ILEN)//TEMP(:LINP)E
		    ILEN = ILEN + LINP
		    LTEMP = LTEMP - LINP
		    TEMP = TEMP(LINP+1:)
		 ELSE0
		  IER = NEWS_READ()E
		  IF (IER.AND.BUFFER(SB:EB).NE.'.') THEN
		    IER = 0P
		    LTEMP = EB-SB+1T
		    IF (LTEMP.GT.0) THEN
		       TEMP = CHAR(LTEMP)//BUFFER(SB:SB+LTEMP-1)
		       IF (.NOT.HEADER_SEEN) THENC
	                  IF (TRIM(TEMP).EQ.0) THEN
			     HEADER_SEEN = .TRUE.
 			  ELSE IF (INDEX(TEMP,': ').EQ.0.AND.I
     &	 			INDEX(TEMP,':'//CHAR(9)).EQ.0.AND.ICHAR( 
     &				TEMP(2:2)).GT.32.AND.LTEMP.LT.255) THENB
			     TEMP = CHAR(LTEMP+1)
     &					//' '//BUFFER(SB:SB+LTEMP-1)
   			     LTEMP = LTEMP + 1
			  END IFI
		       END IF)
                       IF (LOCAL_UPDATE1.NE.0) THENA
	                  CALL COMPRESS(TEMP(2:LTEMP+1),TEMP(2:),LTEMP)
		          TEMP(:1) = CHAR(LTEMP)
	               END IF	:
		    ELSE
		       HEADER_SEEN = .TRUE.C
		       TEMP = CHAR(1)//' '
		       LTEMP = 1
		    END IF
		    LTEMP = LTEMP + 1N
		    LINP = MIN(LTEMP,128-ILEN)
		    INPUT = INPUT(:ILEN)//TEMP(:LINP) 
		    ILEN = ILEN + LINP
		    LTEMP = LTEMP - LINP
		    TEMP = TEMP(LINP+1:)
		  ELSE IF (IER) THEN
		    IER = 0/
		    INPUT = INPUT(:ILEN)//CHAR(0)F
		    ILEN = -1281
		  ELSE
		    ILEN = 128
		  END IF
		 END IFs
	      ELSES
		 TEMP = TEMP(129:)
	      END IF 
	   END IF
	   IF (IER.NE.0.AND.ILEN.GT.0) THEN
	      CALL ERRSNS(IDUMMY,IER1))
	      IF (IER1.EQ.RMS$_RER) THEN	! Ignore this error1
		 IER = 0
		 ILEN = 0E
	      ELSEF
		 CALL SYS_GETMSG(IER1)
		 LENGTH = 0S
		 IER1 = IERD
		 CALL DISCONNECT_REMOTEN
		 IER = IER1	! IER is set to 0 by DISCONNECT_REMOTE
	      END IF	
	   ELSE IF (ABS(ILEN).EQ.128) THENF
	      CALL WRITE_QUEUE(%VAL(SCRATCH_R),SCRATCH_R,INPUT)
	      LENGTH = LENGTH + 1
	   END IF
	END DOf

	RETURNN
	END




	SUBROUTINE REMOTE_REMOVE_FOLDER(IER)Q

	IMPLICIT INTEGER (A-Z)=

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	RETURNR
	END



	SUBROUTINE CONNECT_REMOTE_FOLDER(READ_ONLY,IER)
C 
C  SUBROUTINE CONNECT_REMOTE_FOLDER 
CE
C  FUNCTION: Connects to folder that is located on other DECNET node.G
CF
	IMPLICIT INTEGER (A-Z))

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT
	DATA REMOTE_UNIT /15/

	COMMON /COMMAND_SWITCHES/ LOGIN_SWITCH,SYSTEM_SWITCHE
	COMMON /COMMAND_SWITCHES/ SYSTEM_LOGIN_BTIM(2)L
	COMMON /COMMAND_SWITCHES/ REVERSE_SWITCH,SEPARATE
	CHARACTER*4 SEPARATEE

	COMMON /READIT/ READITE

	COMMON /NEWS_INIT/ END_READ

	INCLUDE 'BULLUSER.INC'N

	INCLUDE 'BULLFOLDER.INC'E

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFILES.INC'

	CHARACTER*12 FOLDER_BBOARD_SAVE,FOLDER_OWNER_SAVE
	CHARACTER*44 FOLDER_SAVE 

	DIMENSION DUMMY(4)2

	IF (FOLDER1(:1).GE.'a'.AND.FOLDER1(:1).LE.'z') THEN
	   END_READ = 0
	   IF (.NOT.NEWS_LOGIN()) THEN:
	      IER = 2
	      RETURNL
	   END IF
	   CALL NEWS_GROUP(IER)
	   IF (IER.NE.0) RETURN
	   IF (REMOTE_SET.EQ.1) CLOSE(UNIT=REMOTE_UNIT)
	   RETURN
	END IFN

	REMOTE_UNIT = 31 - REMOTE_UNITI

	SAME = .TRUE.
	LEN_BBOARD = TRIM(FOLDER1_BBOARD)
	IF (INDEX(FOLDER1_BBOARD,'*').GT.0) THEN  ! Remote folder name differentI
	   SAME = .FALSE.			  ! from local?  Yes.
	   LEN_BBOARD = LEN_BBOARD - 1T
	END IF 

	OPEN (UNIT=REMOTE_UNIT,STATUS='UNKNOWN',IOSTAT=IER,RECL=256,T
     &		FILE=FOLDER1_BBOARD(3:LEN_BBOARD)//'::"TASK=BULLETIN1"')

	IF (IER.EQ.0) THENN
	   IF (.NOT.SAME) THEN.
	      FOLDER1_FILE = FOLDER_FILE'
	      FOLDER_FILE = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))
     &		//FOLDER1M
	      REMOTE_SET_SAVE = REMOTE_SET 
	      REMOTE_SET = .FALSE.)
	      CALL OPEN_BULLDIR
	      CALL READDIR(0,IER)
	      CALL CLOSE_BULLDIRF
	      REMOTE_SET = REMOTE_SET_SAVE+
	      FOLDER_FILE = FOLDER1_FILE
	      FOLDER_SAVE = FOLDER1
	      FOLDER1 = BULLDIR_HEADER(13:)
	      IF (NEMPTY.EQ.0) FOLDER1 = FOLDER1(:25)
	   END IF
	   SYSLOG = .FALSE.
	   IF (READIT.EQ.1) THENR
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,'SYSTEM?'
	      READ(REMOTE_UNIT,'(A)',IOSTAT=IER) IER1
	      IF (IER1) THENE
		 WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,FOLDER1//'+'/
		 SYSLOG = .TRUE.
	      END IFO
	   END IF
	   IF (.NOT.SYSLOG) THENE
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,FOLDER1
	   END IF
	   FOLDER_OWNER_SAVE = FOLDER1_OWNERE
	   FOLDER_BBOARD_SAVE = FOLDER1_BBOARD)
	   FOLDER_NUMBER_SAVE = FOLDER1_NUMBERL
	   IF (IER.EQ.0) THEN
	      IF (SYSLOG) THEND
		 READ(REMOTE_UNIT,'(7A)',IOSTAT=IER)IER1,READ_ONLY,T
     &		   DUMMY(1),DUMMY(2),DUMMY(3),DUMMY(4),FOLDER1_COM
	      ELSE(
		 READ(REMOTE_UNIT,'(5A)',IOSTAT=IER)IER1,READ_ONLY,F
     &		   DUMMY(1),DUMMY(2),FOLDER1_COM
	      END IF 
	   END IF
	   IF (.NOT.SAME) FOLDER1 = FOLDER_SAVE
	   FOLDER1_BBOARD = FOLDER_BBOARD_SAVEF
	   FOLDER1_NUMBER =  FOLDER_NUMBER_SAVE
	   FOLDER1_OWNER = FOLDER_OWNER_SAVE=
	END IF	

	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 process=
	      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)E
		 CALL CLR2(SET_FLAG,FOLDER_NUMBER_SAVE)A
		 IF (IER.EQ.0) REWRITE (4) USER_ENTRYT
		 CALL CLOSE_BULLUSER
	      END IFH
	   END IF
	   IER = 2T
	ELSEI
	   CLOSE (UNIT=31-REMOTE_UNIT)
CT
C  If remote folder has returned a last read time for the folder,P
C  and if in /LOGIN mode, or last selected folder was a differentN
C  folder, or folder specified with "::", then update last read time.R
CT
	   IF (((FOLDER_NUMBER.NE.FOLDER1_NUMBER.OR.READIT.EQ.1)T
     &		.AND.(DUMMY(1).NE.0.OR.DUMMY(2).NE.0))
     &		.OR.FOLDER1_NUMBER.EQ.-1) THEN
	      CALL COPY2(LAST_READ_BTIM(1,FOLDER1_NUMBER+1),DUMMY)I
	      IF (SYSLOG) THENU
		 CALL COPY2(LAST_SYS_BTIM(1,FOLDER1_NUMBER+1),DUMMY(3))/
	      END IF
	   END IF
	   IER = 0
	END IFR

	RETURNR
	END



	SUBROUTINE REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)

	IMPLICIT INTEGER (A-Z)C

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'I

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /BUFFER/ BUFFER,SB,EBF
	CHARACTER BUFFER*1280

	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*256 MESSAGE_IDT

	COMMON /NEXT/ NEXTM
	LOGICAL NEXT /.FALSE./R

	COMMON /NEWGROUP/ NEWGROUPP

	CHARACTER*8 NUMBERC

	DIMENSION IN_BTIM(2)n

	IF (REMOTE_SET.EQ.1) THEN
	   IF (ICOUNT.GE.0) THENL
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 8,ICOUNTR
	   ELSE
	      WRITE (REMOTE_UNIT,'(3A)',IOSTAT=IER) 8,-1,MSG_KEY 
	   END IF
	   IF (IER.EQ.0) THEN
	      IF (ICOUNT.EQ.0) THEN
		 READ (REMOTE_UNIT,'(2A)',IOSTAT=IER) ICOUNT,BULLDIR_HEADERR
	      ELSE IF (ICOUNT.EQ.-1) THEN
		 READ (REMOTE_UNIT,'(2A)',IOSTAT=IER1) IER,BULLDIR_ENTRY
		 IF (IER1.GT.0) THEN
		    CALL ERROR_AND_EXIT0
		 ELSE IF (IER.NE.0) THEN
		    CALL CONVERT_ENTRY_FROMBIN
		 END IF'
		 RETURNA
	      ELSEN
		 READ (REMOTE_UNIT,'(2A)',IOSTAT=IER) ICOUNT,BULLDIR_ENTRY
	      END IFL
	   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_FROMBIN_
	   END IF
	ELSE IF (REMOTE_SET.EQ.3) THENR
	   IF (ICOUNT.EQ.0) THENI
	      NBULL = F_NBULL
	      ICOUNT = 1 
	      RETURNF
	   ELSE IF (ICOUNT.EQ.-1) THENP
	      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_EXITT
	      IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	   ELSE
	      IER = 2
	      IF (NEXT.AND..NOT.NEWGROUP) THENM
		 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
	      ELSEE
		 IF (ICOUNT.LT.F_START) ICOUNT = F_START
		 IF (ICOUNT.GT.F_NBULL) ICOUNT = F_NBULL
		 IF (.NOT.OTS$CVT_L_TI(ICOUNT,NUMBER,,,)) RETURN
		 IF (.NOT.NEWS_WRITE('HEAD '//NUMBER))
     &						CALL ERROR_AND_EXIT 
		 IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	      END IFB
	      IF (BUFFER(:2).NE.'22') THENR
		 DO WHILE (NEXT.AND.NEWGROUP.AND.ICOUNT.GT.F_START)H
		    ICOUNT = ICOUNT - 1T
		    IF (.NOT.OTS$CVT_L_TI(ICOUNT,NUMBER,,,)) RETURN&
		    IF (.NOT.NEWS_WRITE('HEAD '//NUMBER)) 
     &						CALL ERROR_AND_EXITL
		    IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
		    IF (BUFFER(:2).EQ.'22') THEN
		       NEXT = .FALSE.L
		       DO WHILE (BUFFER(SB:EB).NE.'.')
	                  IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	               END DO
	            END IF(
		 END DO
		 IF (INCMD(:4).EQ.'BACK'.AND.ICOUNT.GE.F_START) THEN
		    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_EXIT
		    IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXITM
		 ELSE IF (INCMD(:4).NE.'READ'.AND..NOT.NEXT) THENE
		    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_EXITC
		 END IFI
	      END IF 
	      IF (BUFFER(:2).NE.'22') RETURNe
	      IER = OTS$CVT_TI_L(BUFFER(5:INDEX(BUFFER(5:),' ')+3),
     &							ICOUNT,,%VAL(1))S
	      IF (.NOT.IER) RETURNC
	      START = ICOUNT=
	      BULLETIN_NUM = STARTS
	   END IF
	   NEWGROUP = .FALSE.
	   MESSAGE_ID = BUFFER(INDEX(BUFFER,'<')+1:INDEX(BUFFER,'>')-1)
	   IER = 0C
	   CALL NEWS_HEADER(IER) 
	   IF (IER.GT.0) THEN
	      CALL ERROR_AND_EXIT
	   ELSE
	      CALL CONVERT_ENTRY_FROMBINQ
	   END IF
	   BLOCK = START
	   MSG_NUM = STARTR
	   SYSTEM = 0
	   IF (ICOUNT.NE.-1) THEN
	      ICOUNT = ICOUNT + 1
	   ELSE
	      IER = START
	   END IF
	END IFC

	RETURNL
	END





	SUBROUTINE GET_MSGBTIM(MSG_KEY,BTIM)e

	IMPLICIT INTEGER (A-Z)F

	INTEGER BTIM(2)

	CHARACTER*8 MSG_KEY,INPUT

	INPUT = MSG_KEY

	DO I=1,8 
	   INPUT(9-I:9-I) = MSG_KEY(I:I)D
	END DO/

	CALL LIB$MOVC3(8,%REF(INPUT),BTIM(1))

	RETURNE
	END



	SUBROUTINE NEWS_GROUP(IER)D

	IMPLICIT INTEGER (A-Z)E

	INCLUDE 'BULLFOLDER.INC'E

	COMMON /BUFFER/ BUFFER,SB,EBC
	CHARACTER BUFFER*1280

	COMMON /NEWGROUP/ NEWGROUP

	IER = NEWS_WRITE('GROUP '//
     &			 FOLDER1_DESCRIP(:INDEX(FOLDER1_DESCRIP,' ')-1))A
	IF (.NOT.IER) RETURNA

	IER = NEWS_READ()
	IF (.NOT.IER) RETURNV

	IF (BUFFER(:3).EQ.'411') RETURN

	NEWGROUP = .TRUE.

	BUFFER = BUFFER(5:)

	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_COUNT,,%VAL(1)) 
	IF (.NOT.IER) RETURNF
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)
	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_START,,%VAL(1))E
	IF (.NOT.IER) RETURNT
	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:)

	IER = NEWS_WRITE('STAT') 
	IF (.NOT.IER) RETURNR

	IER = NEWS_READ()
	IF (.NOT.IER) RETURNT

	IER = OTS$CVT_TI_L(BUFFER(SB+4:
     &			   INDEX(BUFFER(SB+4:),' ')+SB+2),START,,%VAL(1))
	IF (IER.AND.START.GT.F1_START) F1_START = START

	IF (F1_START.EQ.0) F1_NBULL = 0

	IER = 0

	RETURNI
	END



	SUBROUTINE NEWS_TIME(INTIME,BTIM)

	IMPLICIT INTEGER (A-Z)R

	CHARACTER*(*) INTIMEE

	CHARACTER*20 TIME

	I = 1
	LTIME = TRIM(INTIME)D
	DO WHILE (I.LE.LTIME.AND.(ICHAR(INTIME(I:I)).LT.ICHAR('0').OR. 
     &			ICHAR(INTIME(I:I)).GT.ICHAR('9')))_
	   I = I + 1F
	END DO 

	IF (I.GT.LTIME) THEN
	   CALL SYS_BINTIM('-',BTIM)(
	   RETURN
	END IFT

	CALL STR$UPCASE(TIME,INTIME(I:))N

	DO J = 1,2G
	   I = 1
	   DO WHILE (TIME(I:I).NE.' '.AND.I.LT.LEN(TIME))
	      I = I + 1
	   END DO
	   TIME(I:I) = '-'E
	END DO)

	IF (I.EQ.LEN(TIME)) RETURNI

	IF (TIME(I+3:I+3).EQ.' ') THEN(
	   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 IFF

	I = 1
	DO J = 1,2 
	   DO WHILE (TIME(I:I).NE.' '.AND.I.LE.LEN(TIME))
	      I = I + 1
	   END DO
	   I = I + 1E
	END DOF

	IF (I-2.GT.LEN(TIME).OR.I-2.LE.0) RETURN	

	CALL SYS_BINTIM(TIME(:I-2),BTIM)E
                                                  
	IF (INDEX(INTIME,'GMT').GT.0) CALL CONVERT_FROM_GMT(BTIM)

	RETURN=
	END



	SUBROUTINE NEWS_LISTM

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFOLDER.INC' 

	COMMON /BUFFER/ BUFFER,SB,EB_
	CHARACTER BUFFER*1280

	COMMON /LOCAL_UPDATE/ LOCAL_UPDATE1
	DATA LOCAL_UPDATE1/0/

	CHARACTER TODAY*24O

	DIMENSION EXPIRED(2)	

	CALL LIB$DATE_TIME(TODAY)

	IF (.NOT.NEWS_LOGIN()) RETURN

	IF (.NOT.NEWS_WRITE('LIST')) RETURN
	IF (.NOT.NEWS_READ()) RETURNB
	IF (BUFFER(:3).NE.'215') RETURN

	SPECIAL = SYS_TRNLNM('BULL_SPECIAL_NEWS_UPDATE','DEFINED').OR.B
     &	 (INDEX(TODAY,' 03:').NE.0)	! Delete non-existant groups at 3

        CALL INIT_QUEUE(LOCAL_UPDATE1,%DESCR(NEWS_FOLDER_NUMBER))E

        LOCAL_UPDATE = LOCAL_UPDATE1

	CALL OPEN_BULLNEWS_SHARED	! Open folder fileA

	NEWS_FOLDER1_BBOARD = '::'I

	CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER1)U
	IF (IER1.NE.0) THEN
	   NEWS_FOLDER1 = 'a'
	   NEWS_FOLDER1_NUMBER = 1000
	   NEWS_F1_COUNT = 1001
	   NEWS_F1_EXPIRE = 14a
	   NEWS_F1_EXPIRE_LIMIT = 0
	   NEWS_F1_FLAG = 0
	   CALL SYS_BINTIM('5-NOV-2956 00:00:00.00',EXPIRED)l
           CALL GET_MSGKEY(EXPIRED,NEWS_F1_EXPIRED_DATE)
	   WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COME
	END IF.
	NEWS_FLAG_DEFAULT = NEWS_F1_FLAGM
	NEWS_EXPIRE_DEFAULT = NEWS_F1_EXPIREO
	NEWS_EXPIRE_LIMIT_DEFAULT = NEWS_F1_EXPIRE_LIMITT
	IF (NEWS_F1_COUNT.LT.1001) NEWS_F1_COUNT = 1001
	NEWS_F_COUNT = NEWS_F1_COUNTA
	DO WHILE (NEWS_READ().AND.BUFFER(SB:EB).NE.'.')
	   FLEN = INDEX(BUFFER(SB:),' ') - 1D
	   NEWS_FOLDER1 = BUFFER(SB:MIN(44,FLEN)+SB-1)G
	   IF (IER1.EQ.0) THENO
	      CALL READ_FOLDER_FILE_KEYNAME_TEMP(NEWS_FOLDER1,IER)'
	   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))T
	   SP = EP + 2E
	   EP = INDEX(BUFFER(SP:),' ')+SP-2
	   IER2 = OTS$CVT_TI_L(BUFFER(SP:EP),NEWS_F1_START,,%VAL(1))
	   IF (NEWS_F1_START.EQ.0) NEWS_F1_NBULL = 0
	   CALL SYS_BINTIM('-',NEWS_F1_NEWEST_BTIM)
	   SP = EP + 1N
	   IF (IER.NE.0.OR.IER1.NE.0) THENQ
	      CALL STR$UPCASE(NEWS_FOLDER,NEWS_FOLDER1)
	      IER2 = 1A
	      I = FLENI
	      DO WHILE (IER2.NE.0.AND.I.GT.1)
		 IF (NEWS_FOLDER(I:I).EQ.'.') THEN  
		    NEWS_FOLDER = NEWS_FOLDER1(:I)
		    DO WHILE (REC_LOCK(IER))
	               READ (7,KEY=NEWS_FOLDER,
     &		   	     KEYID=0,IOSTAT=IER2) NEWS_FOLDER_COMR
		    END DO
	         END IF
	         IF (IER2.NE.0) I = I - 1
	      END DO 
	      IF (FLEN.GT.44) THENS
		 NEWS_FOLDER1_DESCRIP = BUFFER(SB+44:FLEN+SB-1)//N
     &					BUFFER(SP:EB)
	      ELSE
		 NEWS_FOLDER1_DESCRIP = BUFFER(SP:EB)C
	      END IFT
	      IER = 0
	      DO WHILE (IER.EQ.0.AND.IER1.EQ.0)
		 DO WHILE (REC_LOCK(IER)) 
		    READ (7,KEY=NEWS_F_COUNT,KEYID=1,IOSTAT=IER)
		 END DO
		 IF (IER.EQ.0) NEWS_F_COUNT = NEWS_F_COUNT + 1
	      END DOF
	      NEWS_FOLDER1_NUMBER = NEWS_F_COUNT.
	      IF (IER2.EQ.0) THEN U
	         NEWS_F1_FLAG = NEWS_F_FLAG
		 IF (I.NE.INDEX(NEWS_FOLDER1,'.')) THENI
	            NEWS_F1_EXPIRE = NEWS_F_EXPIREI
	            NEWS_F1_EXPIRE_LIMIT = NEWS_F_EXPIRE_LIMIT 
	         END IF
	      ELSE 
	         NEWS_F1_FLAG = NEWS_FLAG_DEFAULT
	         NEWS_F1_EXPIRE = 0
	         NEWS_F1_EXPIRE_LIMIT = 0
	      END IF=
              CALL GET_MSGKEY(NEWS_F1_NEWEST_BTIM,NEWS_F1_CREATED_DATE)T
              CALL SYS_BINTIM('5-NOV-2956 00:00:00.00',EXPIRED)_
              CALL GET_MSGKEY(EXPIRED,NEWS_F1_EXPIRED_DATE)I
	      IF (BTEST(NEWS_F1_FLAG,8)) THEN .
		 NEWS_F1_COUNT = 0
		 NEWS_F1_START = 0
		 NEWS_F1_NBULL = 0
	         NEWS_F1_FIRST = 0
	         NEWS_F1_LAST = 0
	      END IF
	      WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM
	      IF (IER.EQ.0) THEN 
	  	 NEWS_F_COUNT = NEWS_F_COUNT + 1
		 IF (BTEST(NEWS_F1_FLAG,8).AND.A
     &			.NOT.BTEST(NEWS_F1_FLAG,9)) THEN 
	            CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,
     &                                  %DESCR(NEWS_FOLDER1_NUMBER))
	         END IF
	      END IFR
	   ELSE IF (BTEST(NEWS_F1_FLAG,8).AND./
     &			.NOT.BTEST(NEWS_F1_FLAG,9)) THENL
	      IF (NEWS_F1_LAST.NE.NEWS_F1_NBULL.AND..NOT.SPECIAL.AND.
     &		  NEWS_F1_START.LE.NEWS_F1_NBULL) THEN
		 IF (NEWS_F1_FIRST.GT.NEWS_F1_START.AND.
     &		     NEWS_F1_FIRST.GT.NEWS_F1_NBULL) THEN_
		    NEWS_F1_LAST = 0
		    NEWS_F1_START = F1_START
		    NEWS_F1_NBULL = F1_NBULL
		    REWRITE (7,IOSTAT=IER) NEWS_FOLDER1_COMN
		 END IFT
		 IF (NEWS_F1_LAST.LT.NEWS_F1_NBULL) THEN
	            CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,
     &					%DESCR(NEWS_FOLDER1_NUMBER))     
	         END IF
	      END IF(
	   ELSE IF (.NOT.BTEST(NEWS_F1_FLAG,9)) THEN 
	      UPDATE = .FALSE.N
	      IF (FLEN.GT.44) THEN(
		 IF (NEWS_FOLDER1_DESCRIP.NE.O
     &		     BUFFER(SB+44:FLEN+SB-1)//BUFFER(SP:EB)) THEN 
		    NEWS_FOLDER1_DESCRIP =
     &			BUFFER(SB+44:FLEN+SB-1)//BUFFER(SP:EB)L
		    UPDATE = .TRUE. 
		 END IFW
	      ELSE IF (NEWS_FOLDER1_DESCRIP.NE.BUFFER(SP:EB)) THEN 
		 NEWS_FOLDER1_DESCRIP = BUFFER(SP:EB) 
		 UPDATE = .TRUE.
	      END IFX
	      IF (SPECIAL) THEN
		 IF (UPDATE) THEN(
		    NEWS_F1_START = F1_START
		    NEWS_F1_NBULL = F1_NBULL
		 END IF_
	      ELSE IF (.NOT.UPDATE) THENO
		 UPDATE = F1_START.NE.NEWS_F1_START.OR.(
     &			  F1_NBULL.NE.NEWS_F1_NBULL
	      END IF 
	      IF (UPDATE) REWRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM
	   END IF
	END DOL

	CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER1)F
	NEWS_F1_COUNT = NEWS_F_COUNTU
	REWRITE (7) NEWS_FOLDER1_COM 

	IF (SPECIAL) THEN
	   CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER)R
	   DO WHILE (IER.EQ.0)D
	      CALL READ_FOLDER_FILE_TEMP(IER)
	      IF (IER.EQ.0.AND..NOT.BTEST(NEWS_F1_FLAG,10)) THENF
		 NEWS_F1_NBULL = F1_NBULLA
		 NEWS_F1_START = F1_STARTT
 		 CALL NEWS_GROUP(IER)
		 IF (IER.EQ.0.AND..NOT.BTEST(NEWS_F1_FLAG,9)) THEN
                    IF (BTEST(NEWS_F1_FLAG,8)) THEN 
                       IF (NEWS_F1_LAST.NE.F1_NBULL.AND.
     &		           F1_START.LE.F1_NBULL) THENF
	    	    	  IF (NEWS_F1_FIRST.GT.F1_START.AND.M
     &		     	      NEWS_F1_FIRST.GT.F1_NBULL) THEN'
			     NEWS_F1_LAST = 0
			     REWRITE (7,IOSTAT=IER) NEWS_FOLDER1_COME
			  END IF
                          IF (NEWS_F1_LAST.LT.F1_NBULL) THEN
                             CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),I
     &                        LOCAL_UPDATE,%DESCR(NEWS_FOLDER1_NUMBER)).
			  END IF 
                       END IFE
 		    ELSE IF ((F1_START.NE.NEWS_F1_START.OR.
     &			F1_NBULL.NE.NEWS_F1_NBULL) 
     &			.AND.F1_START.GT.0) THENR
		       CALL SYS_BINTIM('-',F1_NEWEST_BTIM)
		       CALL REWRITE_FOLDER_FILE_TEMP(IER1)
		    END IF
		 ELSE IF (IER.NE.0.AND.(.NOT.BTEST(NEWS_F1_FLAG,8).OR.
     &			  NEWS_F1_NBULL.LT.NEWS_F1_START)) THEN
		    DELETE (UNIT=7) 
		    IER = 0R
		 END IF=
	      END IFU
	   END DO
	END IF 

	CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,%DESCR(0))

	CALL CLOSE_BULLNEWS

	RETURN
	END


	SUBROUTINE LOWERCASE(INPUT)

	CHARACTER*(*) INPUT

	DO I=1,LEN(INPUT)
	   IF (INPUT(I:I).GE.'A'.AND.INPUT(I:I).LE.'Z') THENA
	      INPUT(I:I) = CHAR(ICHAR(INPUT(I:I)) - ICHAR('A') + ICHAR('a'))E
	   END IF
	END DOT

	RETURNH
	END



	SUBROUTINE NEWS_POST(FILENAME,FILEOPEN,IER,SUBJECT)

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLNEWS.INC'T

	INCLUDE 'BULLFOLDER.INC'I

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'E

        INCLUDE 'BULLFILES.INC'

	COMMON /BUFFER/ BUFFER,SB,EBI
	CHARACTER BUFFER*1280

	COMMON /REF/ REFERENCES,LREFO
	CHARACTER*256 REFERENCESD

	COMMON /PATH/ PATHNAME,LPATHR
	CHARACTER*132 PATHNAMEE

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*256 MESSAGE_ID1

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /NEWSGROUPS/ NEWSGROUPS1
	CHARACTER*256 NEWSGROUPSE

        COMMON /ZONE/ ZONE,LZONE
	CHARACTER ZONE*41

        COMMON /LOCALPOST/ LOCAL_POST
	DATA LOCAL_POST /.FALSE./

	CHARACTER*(*) FILENAME,SUBJECTT

	CHARACTER TODAY*24,GROUPS*256

	DIMENSION NOW(2) 

	IER = 1

	CREATE = FILENAME(:8).EQ.'newgroup'

	IF (FILENAME.NE.'cancel') THENE
	   IF (.NOT.FILEOPEN) THENS
	      OPEN (UNIT=3,FILE=FILENAME,STATUS='OLD',IOSTAT=IER1)
	      IF (IER1.NE.0) RETURN
	   END IF

	   IER1 = 0
	   DO WHILE (IER1.EQ.0)
	      READ (3,'(A)',IOSTAT=IER1) BUFFER
	      IF (IER1.NE.0) GO TO 900E
	      IF (TRIM(BUFFER).GT.0) IER1 = 1
	   END DO

	   REWIND (UNIT=3)
	END IFO

	IER = SYS$GETTIM(NOW)
	CALL CONVERT_TO_GMT(NOW)R
	IER = SYS$ASCTIM(,TODAY,NOW,)

	NEWS_MSGID = TODAY(:2)//TODAY(4:6)//TODAY(10:11)//'.'//
     &		TODAY(13:14)//TODAY(16:17)//TODAY(19:20)//TODAY(22:23)
	IF (NEWS_MSGID(:1).EQ.' ') NEWS_MSGID = NEWS_MSGID(2:)P

	IF (REMOTE_SET.EQ.3.OR.NEWS_FEED()) THEN 
	   IF (.NOT.NEWS_LOGIN()) GO TO 900
	   IF (.NOT.NEWS_WRITE('POST')) GO TO 900
	   IF (.NOT.NEWS_READ()) GO TO 900 
	   IF (BUFFER(:3).NE.'340') THENE
	      WRITE (6,'('' ERROR: Posting not allowed.'')') 
	      GO TO 900
	   END IF
	ELSEF
	   I = INDEX(NEWS_MSGID,'.')I
	   LENGTH = 0
	   OPEN (UNIT=8,FILE=NEWS_DIRECTORY(:TRIM(NEWS_DIRECTORY))//I
     &	        NEWS_MSGID(:I-1)//l
     &		NEWS_MSGID(I+1:TRIM(NEWS_MSGID))//'.POST',IOSTAT=IER, 
     &		STATUS='NEW',DISPOSE='DELETE',RECL=256)
           IF (IER.NE.0) RETURNM
	   LOCAL_POST = .TRUE.N
           CALL INIT_QUEUE(GROUP_LIST1,FOLDER)
           GROUP_LIST = GROUP_LIST1T
 	END IF

	IF (LPATH.EQ.0) CALL GET_PATHNAME

	IF (REMOTE_SET.GE.3.OR.CREATE.OR.NEWS_FEED()) THEN)
	   IF (CREATE) THEN
	      GROUPS = 'Newsgroups: '//FILENAME(10:TRIM(FILENAME))4
           ELSE IF (NEWS_FEED()) THENO
              GROUPS = 'Newsgroups: '//FOLDER1_DESCRIP
	   ELSE IF (.NOT.BTEST(FOLDER_FLAG,8).AND.P
     &		TRIM(NEWSGROUPS).GT.0.AND.INCMD(:2).EQ.'RE') THENF
	      GROUPS = 'Newsgroups: '//NEWSGROUPS
	   ELSE
	      GROUPS = 'Newsgroups: '//FOLDER_NAME2
	   END IF
	   IF (FILENAME.NE.'cancel'.AND..NOT.CREATE) THEN
	      NGROUPS = 0
              IF (BTEST(FOLDER_FLAG,8)) THEN
		 CALL WRITE_QUEUE(%VAL(GROUP_LIST),GROUP_LIST,FOLDER).
		 NGROUPS = NGROUPS + 1
              END IF
	      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))E
		    CALL LOWERCASE(FOLDER1_NAME)
		    CALL READ_FOLDER_FILE_KEYNAME_TEMP
     &			(FOLDER1_NAME(:FLEN),IER1) 
		    IF (IER1.EQ.0.AND..NOT.BTEST(FOLDER1_FLAG,9)) THEN -
		       GROUPS = GROUPS(:TRIM(GROUPS))//T
     &			','//FOLDER1_NAME(:TRIM(FOLDER1_NAME))+
                       IF (BTEST(FOLDER1_FLAG,8).AND.LOCAL_POST) THENI
                          CALL WRITE_QUEUE(%VAL(GROUP_LIST),GROUP_LIST,E
     &				FOLDER1)
		          NGROUPS = NGROUPS + 1 
	               END IF
	            END IF
		 END DO
		 CALL CLOSE_BULLNEWS
	      END IFC
	   END IF
	   IF (.NOT.NEWS_WRITE(GROUPS(:TRIM(GROUPS)))) GO TO 900 
	END IFI
	ATSIGN = INDEX(PATHNAME,'@')S
	PCSIGN = INDEX(PATHNAME,'%')I
	CALL LOWERCASE(USERNAME))
	IF (PCSIGN.GT.0) THEN
	   IF (.NOT.NEWS_WRITE('Path: '//PATHNAME(ATSIGN+1:LPATH)//'!' 
     &	       //PATHNAME(PCSIGN+1:ATSIGN-1)//'!'
     &	       //USERNAME(:TRIM(USERNAME)))) GO TO 900 
	ELSEF
	   IF (.NOT.NEWS_WRITE('Path: '//PATHNAME(ATSIGN+1:LPATH)//'!'
     &	       //USERNAME(:TRIM(USERNAME)))) GO TO 900F
	END IF_
	IF (.NOT.NEWS_WRITE('From: '//USERNAME(:TRIM(USERNAME))//
     &	   PATHNAME(:LPATH))) GO TO 900
	CALL STR$UPCASE(USERNAME,USERNAME) 
	IF (.NOT.NEWS_WRITE('Subject: '//SUBJECT(:TRIM(SUBJECT))))
     &	   GO TO 900

	IF (INCMD(:2).EQ.'RE') THEN
	   IF (.NOT.NEWS_WRITE('References: '//REFERENCES(:LREF)))
     &	      GO TO 900
	END IFS

	IF (NGROUPS.GT.0) THENR
	   FROM = USERNAMEW
	   DESCRIP = SUBJECTT
	END IFI

        NEWS_MSGID = NEWS_MSGID(:TRIM(NEWS_MSGID))//PATHNAME(:LPATH)
	IF (.NOT.NEWS_WRITE('Message-ID: <'//NEWS_MSGID(:
     &	   TRIM(NEWS_MSGID))//'>')) GO TO 900

	TODAY = TODAY(:2)//' '//TODAY(4:6)//' '//TODAY(10:20)
	IF (TODAY(1:1).EQ.' ') TODAY = TODAY(2:)F

	IF (LORGAN.EQ.0) THEN
	   IF (SYS_TRNLNM('BULL_NEWS_ORGANIZATION','DEFINED')) THEN
	      IER1 = SYS_TRNLNM('BULL_NEWS_ORGANIZATION',ORGANIZATION)_
	   END IF
	   LORGAN = TRIM(ORGANIZATION)F
	END IFN

	IF (LORGAN.GT.0) THEN
	   IF (.NOT.NEWS_WRITE('Organization: '//ORGANIZATION(:LORGAN)))_
     &		GO TO 900	
	END IFF

	IF (.NOT.NEWS_WRITE('Date: '//TODAY(:TRIM(TODAY))//' '//_
     &		ZONE(:LZONE))) GO TO 900

        IF (REMOTE_SET.EQ.4.AND..NOT.C
     &		(CREATE.OR.FILENAME.EQ.'cancel')) THEN
	   IF (CLI$PRESENT('EXPIRATION')) THEN   
       	      IF (.NOT.NEWS_WRITE('Expires: '//EXDATE(
     &		   FIRST_ALPHA(EXDATE):2) 
     &		   //' '//EXDATE(4:6)//' '//EXDATE(10:TRIM(EXDATE))_
     &		   //' '//EXTIME(:8)//' '//ZONE(:LZONE))) GO TO 900U
	   ELSE
	      IF ( FOLDER_BBEXPIRE.GT.0) THEN
                 CALL GET_EXDATE(EXDATE,FOLDER_BBEXPIRE)
              ELSE
	         CALL GET_EXDATE(EXDATE,NEWS_EXPIRE_DEFAULT)S
              END IF
	      EXTIME = '00:00:00.00' 
	   END IF
	END IF

	IF (CREATE) THEN 
	   IF (.NOT.NEWS_WRITE('Control: '//FILENAME(:TRIM(FILENAME))))
     &		 RETURNS
	END IF 

	IF (FILENAME.EQ.'cancel') THEN 
	   IF (.NOT.NEWS_WRITE('Control: cancel <'N
     &		//MESSAGE_ID(:TRIM(MESSAGE_ID))//'>')) RETURNU
	   IF (.NOT.NEWS_WRITE('.')) RETURN
	   IF (REMOTE_SET.EQ.3.OR.NEWS_FEED()) THEN
	      IF (.NOT.NEWS_READ()) RETURN_
	      IF (BUFFER(:3).EQ.'240') IER = 0U
	   ELSE
	      CLOSE (UNIT=8,STATUS='SAVE')O
	      IER = 0
	   END IF
	   LOCAL_POST = .FALSE.
	   RETURN
	END IF

	IF (.NOT.NEWS_WRITE(' ')) GO TO 900

	IER1 = 0E
	DO WHILE (IER1.EQ.0)I
	   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 900 
	END DOF

	IF (REMOTE_SET.EQ.3.OR.NEWS_FEED()) THEN 
    	   IF (.NOT.NEWS_WRITE('.')) GO TO 900 
	   IF (.NOT.NEWS_READ()) GO TO 900)
	   IF (BUFFER(:3).EQ.'240') THENR
	      IER = 0
	   ELSE
	      WRITE (6,'('' ERROR: Server rejected your posting:'')')
	      WRITE (6,'(1X,A)') BUFFER(SB:EB))
	   END IF
	ELSE
	   LENGTH = (LENGTH+127)/128 
           GROUP_LIST = GROUP_LIST1 
	   FOLDER_NUMBER_SAVE = FOLDER_NUMBER
	   DO I=NGROUPS,1,-1U
	      CALL READ_QUEUE(%VAL(GROUP_LIST),GROUP_LIST,FOLDER1)E
	      FOLDER_NUMBER = -1E
              CALL SELECT_FOLDER(.FALSE.,IER)E
	      IF (IER) THEN W
	         CALL ADD_LOCAL_NEWS(8)
	      END IFL
	   END DO
	   IF (FOLDER_NUMBER.NE.FOLDER_NUMBER_SAVE) THEN 
	      FOLDER_NUMBER = FOLDER_NUMBER_SAVE_
	      CALL SELECT_FOLDER(.FALSE.,IER)
	   END IF
    	   IF (.NOT.NEWS_WRITE('.')) GO TO 900 
	   CLOSE (UNIT=8,STATUS='SAVE')
	   IER = 0
	END IFE

900	IF (FILENAME.NE.'cancel'.AND..NOT.FILEOPEN) CLOSE (UNIT=3)

	LOCAL_POST = .FALSE.T

	RETURNL
	END



	SUBROUTINE GET_PATHNAME

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLUSER.INC'T

	COMMON /PATH/ PATHNAME,LPATHR
	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.O
     &	    .NOT.SYS_TRNLNM_SYSTEM('MX_NODE_NAME',PATHNAME)) THEN
	      WRITE (6,'('' ERROR: Cannot find local host name.'')')C
	      RETURN'
	   END IF
	END IFU

	IF (ALPHA(PATHNAME(:1))) PATHNAME = '@'//PATHNAME

	CALL LOWERCASE(PATHNAME)B
	LPATH = TRIM(PATHNAME)2

	RETURNO
	END



	LOGICAL FUNCTION TEST_NEWS(NAME)N

	IMPLICIT INTEGER (A-Z)N

	CHARACTER*(*) NAME1

	TEST_NEWS = .FALSE.

	DO I=1,LEN(NAME)
 	   IF (NAME(I:I).GE.'A'.AND.NAME(I:I).LE.'Z') RETURN
	END DO6

	TEST_NEWS = .TRUE. 

	RETURND
	END



	SUBROUTINE UPDATE_LOCAL_NEWS 

        IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLDIR.INC'O

        INCLUDE 'BULLFOLDER.INC'

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

        COMMON /LOCAL_UPDATE/ LOCAL_UPDATE1C

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

        EXTERNAL BULLETIN_SUBCOMMANDS   

	CHARACTER CNUM*4,NUMBER*8
	EQUIVALENCE (CNUM,NUM) 

        CALL INIT_QUEUE(LOCAL_UPDATE1,CNUM),

        LOCAL_UPDATE = LOCAL_UPDATE1

        CALL READ_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,CNUM)O
	IF (NUM.EQ.0) RETURN 
 R
	CALL OPEN_BULLNEWS_SHARED

	DO WHILE (1)I
           CALL READ_FOLDER_FILE_KEYNUM_TEMP(NUM,IER)1
	   IF (IER.EQ.0) THEN
	      CALL CLOSE_BULLNEWS
	      CALL CONNECT_REMOTE_FOLDER(READ_ONLY,IER)
              LAST = F1_NBULLW
	      FIRST = F1_START(
              IF (IER.EQ.0) THEN
	         FOLDER_COM = FOLDER1_COM
                 CALL OTS$CVT_L_TI(F_LAST+1,NUMBER,,,)
		 REMOTE_SET = 3W
                 INCMD = 'COPY/ORIGINAL '//FOLDER(:TRIM(
     &                  FOLDER))//' '//NUMBER//'-LAST'
                 CALL CLI$DCL_PARSE(INCMD,BULLETIN_SUBCOMMANDS)
                 CALL MOVE(.FALSE.) 
		 CALL OPEN_BULLNEWS_SHARED
		 IF (REMOTE_SET.EQ.4) THEN
		    NEW_F_COUNT = F_COUNTF
		    NEW_NEWS_F_END = NEWS_F_END 
	            CALL READ_FOLDER_FILE_KEYNUM(NUM,IER)
                    CALL GET_MSGKEY(NEWEST_EXBTIM,NEWS_F_EXPIRED_DATE)
	            CALL COPY2(F_NEWEST_BTIM,NEWEST_MSGBTIM) 
	            IF (F_START.EQ.0.AND.NBULL.GT.0) F_START = 1I
	            IF (NEW_NEWS_F_END.GT.NEWS_F_END) THEN 
 	               NEWS_F_END = NEW_NEWS_F_END
	               F_NBULL = NEW_NEWS_F_END
		       F_COUNT = NEW_F_COUNT
	            END IF_
	            F_LAST = LAST
	            NEWS_F_FIRST = FIRST
	            CALL REWRITE_FOLDER_FILE(IER)
	         END IF
              END IF
  	   END IF
           CALL READ_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,CNUM)
	   IF (NUM.EQ.0) THEN
              CALL CLOSE_BULLNEWS  P
	      RETURNM
	   END IF
	END DO

	RETURNP
	END




	SUBROUTINE NEWS2BULLL

	IMPLICIT INTEGER (A-Z)o

	INCLUDE 'BULLFOLDER.INC' 

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*132 INCMD

	COMMON /BUFFER/ BUFFER,SB,EB 
	CHARACTER BUFFER*1280

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	EXTERNAL BULLETIN_SUBCOMMANDS

	CHARACTER TIME*20,FIRST*80,FOLDER_SAVE*44,BBOARD_SAVE*12S

	CHARACTER*8 NUMBERB

	DIMENSION SAVE_F_NEWEST_BTIM(2),NOW(2)C

	IER = SYS$GETTIM(NOW)

	CALL ALLPRIV 

	CALL NEWS_LISTO

	CALL UPDATE_LOCAL_NEWSE

	CALL SEND_POST 

	CALL INIT_QUEUE(FOLDER_Q1,FOLDER_COM)

	FOLDER_Q = FOLDER_Q1	

	CALL OPEN_BULLFOLDER_SHARED		! Get folder fileN

	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,'<')
	      ELIST = INDEX(FOLDER_DESCRIP,'>')
	      IF (SLIST.GT.0.AND.ELIST.GT.SLIST) THEN
		 IF (FOLDER_DESCRIP(SLIST+1:SLIST+1).EQ.'@'.OR.O
     &		     TEST_NEWS(FOLDER_DESCRIP(SLIST+1:ELIST-1))) THEND
		    NUM_FOLDERS = NUM_FOLDERS + 1D
		    CALL WRITE_QUEUE(%VAL(FOLDER_Q),FOLDER_Q,FOLDER_COM)
		 END IF 
	      END IF
	   END IF
	END DOA

	CALL CLOSE_BULLFOLDER			! We don't need file anymore(

	IF (NUM_FOLDERS.EQ.0.OR..NOT.NEWS_LOGIN()) CALL EXITT

	FOLDER_Q = FOLDER_Q1G
	POINT_FOLDER = 0 
	DO WHILE (POINT_FOLDER.LT.NUM_FOLDERS)/
	   POINT_FOLDER = POINT_FOLDER + 1U
	   CALL READ_QUEUE(%VAL(FOLDER_Q),FOLDER_Q,FOLDER_COM)P
	   CALL SELECT_FOLDER(.FALSE.,IER)
	   FOLDER_SAVE = FOLDER
	   BBOARD_SAVE = FOLDER_BBOARDE
	   FOLDER_DESCRIP = FOLDER_DESCRIP(INDEX(FOLDER_DESCRIP,'<')+1:)
	   FOLDER_DESCRIP = FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,'>')-1)S
	   IF (IER) THEN.
	      SAVE_LAST = F_LASTJ
	      CALL OPEN_BULLNEWS_SHARED
	      FOLDER1 = FOLDER_DESCRIP(:TRIM(FOLDER_DESCRIP))
	      CALL READ_FOLDER_FILE_KEYNAME
     &		(FOLDER_DESCRIP(:TRIM(FOLDER_DESCRIP)),IER)N
	      CALL CLOSE_BULLNEWS
	      FOLDER1_DESCRIP = FOLDER_DESCRIPD
              IF (IER.EQ.0) CALL CONNECT_REMOTE_FOLDER(READ_ONLY,IER)P
              IF (IER.EQ.0) FOLDER_COM = FOLDER1_COM
	      IF (IER.EQ.0.AND.BBOARD_SAVE.EQ.'NONE') THENT
	         SAVE_LAST = F_NBULL6
		 CALL OPEN_BULLFOLDER 
	         CALL READ_FOLDER_FILE_KEYNAME(FOLDER_SAVE,IER1) 
		 F_LAST = SAVE_LASTM
                 FOLDER_BBOARD = 'NONEFEED' 
	         CALL REWRITE_FOLDER_FILE(IER1)
	         CALL CLOSE_BULLFOLDER
	      ELSE IF (IER.EQ.0.AND.F_NBULL.NE.SAVE_LAST.AND.
     &		F_NBULL.GE.F_START) THEN
                 REMOTE_SET = 3N
		 IF (SAVE_LAST.GT.F_NBULL.AND.F_START.EQ.1)I
     &			SAVE_LAST = F_START-1
		 SAVE_LAST = MAX(F_START-1,SAVE_LAST)Z
	         CALL OTS$CVT_L_TI(SAVE_LAST+1,NUMBER,,,)
	         INCMD = 'COPY/ORIGINAL '//FOLDER_SAVE(:TRIM(
     &			FOLDER_SAVE))//' '//NUMBER//'-LAST'
		 SAVE_LAST = F_NBULL
	         CALL CLI$DCL_PARSE(INCMD,BULLETIN_SUBCOMMANDS)
		 CALL MOVE(.FALSE.)'
		 CALL OPEN_BULLFOLDERE
	         CALL READ_FOLDER_FILE_KEYNAME(FOLDER_SAVE,IER1)(
		 IF (IER1.EQ.0) THEN
		    F_LAST = SAVE_LAST
	            CALL REWRITE_FOLDER_FILE(IER1)E
		 END IFD
		 CALL CLOSE_BULLFOLDER
	      END IF
	   END IF
	END DOD

	CALL EXIT
	END



	SUBROUTINE DATE_TIME(TIME)

	IMPLICIT INTEGER (A-Z)0

	CHARACTER*36 MONTH
	DATA MONTH/'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'/r

	CHARACTER*(*) TIMEI

	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')+A
     &		 MOD(NMONTH,10))//TIME(1:2)//' '//TIME(13:14)//U
     &		 TIME(16:17)//TIME(19:20)_

	RETURNN
	END



	SUBROUTINE ALLPRIVT

	IMPLICIT INTEGER (A-Z).

	COMMON /PRIVILEGES/ PROCPRIV(2),NEEDPRIV(2)

	PROCPRIV(1) = -1 
	PROCPRIV(2) = -1N
	NEEDPRIV(1) = -1T
	NEEDPRIV(2) = -1U

	RETURN
	END



	SUBROUTINE NEWS_NEW_FOLDER

	IMPLICIT INTEGER (A-Z)R

	INCLUDE 'BULLFOLDER.INC',

	READ (7,IOSTAT=IER,KEYEQ=1000,KEYID=1) NEWS_FOLDER_COMN

	NEWS_FOLDER1 = FOLDER1 
	NEWS_FOLDER1_DESCRIP = FOLDER1_DESCRIP(26:)

	DO WHILE (IER.EQ.0)
	   READ (7,IOSTAT=IER,KEYEQ=NEWS_F_COUNT,KEYID=1)
	   IF (IER.EQ.0) NEWS_F_COUNT = NEWS_F_COUNT + 1T
	END DOO

	NEWS_FOLDER1_NUMBER = NEWS_F_COUNTT
	CALL SYS_BINTIM('-',NEWS_F1_NEWEST_BTIM)
	WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM

	READ (7,KEYEQ=1000,KEYID=1) NEWS_FOLDER1_COM
	NEWS_F1_COUNT = NEWS_F_COUNTR
	REWRITE (7) NEWS_FOLDER1_COM 

	RETURN(
	END



	SUBROUTINE SUBSCRIBEL

	IMPLICIT INTEGER (A-Z)D

	INCLUDE 'BULLUSER.INC'B

	INCLUDE 'BULLFOLDER.INC' 

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	IF (REMOTE_SET.LT.3) THEN
	   WRITE (6,'('' ERROR: Selected folder is not a news folder.'')')R
	   RETURN
	END IFA

	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-1)
	   I = I + 1_
	END DOC

	IF (I.GT.FOLDER_MAX-1) THEN
	   WRITE (6,'('' ERROR: Cannot subscribe.  You have '',
     &		    '' reached the news folder limit of '',I,''.'')')	
     &		    FOLDER_MAX-1
	   RETURN
	ELSE IF (LAST_NEWS_READ2(1,I).EQ.NEWS_FOLDER_NUMBER) THEN
	   WRITE (6,'('' You are already subscribed to '',A,''.'')')
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	   RETURN
	ELSER
	   WRITE (6,'('' You are now subscribed to '',A,''.'')')E
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	END IFA

	CALL OPEN_BULLNEWS_SHARED
	DO J=I,1,-1
	   IF (J.GT.1) THEN
	      CALL READ_FOLDER_FILE_KEYNUM_TEMP(&
     &	         ZEXT(LAST_NEWS_READ2(1,J-1)),IER))
	      IF (FOLDER_DESCRIP.LT.FOLDER1_DESCRIP) THEN
	         CALL COPY2(LAST_NEWS_READ(1,J),LAST_NEWS_READ(1,J-1))A
	      END IF1
	   END IF
	   IF (FOLDER_DESCRIP.GT.FOLDER1_DESCRIP.OR.J.EQ.1) THENI
	      LAST_NEWS_READ2(1,J) = NEWS_FOLDER_NUMBER
	      IF (F_START.LE.F_NBULL) THENN
		 LAST_NEWS_READ2(2,J) = MIN(8191,F_NBULL-(F_START-1))S
		 LAST_NEWS_READ(2,J) = F_START - 1
	      ELSE.
		 LAST_NEWS_READ2(2,J) = 0
		 LAST_NEWS_READ(2,J) = F_NBULL
	      END IFD
	      CALL CLOSE_BULLNEWS
	      RETURN 
	   END IF
	END DOR

	END





	SUBROUTINE UNSUBSCRIBE

	IMPLICIT INTEGER (A-Z).

	INCLUDE 'BULLUSER.INC'N

	INCLUDE 'BULLFOLDER.INC'D

	I = NEWS_FIND_SUBSCRIBE()

	IF (I.GT.FOLDER_MAX-1) 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,''.'')')O
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))
	END IFU

	DO J=I,FOLDER_MAX-2
	   CALL COPY2(LAST_NEWS_READ(1,J),LAST_NEWS_READ(1,J+1))L
	END DOR

	LAST_NEWS_READ(1,FOLDER_MAX-1) = 0E
	LAST_NEWS_READ(2,FOLDER_MAX-1) = 0

	CALL FREE_TAGS(I)

	RETURNL
	END



	SUBROUTINE NEWS_GET_NEWEST_MESSAGE(IER)

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC'R

	INCLUDE 'BULLFOLDER.INC' 

	I = NEWS_FIND_SUBSCRIBE()

	IER = LAST_NEWS_READ(2,I) + 1

	IF (I.GT.FOLDER_MAX-1.OR.IER.GT.F_NBULL) THEN
	   IER = 0 
	   RETURN
	END IFI

	RETURNY
	END



	SUBROUTINE NEWS_UPDATE_NEWEST_MESSAGE(NUMBER)

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC'A

	INCLUDE 'BULLFOLDER.INC'S

	I = NEWS_FIND_SUBSCRIBE()

	IF (I.GT.FOLDER_MAX-1) RETURN

	IF (NUMBER.GT.LAST_NEWS_READ(2,I).OR.
     &	    (LAST_NEWS_READ(2,I).GT.F_NBULL.AND.F_START.LE.F_NBULL)) THEN
	   LAST_NEWS_READ(2,I) = NUMBER
	   LAST_NEWS_READ2(2,I) = MIN(8191,F_NBULL-NUMBER)I
     &			.OR.(LAST_NEWS_READ2(2,I).AND.'C000'X)_
	END IFI

	RETURNG
	END





	SUBROUTINE NEWS_GET_SUBSCRIBE(SUBNUM,SUBMSG) 

	IMPLICIT INTEGER (A-Z)W

	INCLUDE 'BULLUSER.INC' 

	IF (SUBNUM.EQ.0) THEN
	   COUNT = 0F
	   SUBMSG = LAST_NEWS_READ(2,1)
	   RETURN
	ELSE IF (SUBNUM.EQ.-1) THEN
	   DO J=COUNT,FOLDER_MAX-1 
	      CALL COPY2(LAST_NEWS_READ(1,J),LAST_NEWS_READ(1,J+1))
	   END DO

	   LAST_NEWS_READ(1,FOLDER_MAX-1) = 0
	   LAST_NEWS_READ(2,FOLDER_MAX-1) = 0
	ELSE IF (SUBNUM.GT.0) THEN%
	   COUNT = COUNT + 1_
	END IFU

	IF (COUNT.LE.FOLDER_MAX-1) THEN
	   SUBNUM = LAST_NEWS_READ2(1,COUNT)T
	   SUBMSG = LAST_NEWS_READ(2,COUNT)
	ELSE
	   SUBNUM = 0
	END IFB

	RETURNP
	END




	SUBROUTINE NEWS_NEW_NOTIFICATION(MESSAGES)O
CC
C  SUBROUTINE NEWS_NEW_NOTIFICATIONC
C

	IMPLICIT INTEGER (A-Z)B

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'E

	COMMON /READIT/ READITT

	COMMON /POINT/ BULL_POINT

	COMMON /LOGIN_BTIM/ LOGIN_BTIM_SAVE(2)B

	MESSAGES = .FALSE.A

	IF (.NOT.SYS_TRNLNM('BULL_NEWS_SERVER','DEFINED')) RETURN

	CALL NEWS_GET_SUBSCRIBE(0,MSGNUM)

	CALL OPEN_BULLNEWS_SHARED
	SUBNUM = 1L

	FOLDER_DESCRIP = ' ' 
	REORDER = 0
	DO WHILE (SUBNUM.GT.0)O
	   IER = 1_
	   DO WHILE (SUBNUM.NE.0.AND.IER.NE.0)H
	      CALL NEWS_GET_SUBSCRIBE(SUBNUM,MSGNUM)I
	      FOLDER1_DESCRIP = FOLDER_DESCRIPd
	      IF (SUBNUM.NE.0) THEN
		 CALL READ_FOLDER_FILE_KEYNUM(SUBNUM,IER)
		 UNLOCK 7=
		 IF (FOLDER1_DESCRIP.GT.FOLDER_DESCRIP) REORDER = 1_
		 IF (IER.EQ.0.AND.
     &			MSGNUM.GT.F_NBULL.AND.F_START.LE.F_NBULL) THENC
		    CALL NEWS_UPDATE_NEWEST_MESSAGE(F_START-1)
		 ELSE IF (IER.NE.0) THEN
		    SUBNUM = -1
		 ELSE IF (MSGNUM.GE.F_NBULL.OR.F_NBULL.EQ.0.OR.I
     &			  F_START.GT.F_NBULL) THENE
		    IER = 1I
		 END IFE
	      END IF 
	      IF (IER.EQ.0.AND.SUBNUM.GT.0) THENW
		 IF (READIT.EQ.1) THEN
		    IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER).AND.T
     &			.NOT.TEST_SET_FLAG(NEWS_FOLDER_NUMBER)) THENL
		       IER = 1
		    ELSE IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER).OR.L
     &			.NOT.TEST_SET_FLAG(NEWS_FOLDER_NUMBER).OR. 
     &			NEW_FLAG(2).NE.-1) THEN
		       DIFF = COMPARE_BTIM(LOGIN_BTIM_SAVE,F_NEWEST_BTIM) 
		       IF (DIFF.GT.0) IER = 1(
		    END IF
		 END IF+
	      END IFR
	   END DO
	   IF (READIT.EQ.0.AND.SUBNUM.GT.0) THENS
	      WRITE (6,'('' There are new messages in folder '',L
     &		  A,''.'',$)') FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,' ')-1)D
	      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(:INDEX(FOLDER_DESCRIP,' ')-1)F
	      ELSE 
		 CALL CLOSE_BULLNEWS
		 CALL SELECT_FOLDER(.FALSE.,IER1) 
		 IF (IER1) THEN6
		    CALL LOGIN_FOLDER 
		    IF (BULL_POINT.NE.-1) THEN
		       IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER)) THEN 
			  SAVE_BULL_POINT = BULL_POINT
			  REDO = .TRUE.
			  DO WHILE (REDO)
			     REDO = .FALSE.
			     CALL READNEW(REDO)
			     IF (REDO) CALL REDISPLAY_DIRECTORY
			     BULL_POINT = SAVE_BULL_POINT
			  END DO_
		       END IFS
		    END IF
		 END IF_
		 CALL OPEN_BULLNEWS_SHARED
	      END IF
	   END IF
	END DOS

	IF (REORDER.EQ.1) CALL REORDER_SUBSCRIBET

	CALL CLOSE_BULLNEWS

	RETURN 
	END


	SUBROUTINE REORDER_SUBSCRIBEI

	IMPLICIT INTEGER (A-Z)/

	INCLUDE 'BULLFOLDER.INC'_

	INCLUDE 'BULLUSER.INC'A

	I = 1
	DO WHILE (LAST_NEWS_READ2(1,I).NE.0)C
	   I = I + 1.
	END DOL

	I = I - 1

	DO I1=1,I-1
	   DO J=1,I-I1F
	      K = J + 1
	      S1 = LAST_NEWS_READ2(1,J)
	      S2 = LAST_NEWS_READ2(1,K)
	      CALL READ_FOLDER_FILE_KEYNUM(S1,IER)E
	      CALL READ_FOLDER_FILE_KEYNUM_TEMP(S2,IER)
	      IF (IER+IER1.EQ.0.AND.FOLDER1_DESCRIP.LT.FOLDER_DESCRIP) THEN
		 DO L=1,2P
	            TEMP = LAST_NEWS_READ(L,J)T
		    LAST_NEWS_READ(L,J) = LAST_NEWS_READ(L,K)V
		    LAST_NEWS_READ(L,K) = TEMP
		 END DOI
	      END IF(
	   END DO
	END DOM

	RETURN 
	END




	LOGICAL FUNCTION TEST_SET_FLAG(NUMBER)0

	IMPLICIT INTEGER (A-Z)0

	INCLUDE 'BULLUSER.INC'0

	IF (NUMBER.GE.0.AND.NUMBER.LE.FOLDER_MAX-1) THEN1
	   TEST_SET_FLAG = TEST2(SET_FLAG,NUMBER)
	   RETURN
	END IF

	I = NEWS_FIND_SUBSCRIBE()

	TEST_SET_FLAG = .FALSE.

	IF (I.GT.FOLDER_MAX-1) RETURN

	TEST_SET_FLAG = BTEST(LAST_NEWS_READ2(2,I),14)I

	RETURN
	END




	LOGICAL FUNCTION TEST_BRIEF_FLAG(NUMBER)I

	IMPLICIT INTEGER (A-Z)I

	INCLUDE 'BULLUSER.INC'

	IF (NUMBER.GE.0.AND.NUMBER.LE.FOLDER_MAX-1) THENO
	   TEST_BRIEF_FLAG = TEST2(BRIEF_FLAG,NUMBER)
	   RETURN
	END IFI

	I = NEWS_FIND_SUBSCRIBE()

	TEST_BRIEF_FLAG = .FALSE.

	IF (I.GT.FOLDER_MAX-1) RETURN

	TEST_BRIEF_FLAG = BTEST(LAST_NEWS_READ2(2,I),15)

	RETURNR
	END




	LOGICAL FUNCTION TEST_NOTIFY_FLAG(NUMBER)

	IMPLICIT INTEGER (A-Z)T

	INCLUDE 'BULLUSER.INC'R

	IF (NUMBER.GE.0.AND.NUMBER.LE.FOLDER_MAX-1) THEN1
	   TEST_NOTIFY_FLAG = TEST2(NOTIFY_FLAG,NUMBER)
	   RETURN
	END IFD

	I = NEWS_FIND_SUBSCRIBE()

	TEST_NOTIFY_FLAG = .FALSE.

	IF (I.GT.FOLDER_MAX-1) RETURN

	TEST_NOTIFY_FLAG = BTEST(LAST_NEWS_READ2(2,I),13)

	RETURN_
	END



	INTEGER FUNCTION NEWS_FIND_SUBSCRIBE() 

	IMPLICIT INTEGER (A-Z)o

	INCLUDE 'BULLUSER.INC' 

	INCLUDE 'BULLFOLDER.INC'D

	I = 1
	DO WHILE (LAST_NEWS_READ2(1,I).NE.NEWS_FOLDER_NUMBER	
     &					.AND.I.LE.FOLDER_MAX-1)
	   I = I + 1 
	END DO 

	NEWS_FIND_SUBSCRIBE = I

	RETURN 
	END




	SUBROUTINE NEWS_SET_USER_FLAG(NOTIFY,READNEW,BRIEF)

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC''

	I = NEWS_FIND_SUBSCRIBE()

	IF (I.GT.FOLDER_MAX-1) THEN
	   WRITE (6,'('' ERROR: NEWS FOLDER is not subscribed.'')')
	   RETURN
	END IFd

	IF (NOTIFY.EQ.1) LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),13)E
	IF (NOTIFY.EQ.0) LAST_NEWS_READ2(2,I) = IBCLR(LAST_NEWS_READ2(2,I),13)	
	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)

	CALL UPDATE_USERINFO-

	RETURN 
	END



        SUBROUTINE ADD_LOCAL_NEWS(UNIT)R

        IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLDIR.INC'

        COMMON /LAST_RECORD_WRITTEN/ OCOUNT)

	REWIND UNIT
	S
	CALL SYS_BINTIM(EXDATE//' '//EXTIME,EX_BTIM)	

	CALL OPEN_BULLDIR
	CALL OPEN_BULLFIL
	CALL SET_BULLFIL_UPDATE
	OBLOCK = NBLOCK + 1
	CALL COPY_BULL(UNIT,1,OBLOCK,IER)
	IF (IER.NE.0) THEN_
	   CALL CLOSE_BULLFIL
	   CALL CLOSE_BULLDIR
	   RETURN
        END IF
   	LENGTH = OCOUNT - (NBLOCK + 1) + 1
	NBLOCK = NBLOCK + LENGTH + 1
	SYSTEM = 0U
	CALL ADD_ENTRY
        CALL CLOSE_BULLFIL
	CALL UPDATE_NEWS_FOLDER
        CALL CLOSE_BULLDIR

        RETURN
        END,



	SUBROUTINE UPDATE_NEWS_FOLDER
CL
C  SUBROUTINE UPDATE_NEWS_FOLDER
CR
C  FUNCTION: Updates folder info due to new message.
C'

	IMPLICIT INTEGER (A-Z):

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC' 

	NEW_NEWS_F_END = NEWS_F_END
	NEW_F_COUNT = F_COUNT

	CALL OPEN_BULLNEWS_SHARED

	CALL READ_FOLDER_FILE_KEYNAME(FOLDER,IER)

	IF (NEW_NEWS_F_END.GT.NEWS_F_END) THENR
	   CALL SYS_BINTIM(NEWEST_DATE//' '//NEWEST_TIME,NEWS_F_NEWEST_BTIM)N
	   F_NBULL = NEW_NEWS_F_END
	   NEWS_F_END = NEW_NEWS_F_ENDR
	   F_COUNT = NEW_F_COUNTB
	END IF

	IF (F_START.EQ.0.AND.F_NBULL.GT.0) F_START = 1R

	CALL GET_MSGKEY(%REF(NEWS_F_EXPIRED_DATE),%DESCR(NEWEST_EXBTIM))
	IF (COMPARE_BTIM(EX_BTIM,NEWEST_EXBTIM).LT.0)
     &		NEWS_F_EXPIRED_DATE = NEWS_NEWEST_EX_BTIM_KEY(5:)E

	CALL REWRITE_FOLDER_FILE(IER)

	CALL CLOSE_BULLFOLDER

	RETURNI
	END



	SUBROUTINE SEND_POSTU

        IMPLICIT INTEGER (A-Z) (

	INCLUDE 'BULLFILES.INC'
        INCLUDE 'BULLDIR.INC' 

        COMMON /BUFFER/ BUFFER,SB,EB
        CHARACTER BUFFER*1280_
	D
	CHARACTER FILE*132	
	-
	C = 0
	 
        IF (.NOT.NEWS_LOGIN()) RETURN0
	DO WHILE (LIB$FIND_FILE(NEWS_DIRECTORY(:TRIM(NEWS_DIRECTORY))
     &			//'*.POST',FILE,C))	
           IF (.NOT.NEWS_WRITE('POST')) RETURN
           IF (.NOT.NEWS_READ()) RETURN 
           IF (BUFFER(:3).NE.'340') RETURN
 U
           OPEN (UNIT=3,FILE=FILE,IOSTAT=IER,STATUS='OLD')
	   DO WHILE (IER.EQ.0)T
	      READ (3,'(Q,A)',IOSTAT=IER) I,INPUT
              IF (IER.EQ.0) THEN E
           	 IF (.NOT.NEWS_WRITE(INPUT(:I))) GO TO 100
	      END IFG
           END DON
	   IF (INPUT.NE.'.') THEN I
	      IF (.NOT.NEWS_WRITE('.')) GO TO 100
	   END IF
           IF (.NOT.NEWS_READ()) GO TO 100
	   CLOSE (UNIT=3,STATUS='DELETE')   I
	END DOT

100	CLOSE (UNIT=3)

	RETURNE
	END
