%begin
%option "-nocheck-nodiag"
%include "inc:util.imp"
%include "inc:fs.imp"
%include "inc:fsutil.imp"
%string(127)user list, user

%routine try for mail(%string (127) user)
%constinteger Vax mail    =  4
%constinteger our port    = 13
%constinteger Vax port    =  0
%constinteger Vax station = 16_72
%constinteger timeout     = 5000; !Milliseconds
%constinteger BEL = 7

  %integerfn HDX to I(%string(15) s)
  %integer i, j
    %result = -1 %if s = "" %or s = "????"
    i = 0
    %for j = 1, 1, length(s) %cycle
      i = i << 4 + charno(s, j) - '0'
    %repeat
    %result = i
  %end

%bytearray request(0 : 19)
%string(15) reply
%integer l, i
  request(0) = Vax mail
  string(addr(request(1))) = user
  ether open(our port, Vax station << 8 ! Vax port)
  ether write(our port, request(0), 20)
  l = cputime
  %cycle
    -> OK %if dtx & (1 << our port) # 0
  %repeatuntil cputime-l>=timeout
  printstring("Vax timed out")
  newline
  etherclose(our port)
  %return
OK:  l = ether read(our port, byteinteger(addr(reply) + 1), 15)
  ether close(our port)
  length(reply) = l
  i = HDX to I(reply)
  %if i < 0 %start
    printstring("Vax does not know ".user)
  %else
    printstring(user." has ")
    %if i = 0 %then printstring("no new mail") %elsestart
      write(i, 0)
      printstring(" new mail message")
      print symbol('s') %if i # 1
    %finish
  %finish
  newline
%end

user list = cliparam
user list = current user %if user list=""
try for mail(user) %while user list -> user.(",").user list
try for mail(user list)

%endofprogram
