home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / contrib / carmel / c-client / carmel-purge.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1993-07-19  |  2KB  |  90 lines

  1. #!/bin/csh -f
  2. # vmail.purge - zaps all unindexed mail messages.
  3. #
  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.
  12.  
  13. #
  14. # Usage: vmail.purge [ username | somepath/username/.vmail ]
  15.  
  16.  
  17. set pname = $0
  18. set pname = ${pname:t}        # name of this script for error messages
  19.  
  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
  23.  
  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
  28.     else
  29.         setenv USER $1
  30.     endif
  31. endif
  32.  
  33. if ( ! -d ~$USER/.vmail ) then
  34.     echo -n "${pname}: "
  35.     if ( 1 <= $#argv ) then
  36.         sh -c "echo 1>&2  ${pname}: invalid argument $1"
  37.     else
  38.         sh -c "echo 1>&2  ${pname}: $USER has no .vmail directory"
  39.     endif
  40.     exit 1
  41. endif
  42.  
  43. cd ~$USER/.vmail
  44.  
  45. if (!( -d index && -d msg)) then
  46.     sh -c "echo 1>&2 ${pname}: $cwd is missing required components"
  47.     exit 1
  48. endif
  49. #
  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"
  53.     exit 1
  54. endif
  55. #
  56. #
  57. #remove the temporary RECOVER index *must* be done before deletion of messages
  58. # start.
  59. if ( -e index/RECOVER ) then
  60.    rm index/RECOVER
  61.    if ( -e  ~$USER/.inda ) rm ~$USER/.inda
  62.    if ( -e  ~$USER/.indf ) rm ~$USER/.indf
  63. endif
  64. #
  65. #
  66. # create the shell script
  67. #
  68. awk '$1 ~ /^[0-9]/ {print  substr($1,1,6)}' index/* | sort | uniq > $indexed
  69. if ( $status ) then
  70.         sh -c "echo 1>&2  ${pname}: some index probably corrupt"
  71.     exit 1
  72. endif
  73.  
  74. ls msg | awk '{ print substr($1,1,6) }' > $messages
  75. comm -23 $messages $indexed | awk '{ print "rm -f " $1 " " $1 ".wid" }' > $unindexed
  76.  
  77. # provide verbose statistics
  78. #
  79. echo $USER " total:" `wc -l < $messages` " indexed:" `wc -l < $indexed`\
  80.   " purging: " `wc -l < $unindexed`
  81.  
  82. # do the work
  83. #
  84. cd msg
  85. csh -f $unindexed
  86.  
  87. # cleanup
  88. #
  89. rm $messages $indexed $unindexed
  90.