       COMMON /MAICOM/ ENTRY 
      BYTE ENTRY (14,40) 
      BYTE FILNAM(22) 
      BYTE USRNAM(14)
      INTEGER USRBUF(320) 
      INTEGER LUBUF 
      LOGICAL*1 EQUAL 
      LOGICAL*1 FOUND 
      INTEGER IDS,IRET 
      BYTE BELL 
      EQUIVALENCE (IDS,IRET) 
      DATA NENTRY /40/ 
      DATA BELL /7/ 
      DATA LUBUF /320/ 
C	Suppress non-existent file message
      CALL ERRSET(29,,.FALSE.,,.FALSE.)
c	clear buffer from last run
      DO 900 I=1,320
900   USRBUF(I)=0
c     Erase terminal number from last time
      DO 1000 INUM=1,NENTRY
1000  ENTRY(13,INUM)=0
c	Log in each user in proper slot
      CALL GETUSR(USRBUF,LUBUF,IER)
      DO 3000 INUM=1,NENTRY
C	erase no longer used TT from USRBUF
      USRBUF(INUM*8-1)=0
D     WRITE(5,776) (USRBUF(N),N=INUM*8-7,INUM*8)
D776  FORMAT(' ',6A2,I5,I5)
      IF (USRBUF(INUM*8).EQ.0) GOTO 3000
      ITER=(USRBUF(INUM*8))
      IF (EQUAL(USRBUF(INUM*8-7),ENTRY(1,ITER),12)) GOTO 2000
C	User changed at this terminal
D     WRITE(5,777)ITER,(INUM*8-7)
D777  FORMAT(' ',I5,I5)
C	must move 13, cause MVSTR moves 12 then adds null
      CALL MVSTR(ENTRY(1,ITER),USRBUF(INUM*8-7),13)
      ENTRY(13,ITER)=ITER
C	Check this user for a mail directory
      CALL MVSTR (FILNAM,'SD:[10,0]') 
      DO 1400 I=1,14
1400  USRNAM(I)=0
      CALL MVSTR (USRNAM(1),ENTRY(1,ITER),12)
C	Make USRNAM truncated with null again
      DO 1500 I=2,14
1500  IF (USRNAM(I).EQ.32) USRNAM(I)=0
      CALL CONCAT (FILNAM,USRNAM)
      CALL CONCAT (FILNAM,'.MAI')
D     WRITE(5,888)FILNAM
D888  FORMAT(' ',40A1)
      OPEN (NAME=FILNAM,UNIT=1,TYPE='OLD',FORM='FORMATTED',ERR=33) 
C     mail file exists, so tell user
      CLOSE (UNIT=1)
      CALL ASNLUN (2,'TT',ITER)
      WRITE (2,21) BELL,(USRNAM (I),I=1,12)
21    FORMAT (' ',A1,12A1,' You have mail.') 
33    CONTINUE 
c	reset logged on users terminal numbers
2000  ENTRY(13,ITER)=ITER
C     If new mail was created while logged in, also tell user
      IF (ENTRY(14,ITER).EQ.0) GOTO 3000
      CALL ASNLUN (2,'TT',ITER)
      CALL MVSTR (USRNAM(1),ENTRY(1,ITER),12)
C	Make USRNAM truncated with null again
      DO 1600 I=2,14
1600  IF (USRNAM(I).EQ.32) USRNAM(I)=0
      WRITE (2,22) BELL,(USRNAM (I),I=1,12)
22    FORMAT (' ',A1,12A1,' You have new mail.')
      ENTRY(14,ITER)=0
3000  CONTINUE
c	erase any names if user is no longer logged in
      DO 4000 INUM=1,NENTRY
      IF(ENTRY(13,INUM).NE.0) GOTO 4000
      DO 3500 I=1,14
3500  ENTRY(I,INUM)=0
C	done for now
4000  CONTINUE
      CALL EXIT
      END
      SUBROUTINE CONCAT(A,B) 
      BYTE A(1),B(1) 
      CALL MVSTR(A(LENGTH(A)),B) 
      END 
