[comp.os.vms] NEWMAIL.COM - a DCL proc to display new mail counts etc.

dww@stl.stc.co.uk (David Wright) (01/27/88)

I originally posted this 3 months ago, but in view of the continued postings 
on questions it answers - e.g.  "where does VMS hold mail counts, dir's, 
forwarding and what is the format and how can I display it?" - it doesn't
seem to have reached many people.   
I'm pretty sure our postings reach the full list now, so here it is again.

This posting is mainly of use to System Managers.   It contains the program
NEWMAIL.COM, which will list either all your users who have unread new mail,
or else the details of all users (and "SET FORWARD" names) as known to the
mail system on your machine.   MAIL holds this information in file
VMSMAIL.DAT; this program lists VMSMAIL.DAT in a human-readable format. 

I wrote this program after receiving Bruce Bergman's VMSINFO.COM.   That
program listed information for a known user; I wanted to list all users.
Bruce's code made it easy for me to write this program, which contains much
of his code but serves a different purpose.  Feel free to reuse this code in
turn if you wish.

                        David Wright, dww@stl.stc.co.uk        

$!..................... Cut between dotted lines and save ......................
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-5.01 01-Oct-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by DWW on Sunday 8-NOV-1987 10:11:46.00
$!
$! It contains the following 1 file:
$! NEWMAIL.COM
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="NEWMAIL.COM"
$ Check_Sum_is=1211909520
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$! NEWMAIL -  a program to list the information in VMSMAIL.DAT
X$!
X$! usage:
X$!
X$!      @NEWMAIL        Lists users who have new mail
X$!      @NEWMAIL ALL    Lists all users in VMSMAIL.DAT (including the old ones
V$!                                                      you thought had gone...
X)
X$!
X$! Note - this program requires read access to VMSMAIL.DAT, which usually
X$!        requires SYSTEM privilege
X$!
X$! When p1 = ALL all entries in VMSMAIL.DAT are listed; this includes all
X$! users of your machine who have ever received mail and all names for which
X$! mail forwarding has ever been set up, even if it has subsequently been
X$! set 'noforward' again.
X$!
X$! VMS does not remove entries from VMSMAIL.DAT when you set 'noforward'.
X$! You can remove individual entries with the DEC-supplied MAILUAF.COM
X$! program, which is in [SYSHLP.EXAMPLES].    I have written a program to
X$! create a clean new VMSMAIL.DAT file with only the currently valid entries
X$! in it but unlike NEWMAIL.COM it is system specific and would need editing
X$! for other systems.
X$!
X$! D.W.Wright     dww@stl.stc.co.uk     October 1987
X$! VMSMAIL code taken from VMSINFO.COM by Bruce A. Bergman bruceb@telesoft.UUCP
X$ !
X$ !    Set up for errors
X$ !
X$ set noon
X$ on control then goto QUIT
X$ on error then goto QUIT
X$!
X$!      Check parameter
X$!
X$ all = p1 .eqs. "ALL"
X$!
X$ if all then write sys$output "List of user information held in VMSMAIL.DAT"
X$ if .not. all then write sys$output "The following users have unread new mail"
X$ write sys$output ""
X$ !
X$ !    Open the mail information file
X$ !
X$ datafile = "SYS$SYSTEM:VMSMAIL.DAT"
X$ open/share/read/error=FAIL mailfile 'datafile'
X$ !
X$LOOP:
X$ !    Get the mail info record
X$ read /nolock/error=QUIT mailfile record
X$ user         = f$edit(f$extract(0, 31, record),"TRIM")
X$ newmsgs      = f$cvui(33*8, 8, record)
X$ if .not. all .and. newmsgs .eq. 0 then goto LOOP      ! No 'new mail'
X$!
X$ mail_len     = f$cvui(65*8, 8, record)
X$ personal_len = f$cvui(66*8, 8, record)
X$ forward_len  = f$cvui(67*8, 8, record)
X$ !
X$ messages = " has ''newmsgs' new message(s)"
X$ if newmsgs .eq. 0 then messages = ""
X$ !
X$ !    Starting position of variable length info
X$ last_position = 68
X$ !
X$ forward = " - new mail is forwarded to " + -
X        f$extract(last_position, forward_len, record)
X$ if forward_len .le. 0 then forward = ""
X$ last_position = last_position + forward_len
X$ !
X$ personal = " (" + f$extract(last_position, personal_len, record) + ")"
X$ if personal_len .le. 0 then personal = ""
X$ last_position = last_position + personal_len
X$ !
X$ mail_dir = " in [" + user + f$extract(last_position+1, mail_len, record)
X$ if mail_len .eq. 0 then mail_dir = ""
X$!
X$!
X$!
X$ write sys$output user, personal, messages, mail_dir, forward
X$ goto LOOP
X$ !
X$ !
X$QUIT:
X$ close mailfile
X$ exit
X$ !
X$ !    Error handlers
X$ !
X$FAIL:
X$ write sys$output -
X "Unable to open ''datafile' for input - no such file or no privilege"
X$ exit
$ GoSub Convert_File
$ Exit
$! .........................................................................

-- 
Regards,
        David Wright           STL, London Road, Harlow, Essex  CM17 9NA, UK
dww@stl.stc.co.uk <or> ...uunet!mcvax!ukc!stl!dww <or> PSI%234237100122::DWW