2
# vmail.purge - zaps all unindexed mail messages.
4
# The_Epoch vick created this.
5
# 1988 Nov 10 Thu 12:00 bob added code to allow a pathname for $1.
6
# 1988 Nov 14 Mon 10:14 bob rewrote the code that was breaking inside `quotes`.
7
# 1988 Nov 15 Tue 16:44 bob added code to track spurious .vmail files
8
# 1988 Nov 16 Wed 10:44 bob redirected error messages to stderr.
9
# 1989 Feb 14 Tue 13:37 bob add exceptions for corrupt indexes
10
# 1991 Sun Nov 24 10:30 Shoa add removal of RECOVER index.
11
# 1992 Oct 21 Wed 17:01 bob check for Pine read lock files, and abort.
14
# Usage: vmail.purge [ username | somepath/username/.vmail ]
18
set pname = ${pname:t} # name of this script for error messages
20
set indexed = /tmp/VMprg_idx.$$ # a list of indexed messages
21
set messages = /tmp/VMprg_msg.$$ # a list of all messages
22
set unindexed = /tmp/VMprg_Csh.$$ # script to remove unindexed messages
24
if ( 1 <= $#argv ) then
25
if ( ".vmail" == $1:t ) then # assume /u/dp/bob/.vmail
26
set vpath = $1:h # /u/dp/bob
27
setenv USER $vpath:t # bob
33
if ( ! -d ~$USER/.vmail ) then
35
if ( 1 <= $#argv ) then
36
sh -c "echo 1>&2 ${pname}: invalid argument $1"
38
sh -c "echo 1>&2 ${pname}: $USER has no .vmail directory"
45
if (!( -d index && -d msg)) then
46
sh -c "echo 1>&2 ${pname}: $cwd is missing required components"
50
# check for Pine inbox read lock file
51
if ( -e index/.MAIL.rl ) then
52
sh -c "echo 1>&2 ${pname}: $cwd is now running Pine"
57
#remove the temporary RECOVER index *must* be done before deletion of messages
59
if ( -e index/RECOVER ) then
61
if ( -e ~$USER/.inda ) rm ~$USER/.inda
62
if ( -e ~$USER/.indf ) rm ~$USER/.indf
66
# create the shell script
68
awk '$1 ~ /^[0-9]/ {print substr($1,1,6)}' index/* | sort | uniq > $indexed
70
sh -c "echo 1>&2 ${pname}: some index probably corrupt"
74
ls msg | awk '{ print substr($1,1,6) }' > $messages
75
comm -23 $messages $indexed | awk '{ print "rm -f " $1 " " $1 ".wid" }' > $unindexed
77
# provide verbose statistics
79
echo $USER " total:" `wc -l < $messages` " indexed:" `wc -l < $indexed`\
80
" purging: " `wc -l < $unindexed`
89
rm $messages $indexed $unindexed