$ verify = """''f$environment("VERIFY_PROCEDURE")'""," + - """''f$environment("VERIFY_IMAGE")'""" $! $! Clean up and reorganize mail stuff. Everything in the DEAD folder is $! discarded. Everything in the DELETED folder more than a month old is also $! discarded. Then the MAIL.MAI file is rebuilt, and finally the mail $! subdirectory itself is rebuilt. $! $ was_default = f$environment("DEFAULT") $ status = 1 !Assume success $ on error then goto fail $ on control_y then goto fail $ set default SYS$LOGIN $! $! First move all the stuff in DELETED that we intend to save into $! __WEEKLY_SAVE__. $! $ mail select DELETED/since:today-31- !Stuff less than one month old file/all/noconfirm __WEEKLY_SAVE__ $! $! Exit and re-enter mail. This ensures we are in a known state even if there $! were no messages selected. (It's probably unnecessary under VMS V5.) $! $ mail select MAIL 1 copy/noconfirm DEAD !Make sure DEAD exists copy/noconfirm __WEEKLY_SAVE__ !__WEEKLY_SAVE__, too select DEAD delete/all $! $! The games with copy and the exit and re-entry are again here to deal $! with non-existent folders, and may not be needed under V5. They've been $! retained for safety - when it comes to making sure files (or mail messages) $! aren't lost, "if it's not broke, don't fix it" is the watchword. $! $! WARNING: This code assumes that folder MAIL exists! $! $ mail purge/stat/reclaim compress select __WEEKLY_SAVE__ delete/all $! $! Now we can create a new directory and move the mail into it. $! $ create/dir/prot=(S:RWE,O:RWED,G,W) [.WEEKLY_TEMP] $ set file/prot:O:REWD mail.dir $ set file/prot:O:REWD [.MAIL]*.*;* $! $! The following rename may take a long time; we leave MAIL.MAI where it $! is so that mail arriving during the renaming can be placed in it. Note, $! however, that if it requires a MAIL$nnn file, that file will be created $! with a protection that doesn't allow us to delete (hence, rename) it, so $! we will fail later, either in renaming the new file or in deleting the $! old mail directory. $! $ rename/nolog [.MAIL]*.*;*/exclude=mail.mai;* [.WEEKLY_TEMP] $! $! The "window" during which mail might get delivered to a new, incorrect $! MAIL.MAI file exists only between the next three RENAME commands. $! $ rename mail.dir weekly_temp1.dir;1 $ rename weekly_temp.dir mail.dir;1 $! $! Put everything back. Mail arriving from here on causes no problems. $! Note: A possible (untested) improvement would be to add a $! $! $ set file/prot:O:REWD [.WEEKLY_TEMP1]*.*;* $! $! statement here to catch any mail that arrived during the earlier manipu- $! lations. I don't bother because the problem is rare and I'm willing to $! fix it up by hand. $! $ rename [.WEEKLY_TEMP1]*.*;* [.MAIL] $ set file/prot:O:REW [.MAIL]*.*;*/exclude:mail.old;* $ set file/prot=O:REWD weekly_temp1.dir $ delete weekly_temp1.dir; $ mail/subj:"Check and delete MAIL.OLD" _NL: 'f$getjpi("","USERNAME")' $ goto fin $! $! Here on any error $! $fail: $ status = $STATUS $ mail - /subj:"Mail reorganizer FAILED, status ''stat': ''f$message(stat)'" - _NL: 'f$getjpi("","USERNAME")' $ goto fin $! $! Restore state and return $! $fin: $ set default 'was_default' $ exit status + 0*f$verify('verify')