C******************************************************************************
      integer function new_mail_count()
!
! to return the number of new mail messages awaiting the current user.
! it returns an integer value, with a negative value signifying an error.
! for VMS 4.1 -- 4/22/85
!
      include '($jpidef)'
! functions
      integer         lib$getjpi
! locals
      character       username*31
      integer         i
      byte            record(64)
!------------------------------------------------------------------------------
   10 format( a )
!-------------
      open( unit=95, file='sys$system:vmsmail.dat', iostat=i,
     $      status='old', organization='indexed', 
     $      access='keyed', shared, readonly )
      if( i.ne.0 ) goto 999

      i = lib$getjpi( jpi$_username,,,,username )
      if( .not.i ) goto 999

      read(95,key=username,iostat=i) record
      if( i.ne.0 ) goto 999

      new_mail_count = record(34)
      close( 95 )
      return
!-------------
  999 continue
      close( 95 )
      new_mail_count = -1
      return
       end
