home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / interfaces / gnus-mail.shar / pmd < prev    next >
Encoding:
Text File  |  1991-05-03  |  2.1 KB  |  95 lines

  1. #!/bin/csh -f
  2. #
  3. # Configuration.
  4. umask 077
  5. set path=(/usr/local/bin /usr/ucb /bin /usr/bin /etc /usr/etc)
  6. set dir=/n/dinosaur/0/karl/Memos
  7. set tmp=/usr/tmp/karl-$$
  8. #
  9. # Save the mail momentarily, and set a Lines: count in it.
  10. cat - > $tmp
  11. set totlen=`wc -l < $tmp`
  12. set lines=(`sed '1,/^$/d' < $tmp | wc -l`)
  13. @ headerlen = $totlen - $lines
  14. ed - $tmp << EOF >& /dev/null
  15. $headerlen
  16. i
  17. Lines: $lines
  18. .
  19. w
  20. q
  21. EOF
  22. #
  23. # Deduce headers appropriately.
  24. set nonomatch
  25. set from=(`head -1 $tmp`)
  26. if ($#from < 2) then
  27.     echo Bogus mail: From_ line has $#from items.
  28.     sed -e 's/^/|/' < $tmp | sed -e '/^$/,$d'
  29.     exit 23
  30. endif
  31. set from=(`echo "$from[2]" | sed -e 's/@.*//' -e 's/\(.*\)!\(.*\)/\2/'`)
  32. if ("$from" =~ *-[Rr][Ee][Qq][Uu][Ee][Ss][Tt]*) then
  33.     # Mailing list stuff.
  34.     switch ("$from")
  35.         case firearms-request:
  36.             set subdir=list/firearms
  37.             breaksw
  38.         case firearms-politics-request:
  39.             set subdir=list/firearms/politics
  40.             breaksw
  41.         default:
  42.             set subdir=list/general
  43.             breaksw
  44.     endsw
  45. else if ("$from" =~ *[Mm][Aa][Ii][Ll][Ee][Rr]-[Dd][Aa][Ee][Mm][Oo][Nn]*) then
  46.     # BEWARE: Some (bad) csh's can't cope with the preceding regexp.
  47.     # Mailer-Daemon bounces.
  48.     set subdir=mailer-daemon
  49. else
  50.     # Personal mail
  51.     if ((-e $dir/personal/"$from") && (-d $dir/personal/"$from")) then
  52.         set subdir=personal/"$from"
  53.     else
  54.         set subdir=personal/general
  55.     endif
  56. endif
  57. unset nonomatch
  58. #
  59. # Now save the mail appropriately.
  60. #
  61. # Lock.
  62. set keyf=$dir/$subdir/KEY
  63. set seqfile=$dir/$subdir/.last
  64. set success=no
  65. @ retry = 0
  66. while (($retry < 10) && ($success == no))
  67.     rm $keyf
  68.     if ($status == 0) then
  69.         # The key was there when we wanted it.
  70.         set success=yes
  71.     else
  72.         # The key was not there - someone else
  73.         # had already taken it.  Wait and retry.
  74.         sleep 10
  75.         @ retry ++
  76.     endif
  77. end
  78. #
  79. # If we fall out to here without success, we failed 10 times to
  80. # get the key.  Result: Who cares?  We'll go forward anyway,
  81. # and re-assert the key when we're done.
  82. #
  83. # Get next filenumber.
  84. set seq=(`cat $seqfile`)
  85. @ seq ++
  86. echo $seq > $seqfile
  87. #
  88. # Unlock and save.
  89. touch $keyf
  90. sed -e '1s/^From /UNIX-From: /' < $tmp > $dir/"$subdir"/$seq
  91. #
  92. # Clean up and exit.
  93. rm -f $tmp
  94. exit 0
  95.