From:	SMTP%"BULLETIN@PFC.MIT.EDU" 19-AUG-1994 17:58:50.10
To:	EVERHART
CC:	
Subj:	BULLETIN10.FOR

Date: Fri, 19 Aug 1994 17:26:02 -0400 (EDT)
From: BULLETIN@PFC.MIT.EDU
To:   EVERHART@arisia.gce.com
Message-Id: <940819172602.21438991@PFC.MIT.EDU>
Subject: BULLETIN10.FOR

C
C  BULLETIN10.FOR, Version 8/10/94
C  Purpose: Contains subroutines for the BULLETIN utility program.
C  Environment: VAX/VMS
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 (NEWS_READ.GT.0)
	   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(:MIN(LEN(WRITE),256))
	   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.
	   NEWS_WRITE = NEWS_RECONNECT(WRITE)
	   TRY_RECONNECT = .FALSE.
	END IF

	RETURN
	END




	
	LOGICAL FUNCTION NEWS_RECONNECT(WRITE)

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLFOLDER.INC'

	COMMON /POINT/ BULL_POINT

	CHARACTER*(*) WRITE

	CHARACTER*8 NUMBER

	CHARACTER*(FOLDER_RECORD) FOLDER2_COM

	NEWS_RECONNECT = .FALSE.

	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

	NEWS_RECONNECT = .TRUE.

	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 = SETPRV_PRIV().OR.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

	STAT = .TRUE.

	IF (REMOTE_SET.EQ.3.AND.XHDR) THEN
	   STAT = .FALSE.
	   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
	   BACKSEARCH = END
	   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.'.') THEN
		    IF (.NOT.OTS$CVT_TI_L(BUFFER(SB:INDEX(BUFFER(SB:EB),' ')
     &		        +SB-2),START,,%VAL(1))) RETURN
		 END IF
		 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) THEN
		       IF (END.GE.F_NBULL) RETURN
		       START = MIN(F_NBULL,END+1)
		    ELSE
		       START = MAX(F_START,START-NUMDIR)
	            END IF
		    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"
		    STAT = .TRUE. 
		    IF (.NOT.NEWS_WRITE('STAT '//TEMP(:INDEX(TEMP,' ')-1)))F
     &								 RETURN 
		    IF (.NOT.NEWS_READ()) RETURN
		    IF (.NOT.NEWS_WRITE('NEXT')) RETURNc
		    IF (.NOT.NEWS_READ()) RETURN
		    IF (BUFFER(:2).NE.'22') THEN
		       NUMDIR = NUMDIR1I
		    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.' ')s
			  NUMBER = ' '//NUMBER(1:)a
		       END DO
		       MSG_NUM = MSG_NUM + (NUMDIR - NUMDIR1) - 1a
		       IF (.NOT.OTS$CVT_L_TI(MSG_NUM,NUMBER1,,,)) RETURN
		       DO WHILE (NUMBER1(1:1).EQ.' ')m
			  NUMBER1 = NUMBER1(2:)
		       END DOI
		    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) THEN
		 IF (.NOT.NEWS_WRITE
     &		('XHDR SUBJECT '//NUMBER//'-'//NUMBER1)) RETURNE
              ELSE
	         IF (.NOT.NEWS_WRITE 
     &		('XHDR FROM '//NUMBER//'-'//NUMBER1)) RETURN
              END IF
	      IF (.NOT.NEWS_READ()) RETURNE
	      IF (BUFFER(:2).EQ.'22') THEND
		 QXHDR = QXHDR1E
		 IF (.NOT.NEWS_READ()) RETURNA
		 NUMDIR1 = 0
		 DO WHILE (BUFFER(SB:EB).NE.'.'.AND.NUMDIR1.LT.NUMDIR)
		    NUMDIR1 = NUMDIR1 + 1N
		    CALL READ_QUEUE(%VAL(QXHDR),DUMMY,TEMP)N
		    SB1 = INDEX(BUFFER(SB:EB),' ')+SB-1
		    SB1 = FIRST_ALPHA(BUFFER(SB1:EB))+SB1-1 
		    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 = 0
	ELSE IF (REMOTE_SET.EQ.3.AND..NOT.XHDR) THENN
	   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()) RETURNE
	      IF (.NOT.OTS$CVT_TI_L(BUFFER(SB+4:E
     &		  INDEX(BUFFER(SB+4:),' ')+SB+2),I,,%VAL(1))) RETURN
	      IF (BUFFER(:2).NE.'22'.OR.I.LT.START) THENT
		 BUFFER(:3) = '500'C
		 DO WHILE (START.LE.F_NBULL.AND.BUFFER(:2).NE.'22')M
		    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 DOR
		 IF (BUFFER(:2).NE.'22') THENE
		    IER = 0O
		    END = START - 1 
		    RETURN
		 END IFI
	      END IF 
	      IF (.NOT.NEWS_WRITE('HEAD')) RETURN
	      IF (.NOT.NEWS_READ()) RETURNN
	      IER = OTS$CVT_TI_L(BUFFER(SB+4:
     &			INDEX(BUFFER(SB+4:),' ')+SB+2),START,,%VAL(1))L
	      END = START + NUMDIR - 1_
	   END IF
	   IER = 0F
	END IFI

	IF (IER.EQ.0) THENI
	   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))I
		 CALL NEWS_TIME(TEMP(LTEMP+1:TRIM(TEMP(:256))),MSG_BTIM)
	         DO J=257,512
	   	    IF (TEMP(J:J).LT.' '.OR.ICHAR(TEMP(J:J)).GT.126)
     &			TEMP(J:J) = ' '
		 END DO
		 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))U
		 CALL NEWS_HEADER(IER)
		 IF (IER.NE.0) RETURNO
	      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) THENW
		 IER = 2
		 IF (.NOT.NEWS_WRITE('NEXT')) RETURN
		 IF (.NOT.NEWS_READ()) RETURN 
		 IF (BUFFER(:3).NE.'223') THEN
		    END = I - 1N
		    IER = 0N
		    RETURN
		 END IFE
		 IF (.NOT.NEWS_WRITE('HEAD')) RETURN
		 IF (.NOT.NEWS_READ()) RETURNO
		 IER = 0
	      END IFM
	   END DO
	END IF1

	IF (REMOTE_SET.EQ.3) THEN
	   IER = 1I
	   IF (STAT) THEN
	      IF (.NOT.OTS$CVT_L_TI(BULL_POINT,NUMBER,,,)) RETURN
	      IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURN 
	      IF (.NOT.NEWS_READ()) RETURNS
	   END IF
	   IER = 0L
	END IFT

	RETURN 
	END



	INTEGER FUNCTION NEWS_LOGIN

	IMPLICIT INTEGER (A-Z)D

	COMMON /NEWS_CONNECTED/ NEWS_CONNECTEDG
	LOGICAL NEWS_CONNECTED /.FALSE./(

	COMMON /XHDR/ XHDRE
	LOGICAL XHDR /.FALSE./e

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

	IF (.NOT.NEWS_CONNECTED) THEN
	   NEWS_LOGIN = .FALSE.
	   CALL START_NEWS_TIMER()
	   NEWS_CONNECTED = NEWS_CONNECT()N
	   CALL CANCEL_NEWS_TIMER()
	   IF (.NOT.NEWS_CONNECTED) RETURNU
	   IF (.NOT.NEWS_READ()) RETURN
	   IF (INDEX(BUFFER(SB:EB),'InterNetNews').GT.0) THEN
	      IF (.NOT.NEWS_WRITE('mode reader')) RETURN2
	      IF (.NOT.NEWS_READ()) RETURNR
	   END IF
	   IF (.NOT.NEWS_WRITE('XHDR')) RETURN.
	   IF (.NOT.NEWS_READ()) RETURN
	   XHDR = BUFFER(:3).NE.'500'
	END IFO

	NEWS_LOGIN = .TRUE.

	RETURNE
	END


	SUBROUTINE CONVERT_TO_GMT(BTIM)

	IMPLICIT INTEGER (A-Z) 

	COMMON /MONTHS/ MONTH
	CHARACTER*36 MONTHS

	DIMENSION GMT_DIFF(2),BTIM(2)

	CHARACTER HOUR*8I
	DATA HOUR /' '/

	PARAMETER NZONES = 5

	COMMON /ZONE/ ZONE,LZONEC
	CHARACTER*4 ZONEF

	CHARACTER ZONES*(NZONES*4) 
	DATA ZONES /'EST CST MST PST IST'/I

	CHARACTER*8 TIMES(1)A
	DATA TIMES /'-5:30'/.

	CHARACTER TIME*12

	TO_GMT = .TRUE.

	ENTRY CONVERT_FROM_GMT(BTIM)

	IF (HOUR.EQ.' ') THEN
	   IF (.NOT.SYS_TRNLNM_SYSTEM('LISP$TIME_ZONE',HOUR)) THENN
	      IF (SYS_TRNLNM_SYSTEM('MULTINET_TIMEZONE',ZONE)
     &	       .OR.SYS_TRNLNM_SYSTEM('PMDF_TIMEZONE',ZONE)) THEN*
		 IF (INDEX(ZONES,ZONE).LT.5) THENE
	            HOUR = CHAR(ICHAR('4')+(INDEX(ZONES,ZONE)+3)/4)//':00'
	         ELSE
		    HOUR = TIMES((INDEX(ZONES,ZONE)+3)/4-4)C
	         END IF
	      ELSED
	         HOUR = '00:00'
	      END IF1
	   ELSE
	      HOUR = HOUR(:TRIM(HOUR))//':00'
	   END IF
	   ZONE = 'GMT'
	   IER = OTS$CVT_TI_L(HOUR(:INDEX(HOUR,':')-1),DIFF,,%VAL(1))
	   IF (DIFF.GE.5.AND.DIFF.LE.8) THEN	
CI
C  Following computes DST based on US formulaS
C 
	      IER = SYS$ASCTIM(,TIME,BTIM,)
	      IER = OTS$CVT_L_TI(DATE,TIME(:2),,,)T
	      CALL LIB$DAY_OF_WEEK(BTIM,DAY)L
	      M = (INDEX(MONTH,TIME(4:6))+2)/3T
	      IF (M.GE.4.AND.M.LE.10.AND.(M.NE.4.OR.DAY.LT.DATE)U
     &			.AND.(M.NE.10.OR.DATE-DAY.LT.24)) THEN 
		 DIFF = DIFF - 1
	         IER = OTS$CVT_L_TI(DIFF,HOUR(:1),,,)
	      END IF
           END IF
	   IF (DIFF.LT.0) THEND
	      PAST = .TRUE.
	      HOUR = HOUR(2:)
	   ELSE IF (DIFF.GT.12) THEN 
	      PAST = .TRUE.
	      DIFF = 24 - DIFF,
	      HOUR(3:) = HOUR(INDEX(HOUR,':'):)
	      IER = OTS$CVT_L_TI(DIFF,HOUR(:2),,,)O
	      IF (HOUR(:1).EQ.' ') HOUR = HOUR(2:) 
	   ELSE
	      PAST = .FALSE. 
	   END IF
	   LZONE = TRIM(ZONE)
	   IER = SYS_BINTIM('0 '//HOUR(:TRIM(HOUR)),GMT_DIFF)
	END IFE

	IF ((PAST.AND..NOT.TO_GMT).OR.(.NOT.PAST.AND.TO_GMT)) THEN 
	   IER = LIB$SUBX(BTIM,GMT_DIFF,BTIM)
	ELSE 
	   IER = LIB$ADDX(BTIM,GMT_DIFF,BTIM)
	END IFR

	TO_GMT = .FALSE.

	RETURNS
	END




	SUBROUTINE START_NEWS_TIMER()

	IMPLICIT INTEGER (A-Z)B

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

	EXTERNAL KILL_NEWS_CONNECT	

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

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

	RETURNR

	ENTRY CANCEL_NEWS_TIMER()

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

	RETURNW
	END


	SUBROUTINE KILL_NEWS_CONNECT()1

	IMPLICIT INTEGER (A-Z)O

	COMMON /NEWS_CONNECTED/ NEWS_CONNECTED 

	IF (NEWS_CONNECTED) RETURNT

	NLUN = NEWS_GET_CHAN()I

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

	CALL NEWS_DISCONNECT()N

	RETURN 
	END



	SUBROUTINE NEWS_HEADER(IER)

	IMPLICIT INTEGER (A-Z)W

	INCLUDE 'BULLDIR.INC'

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

	COMMON /REF/ REFERENCES,LREFR
	CHARACTER*256 REFERENCES 

	COMMON /NEWSGROUPS/ NEWSGROUPS_
	CHARACTER*256 NEWSGROUPSS

	COMMON /NEWS_HEADER_INFO/ MSGNUM,SUBJECT_LINE,FROM_LINE
	CHARACTER*256 FROM_LINE,SUBJECT_LINEE
	CHARACTER*12 MSGNUM

	CHARACTER*256 TEMP_FROM_LINE(

	EX_BTIM(1) = 0 
	EX_BTIM(2) = 0.

	DESCRIP = ' '
	FROM = ' '1
	SUBJECT_LINE = ' ' 
	FROM_LINE = ' '
	NEWSGROUPS = ' ' 
	LREF = 0N

	MSGNUM = BUFFER(5:INDEX(BUFFER(5:),' ')-1+4)D
	LAST_FROM = .FALSE.

	DO WHILE (BUFFER(SB:EB).NE.'.')
	   IER = NEWS_READ()B
	   IF (.NOT.IER) RETURN
	   IF (BUFFER(SB:EB).NE.'.') THEN
	      IF (BUFFER(SB:SB+7).EQ.'Subject:'.AND.EB.GE.SB+9) THEN
		 SB1 = FIRST_ALPHA(BUFFER(SB+9:EB))+SB+8
	         DO I=SB1,EB 
	   	    IF (BUFFER(I:I).LT.' '.OR.ICHAR(BUFFER(I:I)).GT.126)/
     &			BUFFER(I:I) = ' '
		 END DO 
		 SUBJECT_LINE = 'Subj: '//BUFFER(SB1:EB)
		 DESCRIP = BUFFER(SB1:EB).
		 LAST_FROM = .FALSE.		
	      ELSE IF (BUFFER(SB:SB+4).EQ.'Date:'.AND.EB.GE.SB+6) THEN 
		 CALL NEWS_TIME(BUFFER(SB+6:EB),MSG_BTIM)M
		 LAST_FROM = .FALSE.		
	      ELSE IF (BUFFER(SB:SB+7).EQ.'Expires:'.AND.EB.GE.SB+9) THEN
		 CALL NEWS_TIME(BUFFER(SB+9:EB),EX_BTIM)
		 LAST_FROM = .FALSE.		
	      ELSE IF (BUFFER(SB:SB+4).EQ.'From:'.AND.EB.GE.SB+6) THENI
		 SB1 = FIRST_ALPHA(BUFFER(SB+6:EB))+SB+5
		 FROM_LINE = 'From: '//BUFFER(SB1:EB) 
		 CALL GET_FROM(BUFFER(SB1:EB),EB-SB1+1)
		 LAST_FROM = .TRUE.(
              ELSE IF (BUFFER(SB:SB+10).EQ.'Message-ID:'.AND.(
     &                                              EB.GT.SB+11) THENU
                 NEWS_MSGID = BUFFER(SB+13:EB-1)
		 IF (LREF.EQ.0) THEN
		    REFERENCES = BUFFER(SB+12:EB)U
		 ELSE 
		    REFERENCES = REFERENCES(:LREF)//' '//O
     &				BUFFER(SB+12:EB)
		 END IF 
		 LREF = TRIM(REFERENCES)
		 LAST_FROM = .FALSE.		
	      ELSE IF (BUFFER(SB:SB+10).EQ.'Newsgroups:'.AND.
     &						    EB.GT.SB+11) THENT
		 SB1 = FIRST_ALPHA(BUFFER(SB+12:EB))+SB+11
		 NEWSGROUPS = BUFFER(SB1:EB)
		 LAST_FROM = .FALSE.		
	      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)//' '// 
     &				REFERENCES(:LREF).
	   	 END IF
	         LREF = TRIM(REFERENCES)R
		 LAST_FROM = .FALSE.
              ELSE IF (LAST_FROM.AND.BUFFER(SB:SB).EQ.' ') THEN+
		 FROM_LINE = FROM_LINE(:TRIM(FROM_LINE))//' '// 
     &				BUFFER(SB+FIRST_ALPHA(BUFFER(SB:EB))-1:EB)
	         TEMP_FROM_LINE = FROM_LINE
		 CALL GET_FROM(TEMP_FROM_LINE(7:),TRIM(FROM_LINE))
		 LAST_FROM = .TRUE.U
              ELSE
		 LAST_FROM = .FALSE.		
	      END IFH
	   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) = ' ' 
	END DOO

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

	RETURNS
	END




	SUBROUTINE REMOTE_READ_MESSAGE(BULL_SEARCH,IER)

	IMPLICIT INTEGER (A-Z)	

	INCLUDE 'BULLFOLDER.INC'+

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

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

	CHARACTER*8 NUMBER

	IF (REMOTE_SET.EQ.1) THEN
	   WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 5,BULL_SEARCHI
	ELSET
	   IER = 2D
	   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 = 0N
	END IF.

	RETURNA
	END



	SUBROUTINE REMOTE_GET_NEWEST_MSG(IN_BTIM,START)

	IMPLICIT INTEGER (A-Z)H

	INCLUDE 'BULLFOLDER.INC'T

	INCLUDE 'BULLUSER.INC'$

	COMMON /READIT/ READIT,

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

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

	DIMENSION IN_BTIM(2)D

	CHARACTER TIME*20,FIRST*80I

	CHARACTER*8 NUMBERG

	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) THEN*
	   I = NEWS_FIND_SUBSCRIBE()D
	   START = (LAST_NEWS_READ2(2,I).AND.'1FFF'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))E
     &			.OR.(LAST_NEWS_READ2(2,I).AND.'E000'X) 
	   END IF
	ELSEE
	   START = -1
	   IER = SYS$ASCTIM(,TIME,IN_BTIM,)
	   CALL DATE_TIME(TIME)
	   SKIP = 0
	   DO WHILE (SKIP.GE.0)
	      IF (.NOT.NEWS_WRITE('NEWNEWS '//FOLDER_NAME(:TRIM(0
     &		  FOLDER_NAME))//' '//TIME)) RETURNR
	      IF (.NOT.NEWS_READ()) RETURNG
	      IF (BUFFER(:2).EQ.'23') THEN
		 IF (.NOT.NEWS_READ()) CALL EXIT
		 DO I=1,SKIP
		    IF (.NOT.NEWS_READ()) CALL EXITT
		 END DO
		 FIRST = BUFFER(SB:EB)
		 IF (FIRST.EQ.'.') RETURNZ
		 DO WHILE (BUFFER(SB:EB).NE.'.')
		    IF (.NOT.NEWS_READ()) CALL EXIT 
		 END DO 
		 IF (.NOT.NEWS_WRITE('STAT '//FIRST(:TRIM(FIRST))))E
     &					  CALL EXIT
		 IF (.NOT.NEWS_READ()) CALL EXIT
		 IF (BUFFER(:2).EQ.'22') THENI
		    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,,,)) RETURN/
			  IF (.NOT.NEWS_WRITE('STAT '//NUMBER)) RETURNE
			  IF (.NOT.NEWS_READ()) RETURNN
		       END DOD
		       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 IFN
	      SKIP = SKIP + 1
	   END DO
	END IF 

	RETURNn
	END



	SUBROUTINE REMOTE_COPY_BULL(IER),

	IMPLICIT INTEGER (A-Z)T

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

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

	RETURNE
	END



	SUBROUTINE REMOTE_WRITE_BULL_FILE(OUTPUT)

	IMPLICIT INTEGER (A-Z) 

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	CHARACTER*(*) OUTPUT 

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

	RETURNS
	END



	SUBROUTINE GET_REMOTE_MESSAGE(IER)(
C 
C  SUBROUTINE GET_REMOTE_MESSAGE
C=
C  FUNCTION:
C	Gets remote message.
CI

	IMPLICIT INTEGER (A-Z)H

	INCLUDE 'BULLDIR.INC'

	INCLUDE '($RMSDEF)'

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

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /REMOTE_READ_MESSAGE/ SCRATCH_R1
	DATA SCRATCH_R1 /0/

	COMMON /REF/ REFERENCES,LREF
	CHARACTER*256 REFERENCES_

	COMMON /NEWSGROUPS/ NEWSGROUPSF
	CHARACTER*256 NEWSGROUPS

	COMMON /NEWS_HEADER_INFO/ MSGNUM,SUBJECT_LINE,FROM_LINE
	CHARACTER*256 FROM_LINE,SUBJECT_LINEo
	CHARACTER*12 MSGNUM

	COMMON /LOCAL_UPDATE/ LOCAL_UPDATE1

	CHARACTER*256 TEMP 

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

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

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

	DO WHILE (ILEN.GT.0.AND.IER.EQ.0)
	   IF (REMOTE_SET.EQ.1) THEN(
	      READ (REMOTE_UNIT,'(Q,A)',IOSTAT=IER) ILEN,INPUTW
	   ELSE
	      IF (ILEN.EQ.128) ILEN = 0
	      IF (LTEMP.GT.0) THEN_
		 ILEN = MIN(128,LTEMP)
		 INPUT = TEMP(:ILEN)
		 LTEMP = LTEMP - ILENI
	      END IF(
	      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 IFA
		    LTEMP = LFRO
		    LFRO = 0
		    IER = 0
		    TEMP = CHAR(LTEMP)//FROM_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:)
		 ELSE IF (LSUB.GT.0) THENE
                    IF (LOCAL_UPDATE1.NE.0) THEN
	               CALL COMPRESS(SUBJECT_LINE(:LSUB),SUBJECT_LINE,LSUB)
	            END IFM
		    LTEMP = LSUB
		    LSUB = 0
		    IER = 0_
		    TEMP = CHAR(LTEMP)//SUBJECT_LINE
		    LTEMP = LTEMP + 1S
		    LINP = MIN(LTEMP,128-ILEN)
		    INPUT = INPUT(:ILEN)//TEMP(:LINP) 
		    ILEN = ILEN + LINP
		    LTEMP = LTEMP - LINP
		    TEMP = TEMP(LINP+1:)
		 ELSE9
		  IER = NEWS_READ()O
		  IF (IER.AND.BUFFER(SB:EB).NE.'.') THEN
		    IER = 0(
		    LTEMP = EB-SB+1	
		    IF (LTEMP.GT.0) THEN
		       TEMP = CHAR(LTEMP)//BUFFER(SB:SB+LTEMP-1)
		       IF (.NOT.HEADER_SEEN) THENM
	                  IF (TRIM(TEMP).EQ.0) THEN
			     HEADER_SEEN = .TRUE.
 			  ELSE IF (INDEX(TEMP,': ').EQ.0.AND.T
     &	 			INDEX(TEMP,':'//CHAR(9)).EQ.0.AND.ICHAR(R
     &				TEMP(2:2)).GT.32.AND.LTEMP.LT.255) THENL
			     TEMP = CHAR(LTEMP+1)
     &					//' '//BUFFER(SB:SB+LTEMP-1)E
   			     LTEMP = LTEMP + 1
			  END IFE
		       ELSE IF (BUFFER(SB:SB).EQ.'.') THEN
			  TEMP = CHAR(LTEMP-1)//BUFFER(SB+1:SB+LTEMP-1)
			  LTEMP = LTEMP - 1
		       END IF1
                       IF (LOCAL_UPDATE1.NE.0) THENF
	                  CALL COMPRESS(TEMP(2:LTEMP+1),TEMP(2:),LTEMP)
		          TEMP(:1) = CHAR(LTEMP)
	               END IF	N
		    ELSE
		       HEADER_SEEN = .TRUE..
		       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) THEN
		    IER = 0E
		    INPUT = INPUT(:ILEN)//CHAR(0):
		    ILEN = -128G
		  ELSE
		    ILEN = 128
		  END IF
		 END IF 
	      ELSE(
		 TEMP = TEMP(129:)
	      END IF.
	   END IF
	   IF (IER.NE.0.AND.ILEN.GT.0) THEN
	      CALL ERRSNS(IDUMMY,IER1)F
	      IF (IER1.EQ.RMS$_RER) THEN	! Ignore this errorF
		 IER = 0
		 ILEN = 0 
	      ELSEC
		 CALL SYS_GETMSG(IER1)
		 LENGTH = 0=
		 IER1 = IERS
		 CALL DISCONNECT_REMOTE
		 IER = IER1	! IER is set to 0 by DISCONNECT_REMOTE
	      END IFF
	   ELSE IF (ABS(ILEN).EQ.128) THEN)
	      CALL WRITE_QUEUE(%VAL(SCRATCH_R),SCRATCH_R,INPUT)
	      LENGTH = LENGTH + 1
	   END IF
	END DOL

	RETURNT
	END




	SUBROUTINE REMOTE_REMOVE_FOLDER(IER)R

	IMPLICIT INTEGER (A-Z)	

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	RETURN
	END



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

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

	COMMON /COMMAND_SWITCHES/ LOGIN_SWITCH,SYSTEM_SWITCHG
	COMMON /COMMAND_SWITCHES/ SYSTEM_LOGIN_BTIM(2)
	COMMON /COMMAND_SWITCHES/ REVERSE_SWITCH,SEPARATE
	CHARACTER*4 SEPARATET

	COMMON /READIT/ READIT,

	COMMON /NEWS_INIT/ END_READ

	INCLUDE 'BULLUSER.INC'I

	INCLUDE 'BULLFOLDER.INC' 

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFILES.INC'

	CHARACTER*12 FOLDER_BBOARD_SAVE,FOLDER_OWNER_SAVE
	CHARACTER*44 FOLDER_SAVE 

	DIMENSION DUMMY(4)U

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

	REMOTE_UNIT = 31 - REMOTE_UNIT

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

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

	IF (IER.EQ.0) THENR
	   IF (.NOT.SAME) THENS
	      FOLDER1_FILE = FOLDER_FILEF
	      FOLDER_FILE = FOLDER_DIRECTORY(:TRIM(FOLDER_DIRECTORY))
     &		//FOLDER12
	      REMOTE_SET_SAVE = REMOTE_SETS
	      REMOTE_SET = .FALSE..
	      CALL OPEN_BULLDIR
	      CALL READDIR(0,IER)
	      CALL CLOSE_BULLDIR(
	      REMOTE_SET = REMOTE_SET_SAVE 
	      FOLDER_FILE = FOLDER1_FILED
	      FOLDER_SAVE = FOLDER1
	      FOLDER1 = BULLDIR_HEADER(13:)
	      IF (NEMPTY.EQ.0) FOLDER1 = FOLDER1(:25)
	   END IF
	   SYSLOG = .FALSE.
	   IF (READIT.EQ.1) THENE
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,'SYSTEM?'
	      READ(REMOTE_UNIT,'(A)',IOSTAT=IER) IER1
	      IF (IER1) THENB
		 WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,FOLDER1//'+'X
		 SYSLOG = .TRUE.
	      END IFN
	   END IF
	   IF (.NOT.SYSLOG) THENF
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 1,FOLDER1
	   END IF
	   FOLDER_OWNER_SAVE = FOLDER1_OWNER_
	   FOLDER_BBOARD_SAVE = FOLDER1_BBOARDO
	   FOLDER_NUMBER_SAVE = FOLDER1_NUMBER)
	   IF (IER.EQ.0) THEN
	      IF (SYSLOG) THEN(
		 READ(REMOTE_UNIT,'(7A)',IOSTAT=IER)IER1,READ_ONLY,F
     &		   DUMMY(1),DUMMY(2),DUMMY(3),DUMMY(4),FOLDER1_COM
	      ELSE1
		 READ(REMOTE_UNIT,'(5A)',IOSTAT=IER)IER1,READ_ONLY,T
     &		   DUMMY(1),DUMMY(2),FOLDER1_COM
	      END IF,
	   END IF
	   IF (.NOT.SAME) FOLDER1 = FOLDER_SAVE
	   FOLDER1_BBOARD = FOLDER_BBOARD_SAVE)
	   FOLDER1_NUMBER =  FOLDER_NUMBER_SAVE
	   FOLDER1_OWNER = FOLDER_OWNER_SAVER
	END IFT

	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.B
     &	       TEST_BULLCP().NE.2) THEN			! Not BULLCP process 
	      IF (TEST2(BRIEF_FLAG,FOLDER_NUMBER_SAVE)
     &		  .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_ENTRYE
		 CALL CLOSE_BULLUSER
	      END IF_
	   END IF
	   IER = 2 
	ELSE 
	   CLOSE (UNIT=31-REMOTE_UNIT) 
CO
C  If remote folder has returned a last read time for the folder,1
C  and if in /LOGIN mode, or last selected folder was a different
C  folder, or folder specified with "::", then update last read time.
C
	   IF (((FOLDER_NUMBER.NE.FOLDER1_NUMBER.OR.READIT.EQ.1)r
     &		.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)*
	      IF (SYSLOG) THENO
		 CALL COPY2(LAST_SYS_BTIM(1,FOLDER1_NUMBER+1),DUMMY(3))E
	      END IFD
	   END IF
	   IER = 0M
	END IF 

	RETURNL
	END



	SUBROUTINE REMOTE_GET_HEADER(BULLETIN_NUM,ICOUNT,IER)

	IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLFOLDER.INC'_

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*256 INCMD

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

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

	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*256 MESSAGE_ID 

	COMMON /NEXT/ NEXT
	LOGICAL NEXT /.FALSE./ 

	COMMON /NEWGROUP/ NEWGROUPC

	CHARACTER*8 NUMBERA

	DIMENSION IN_BTIM(2)t

	IF (REMOTE_SET.EQ.1) THEN
	   IF (ICOUNT.GE.0) THENN
	      WRITE (REMOTE_UNIT,'(2A)',IOSTAT=IER) 8,ICOUNT 
	   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_HEADERI
	      ELSE IF (ICOUNT.EQ.-1) THEN
		 READ (REMOTE_UNIT,'(2A)',IOSTAT=IER1) IER,BULLDIR_ENTRY
		 IF (IER1.GT.0) THEN
		    CALL ERROR_AND_EXIT 
		 ELSE IF (IER.NE.0) THEN
		    CALL CONVERT_ENTRY_FROMBIN
		 END IF2
		 RETURN	
	      ELSE(
		 READ (REMOTE_UNIT,'(2A)',IOSTAT=IER) ICOUNT,BULLDIR_ENTRY
	      END IFN
	   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_FROMBINF
	   END IF
	ELSE IF (REMOTE_SET.EQ.3) THENP
	   IF (ICOUNT.EQ.0) THEN
	      NBULL = F_NBULL
	      ICOUNT = 1L
	      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_EXITS
	      IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	   ELSE
	      IER = 2
	      IF (NEXT.AND..NOT.NEWGROUP) THEN	
		 IF (.NOT.NEWS_WRITE('NEXT')) CALL ERROR_AND_EXITT
		 IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
		 IF (BUFFER(:3).NE.'223') RETURN
		 IF (.NOT.NEWS_WRITE('HEAD')) CALL ERROR_AND_EXITI
		 IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT
	      ELSEA
		 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 IFT
	      IF (BUFFER(:2).NE.'22') THEN.
		 DO WHILE (NEXT.AND.NEWGROUP.AND.ICOUNT.GT.F_START)D
		    ICOUNT = ICOUNT - 12
		    IF (.NOT.OTS$CVT_L_TI(ICOUNT,NUMBER,,,)) RETURNT
		    IF (.NOT.NEWS_WRITE('HEAD '//NUMBER))1
     &						CALL ERROR_AND_EXIT
		    IF (.NOT.NEWS_READ()) CALL ERROR_AND_EXIT'
		    IF (BUFFER(:2).EQ.'22') THEN
		       NEXT = .FALSE.
		       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))=
	      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_FROMBINR
	   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)

	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'T

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

	COMMON /NEWGROUP/ NEWGROUP

	IF (INDEX(FOLDER1_DESCRIP,' ').EQ.0) THEN
	   IER = 1I
	   RETURN
	END IF'

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

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

	IER = 1

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

	NEWGROUP = .TRUE.

	BUFFER = BUFFER(5:)

	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_COUNT,,%VAL(1))S
	IF (.NOT.IER) RETURNO
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)
	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_START,,%VAL(1))E
	IF (.NOT.IER) RETURNF
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)
	IER = OTS$CVT_TI_L(BUFFER(:INDEX(BUFFER,' ')-1),F1_NBULL,,%VAL(1)) 
	IF (.NOT.IER) RETURNR
	BUFFER = BUFFER(INDEX(BUFFER,' ')+1:)

	IER = NEWS_WRITE('STAT')E
	IF (.NOT.IER) RETURNI

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

	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

	RETURNR
	END



	SUBROUTINE NEWS_TIME(INTIME,BTIM)

	IMPLICIT INTEGER (A-Z)C

	CHARACTER*(*) INTIME 

	CHARACTER*20 TIME

	I = 1
	LTIME = TRIM(INTIME)V
	DO WHILE (I.LE.LTIME.AND.(ICHAR(INTIME(I:I)).LT.ICHAR('0').OR.E
     &			ICHAR(INTIME(I:I)).GT.ICHAR('9'))) 
	   I = I + 1Q
	END DOR

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

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

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

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

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

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

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

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

	RETURN 
	END



	SUBROUTINE NEWS_LISTA

	IMPLICIT INTEGER (A-Z)L

	INCLUDE 'BULLFOLDER.INC'_

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

	COMMON /LOCAL_UPDATE/ LOCAL_UPDATE1
	DATA LOCAL_UPDATE1/0/

	COMMON /NEWSLIST/ NEWSLIST 

	CHARACTER TODAY*24N

	DIMENSION EXPIRED(2)F

	CALL LIB$DATE_TIME(TODAY)

	IF (.NOT.NEWS_LOGIN()) RETURN

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

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

	RECOUNT = SYS_TRNLNM('BULL_NEWS_RECOUNT','DEFINED')

        CALL INIT_QUEUE(LOCAL_UPDATE1,%DESCR(NEWS_FOLDER_NUMBER)) 

        LOCAL_UPDATE = LOCAL_UPDATE1

	NEWSLIST = .TRUE.
	CALL OPEN_BULLNEWS_SHARED	! Open folder file 

	NEWS_FOLDER1_BBOARD = '::'h

	CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER1)e
	IF (IER1.NE.0) THEN
	   NEWS_FOLDER1 = 'a'
	   NEWS_FOLDER1_NUMBER = 1000
	   NEWS_F1_COUNT = 1001
	   NEWS_F1_EXPIRE = 14.
	   NEWS_F1_EXPIRE_LIMIT = 0
	   NEWS_F1_FLAG = 0
	   CALL SYS_BINTIM('5-NOV-2956 00:00:00.00',EXPIRED)B
           CALL GET_MSGKEY(EXPIRED,NEWS_F1_EXPIRED_DATE)
	   WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COMO
	END IF 
	NEWS_FLAG_DEFAULT = NEWS_F1_FLAGR
	NEWS_EXPIRE_DEFAULT = NEWS_F1_EXPIRE 
	NEWS_EXPIRE_LIMIT_DEFAULT = NEWS_F1_EXPIRE_LIMIT
	IF (NEWS_F1_COUNT.LT.1001) NEWS_F1_COUNT = 1001
	NEWS_F_COUNT = NEWS_F1_COUNT
	DO WHILE (NEWS_READ().AND.BUFFER(SB:EB).NE.'.')
	   FLEN = INDEX(BUFFER(SB:),' ') - 1
	   NEWS_FOLDER1 = BUFFER(SB:MIN(44,FLEN)+SB-1)E
	   IF (IER1.EQ.0) THENC
	      CALL READ_FOLDER_FILE_KEYNAME_TEMP(NEWS_FOLDER1,IER)O
	   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 + 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 = 0L
	   CALL SYS_BINTIM('-',NEWS_F1_NEWEST_BTIM)
	   SP = EP + 1
	   IF (IER.NE.0.OR.IER1.NE.0) THEN 
	      CALL STR$UPCASE(NEWS_FOLDER,NEWS_FOLDER1)
	      IER2 = 1 
	      I = FLENA
	      DO WHILE (IER2.NE.0.AND.I.GT.1)
		 IF (NEWS_FOLDER(I:I).EQ.'.') THEN R
		    NEWS_FOLDER = NEWS_FOLDER1(:I)
		    DO WHILE (REC_LOCK(IER))
	               READ (7,KEY=NEWS_FOLDER,
     &		   	     KEYID=0,IOSTAT=IER2) NEWS_FOLDER_COME
		    END DO
	         END IF
	         IF (IER2.NE.0) I = I - 1
	      END DO
	      IF (FLEN.GT.44) THEN 
		 NEWS_FOLDER1_DESCRIP = BUFFER(SB+44:FLEN+SB-1)//.
     &					BUFFER(SP:EB)
	      ELSEF
		 NEWS_FOLDER1_DESCRIP = BUFFER(SP:EB)R
	      END IF 
	      IER = 0
	      DO WHILE (IER.EQ.0.AND.IER1.EQ.0)
		 DO WHILE (REC_LOCK(IER))N
		    READ (7,KEY=NEWS_F_COUNT,KEYID=1,IOSTAT=IER)
		 END DOQ
		 IF (IER.EQ.0) NEWS_F_COUNT = NEWS_F_COUNT + 1
	      END DOI
	      NEWS_FOLDER1_NUMBER = NEWS_F_COUNTI
	      IF (IER2.EQ.0) THEN .
	         NEWS_F1_FLAG = NEWS_F_FLAG
		 IF (I.NE.INDEX(NEWS_FOLDER1,'.')) THEN.
	            NEWS_F1_EXPIRE = NEWS_F_EXPIREE
	            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 IFI
              CALL GET_MSGKEY(NEWS_F1_NEWEST_BTIM,NEWS_F1_CREATED_DATE)_
              CALL SYS_BINTIM('5-NOV-2956 00:00:00.00',EXPIRED)	
              CALL GET_MSGKEY(EXPIRED,NEWS_F1_EXPIRED_DATE)_
	      NEWS_F1_COUNT = MAX(0,NEWS_F1_NBULL - NEWS_F1_START + 1)U
	      IF (BTEST(NEWS_F1_FLAG,8)) THEN 
		 NEWS_F1_COUNT = 0
		 NEWS_F1_START = 0
		 NEWS_F1_NBULL = 0
	         NEWS_F1_FIRST = 0E
	         NEWS_F1_LAST = 0
	      END IFN
	      IF (FLEN.GT.44.AND.FLEN-44+EB-SP+1.LT. 
     &		  LEN(NEWS_FOLDER1_DESCRIP)) THENR
	         WRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM)
	         IF (IER.EQ.0) THEN E
	            NEWS_F_COUNT = NEWS_F_COUNT + 1
		    IF (BTEST(NEWS_F1_FLAG,8).AND.
     &			.NOT.BTEST(NEWS_F1_FLAG,9)) THEND
	               CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,A
     &                                  %DESCR(NEWS_FOLDER1_NUMBER))
	            END IFI
		 END IF.
	      END IFN
	   ELSE IF (BTEST(NEWS_F1_FLAG,8).AND.R
     &			.NOT.BTEST(NEWS_F1_FLAG,9)) THEN(
	      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_COM 
		 END IF(
		 IF (NEWS_F1_LAST.LT.NEWS_F1_NBULL) THEN
	            CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,
     &					%DESCR(NEWS_FOLDER1_NUMBER))     
	         END IF
	      END IFE
	   ELSE IF (.NOT.BTEST(NEWS_F1_FLAG,9)) THEN 
	      UPDATE = .FALSE.3
	      IF (FLEN.GT.44) THEN(
		 IF (NEWS_FOLDER1_DESCRIP.NE.C
     &		     BUFFER(SB+44:FLEN+SB-1)//BUFFER(SP:EB)) THEN 
		    NEWS_FOLDER1_DESCRIP =
     &			BUFFER(SB+44:FLEN+SB-1)//BUFFER(SP:EB)E
		    UPDATE = .TRUE.E
		 END IF 
	      ELSE IF (NEWS_FOLDER1_DESCRIP.NE.BUFFER(SP:EB)) THENR
		 NEWS_FOLDER1_DESCRIP = BUFFER(SP:EB)R
		 UPDATE = .TRUE.
	      END IFL
	      IF (SPECIAL) THEN
		 IF (UPDATE) THEN=
		    NEWS_F1_START = F1_START
		    NEWS_F1_NBULL = F1_NBULL
		 END IF 
	      ELSE IF (.NOT.UPDATE) THEN
		 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 DO

	CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER1)C
	NEWS_F1_COUNT = NEWS_F_COUNTM
	REWRITE (7) NEWS_FOLDER1_COMS

	IF (SPECIAL) THEN
	   CALL READ_FOLDER_FILE_KEYNUM_TEMP(1000,IER)L
           LAST = FOLDER1_NUMBER
	   DO WHILE (IER.EQ.0)B
	      CALL READ_FOLDER_FILE_TEMP(IER)
	      DO WHILE (IER.EQ.0.AND.LAST.EQ.FOLDER1_NUMBER) ! oops
		 DELETE (7)E
		 CALL READ_FOLDER_FILE_TEMP(IER)
	      END DOO
	      LAST = FOLDER1_NUMBER
	      IF (IER.EQ.0.AND..NOT.BTEST(NEWS_F1_FLAG,10)) THEND
		 NEWS_F1_NBULL = F1_NBULL
		 NEWS_F1_START = F1_STARTQ
	         NEWS_F1_COUNT = F1_COUNT
 		 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) THENO
	    	    	  IF (NEWS_F1_FIRST.GT.F1_START.AND.)
     &		     	      NEWS_F1_FIRST.GT.F1_NBULL) THEN)
			     NEWS_F1_LAST = 0
			     REWRITE (7,IOSTAT=IER) NEWS_FOLDER1_COM,
			  END IFI
                          IF (NEWS_F1_LAST.LT.F1_NBULL) THEN
                             CALL WRITE_QUEUE(%VAL(LOCAL_UPDATE),:
     &                        LOCAL_UPDATE,%DESCR(NEWS_FOLDER1_NUMBER))D
			  END IF 
                       END IFF
 		    ELSE IF (((F1_START.NE.NEWS_F1_START.OR.R
     &			F1_NBULL.NE.NEWS_F1_NBULL).AND.F1_START.GT.0).OR.
     &			NEWS_F1_COUNT.NE.F1_COUNT) THEN
		       CALL SYS_BINTIM('-',F1_NEWEST_BTIM)
		       CALL REWRITE_FOLDER_FILE_TEMP(IER1)
		    END IF
		 ELSE IF (IER.EQ.1.AND.(.NOT.BTEST(NEWS_F1_FLAG,8).OR.
     &			  NEWS_F1_NBULL.LT.NEWS_F1_START.
     &			  .OR.NEWS_F1_START.EQ.0)) THEN
		    DELETE (UNIT=7)
		    IER = 0P
		 END IFN
	      END IFD
	   END DO
	END IFR

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

	CALL CLOSE_BULLNEWS
	NEWSLIST = .FALSE.D

	RETURN 
	END


	SUBROUTINE LOWERCASE(INPUT)

	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 DOR

	RETURN
	END



	SUBROUTINE NEWS_POST(FILENAME,FILEOPEN,IER,SUBJECT)

	IMPLICIT INTEGER (A-Z)O

	INCLUDE 'BULLNEWS.INC'

	INCLUDE 'BULLFOLDER.INC'2

	INCLUDE 'BULLDIR.INC'

	INCLUDE 'BULLUSER.INC'

        INCLUDE 'BULLFILES.INC' 

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

	COMMON /REF/ REFERENCES,LREFD
	CHARACTER*256 REFERENCESS

	COMMON /PATH/ PATHNAME,LPATH
	CHARACTER*132 PATHNAME_

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*256 INCMD

	COMMON /MSGID/ MESSAGE_ID
	CHARACTER*256 MESSAGE_ID_

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	COMMON /NEWSGROUPS/ NEWSGROUPSR
	CHARACTER*256 NEWSGROUPSM

        COMMON /ZONE/ ZONE,LZONE
	CHARACTER ZONE*4.

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

	COMMON /NEWS_HEADER_INFO/ MSGNUM,SUBJECT_LINE,FROM_LINE
	CHARACTER*256 FROM_LINE,SUBJECT_LINE 
	CHARACTER*12 MSGNUM

	COMMON /TEMP_INPUT/ GROUP_TEMPt
	CHARACTER GROUP_TEMP*256(

	CHARACTER*(*) FILENAME,SUBJECT 

	CHARACTER TODAY*24,UNAME*132E
	DATA UNAME /'()'/

	DIMENSION NOW(2) 

	IER = 1

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

	IF (FILENAME.NE.'cancel') THENo
	   IF (.NOT.FILEOPEN) THENB
	      OPEN (UNIT=3,FILE=FILENAME,STATUS='OLD',IOSTAT=IER1)e
	      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 9000
	      IF (TRIM(BUFFER).GT.0) IER1 = 1
	   END DO

	   REWIND (UNIT=3)D
	END IF 

	IER = SYS$GETTIM(NOW)
	CALL CONVERT_TO_GMT(NOW) 
	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:)F

	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 900B
	   IF (BUFFER(:3).NE.'340') THENE
	      WRITE (6,'('' ERROR: Posting not allowed.'')')E
	      GO TO 900
	   END IF
	ELSE=
	   I = INDEX(NEWS_MSGID,'.')E
	   LENGTH = 0
	   OPEN (UNIT=8,FILE=NEWS_DIRECTORY(:TRIM(NEWS_DIRECTORY))//
     &	        NEWS_MSGID(:I-1)//B
     &		NEWS_MSGID(I+1:TRIM(NEWS_MSGID))//'.POST',IOSTAT=IER,S
     &		STATUS='NEW',DISPOSE='DELETE',RECL=256) 
           IF (IER.NE.0) RETURNB
	   LOCAL_POST = .TRUE.B
           CALL INIT_QUEUE(GROUP_LIST1,FOLDER)
           GROUP_LIST = GROUP_LIST1N
 	END IF

	IF (LPATH.EQ.0) CALL GET_PATHNAME

 	IF (REMOTE_SET.GE.3.OR.CREATE.OR.NEWS_FEED()) THEN
	   IF (CREATE) THEN
	      INPUT = 'Newsgroups: '//FILENAME(10:TRIM(FILENAME))
           ELSE IF (NEWS_FEED()) THEN 
              INPUT = 'Newsgroups: '//FOLDER1_DESCRIPS
	   ELSE IF (.NOT.BTEST(FOLDER_FLAG,8).AND. 
     &		TRIM(NEWSGROUPS).GT.0.AND.INCMD(:2).EQ.'RE') THEND
	      INPUT = 'Newsgroups: '//NEWSGROUPS_
	   ELSE
	      INPUT = 'Newsgroups: '//FOLDER_NAME
	   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)D
		 NGROUPS = NGROUPS + 1
              END IF
	      IF (CLI$PRESENT('GROUPS')) THEN
		 CALL OPEN_BULLNEWS_SHARED
		 FLEN = 0_
		 DO WHILE (CLI$GET_VALUE('GROUPS',GROUP_TEMP))
	            IER = SYS_TRNLNM(GROUP_TEMP,GROUP_TEMP)
	            DO WHILE (TRIM(GROUP_TEMP).GT.0) 
	      	       COMMA = INDEX(GROUP_TEMP,',')
		       IF (COMMA.GT.0) THENS
	     		  FOLDER1_NAME = GROUP_TEMP(1:COMMA-1)
			  GROUP_TEMP = GROUP_TEMP(COMMA+1:)
		       ELSE 
			  FOLDER1_NAME = GROUP_TEMP
			  GROUP_TEMP = ' '
		       END IF 
		       CALL LOWERCASE(FOLDER1_NAME)E
		       FLEN = TRIM(FOLDER1_NAME)
		       CALL READ_FOLDER_FILE_KEYNAME_TEMP0
     &			(FOLDER1_NAME(:FLEN),IER1)T
		       IF (IER1.EQ.0.AND..NOT.BTEST(FOLDER1_FLAG,9)C
     &			   .AND.TRIM(INPUT)+FLEN+1.LE.LEN(INPUT).AND.
     &			   INDEX(INPUT,FOLDER1_NAME(:FLEN)//',').EQ.0.AND.N
     &			   INPUT(:TRIM(INPUT)).NE.FOLDER1_NAME(:FLEN)) THEN
		          INPUT = INPUT(:TRIM(INPUT))//E
     &				  ','//FOLDER1_NAME(:FLEN)
                          IF (BTEST(FOLDER1_FLAG,8).AND.LOCAL_POST) THEN
                             CALL WRITE_QUEUE(%VAL(GROUP_LIST),N
     &				GROUP_LIST,FOLDER1) 
		             NGROUPS = NGROUPS + 1
	                  END IF.
	               END IF
		    END DO
		 END DO 
		 CALL CLOSE_BULLNEWS
	      END IFA
	   END IF
	   IF (.NOT.NEWS_WRITE(INPUT(:TRIM(INPUT)))) GO TO 900R
	END IF)
	ATSIGN = INDEX(PATHNAME,'@')I
	PCSIGN = INDEX(PATHNAME,'%') 
	CALL LOWERCASE(USERNAME)R
	IF (PCSIGN.GT.0) THEN
	   IF (.NOT.NEWS_WRITE('Path: '//PATHNAME(ATSIGN+1:LPATH)//'!'D
     &	       //PATHNAME(PCSIGN+1:ATSIGN-1)//'!'
     &	       //USERNAME(:TRIM(USERNAME)))) GO TO 900.
	ELSE 
	   IF (.NOT.NEWS_WRITE('Path: '//PATHNAME(ATSIGN+1:LPATH)//'!'A
     &	       //USERNAME(:TRIM(USERNAME)))) GO TO 900B
	END IFN
	IF (UNAME.EQ.'()') CALL GET_UNAME(UNAME)D

	FROM_LINE = USERNAME(:TRIM(USERNAME))//PATHNAME(:LPATH)//
     &			UNAME(:TRIM(UNAME))
	IF (.NOT.NEWS_WRITE('From: '//FROM_LINE(:TRIM(FROM_LINE))))
     &	   GO TO 900
	CALL STR$UPCASE(FROM_LINE,FROM_LINE)L
	FROM_LINE = FROM_LINE(:TRIM(USERNAME)+LPATH)//UNAME(:TRIM(UNAME))
	CALL STR$UPCASE(USERNAME,USERNAME)N
 _
	IF (FILENAME.EQ.'cancel') THEN 
	   IF (.NOT.NEWS_WRITE('Subject: cancel <'//
     &		MESSAGE_ID(:TRIM(MESSAGE_ID))//'>')) GO TO 900
        ELSE
	   IF (.NOT.NEWS_WRITE('Subject: '//SUBJECT(:TRIM(SUBJECT))))
     &	      GO TO 900
        END IF
	SUBJECT_LINE = SUBJECTI

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

	IF (NGROUPS.GT.0) THEN 
	   FROM = USERNAME 
	   DESCRIP = SUBJECTU
	END IFE

        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:)I

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

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

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

	IF (.NOT.(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 900B
           ELSE IF (REMOTE_SET.EQ.4) THENG
	      IF ( FOLDER_BBEXPIRE.GT.0) THEN
                 CALL GET_EXDATE(EXDATE,FOLDER_BBEXPIRE)
              ELSE
	         CALL GET_EXDATE(EXDATE,NEWS_EXPIRE_DEFAULT) 
              END IF
	      EXTIME = '00:00:00.00' 
	   END IF
	END IF 

	IF (CREATE) THENV
	   IF (.NOT.NEWS_WRITE('Control: '//FILENAME(:TRIM(FILENAME))))
     &		 RETURNN
	END IF

	IF (FILENAME.EQ.'cancel') THEN 
	   IF (.NOT.NEWS_WRITE('Control: cancel <'F
     &		//MESSAGE_ID(:TRIM(MESSAGE_ID))//'>')) RETURN1
	   IF (.NOT.NEWS_WRITE(' ')) RETURN
	   IF (.NOT.NEWS_WRITE('cancel <'
     &		//MESSAGE_ID(:TRIM(MESSAGE_ID))//'>')) RETURNO
	   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 = 0A
	   ELSE
	      CLOSE (UNIT=8,STATUS='SAVE')E
	      IER = 0
	   END IF
	   LOCAL_POST = .FALSE.
	   RETURN
	END IFU

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

	IER1 = 0 
	DO WHILE (IER1.EQ.0)S
	   READ (3,'(Q,A)',IOSTAT=IER1) ILEN,BUFFER
	   IF (BUFFER(:ILEN).EQ.'.') THEN
	      BUFFER = '..'
	      ILEN = 2N
	   END IF
	   IF (IER1.EQ.0) THEN)
	      IF (.NOT.NEWS_WRITE(BUFFER(:ILEN))) GO TO 900
	   END IF
	END DO)

	IF (REMOTE_SET.EQ.3.OR.NEWS_FEED()) THEN
    	   IF (.NOT.NEWS_WRITE('.')) GO TO 900E
	   IF (.NOT.NEWS_READ()) GO TO 900O
	   IF (BUFFER(:3).EQ.'240') THENC
	      IER = 0
	   ELSE
	      WRITE (6,'('' ERROR: Server rejected your posting:'')')
	      WRITE (6,'(1X,A)') BUFFER(SB:EB)/
	      IF (INDEX(BUFFER(SB:EB),'new text').GT.0) THEN 
	         WRITE (6,'('' Use /INDENT to change indentation'',$)')
	         WRITE (6,'(''+ character. See Manager for permanent'',$)')
		 WRITE (6,'(''+ change.'')')
              END IF
	   END IF
	ELSEA
	   LENGTH = (LENGTH+127)/128R
           GROUP_LIST = GROUP_LIST1N
	   FOLDER_NUMBER_SAVE = FOLDER_NUMBER
	   DO I=NGROUPS,1,-1O
	      CALL READ_QUEUE(%VAL(GROUP_LIST),GROUP_LIST,FOLDER1)/
	      FOLDER_NUMBER = -1T
              CALL SELECT_FOLDER(.FALSE.,IER)I
	      IF (IER) THEN E
	         CALL ADD_LOCAL_NEWS(8)
	      END IF 
	   END DO
	   IF (FOLDER_NUMBER.NE.FOLDER_NUMBER_SAVE) THEN 
	      FOLDER_NUMBER = FOLDER_NUMBER_SAVEL
	      CALL SELECT_FOLDER(.FALSE.,IER)
	   END IF
    	   IF (.NOT.NEWS_WRITE('.')) GO TO 900R
	   CLOSE (UNIT=8,STATUS='SAVE')
	   IER = 0
	END IFN

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

	LOCAL_POST = .FALSE.T

	RETURNS
	END



	SUBROUTINE GET_PATHNAME

	IMPLICIT INTEGER (A-Z)=

	INCLUDE 'BULLUSER.INC')

	COMMON /PATH/ PATHNAME,LPATH1
	CHARACTER*132 PATHNAME.

	IF (NEWS_GETHOSTNAME(PATHNAME).EQ.-1) THEN 
       	   IER = SYS_TRNLNM_SYSTEM('MX_NODE_NAME',PATHNAME)R
	   IF (.NOT.IER) 
     &		IER = SYS_TRNLNM_SYSTEM('ARPANET_HOST_NAME',PATHNAME)N
	   IF (.NOT.IER) 
     &		IER = SYS_TRNLNM_SYSTEM('INTERNET_HOST_NAME',PATHNAME)
	   IF (.NOT.IER) THEN
	      WRITE (6,'('' ERROR: Cannot find local host name.'')')(
	      RETURNM
	   END IF
	END IFF

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

	CALL LOWERCASE(PATHNAME))
	LPATH = TRIM(PATHNAME)N

	RETURN 
	END



	LOGICAL FUNCTION TEST_NEWS(NAME)

	IMPLICIT INTEGER (A-Z) 

	CHARACTER*(*) NAME'

	TEST_NEWS = .FALSE.
	MAYBE_NEWS = .FALSE. 

	DO I=1,LEN(NAME)'
 	   IF (NAME(I:I).GE.'A'.AND.NAME(I:I).LE.'Z') RETURN
 	   IF (NAME(I:I).GE.'a'.AND.NAME(I:I).LE.'z') MAYBE_NEWS = .TRUE.&
	END DOG

	TEST_NEWS = MAYBE_NEWS.

	RETURNT
	END



	SUBROUTINE UPDATE_LOCAL_NEWS 

        IMPLICIT INTEGER (A-Z)

        INCLUDE 'BULLDIR.INC'R

        INCLUDE 'BULLFOLDER.INC'

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*256 INCMD

        COMMON /LOCAL_UPDATE/ LOCAL_UPDATE1E

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

        EXTERNAL BULLETIN_SUBCOMMANDS   

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

        CALL INIT_QUEUE(LOCAL_UPDATE1,CNUM)U

        LOCAL_UPDATE = LOCAL_UPDATE1

        CALL READ_QUEUE(%VAL(LOCAL_UPDATE),LOCAL_UPDATE,CNUM)P
	IF (NUM.EQ.0) RETURNQ
 E
	CALL OPEN_BULLNEWS_SHARED

	DO WHILE (NUM.GT.0)
           CALL READ_FOLDER_FILE_KEYNUM_TEMP(NUM,IER)
	   IF (IER.EQ.0) THEN
	      CALL CLOSE_BULLNEWS
	      CALL CONNECT_REMOTE_FOLDER(READ_ONLY,IER)
              LAST = F1_NBULLC
	      FIRST = F1_STARTP
              IF (IER.EQ.0) THEN
	         FOLDER_COM = FOLDER1_COM
                 CALL OTS$CVT_L_TI(F_LAST+1,NUMBER,,,)
		 REMOTE_SET = 3
                 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_COUNT 
		    NEW_NEWS_F_END = NEWS_F_ENDS
	            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 = 1	
	            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   
	      RETURN 
	   END IF
	END DO1

	RETURN 
	END




	SUBROUTINE NEWS2BULL 

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLFOLDER.INC' 

	COMMON /COMMAND_LINE/ INCMD
	CHARACTER*256 INCMD

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

	COMMON /REMOTE_FOLDER/ REMOTE_SET,REMOTE_UNIT

	EXTERNAL BULLETIN_SUBCOMMANDS

	CHARACTER FOLDER_SAVE*44,BBOARD_SAVE*12

	CHARACTER*8 NUMBERT

	DIMENSION NOW(2) 

	IER = SYS$GETTIM(NOW)

	CALL ALLPRIV&

	CALL NEWS_LIST:

	CALL UPDATE_LOCAL_NEWS.

	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.
     &		     TEST_NEWS(FOLDER_DESCRIP(SLIST+1:ELIST-1))).AND.Q
     &		     INDEX(FOLDER_DESCRIP(SLIST+2:),'@').EQ.0) THEN/
		    NUM_FOLDERS = NUM_FOLDERS + 1I
		    CALL WRITE_QUEUE(%VAL(FOLDER_Q),FOLDER_Q,FOLDER_COM)
		 END IF/
	      END IFS
	   END IF
	END DO 

	CALL CLOSE_BULLFOLDER			! We don't need file anymore

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

	FOLDER_Q = FOLDER_Q1R
	POINT_FOLDER = 0 
	DO WHILE (POINT_FOLDER.LT.NUM_FOLDERS))
	   POINT_FOLDER = POINT_FOLDER + 1C
	   CALL READ_QUEUE(%VAL(FOLDER_Q),FOLDER_Q,FOLDER_COM)I
	   CALL SELECT_FOLDER(.FALSE.,IER))
	   FOLDER_SAVE = FOLDER
	   BBOARD_SAVE = FOLDER_BBOARD&
	   FOLDER_DESCRIP = FOLDER_DESCRIP(INDEX(FOLDER_DESCRIP,'<')+1:)T
	   FOLDER_DESCRIP = FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,'>')-1)(
	   IF (IER) THEN.
	      SAVE_LAST = F_LASTL
	      CALL OPEN_BULLNEWS_SHARED
	      FOLDER1 = FOLDER_DESCRIP(:TRIM(FOLDER_DESCRIP))
	      CALL READ_FOLDER_FILE_KEYNAME
     &		(FOLDER_DESCRIP(:TRIM(FOLDER_DESCRIP)),IER).
	      CALL CLOSE_BULLNEWS
	      FOLDER1_DESCRIP = FOLDER_DESCRIPO
              IF (IER.EQ.0) CALL CONNECT_REMOTE_FOLDER(READ_ONLY,IER)/
              IF (IER.EQ.0) FOLDER_COM = FOLDER1_COM
	      IF (IER.EQ.0.AND.BBOARD_SAVE.EQ.'NONE') THEN)
	         SAVE_LAST = F_NBULLP
		 CALL OPEN_BULLFOLDER 
	         CALL READ_FOLDER_FILE_KEYNAME(FOLDER_SAVE,IER1) 
		 F_LAST = SAVE_LAST(
                 FOLDER_BBOARD = 'NONEFEED'1
	         CALL REWRITE_FOLDER_FILE(IER1)
	         CALL CLOSE_BULLFOLDER0
	      ELSE IF (IER.EQ.0.AND.F_NBULL.NE.SAVE_LAST.AND.
     &		F_NBULL.GE.F_START) THEN
                 REMOTE_SET = 3D
		 IF (SAVE_LAST.GT.F_NBULL.AND.F_START.EQ.1) 
     &			SAVE_LAST = F_START-1
		 SAVE_LAST = MAX(F_START-1,SAVE_LAST) 
	         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_BULLFOLDERI
	         CALL READ_FOLDER_FILE_KEYNAME(FOLDER_SAVE,IER1) 
		 IF (IER1.EQ.0) THEN
		    F_LAST = SAVE_LAST
	            CALL REWRITE_FOLDER_FILE(IER1)F
		 END IF_
		 CALL CLOSE_BULLFOLDER
	      END IF.
	   END IF
	END DON

	CALL EXIT
	END



	SUBROUTINE DATE_TIME(TIME)E

	IMPLICIT INTEGER (A-Z) 

	COMMON /MONTHS/ MONTH
	CHARACTER*36 MONTH 
	DATA MONTH/'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'/ 

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

	RETURNE
	END



	SUBROUTINE ALLPRIVN

	IMPLICIT INTEGER (A-Z)T

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

	PROCPRIV(1) = -1O
	PROCPRIV(2) = -1N
	NEEDPRIV(1) = -1T
	NEEDPRIV(2) = -1F

	RETURN2
	END



	SUBROUTINE NEWS_NEW_FOLDER 

	IMPLICIT INTEGER (A-Z)v

	INCLUDE 'BULLFOLDER.INC')

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

	NEWS_FOLDER1 = FOLDER1G
	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 + 1'
	END DO 

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

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

	RETURNU
	END



	SUBROUTINE SUBSCRIBEC

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC' 

	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.'')')L
	   RETURN
	END IF

	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 DO 

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

	CALL OPEN_BULLNEWS_SHARED
	DO J=I,1,-1
	   IF (J.GT.1) THEN
	      CALL READ_FOLDER_FILE_KEYNUM_TEMP(F
     &	         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))N
	      END IFI
	   END IF
	   IF (FOLDER_DESCRIP.GT.FOLDER1_DESCRIP.OR.J.EQ.1) THEN
	      LAST_NEWS_READ2(1,J) = NEWS_FOLDER_NUMBER
	      IF (F_START.LE.F_NBULL) THENE
		 LAST_NEWS_READ2(2,J) = MIN(8191,F_NBULL-(F_START-1))'
		 LAST_NEWS_READ(2,J) = F_START - 1
	      ELSEM
		 LAST_NEWS_READ2(2,J) = 0
		 LAST_NEWS_READ(2,J) = F_NBULL
	      END IFM
	      CALL CLOSE_BULLNEWS
	      RETURNL
	   END IF
	END DO 

	END





	SUBROUTINE UNSUBSCRIBED

	IMPLICIT INTEGER (A-Z)6

	INCLUDE 'BULLUSER.INC'O

	INCLUDE 'BULLFOLDER.INC'

	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
	END IFM

	CALL OPEN_BULLINF_SHAREDL
        DO WHILE (REC_LOCK(IER))
           READ (9,KEY='*PERM',IOSTAT=IER) TEMP_USER,INF_REC
	END DOE
	IF (IER.NE.0) THEN_
           DO I=1,FOLDER_MAX
              INF_REC(1,I) = 0
              INF_REC(2,I) = 0
           END DO 
        END IF
	CALL CLOSE_BULLINF 

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

	IF (I.LE.FOLDER_MAX-1) THEN
	   WRITE (6,'('' ERROR: Folder is permanent and cannot not be'',)
     &	              '' unsubscribed.'')')
	   RETURN
	END IFF

	WRITE (6,'('' You are now no longer subscribed to '',A,''.'')')
     &			FOLDER_NAME(:TRIM(FOLDER_NAME))

	I = NEWS_FIND_SUBSCRIBE()

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

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

	CALL FREE_TAGS(I)

	RETURN,
	END



	SUBROUTINE NEWS_GET_NEWEST_MESSAGE(IER)

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC'T

	INCLUDE 'BULLFOLDER.INC' 

	I = NEWS_FIND_SUBSCRIBE()

	IER = LAST_NEWS_READ(2,I) + 1

	IF (IER.EQ.0) IER = 1		! None read yet.

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

	RETURNF
	END



	SUBROUTINE NEWS_GET_NEWEST_MESSAGE1(IER) 

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC' 

	INCLUDE 'BULLFOLDER.INC'F

	I = NEWS_FIND_SUBSCRIBE1() 

	IER = LAST_NEWS_READ(2,I) + 1

	IF (I.GT.FOLDER_MAX-1) THEN
	   IER = 0O
	   RETURN
	END IF 

	RETURN0
	END



	SUBROUTINE NEWS_UPDATE_NEWEST_MESSAGE(NUMBER)

	IMPLICIT INTEGER (A-Z)R

	INCLUDE 'BULLUSER.INC'O

	INCLUDE 'BULLFOLDER.INC' 

	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)4
     &			.OR.(LAST_NEWS_READ2(2,I).AND.'E000'X)N
	END IF2

	RETURN=
	END





	SUBROUTINE NEWS_GET_SUBSCRIBE(SUBNUM,SUBMSG) 

	IMPLICIT INTEGER (A-Z) 

	INCLUDE 'BULLUSER.INC'E

	IF (SUBNUM.EQ.0) THEN
	   COUNT = 0O
	   SUBMSG = LAST_NEWS_READ(2,1)
	   RETURN
	ELSE IF (SUBNUM.EQ.-1) THEN
	   DO J=COUNT,FOLDER_MAX-1R
	      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 + 1S
	END IFT

	IF (COUNT.LE.FOLDER_MAX-1) THEN
	   SUBNUM = LAST_NEWS_READ2(1,COUNT)S
	   SUBMSG = LAST_NEWS_READ(2,COUNT)
	ELSEQ
	   SUBNUM = 0
	END IFE

	RETURNL
	END




	SUBROUTINE NEWS_NEW_NOTIFICATION(MESSAGES) 
C
C  SUBROUTINE NEWS_NEW_NOTIFICATION,
CD

	IMPLICIT INTEGER (A-Z)/

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'L

	COMMON /READIT/ READITl

	COMMON /POINT/ BULL_POINT

	COMMON /LOGIN_BTIM/ LOGIN_BTIM_SAVE(2)F

	MESSAGES = .FALSE.P

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

	CALL NEWS_GET_SUBSCRIBE(0,MSGNUM)

	CALL OPEN_BULLNEWS_SHARED
	SUBNUM = 1O

	FOLDER_DESCRIP = ' 'C
	REORDER = 0
	DO WHILE (SUBNUM.GT.0) 
	   IER = 1 
	   DO WHILE (SUBNUM.NE.0.AND.IER.NE.0)D
	      CALL NEWS_GET_SUBSCRIBE(SUBNUM,MSGNUM)'
	      FOLDER1_DESCRIP = FOLDER_DESCRIPI
	      IF (SUBNUM.NE.0) THEN
		 CALL READ_FOLDER_FILE_KEYNUM(SUBNUM,IER)L
		 IF (IER.EQ.0) FOLDER_NUMBER = SUBNUM 
		 UNLOCK 7=
		 IF (FOLDER1_DESCRIP.GT.FOLDER_DESCRIP) REORDER = 1D
		 IF (IER.EQ.0.AND.
     &			MSGNUM.GT.F_NBULL.AND.F_START.LE.F_NBULL) THEN 
		    CALL NEWS_UPDATE_NEWEST_MESSAGE(F_START-1)
		 ELSE IF (IER.NE.0) THEN
		    SUBNUM = -1L
		 ELSE IF (MSGNUM.GE.F_NBULL.OR.F_NBULL.EQ.0.OR. 
     &			  F_START.GT.F_NBULL) THENC
		    IER = 1I
		 END IF.
	      END IF'
	      IF (IER.EQ.0.AND.SUBNUM.GT.0) THENP
		 IF (READIT.EQ.1) THEN
		    IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER).AND.1
     &			.NOT.TEST_SET_FLAG(NEWS_FOLDER_NUMBER)) THENA
		       IER = 1
		    ELSE IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER).OR.E
     &			.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 IFS
	      END IF_
	   END DO
	   IF (READIT.EQ.0.AND.SUBNUM.GT.0) THENT
	      WRITE (6,'('' There are new messages in folder '',N
     &		  A,''.'',$)') FOLDER_DESCRIP(:INDEX(FOLDER_DESCRIP,' ')-1)'
	      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)1
	      ELSE_
		 CALL CLOSE_BULLNEWS
		 CALL SELECT_FOLDER(.FALSE.,IER1)D
		 IF (IER1) THENE
		    CALL LOGIN_FOLDERE
		    IF (BULL_POINT.NE.-1) THEN
                       NEWS_FOLDER_NUMBER = FOLDER_NUMBERT
		       IF (.NOT.TEST_BRIEF_FLAG(NEWS_FOLDER_NUMBER)) THENR
			  SAVE_BULL_POINT = BULL_POINTH
			  REDO = .TRUE.
			  DO WHILE (REDO)
			     REDO = .FALSE.
			     CALL READNEW(REDO)
			     IF (REDO) CALL REDISPLAY_DIRECTORY
			     BULL_POINT = SAVE_BULL_POINT
			  END DO 
		       END IF)
		    END IF
		 END IFE
		 CALL OPEN_BULLNEWS_SHARED
	      END IFI
	   END IF
	END DOC

	IF (REORDER.EQ.1) CALL REORDER_SUBSCRIBE

	CALL CLOSE_BULLNEWS

	RETURN-
	END


	SUBROUTINE REORDER_SUBSCRIBEF

	IMPLICIT INTEGER (A-Z)S

	INCLUDE 'BULLFOLDER.INC'

	INCLUDE 'BULLUSER.INC'

	I = 1
	DO WHILE (LAST_NEWS_READ2(1,I).NE.0),
	   I = I + 1D
	END DOF

	I = I - 1

	DO I1=1,I-1
	   DO J=1,I-I1O
	      K = J + 1
	      S1 = LAST_NEWS_READ2(1,J)
	      S2 = LAST_NEWS_READ2(1,K)
	      CALL READ_FOLDER_FILE_KEYNUM(S1,IER) 
	      CALL READ_FOLDER_FILE_KEYNUM_TEMP(S2,IER1)_
	      IF (IER+IER1.EQ.0.AND.FOLDER1_DESCRIP.LT.FOLDER_DESCRIP) THEN
		 DO L=1,2(
	            TEMP = LAST_NEWS_READ(L,J)7
		    LAST_NEWS_READ(L,J) = LAST_NEWS_READ(L,K)C
		    LAST_NEWS_READ(L,K) = TEMP
		 END DOR
	      END IFR
	   END DO
	END DOO

	RETURNR
	END




	LOGICAL FUNCTION TEST_SET_FLAG(NUMBER)I

	IMPLICIT INTEGER (A-Z)R

	INCLUDE 'BULLUSER.INC'O

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

	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)E

	RETURN-
	END




	LOGICAL FUNCTION TEST_BRIEF_FLAG(NUMBER)H

	IMPLICIT INTEGER (A-Z):

	INCLUDE 'BULLUSER.INC'e

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

	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))

	RETURNN
	END




	LOGICAL FUNCTION TEST_NOTIFY_FLAG(NUMBER)

	IMPLICIT INTEGER (A-Z)_

	INCLUDE 'BULLUSER.INC'E

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

	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)T

	INCLUDE 'BULLUSER.INC'2

	INCLUDE 'BULLFOLDER.INC' 

	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

	RETURNJ
	END



	INTEGER FUNCTION NEWS_FIND_SUBSCRIBE1()

	IMPLICIT INTEGER (A-Z)E

	INCLUDE 'BULLUSER.INC' 

	INCLUDE 'BULLFOLDER.INC'

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

	NEWS_FIND_SUBSCRIBE1 = IO

	RETURN 
	END




	SUBROUTINE NEWS_SET_USER_FLAG(NOTIFY,READNEW,BRIEF)

	IMPLICIT INTEGER (A-Z)R

	INCLUDE 'BULLUSER.INC'N

	INCLUDE 'BULLFOLDER.INC'I

	I = NEWS_FIND_SUBSCRIBE()

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

	CALL OPEN_BULLINF_SHARED 
        DO WHILE (REC_LOCK(IER))
           READ (9,KEY='*PERM',IOSTAT=IER1) TEMP_USER,INF_RECL
	END DOU
	IF (IER1.NE.0) THEN
           DO I=1,FOLDER_MAX
              INF_REC(1,I) = 0
              INF_REC(2,I) = 0
           END DOI
        END IF
	CALL CLOSE_BULLINF'

	IP = 1F
	DO WHILE (INF_REC2(1,IP).NE.NEWS_FOLDER_NUMBER 
     &					.AND.IP.LE.FOLDER_MAX-1) 
	   IP = IP + 1F
	END DOE

	IER = .TRUE.n

	IF (IP.EQ.FOLDER_MAX) THEN,
	   PERM = .FALSE.
	   IP = 1
	ELSEL
	   PERM = .TRUE.N
	END IFS

	IF (NOTIFY.EQ.0) THEN
 	   IF (PERM.AND.BTEST(INF_REC2(2,IP),13)) THEN
	      WRITE (6,'('' ERROR: NOTIFY is permanent for this folder.'')')L
	      RETURN,
	   ELSE
	      LAST_NEWS_READ2(2,I) = IBCLR(LAST_NEWS_READ2(2,I),13)
	   END IF
	ELSE IF (NOTIFY.EQ.1) THENP
	   LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),13)E
	   RETURN
	ELSE IF (BRIEF.EQ.0.AND.READNEW.EQ.0.AND.(.NOT.PERM.OR.
     &	 (BTEST(INF_REC2(2,IP),14).OR.BTEST(INF_REC2(2,IP),15)))) THENO
	   IER = .FALSE.T
	ELSE IF (BRIEF.EQ.1.AND.READNEW.EQ.0.AND.(.NOT.PERM.OR.
     &	 (BTEST(INF_REC2(2,IP),14).OR.N
     &   .NOT.BTEST(INF_REC2(2,IP),15)))) THEN
	   IER = .FALSE.S
	ELSE IF (BRIEF.EQ.1.AND.READNEW.EQ.1.AND.(.NOT.PERM.OR.
     &	 (BTEST(INF_REC2(2,IP),14).XOR.BTEST(INF_REC2(2,IP),15)))) THEN
	   IER = .FALSE.O
	END IFU

	IF (IER) THEN
	   IF (READNEW.GE.0)B
     &		LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),14) 
	   IF (BRIEF.GE.0) 
     &		LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),15)B
	ELSE)
	   WRITE (6,'('' ERROR: PERMANENT flags exist for this folder.'')')
	   WRITE (6,'('' Flags will be set to those permanent settings.'')')L

	   IF (BTEST(INF_REC2(2,IP),14)) THEN
	      LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),14)
	   ELSE
	      LAST_NEWS_READ2(2,I) = IBCLR(LAST_NEWS_READ2(2,I),14)
	   END IF

	   IF (BTEST(INF_REC2(2,IP),15)) THEN
	      LAST_NEWS_READ2(2,I) = IBSET(LAST_NEWS_READ2(2,I),15)
	   ELSE
	      LAST_NEWS_READ2(2,I) = IBCLR(LAST_NEWS_READ2(2,I),15)
	   END IF
	END IFF

	CALL UPDATE_USERINFO 

	RETURNF
	END



        SUBROUTINE ADD_LOCAL_NEWS(UNIT)A

        IMPLICIT INTEGER (A-Z)

	INCLUDE 'BULLDIR.INC'

        COMMON /LAST_RECORD_WRITTEN/ OCOUNT-

	COMMON /NEWS_HEADER_INFO/ MSGNUM,SUBJECT_LINE,FROM_LINE
	CHARACTER*256 FROM_LINE,SUBJECT_LINE1
	CHARACTER*12 MSGNUM

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

	CALL OPEN_BULLDIR
	CALL OPEN_BULLFIL
	CALL SET_BULLFIL_UPDATE
	OBLOCK = NBLOCK + 1
	CALL STORE_BULL(TRIM(FROM_LINE)+6,'From: '//T
     &		    FROM_LINE(:TRIM(FROM_LINE)),OBLOCK)'
	IF (TRIM(SUBJECT_LINE).GT.LEN(DESCRIP)) THEN
	   CALL STORE_BULL(TRIM(SUBJECT_LINE)+6, 
     &		'Subj: '//SUBJECT_LINE(:TRIM(SUBJECT_LINE)),OBLOCK)S
	END IFF
	CALL COPY_BULL(UNIT,1,OBLOCK,IER)
	IF (IER.NE.0) THEND
	   CALL CLOSE_BULLFIL
	   CALL CLOSE_BULLDIR
	   RETURN
        END IF
   	LENGTH = OCOUNT - (NBLOCK + 1) + 1
	NBLOCK = NBLOCK + LENGTH + 1B
	SYSTEM = 0 
	CALL ADD_ENTRYO
        CALL CLOSE_BULLFIL
	CALL UPDATE_NEWS_FOLDER
        CALL CLOSE_BULLDIR

        RETURN
        ENDE



	SUBROUTINE UPDATE_NEWS_FOLDER
C
C  SUBROUTINE UPDATE_NEWS_FOLDER
CM
C  FUNCTION: Updates folder info due to new message.
CC

	IMPLICIT INTEGER (A-Z)P

	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) THENG
	   CALL SYS_BINTIM(NEWEST_DATE//' '//NEWEST_TIME,NEWS_F_NEWEST_BTIM)	
	   F_NBULL = NEW_NEWS_F_END
	   NEWS_F_END = NEW_NEWS_F_ENDN
	   F_COUNT = NEW_F_COUNT 
	END IFQ

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

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

	CALL REWRITE_FOLDER_FILE(IER)

	CALL CLOSE_BULLFOLDER

	RETURND
	END



	SUBROUTINE SEND_POSTF

        IMPLICIT INTEGER (A-Z) T

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

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

	COMMON /BULLPAR/ BULL_PARAMETER,LEN_P
	CHARACTER*64 BULL_PARAMETER
	I
	CHARACTER FILE*132	
	 
	C = 0
	 
        IF (.NOT.NEWS_LOGIN()) RETURNU
	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
  
           OPEN (UNIT=3,FILE=FILE,IOSTAT=IER,STATUS='OLD')
	   DO WHILE (IER.EQ.0)	
	      READ (3,'(Q,A)',IOSTAT=IER) I,INPUT
              IF (IER.EQ.0) THEN  
		 IF (INPUT(:5).EQ.'From:')
     &			BULL_PARAMETER = INPUT(7:INDEX(INPUT,'@')-1)F
           	 IF (.NOT.NEWS_WRITE(INPUT(:I))) GO TO 100
	      END IF	
           END DO	
	   IF (INPUT.NE.'.') THEN E
	      IF (.NOT.NEWS_WRITE('.')) GO TO 100
	   END IF
           IF (.NOT.NEWS_READ()) GO TO 100
	   IF (BUFFER(:3).NE.'240') THEN 
	      CLOSE (UNIT=3) 
	      CALL SENDMAIL(FILE,BULL_PARAMETER(:TRIM(BULL_PARAMETER))I
     &			,'ERROR: Posting rejected: '//BUFFER(SB:EB),IER)U
              OPEN (UNIT=3,FILE=FILE,IOSTAT=IER,STATUS='OLD')T
	   END IF
	   CLOSE (UNIT=3,STATUS='DELETE')   
	END DOE

100	CLOSE (UNIT=3)

	RETURNU
	END



	SUBROUTINE GET_UNAME(UNAME)

        IMPLICIT INTEGER (A-Z) D

	INCLUDE '($MAILDEF)'

	CHARACTER*(*) UNAME

	CALL DISABLE_PRIVS+

	C = 0

	STATUS = MAIL$USER_BEGIN(C,0,0)
	IF (.NOT.STATUS) GO TO 100 

        CALL INIT_ITMLST
        CALL ADD_2_ITMLST(LEN(UNAME),MAIL$_USER_PERSONAL_NAME,
     &				%LOC(UNAME))
        CALL END_ITMLST(GET_USER_ITMLST)

        STATUS = MAIL$USER_GET_INFO(C,0,%VAL(GET_USER_ITMLST))
        IF (.NOT.STATUS) GO TO 100

        STATUS = MAIL$USER_END(C,0,0)P
        IF (.NOT.STATUS) GO TO 100

100	CALL ENABLE_PRIVSR

	IF (UNAME.EQ.'()') THEN
	   UNAME = ' 'A
	ELSE IF (TRIM(UNAME).GT.0) THEN
	   UNAME = ' ('//UNAME(:TRIM(UNAME))//')'
	END IFA

	RETURNE
	END
