From:	SMTP%"lauri@elwing.fnal.gov" 18-MAY-1993 17:07:21.99
To:	EVERHART
CC:	
Subj:	Re: NEW-MAIL COUNT with VMS-Mail in batch mode not displayed ?

From: lauri@fndcd.fnal.gov (Laurelin of Middle Earth)
X-Newsgroups: comp.os.vms
Subject: Re: NEW-MAIL COUNT with VMS-Mail in batch mode not displayed ?
Date: 18 May 1993 15:11:28 GMT
Organization: Fermi National Accelerator Lab
Lines: 80
Message-ID: <1taub0$2bq@fnnews.fnal.gov>
Reply-To: lauri@elwing.fnal.gov
NNTP-Posting-Host: elwing.fnal.gov
To: Info-VAX@KL.SRI.COM
X-Gateway-Source-Info: USENET

In a previous article Hany (somebody) and Carl Houseman write:
>>
>>I don't know what the original poster was trying to accomplish, but I need to
>>know how many new mails I have as a first step in a batch program that will
>>send these messages to a list of users. This was also a first step in the
>>program VACATION, but it was somehow done in FORTRAN. There must be a way to
>>do the same thing in DCL, so does anybody know how ?
>
>You could use DCL to read VMSMAIL_PROFILE.DATA directly, based on the file
>format that's been published here and elsewhere.  However, reading the file
>directly is prone to breaking since only callable mail is supported by DEC
>for accessing the file.  The better way would be a program in the language
>of your choice using callable mail to return the new-mail count in a symbol.
>

I wouldn't trust anything that relied upon the new mail count in
VMSMAIL_PROFILE.DATA.  If you've read this list for very long  then you know
about the FAQ where there are more newmail messages in VMSMAIL_PROFILE.DATA
than are really in the mail file.

So what is left?  Brute force.  We use something along the lines of the
following, not elegant and not pretty, but it does get the number of
messages in the NEWMAIL folder.  The chunk of DCL below is actually a
subroutine (gosub) in a larger procedure which uses num_of_messages.

NOTE: I have no idea whether or not this will work if the account in
question uses DECwindows mail with a different folder-name for incoming
messages!  (And, being one of those people who is unabashedly opposed to
rodents in any form, I am not about to test out DECwindows to find out).


-- lauri
 ----------------------------------------------------------------------------- 
| Laurelin Loebel            "All that is gold does not glitter,              |
| lauri@elwing.fnal.gov        Not all those who wander are lost..." - JRRT   |
|...they don't generally like what i say anyway, so i don't speak for them... |
 ----------------------------------------------------------------------------- 

$ Set NoOn
$ Set Verify
$!
$!  Get the number of new mail messages
$!
$
$ GET_NUM_OF_MESSAGES:
$
$ num_of_messages = 0		
$
$ define/user sys$output mail_directory.txt
$ mail
	directory/new
	exit
$ open/read mail__directory mail_directory.txt
$!
$ done := FALSE
$ mail_dir_loop1:					! look for flag strings
$	read mail__directory mail_line
$!
$	if ( f$locate("%MAIL-W-NONEWMAIL",mail_line) .ne. f$length(mail_line) )
$	then
$		goto mail_dir_end
$	endif
$
$	mail_line = f$edit(mail_line,"COMPRESS")	! found header line
$	if ( f$element(1," ",mail_line) .eqs. "#" )
$	then
$		read mail__directory blank_line		! one more blank line
$		done := TRUE
$	endif
$ 	if ( .not. done ) then $ goto mail_dir_loop1
$ mail_dir_loop2:					! now count the messages
$	read/end_of_file=mail_dir_end mail__directory mail_line
$	num_of_messages = num_of_messages + 1
$ goto mail_dir_loop2
$ mail_dir_end:
$
$ close mail__directory
$ delete mail_directory.txt;
$
$ write sys$output "number of messages = ", num_of_messages

