File: mailserver

package info (click to toggle)
metamail 2.7-47sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,360 kB
  • ctags: 1,331
  • sloc: ansic: 16,102; sh: 10,934; csh: 229; makefile: 174
file content (151 lines) | stat: -rwxr-xr-x 4,062 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/csh -efb
# (The "-fb" might need to be changed to "-f" on some systems)
#
# Mailserver -- a simple MIME mailserver script.
# Makes all files under a tree available for MIME-based retrieval.
# By default, it sends them as the MIME type "application/octet-stream"
# However, for a file named "x/y/foo.bar", you can specify a "right"
# MIME content-type by putting it in the file "x/y/foo.bar.ct".

# In a distributed sendmail environment, this script can be installed with lines
#	somewhat like the following two in /usr/lib/aliases:
# mail-server: local-mail-server@some-single-machine
# local-mail-server: "|/full/path/to/mailserver"

# By default the program uses "mail-server" as its local return address.
#   and makes available all files under /usr/spool/ftp.
# You might need or want to change the following parameters:
set LOCALADDR=mail-server
set ROOTDIR=/usr/spool/ftp
set MAINTAINER=postmaster
set LOGADDR=andrew@thumper.bellcore.com
# If LOGADDR is the empty string, no logging is done.
#
# The real program begins here.

rehash
set FromName=""
set Subject=""
set TmpFile=`tempfile -p metamail -m 600`
set FOORAW=$<
while ("$FOORAW" != "") 
set FOO=(` echo "$FOORAW" | tr "[" "x"`)
set BAR=($FOO)
set BARLC=(`echo $FOO | tr A-Z a-z`)
if ($BARLC[1] == "from:") then
	if ("$FromName" == "") then
		set FromName = ($BAR[2-])
	endif
else if ($BARLC[1] == "reply-to:") then
	set FromName = ($BAR[2-])
else if ($BARLC[1] == "subject:") then
	set Subject = ($BAR[2-])
endif
set FOORAW=$<
end
# Now, stdin just has the body left, to do with as we please.
# We choose to interpret the first line as the request, nothing more
if ("$Subject" == "") then
    set Subject=$<
endif

if ("$FromName" == "") then
	cat > $TmpFile <<!
From: $LOCALADDR@`hostname`
To: $MAINTAINER
Subject: $Subject

The metamail mailserver script, installed locally as $LOCALADDR, 
has received a request without any reply address.

It is possible that this is the result of a user running the "mailserver" 
program by hand.  It is intended to be run as an automated recipient of 
mail requests, rather than an interactive program.

No reply is being generated, but the contents of the request are 
reproduced below.  If no message appears below, then this program was 
probably run in some circumstance other than mail delivery.
--------------------
!
	cat $TmpFile - | /usr/sbin/sendmail $MAINTAINER
	# Takes the rest of the message from standard input
	rm $TmpFile
	exit 0
endif

set danger=`echo $Subject | fgrep ..`
if ($danger != "") then
	cat > $TmpFile <<!
From: $LOCALADDR@`hostname`
To: $FromName
Subject: Re: $Subject

For security reasons, this mailserver automatically rejects all requests 
that contain ".." in the path name.

The file you requested, if it exists, will not be sent to you.
!
	/usr/sbin/sendmail -t < $TmpFile
	rm $TmpFile
	exit 0
endif

cd $ROOTDIR
if (! -e "$Subject") then
	cat > $TmpFile <<!
From: $LOCALADDR@`hostname`
To: $FromName
Subject: Re: $Subject

You recently sent mail to this mail-server requesting the file: 
	$Subject

That file does not exist, so your request could not be met.

Here is a list of the currently available files:
--------------------------------
!
	ls -R >> $TmpFile
	/usr/sbin/sendmail -t < $TmpFile
	rm $TmpFile
	exit 0
endif

if (-e ${Subject}.ct) then
	set ct=`cat ${Subject}.ct`
else 
	set ct="application/octet-stream"
endif

metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject"
if ($status != 0) then
	cat > $TmpFile <<!
From: $LOCALADDR@`hostname`
To: $FromName
Subject: Re: $Subject

You recently sent mail to this mail-server requestion the file: 
	$Subject

An unanticipated error apparently precluded delivery of the file.
Please accept our apologies.

Command failed: 
  metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject"

!
	/usr/sbin/sendmail -t < $TmpFile
	rm $TmpFile
	exit 0
endif

if ("$LOGADDR" != "") then
	/usr/sbin/sendmail -t <<!
From: ${LOCALADDR}@`hostname`
To: $LOGADDR
Subject: Autosend delivery report

The file: $Subject 
was sent to: $FromName
!
exit 0