From:	CSBVAX::MRGATE!siegel@scivax.stsci.edu@SMTP  1-MAY-1988 22:57
To:	ARISIA::EVERHART
Subj:	Re: Dcl & mail questions


Received: from scivax.stsci.edu by KL.SRI.COM with TCP; Fri 29 Apr 88 12:32:40-PDT
Date: 29 Apr 88 15:30:00 EST
From: "HOWARD SIEGEL" <siegel@scivax.stsci.edu>
Subject: Re: Dcl & mail questions
To: "info-vax" <info-vax@kl.sri.com>
cc: siegel      
Reply-To: "HOWARD SIEGEL" <siegel@scivax.stsci.edu>


HERBASA KHAN <CS_4313_12%uta.edu@RELAY.CS.NET> asks:

> I an thinking of writing a DCL procedure that will,
>
> 1- Run from batch
> 2- Determine the number of old messages.
> 3- Extract and delete only the old messages leaving the new ones.
> 4- Copy the extracted files to tape
> 
> The problem is in determining how may old messges exist. Is there
> any way the program can determine this with out it being entered by a user?
> 
> Since my knowledge of DCL is limited I will be thankful for any information
> regarding other problems I may encounter.

The following command procedure is one I put together to extract mail from
specified folders into files each containing one message.  The output files
are named with the folder name and have a 5 digit sequence number for the file
type (eg. INFO_VAX.00030).  While this procedure does not do everthing you
asked for, it does give the basics for (2) and (3).

The procedure is invoked with the following command line

	@EXTRACT <folder-name> <extract-count> <sequence-number>

If any inputs are not present, then the procedure will prompt for them.
If the <extract-count> is specified as "*" then all of the messages will
be extracted.  If the <sequence-number> is specified as "*" then the sequence
numbers will begin with 1.

The procedure works as follows:

	- After getting the folder name, a temporary command procedure is
	  created to start up MAIL and select the requested folder.  This
	  procedure is then executed with output to a temporary log file.
	  MAIL will either output a message of the form
		%MAIL-I-SELECTED, n messages selected
	  if the folder exists, or
		%MAIL-E-NOTEXIST, folder <folder-name> does not exit
	  if the folder does not exist

	- The log file is opened and the MAIL status is read.  If the status
	  is for a warning or error, then the procedure will write the message
	  to the terminal and exit.  If the message was of the "n messages
	  selected" type, the message count is extracted and used to determine
	  the number of messages to be extracted.

	- The procedure then sits in a loop appending READ and EXTRACT commands
	  for each message to extract to the temporary command procedure
	  previously created.  When finished, the temporary procedure is
	  invoked to actually extract the messages.

	- Clean up temporary files.

Since you want to perform everything automatically, you would make the
following changes:

	- If you only have the one mail folder MAIL, then you would
	  eliminate the folder-name input argument, and any prompting for
	  the folder name.  OR you could leave this part in, but always
	  use the folder name "MAIL" as the input argument.
	  
	- If you have more than one folder for old mail, then you would
	  have to add some extract code to get a directory of the folders
	  and parse out the names.  Judicious use of a log file and the
	  F$EDIT and F$ELEMENT lexical functions will accomplish this.

	- Since you want to extract all of the messages, eleminate the
	  <extract-count> argument and all of the prompting, and just use the
	  message count the MAIL returns when the folder is selected.

	- I do not automatically delete the messages when they are extracted.
	  You would put a DELETE command after the READ and EXTRACT commands
	  in the temporary command procedure to accomplish this.

	- You need to determine how you want the message files to be
	  structured.  As shown, the messages are extract one to a file using
	  the file names "<folder-name>.<seq-num>". If you want a folder per
	  file, eliminate the sequence-number sections, and use EXTRACT/APPEND
	  commands for all but the first message in the folder.
	  
Sorry if this is a bit long, but I wanted to explain things since the
procedure is not well documented and the requestor inidicated he was not
an expert in DCL.

<--=--> Cut Here <--=--> Cut Here <--=--> Cut Here <--=--> Cut Here <--=-->

$!
$!  EXTRACT.COM - Procedure to extract mail messages
$!
$  CMDFILNAM = "SCRATCH_DIR:MAILEXTRACT.CMD"
$  LOGFILNAM = "SCRATCH_DIR:MAILEXTRACT.LOG"
$!
$GET_FOLDER_NAME:
$  IF P1 .NES. "" THEN GOTO HAVE_FOLDER_NAME
$  INQUIRE P1 "Folder"
$  GOTO GET_FOLDER_NAME
$!
$HAVE_FOLDER_NAME:
$  FOLDER_NAME = P1
$!
$GET_FOLDER_STATUS:
$  CREATE 'CMDFILNAM
$  OPEN/APPEND CMDFIL 'CMDFILNAM
$  WRITE CMDFIL "$ MAIL"
$  WRITE CMDFIL "SET FOLDER ''FOLDER_NAME'"
$  CLOSE CMDFIL
$  @'CMDFILNAM/OUT='LOGFILNAM
$  OPEN INFIL 'LOGFILNAM
$LOOP_1:
$  READ INFIL MAIL_STATUS
$  IF F$EXTRACT(0,1,MAIL_STATUS) .NES. "%" THEN GOTO LOOP_1
$  CLOSE INFIL
$  DELETE 'LOGFILNAM;*
$!
$CHECK_FOLDER_STATUS:
$  STR = F$ELEMENT(0, ",", MAIL_STATUS)
$  STR = F$ELEMENT(1, "-", STR)
$  IF STR .EQS. "I" THEN GOTO GET_MESSAGE_COUNT
$  WRITE SYS$OUTPUT MAIL_STATUS
$  EXIT
$!
$GET_MESSAGE_COUNT:
$  STR = F$EDIT(F$ELEMENT(1, ",", MAIL_STATUS),"TRIM")
$  STR = F$ELEMENT(0, " ", STR)
$  MAXMSGCNT = F$INTEGER(STR)
$!
$GET_EXTRACT_COUNT:
$  IF P2 .NES. "" THEN GOTO HAVE_EXTRACT_COUNT
$  INQUIRE P2 "Number of messages to extract? (*=''MAXMSGCNT')"
$  GOTO GET_EXTRACT_COUNT
$!
$HAVE_EXTRACT_COUNT:
$  IF P2 .EQS. "*" THEN P2 = MAXMSGCNT
$  IF P2 .GT. MAXMSGCNT THEN P2 = MAXMSGCNT
$  MSGCNT = P2
$!
$GET_SEQUENCE_NUMBER:
$  IF P3 .EQS. "*" THEN P3 = "1"
$  IF P3 .NES. "" THEN GOTO HAVE_SEQUENCE_NUMBER
$  INQUIRE P3 "Starting sequence number? "
$  GOTO GET_SEQUENCE_NUMBER
$!
$HAVE_SEQUENCE_NUMBER:
$  SEQNUM = F$INTEGER(P3)
$!
$EXTRACT_MESSAGES:
$  OPEN/APPEND CMDFIL 'CMDFILNAM
$  NUM = 1
$LOOP:
$  IF MSGCNT .EQ. 0 THEN GOTO LOOP_END
$  WRITE CMDFIL "READ ''NUM'"
$  SEQSTR = F$FAO("!5ZL", SEQNUM)
$  WRITE CMDFIL "EXTRACT ''FOLDER'.''SEQSTR'"
$  NUM = NUM + 1
$  SEQNUM = SEQNUM + 1
$  MSGCNT = MSGCNT - 1
$  GOTO LOOP
$LOOP_END:
$  WRITE CMDFIL "EXIT"
$  CLOSE CMDFIL
$  @'CMDFILNAM/OUTPUT=NLA0:
$  DELETE 'CMDFILNAM;*

<--=--> Cut Here <--=--> Cut Here <--=--> Cut Here <--=--> Cut Here <--=-->

     +--------------------------------------+--------------------------+
     !  Howard Siegel - TRW, Inc.           !  "I am quite sure  that  !
     !                                      !  you could  elevate  an  !
     !  ARPAnet:  siegel@scivax.arpa        !  earwig to the level of  !
     !  SPAN:     SCIVAX::SIEGEL            !  a  nuclear  scientist,  !
     !  USnail:   One Space Park, O2/2751   !  but it would still  be  !
     !            Redondo Beach, Ca. 90278  !  a very stupid thing to  !
     !  AT&T:     213/535-5083              !  do!"                    !
     +--------------------------------------+--------------------------+
------
