home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / bin / mailserver < prev    next >
Encoding:
Text File  |  1993-02-26  |  3.9 KB  |  151 lines

  1. #!/bin/csh -f
  2. # Mailserver -- a simple MIME mailserver script.
  3. # Makes all files under a tree available for MIME-based retrieval.
  4. # By default, it sends them as the MIME type "application/octet-stream"
  5. # However, for a file named "x/y/foo.bar", you can specify a "right"
  6. # MIME content-type by putting it in the file "x/y/foo.bar.ct".
  7.  
  8. # In a distributed sendmail environment, this script can be installed with lines
  9. #    somewhat like the following two in /usr/lib/aliases:
  10. # mail-server: local-mail-server@some-single-machine
  11. # local-mail-server: "|/full/path/to/mailserver"
  12.  
  13. # By default the program uses "mail-server" as its local return address.
  14. #   and makes available all files under /usr/spool/ftp.
  15. # You might need or want to change the following parameters:
  16. set LOCALADDR=mail-server
  17. set ROOTDIR=/usr/spool/ftp
  18. set MAINTAINER=postmaster
  19. set METAMAILDIR=/usr/local/bin
  20. set LOGADDR=andrew@thumper.bellcore.com
  21. # If LOGADDR is the empty string, no logging is done.
  22. #
  23. # The real program begins here.
  24.  
  25. setenv PATH ${METAMAILDIR}:${PATH}
  26. rehash
  27. set FromName=""
  28. set Subject=""
  29. set TmpFile=/tmp/ms.$$
  30. set FOORAW=$<
  31. while ("$FOORAW" != "") 
  32. set FOO=(` echo "$FOORAW" | tr "[" "x"`)
  33. set BAR=($FOO)
  34. set BARLC=(`echo $FOO | tr A-Z a-z`)
  35. if ($BARLC[1] == "from:") then
  36.     if ("$FromName" == "") then
  37.         set FromName = ($BAR[2-])
  38.     endif
  39. else if ($BARLC[1] == "reply-to:") then
  40.     set FromName = ($BAR[2-])
  41. else if ($BARLC[1] == "subject:") then
  42.     set Subject = ($BAR[2-])
  43. endif
  44. set FOORAW=$<
  45. end
  46. # Now, stdin just has the body left, to do with as we please.
  47. # We choose to interpret the first line as the request, nothing more
  48. if ("$Subject" == "") then
  49.     set Subject=$<
  50. endif
  51.  
  52. if ("$FromName" == "") then
  53.     cat > $TmpFile <<!
  54. From: $LOCALADDR@`hostname`
  55. To: $MAINTAINER
  56. Subject: $Subject
  57.  
  58. The metamail mailserver script, installed locally as $LOCALADDR, 
  59. has received a request without any reply address.
  60.  
  61. It is possible that this is the result of a user running the "mailserver" 
  62. program by hand.  It is intended to be run as an automated recipient of 
  63. mail requests, rather than an interactive program.
  64.  
  65. No reply is being generated, but the contents of the request are 
  66. reproduced below.  If no message appears below, then this program was 
  67. probably run in some circumstance other than mail delivery.
  68. --------------------
  69. !
  70.     cat $TmpFile - | /usr/lib/sendmail $MAINTAINER
  71.     # Takes the rest of the message from standard input
  72.     rm $TmpFile
  73.     exit 0
  74. endif
  75.  
  76. set danger=`echo $Subject | fgrep ..`
  77. if ($danger != "") then
  78.     cat > $TmpFile <<!
  79. From: $LOCALADDR@`hostname`
  80. To: $FromName
  81. Subject: Re: $Subject
  82.  
  83. For security reasons, this mailserver automatically rejects all requests 
  84. that contain ".." in the path name.
  85.  
  86. The file you requested, if it exists, will not be sent to you.
  87. !
  88.     /usr/lib/sendmail -t < $TmpFile
  89.     rm $TmpFile
  90.     exit 0
  91. endif
  92.  
  93. cd $ROOTDIR
  94. if (! -e "$Subject") then
  95.     cat > $TmpFile <<!
  96. From: $LOCALADDR@`hostname`
  97. To: $FromName
  98. Subject: Re: $Subject
  99.  
  100. You recently sent mail to this mail-server requestion the file: 
  101.     $Subject
  102.  
  103. That file does not exist, so your request could not be met.
  104.  
  105. Here is a list of the currently available files:
  106. --------------------------------
  107. !
  108.     ls -R >> $TmpFile
  109.     /usr/lib/sendmail -t < $TmpFile
  110.     rm $TmpFile
  111.     exit 0
  112. endif
  113.  
  114. if (-e ${Subject}.ct) then
  115.     set ct=`cat ${Subject}.ct`
  116. else 
  117.     set ct="application/octet-stream"
  118. endif
  119.  
  120. metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject"
  121. if ($status != 0) then
  122.     cat > $TmpFile <<!
  123. From: $LOCALADDR@`hostname`
  124. To: $FromName
  125. Subject: Re: $Subject
  126.  
  127. You recently sent mail to this mail-server requestion the file: 
  128.     $Subject
  129.  
  130. An unanticipated error apparently precluded delivery of the file.
  131. Please accept our apologies.
  132.  
  133. Command failed: 
  134.   metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject"
  135.  
  136. !
  137.     /usr/lib/sendmail -t < $TmpFile
  138.     rm $TmpFile
  139.     exit 0
  140. endif
  141.  
  142. if ("$LOGADDR" != "") then
  143.     /usr/lib/sendmail -t <<!
  144. From: ${LOCALADDR}@`hostname`
  145. To: $LOGADDR
  146. Subject: Autosend delivery report
  147.  
  148. The file: $Subject 
  149. was sent to: $FromName
  150. !
  151. exit 0
  152.