From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 11-JUN-1992 07:43:57.15
To:	"IN%\"Y1Z@ECLX.PSU.Edu\""
	<"IN%\"Y1Z@ECLX.PSU.Edu\"%MUVAXA%MRGATE"@ADMINA>
CC:	Info-Vax <info-vax@sri.com>
Subj:	RE: Reuse DiskSpace of deleted mail?

The following is a set of procderes I wrote to compress mail to a non-disquota 
scratch area.

It is about 99% safe; every once in a while someone claims that they had mail 
missing after the compress.  Use at your own risk.

Note: One known problem is that if newmail arrives during the compress, it will
not show up as New Mail. See the last section.

Please be sure to set the logicals as required.


I have 1200 users, and many of them use this regularly.

-----------------------------------------------------------------------------

Directory SYS$RFEROOT:[RFEUSER]

CMPRSS_USR_MAIL.COM;69              21/21       5-DEC-1990 01:30:36.04
CMPRSS_USR_MAIL.ERR;1                2/3       25-APR-1990 11:16:02.70
CMPRSS_USR_MAIL.MAI;2                3/3       27-AUG-1990 17:42:41.64
CMPRSS_USR_MAIL.NOTICE;1             2/3        5-DEC-1990 01:30:44.43
COMPRESS_MAIL_UTILITY.COM;10         7/9       21-MAY-1992 14:32:05.24

-----------------------------------------------------------------------------



-----------------------------------------------------------------------------

$!============================================================================
$!+++++ Screen_Commands.com - Defines symbols for VT200 screen setups
$!============================================================================
$!
$! Execute only of not invoked prior by same process. (added by MdN)
$!
$ IF F$TYPE(SCR_PRE_INV) .NES. "" THEN EXIT
$ SCR_PRE_INV :== TRUE
$!
$ SAY :== WRITE SYS$OUTPUT
$ ASK :== INQUIRE/NOPUNCTUATION
$!
$ BELL[0,7] == 7        
$ ESC[0,7]  == 27  
$ CSI       == ESC + "["
$!
$ TOP    == CSI + "0;0H"       !Position cursor at 1,1
$ HALF   == CSI + "11;0H"      !Position cursor at 1,10
$ CEOS	 == CSI + "0J"         !Clear from cursor to end-of-screen
$ CEOL	 == CSI + "0K"         !Clear from cursor to end-of-line
$ CLR    == CSI + "2J"         !Clear Screen from top
$ CLRT   == CLR + TOP          !Clear screen, position cursor at 1,1
$ LITE   == CSI + "?5h"        !Set screen lite background
$ DARK   == CSI + "?5l"        !Set screen dark background
$ DDT    == ESC + "#3"         !Doublehigh,doublewide - tophalf of character
$ DDB    == ESC + "#4"         !Doublehigh,doublewide - bottomhalf of character
$ SSN    == ESC + "#5"         !Singlehigh,singlewide
$ SW     == ESC + "#6"         !Singlehigh,doublewide
$ DST    == ESC + "#:"         !Doublehigh,singlewide - tophalf of character
$ DSB    == ESC + "#;"         !Doublehigh,singlewide - bottomhalf of character
$ BOLD   == CSI + "1m"         !Start boldface
$ RVSE   == CSI + "7m"         !start reverse-video
$ FLASH  == CSI + "5m"         !Start flashing
$ UND1   == CSI + "4m"         !Start underline
$ UND0   == CSI + "24m"        !Stop underline
$ NML    == CSI + "0m"         !Set screen to default settings
$ SLOW   == CSI + "?4h"        !Set screen slow scroll
$ FAST   == CSI + "?4l"        !Set screen jump scroll
$ PRTON  == CSI + "?5i"	       !Auto Screen print on
$ PRTOFF == CSI + "?4i"	       !Auto Screen print off
$ CUROFF == CSI + "?25l"       !Cursor off
$ CURON  == CSI + "?25h"       !Cursor on
$ GRON   == ESC + "(0"         !Graphics on
$ GROF   == ESC + "(B"         !Graphics off
$ GET    :== READ SYS$COMMAND /PROMPT=
$ DATE   :== F$EXTRACT(0,11,F$TIME())
$!
$  EXIT
$!
$!=========================================================================
$! Author       : Thomas Brand
$! Created      : 1987
$!                
$! Function     : Defines various mnemonic symbols which can be used to 
$!                control the VT screens
$!                
$! Parameters   : None
$!                
$! Files Used   : None
$!                
$! Documentation: 
$!                
$! Modifications: 
$!   Date	By	Details
$! 
$!=========================================================================

----------------------------------------------------------------------------

$!=============================================================================
$!+++++ Compress_Mail.COM  - Compresses user [.mail]mail.mai file (interactive)
$!=============================================================================
$!
$	SET NOON
$	IF F$TYPE(PRTOFF) .EQS. "" THEN 
$!
$	Save_Dir = F$env("DEFAULT")
$	Save_Ctl = F$env("CONTROL")
$	SET DEFAULT SYS$LOGIN:
$	SET NOCONTROL_Y
$       Uname = F$EDIT(F$GETJPI("","USERNAME"),"COLLAPSE")
$!
$	SAY CLRT 
$	SAY "         ''DDT'Compress Mail Utility "
$	SAY "         ''BOLD'''DDB'Compress Mail Utility''NML'"
$	SAY ""
$	SAY ""
$!
$!..... Checks SYS$LOGIN:[.MAIL] subdirectory for E-mail.
$ 	IF F$SEARCH("[.MAIL]MAIL.MAI") .EQS. "" 
$	   THEN SAY BELL
$		SAY BELL
$		SAY " Your MAIL.MAI file is not in the Directory"+ -
		    " [''Uname'.MAIL]"
$		SAY " This procedure only processes files in [''Uname'.MAIL]"
$		SAY ""
$		SAY " To move your mail files to the subdirectory:"
$		SAY "       1. Enter MAIL"
$		SAY "       2. MAIL> SET MAIL [''Uname'.MAIL]"
$		SAY "       3. MAIL> EXIT"
$		SAY "       4. Try to compress your mail again."
$		SAY ""
$		SAY " For help on this, please call your Automation Services 
Coordinator (x2000)."
$		SAY BELL
$		SAY BELL
$		GOTO The_End
$	   ENDIF
$
$!
$!------------------------------------------
$!
$!
$	SAY "Your old mail file is:"
$	DIREC/DATE/SIZE=ALL/WIDTH=FILE=30 [.MAIL]MAIL.MAI
$!
$	Pid   = F$EXTR(4,4,F$GETJPI("","PID"))
$!	DEFINE SYS$OUTPUT NL:
$	SUBMIT/NONOTIFY/NOPRINT/KEEP -
              /LOG=USER_SCRATCH:'Uname'_'Pid'_MAIL.LOG -
              RFE$USER:CMPRSS_USR_MAIL.COM /PARAMETER=('Uname','Pid',NO)
$	DEASS SYS$OUTPUT
$	E_Num = $ENTRY
$!
$	SAY "   Compress job has been started.  Please wait for completion."
$	SAY "              ''FLASH'This may take ''BOLD'several''NML'''FLASH' 
minutes!!''NML'"
$	SAY "   Job number is : ''E_num'."
$	SAY BELL
$!
$	SYNCHRONIZE/ENTRY='E_Num'
$!
$	SAY BELL + "Compress job has finished.  Your new mail file is:"
$	DIREC/DATE/SIZE=ALL/WIDTH=FILE=30 [.MAIL]MAIL.MAI
$	SAY ""
$!
$!
$The_End:
$	READ/END=The_End/Err=The_End/TIME=60 SYS$COMMAND SYS$INPUT -
	    /PROMPT="Press <RETURN> to continue : "
$	SAY CLRT 
$	SET DEFAULT 'Save_Dir'
$	SET CONTROL=('Save_Ctl')
$!
$ EXIT                                             
$!=============================================================================
$!
$!  	This comfile submits the RFE$USER:CMPRSS_USR_MAIL.COM procedure
$!  to compress a users MAIL.MAI file if the file is found in the users
$!  [.mail] subdirectory.  The advantage of useing this routine is that the
$!  MAIL.MAI file gets compressed in the USER_SCRATCH: area, not in the users
$!  own directory.  This avoids complications with DISKQUOTA.
$!
$!	The parameters on the SUBMIT.../PARAM=(,,,) are the USERNAME, 
$!  Process ID, and "NO" to tell the batch job NOT to append the data if 
$!  called from this procedure.  (If submitted by RFE$USER:SYLOGIN_PURGE.COM,
$!  P3 is "YES".)
$!	
$!=============================================================================


------------------------ cut here ---------------------------------
 
SYS$RFEROOT:[RFEUSER]CMPRSS_USR_MAIL.COM;69
 
$!============================================================================
$!+++++ RFE$USER:CMPRSS_USR_MAIL.COM -  Compress a users MAIL.MAI file.
$!============================================================================
$!
$  	SET VER
$	ON ERROR 	THEN GOTO Err_Exit
$	ON SEVERE_ERROR THEN GOTO Err_Exit
$!
$	IF (P1 .EQS. "") .OR. (P2 .EQS. "") -
           THEN GOTO Err_Exit   !Parameters missing.
$!
$	DDD := DEL/SYM/GLOB/ALL ! Delete all global symbols such as
$	DDD                     !    copy/confirm, purge/confirm, etc.
$	Uname 	 = P1		! Username submitting this job.
$	Pid 	 = P2		! Submitting job process id.
$!
$	DEFINE M_Org_File USER_SCRATCH:'Uname'_'Pid'_MAIL.ORG. !original file
$	DEFINE M_Cmp_File USER_SCRATCH:'Uname'_'Pid'_Mail.CMP. !compressed file
$	DEFINE CONVWORK   USER_SCRATCH:'Uname'_'Pid'_Mail.Cnv. !temp work file
$	DEFINE SORTWORK0  USER_SCRATCH:'Uname'_'Pid'_Mail.SR0. !temp sort file
$	DEFINE SORTWORK1  USER_SCRATCH:'Uname'_'Pid'_Mail.SR1. !temp sort file
$	DEFINE SORTWORK2  USER_SCRATCH:'Uname'_'Pid'_Mail.SR2. !temp sort file
$	DEFINE SYS$SCRATCH USER_SCRATCH                        !temp scratch
$!
$	SET DEF SYS$LOGIN
$	SET PROT=O:RWED [.MAIL]MAIL.MAI;*            !Make sure only one version
$	IF .NOT. $STATUS THEN GOTO Err_Prot
$	PURGE /LOG [.MAIL]MAIL.MAI		     ! of the mail file exists.
$	RENAME/LOG [.MAIL]MAIL.MAI  [.MAIL]MAIL.HOLD !Rename so that we can see
$	IF .NOT. $STATUS THEN GOTO Err_Rename
$!
$!-------------------------------------------------------------
$	CNT = 0                                      ! if new mail comes in
$Try_Copy:                                           
$	COPY/LOG   [.MAIL]MAIL.HOLD 	M_Org_File 
$	IF .NOT. $STATUS 
$	    THEN WAIT 00:00:10
$		 CNT = CNT + 1
$		 IF CNT .GT. 5 THEN GOTO Err_Copy    !Try to copy 5 times in 
$		 GOTO Try_Copy                       !case file is open during
$	ENDIF                                        !copy attempt.
$!
$!-------------------------------------------------------------
$!..... Compress the file
$	SET DEF USER_SCRATCH:
$	DEFINE SYS$INPUT SYS$COMMAND
$	MAIL
	  SET FILE     M_ORG_FILE
   	  COMPRESS/OUT=M_CMP_FILE
	EXIT
$!
$!..... Check for error during compress
$	MPid = F$EXTR(4,4,"''F$GETJPI("","PID")'")
$ 	IF (F$SEARCH("MAIL_''MPid'_COMPRESS.TMP") .NES. "") .OR. - 
           (F$SEARCH("M_CMP_FILE") .EQS. "")               THEN GOTO Err_cmprss
$!
$!-------------------------------------------------------------
$!..... Replace the old mail file with the new compressed version
$	SET DEF SYS$LOGIN
$       IF F$SEARCH("SYS$LOGIN_DEVICE:[000000]QUOTA.SYS") .EQS. "" -
           THEN GOTO Skip_Quota_Check

$!
$!..... First get the file sizes.
$	Old_size = F$FILE("[.MAIL]MAIL.HOLD","EOF")
$	New_size = F$FILE("M_CMP_FILE","EOF")
$	New_size = New_size  + 6 	 !pad with 6 blocks for cluster_size
$!
$!..... Now get the available quota
$	DEF SYS$OUTPUT USER_SCRATCH:'Uname'_'Pid'_MAIL.QUOTA;
$	SH QUOTA
$	DEASSIGN SYS$OUTPUT
$	OPEN/READ Q_File USER_SCRATCH:'Uname'_'Pid'_MAIL.QUOTA;
$	READ/ERR=Err_Qread Q_File Q_Rec       !Gets "$SH QUOTA "
$	READ/ERR=Err_Qread Q_File Q_Rec       !gets "User [xxx,xxx] ....."
$	Q_rec = F$ELEMENT(2,",",Q_rec)        !gets " nnn available"
$	Avail_Quota = F$ELEMENT(1," ",Q_rec)  !gets "nnn"
$!
$	IF F$ELEMENT(2," ",Q_rec) .EQS. "OVERDRAWN"
$	   THEN Space_avail = -Avail_quota + Old_size !ex. (-45 avail + 33 over)
$	   ELSE Space_avail =  Avail_quota + Old_size !ex. ( 45 avail + 33 over)
$	ENDIF
$!
$	IF New_size .GE. Space_Avail THEN GOTO Err_Insuf_Quota
$!
$Skip_Quota_Check:
$	SET FILE/LOG/PROT=O:RWED  [.MAIL]MAIL.hold;*
$	IF .NOT. $STATUS THEN GOTO Err_Exit
$	DELETE/LOG 		  [.MAIL]MAIL.hold;*
$	IF .NOT. $STATUS THEN GOTO Err_Exit
$	COPY/LOG   M_CMP_FILE 	  [.MAIL]MAIL.MAI;   /PROT=(S:RW,O:RW,G,W)
$	IF .NOT. $STATUS THEN GOTO Err_Exit
$!
$!-------------------------------------------------------------
$!..... Check if new mail has come in during the compress
$       IF F$SEARCH("[.MAIL]MAIL.MAI;-1") .NES. "" -
 	   THEN GOSUB Cmp_Reset   	!if so, reset the mail file....
$!
$!-------------------------------------------------------------
$Clean_Up:
$!	If we get to here, all went OK so we can delete the temp files.
$	SET FILE/PROT=(S:RWED,O:RWED,G,W) -
            USER_SCRATCH:'Uname'_'Pid'_MAIL.*;*  
$	DELETE/LOG USER_SCRATCH:'Uname'_'Pid'_MAIL.*;*/EXCLUDE=*.ORG
$	RENAME/LOG USER_SCRATCH:'Uname'_'Pid'_MAIL.ORG;* -
		   USER_SCRATCH:'Uname'_MAIL.OLD;
$!
$ EXIT
$!
$!-------------------------------------------------------------
$!-------------------------------------------------------------
$Cmp_Reset:
$!SUBROUTINE  -  moves mail from the newest MAIL.MAI to the compressed
$!               old MAIL.MAI file (which has a higher version number...)
$! 
$!..... Create a "NEWMAIL" folder in the compressed mail-file
$	MAIL/SUBJ="Notice: Please Read!!" RFE$USER:Cmprss_Usr_Mail.notice -
            'Uname'
$!
$!..... If new mail was found, move it to the new, compressed mail file.
$	DEFINE SYS$INPUT SYS$COMMAND
$	MAIL
	  SET FILE  [.MAIL]MAIL.MAI;-1    ! Select the "new" mail-file
 	  SEL NEWMAIL                     ! Select the newmail folder
 	  MOVE/ALL  NEWMAIL  [.MAIL]      ! Move all new mails to newest file
	  PURGE				  ! Force deletion of these mails
	EXIT
$!
$	SET FILE/LOG/PROT=O:RWED [.MAIL]MAIL.MAI;-1
$   	PURGE/LOG [.MAIL]MAIL.MAI
$
$RETURN
$!
$!-------------------------------------------------------------
$!-------------------------------------------------------------
$!
$!  Error handling...
$!
$Err_Rename:
$       Err_type = "%CMPMAIL-F-RENORG, Can't rename original"
$       GOTO Send_Mail
$Err_Prot:
$       Err_type = "%CMPMAIL-F-PROTORG, Protection on original file."
$       GOTO Send_Mail
$Err_Copy:
$       Err_type = "%CMPMAIL-W-COPYORG, Unable to copy original file."
$       RENAME/LOG [.MAIL]MAIL.HOLD  [.MAIL]MAIL.MAI.
$       GOTO Send_Mail
$Err_Cmprss:
$       Err_type = "%CMPMAIL-F-CMPERR, Error during compress."
$       GOTO Send_Mail
$Err_Qread:
$	Err_type = "%CMPMAIL-F-GETQUOT, Can't Read Quota file"
$	GOTO Send_Mail
$Err_Insuf_Quota:
$       Err_type = "%CMPMAIL-F-INSQUOTA, Insuff Quota for new mailfile."
$	RENAME [.MAIL]MAIL.HOLD [.MAIL]MAIL.MAI.0
$!
$!	Make sure no new mail has been received in the meantime
$       IF F$SEARCH("[.MAIL]MAIL.MAI;-1") .NES. "" -
	   THEN GOSUB Cmp_Reset   	!if so, reset the mail file....
$!
$       MAIL/NOSELF/SUBJ="Error Compressing mail file; insufficient quota." -
             RFE$USER:CMPRSS_USR_MAIL.MAI 'Uname', BRAND
$	GOTO Send_Mail
$!
$Err_Exit:
$	Err_type = "%CMPMAIL-F-UNDEFERR, Undefined Error. Check logfile."
$!
$Send_Mail:
$       MAIL/NOSELF/SUBJ="''Err_type'. ''UNAME'_''Pid'_MAIL.LOG." -
             RFE$USER:CMPRSS_USR_MAIL.ERR TROUBLE, BRAND
$ EXIT
$!============================================================================
$!
$!     This procedure is run from either RFE$USER:SYLOGIN_PURGE.COM
$!   or from RFE$USER:COMPRESS_MAIL_UTILITY.COM.  The first job checks
$!   to see if the users MAIL.MAI file has not been compressed in more
$!   than MAX_AGE days; the second comfile is called interactively by
$!   the user from the LEX File-Management menu (Option M).
$!
$!
$!   This procedure compresses user MAIL.MAI files using a scratch area.
$!   To avoid DISKQUOTA problems:
$!      1. the mail file is copied to the user scratch area (temp hold)
$!      2. the mail file is compressed in the user_scratch area
$!      3. the user quota is check against the new mail file size
$!      4. the mail file is deleted from the [.mail] directory
$!      5. the compressed file is copied to the [.mail] directory
$!      6. the compressed file is deleted from the scratch directory.
$!      7. the logfile file is deleted from the scratch directory.
$!
$!  If there is an error in copying the files, a mail message will be
$!  sent to TROUBLE.
$!
$!============================================================================
$!  Files used by this procedure are:
$!
$!  USER_SCRATCH:'Uname'_'Pid'_MAIL.ORG.
$!       the copy of the original SYS$LOGIN:[MAIL]MAIL.MAI file
$!
$!  USER_SCRATCH:'Uname'_'Pid'_Mail.Cnv.
$!       temporary work file used by MAIL/COMPRESS
$!
$!  USER_SCRATCH:'Uname'_'Pid'_Mail.SR0.
$!       temporary sort file used by MAIL/COMPRESS
$!
$!  USER_SCRATCH:'Uname'_'Pid'_Mail.SR1.
$!       temporary sort file used by MAIL/COMPRESS
$!
$!  USER_SCRATCH:'Uname'_'Pid'_Mail.SR2.
$!       temporary sort file used by MAIL/COMPRESS
$!
$!  USER_SCRATCH:MAIL_COMPRESS_????.TMP.   ! owner=username
$!       the standard intermediate compress file produced by the
$!       MAIL/COMPRESS utility.  If the compress was successful, this
$!       file gets renamed to 'Uname'_'Pid'_Mail.CMP.
$!
$!  USER_SCRATCH:'Uname'_'Pid'_Mail.CMP.
$!       the new compressed MAIL.MAI file
$!
$!  USER_SCRATCH:'Uname'_'Pid'_MAIL.DFF
$!       statistics file; shows how much space was saved with this compression.
$!       If the compression was automatic (ie from RFE$USER:SYLOGIN_PURGE.COM),
$!       this data gets appended to RFE$INFO:MAIL_BLKS_COMPRESSED.DAT
$!
$!  USER_SCRATCH:'Uname'_'Pid'_Mail.LOG.
$!       logfile from this batch process
$!
$!  RFE$USER:CMPRSS_USR_MAIL.ERR
$!       error message which is sent to TROUBLE if this procedure bombs.
$!       the subject line includes the 'Uname' and the PID used for
$!       the above files.
$!
$!============================================================================
$!  Modifications:
$!  Date        By      Comments
$!  15-Jun-90   TRB     Added check/fix for new mail coming in during
$!                      the compress
$!
$!
$!
$!============================================================================



----------------   cut here ------------------------------------------- 


SYS$RFEROOT:[RFEUSER]CMPRSS_USR_MAIL.ERR;1
 
    There has been an error in the RFE$USER:CMPRSS_USR_MAIL.COM batch job.

Please check the logfile USER_SCRATCH:'username'_'pid'_MAIL.LOG for the error.

The files created were: 

USER_SCRATCH:'Uname'_'Pid'_MAIL.ORG. !copy of the original MAIL.MAI file
USER_SCRATCH:'Uname'_'Pid'_Mail.Cnv. !temporary work file used by MAIL/COMPRESS
USER_SCRATCH:'Uname'_'Pid'_Mail.CMP. !the new compressed MAIL.MAI file
USER_SCRATCH:'Uname'_'pid'_MAIL.DFF  !statistics file; shows how much space was
				     !save with this compression.  If automatic
				     !compression, this gets appended to
				     !RFE$INFO:MAIL_BLKS_COMPRESSED.DAT
USER_SCRATCH:'Uname'_'Pid'_Mail.LOG. !logfile from the batch process 

 
-------------------------  cut here ------------------------------

SYS$RFEROOT:[RFEUSER]CMPRSS_USR_MAIL.MAI;2
 
   The compress user mail utility was unable to compress your mail file since
you do not have sufficient diskspace available.  Even with the deletion of 
your old mail file, there would not have been enough diskspace for the new mail
file. 

   Before compressing your mail again, please purge your directory and delete 
any old file(s) you don't need anymore.  

   For further help, please call you Automation Services Coordinator on 
tel x2000. 

------------------------------------------------------------------------------

   Die Compress_User_Mail Utility konnte ihre MAIL Datai nicht comprimieren.  
Selbst wenn man die alte Datei zuerst gelvscht hdtte, w|rde der zur 
Verf|gung stehende Plattenplatz nicht ausreichen.

   Bevor sie nochmals versuchen, Ihre Mail Datei zu comprimieren, f|hren Sie
bitte erst ein PURGE Ihres Directory durch und lvschen sie alte Dateien, die Sie
nicht mehr brauchen.

Wenn Sie weitere Hilfe benvtigen, rufen Sie bitte Ihren Automation Service 
Coordinator unter der Rufnummer 2000 an.
 


----------------------------  cut here  --------------------------------


SYS$RFEROOT:[RFEUSER]CMPRSS_USR_MAIL.NOTICE;1
 

     !!! Notice !!!   !!! Notice !!!   !!! Notice !!!   !!! Notice !!!   

-------------------------------------------------------------------------------

     New mail came in while your mail file was being compressed.  This
  mail is in your NEWMAIL but is not selectable with the command "READ/NEWMAIL"
  
     To read this mail, enter the command "SELECT NEWMAIL" at the mail prompt!
  Example:

MAIL> SELECT NEWMAIL 

-------------------------------------------------------------------------------

      Wdhrend ihre MAIL datei compressed wurde, bekamen Sie neue MAIL.  
  Diese neue mail befindet sich im NEWMAIL folder, aber kann nicht mit dem
  Befehl "READ/NEWMAIL" gelesen werden.

  Bitte lesen sie diese Mail in dem sie den Befehl "SELECT NEWMAIL" ben|tzen!
  Beispiel:

MAIL> SELECT NEWMAIL

-------------------------------------------------------------------------------



