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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
|
#!/bin/sh -e
# Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
#
# Permission to use, copy, modify, and distribute this material
# for any purpose and without fee is hereby granted, provided
# that the above copyright notice and this permission notice
# appear in all copies, and that the name of Bellcore not be
# used in advertising or publicity pertaining to this
# material without the specific, prior written permission
# of an authorized representative of Bellcore. BELLCORE
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
# OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
# Conversion from C shell to Bourne shell by Z-Code Software Corp.
# Conversion Copyright (c) 1992 Z-Code Software Corp.
# Permission to use, copy, modify, and distribute this material
# for any purpose and without fee is hereby granted, provided
# that the above copyright notice and this permission notice
# appear in all copies, and that the name of Z-Code Software not
# be used in advertising or publicity pertaining to this
# material without the specific, prior written permission
# of an authorized representative of Z-Code. Z-CODE SOFTWARE
# MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
# OF THIS MATERIAL FOR ANY PURPOSE. IT IS PROVIDED "AS IS",
# WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
# Brought into line with metamail 2.7 beta release Csh version
# Dave Shield February 1994
if test -f /usr/sbin/sendmail
then
MAILCOMMAND=/usr/sbin/sendmail
else
MAILCOMMAND=/bin/mail
fi
if test "$#" -lt 3
then
echo "Usage: showexternal body-file access-type name [site [directory [mode]]]"
exit 1
fi
if [ -z "$METAMAIL_TMPDIR" ]
then
METAMAIL_TMPDIR=/tmp
fi
# Check argument integrity. Don't trust mail headers
if echo "$1$2$3$4$5$6$7" | grep -q '[[:space:]]'
then
echo "Illegal white space in arguments -- possibly a mail bomb?!"
echo "Command was:"
echo \'$0\' \'$1\' \'$2\' \'$3\' \'$4\' \'$5\' \'$6\' \'$7\'
exit 2
fi
bodyfile=$1
atype=$(echo "$2" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz)
name=$3
site=$4
dir=$5
mode=$6
server=$7
if test -z "$server" -a $atype = "mail-server"
then
server=${name}@${site}
echo WARNING -- old style mailserver syntax, using server "$server"
fi
ctype=$(grep -i content-type: "$bodyfile" | sed -e 's/............: //')
if test -z "$ctype"
then ctype="text/plain"
fi
cenc=$(grep -i content-transfer-encoding: "$bodyfile" | sed -e 's/.........................: //')
username=
pass=
TMPDIR=$METAMAIL_TMPDIR/XXXternal.$$
trap 'cd $METAMAIL_TMPDIR ; rmdir "$TMPDIR" >/dev/null 2>&1' 1 2 3 15
mkdir $TMPDIR
PUSHED_DIR=`pwd`
cd $TMPDIR
NEWNAME="mm.ext.$$"
NEEDSCONFIRMATION=1
case $atype in
anon-ftp)
echo "This mail message contains a POINTER (reference) to data that is "
echo not included in the message itself. Rather, the data can be retrieved
echo automatically using anonymous FTP to a site on the network. ;;
ftp)
echo "This mail message contains a POINTER (reference) to data that is "
echo not included in the message itself. Rather, the data can be retrieved
echo automatically using the FTP protocol to a site on the network. ;;
mail-server)
TMPF=$(mktemp /tmp/ext.junk.XXXXXX)
cat > $TMPF <<!
This mail message contains a POINTER (reference) to data that is not
included in the message itself. Rather, the data can be retrieved by
sending a special mail message to a mail server on the network.
However, doing this automatically is slightly dangerous, because
someone might be using this mechanism to cause YOU to send obnoxious
mail. For that reason, the mail message that WOULD be sent is being
shown to you first for your approval.
This is the message that will be sent if you choose to go ahead and
retrieve the external data:
Subject: Automated Mail Server Request
To: $server
!
sed -e 1,/^\$/d < "$bodyfile" >> $TMPF
sensible-pager $TMPF
rm $TMPF ;;
*)
NEEDSCONFIRMATION=0 ;;
esac
if test $NEEDSCONFIRMATION -ne 0
then
echo ""
echo -n "Do you want to proceed with retrieving the external data? [y] "
read ANS
case "$ANS" in
[Nn]*) cd $METAMAIL_TMPDIR
rm -rf $TMPDIR;
exit 0 ;;
esac
fi
case "$atype" in
anon-ftp | ftp)
case "$atype" in
anon-ftp )
username=anonymous
pass=`whoami`@`hostname`
;;
esac
if test -z "$site"
then
echo -n "Site for ftp access: "
read site
fi
if test -z "$username"
then
echo -n "User name at site ${site}: "
read username
fi
if test -z "$pass"
then
echo -n "Password for user $username at site ${site}: "
stty -echo
read pass
stty echo
echo ""
fi
if test -z "$dir"
then
DIRCMD=""
else
DIRCMD="cd $dir"
fi
if test -z "$mode"
then
MODECMD=""
else
MODECMD="type $mode"
fi
echo OBTAINING MESSAGE BODY USING FTP
echo SITE: "$site" USER: "$username"
${FTP:-ftp} -n <<!
open $site
user $username $pass
$DIRCMD
$MODECMD
get $name $NEWNAME
quit
!
if test ! -r "$NEWNAME"
then
echo FTP failed.
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
exit 1
fi
;;
afs|local-file)
if test ! -r "$name"
then
echo local file not found
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
exit 1
fi
NEWNAME=$name
echo GETTING BODY FROM FILE NAMED: "$NEWNAME" ;;
mail-server)
if test -z "$bodyfile"
then
echo mail-server access-type requires a body file
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
exit 1
fi
echo Subject: Automated Mail Server Request > "$NEWNAME"
echo To: "$server" >> "$NEWNAME"
echo >> "$NEWNAME"
sed -e 1,/^\$/d < "$bodyfile" >> "$NEWNAME"
$MAILCOMMAND -t < "$NEWNAME"
if test $? -ne 0
then
echo sendmail failed
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
exit 1
fi
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
echo Your "$ctype" data has been requested from a mail server.
exit 0 ;;
*)
echo UNRECOGNIZED ACCESS-TYPE
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
exit 1 ;;
esac
if test "$cenc" = base64
then
mimencode -u -b < "$NEWNAME" > OUT
mv OUT "$NEWNAME"
elif test "$cenc" = quoted-printable
then
mimencode -u -q < "$NEWNAME" > OUT
mv OUT "$NEWNAME"
fi
cd $PUSHED_DIR
case "$atype" in
local-file ) metamail -b -p -c "$ctype" "$NEWNAME" ;;
* ) metamail -b -p -c "$ctype" "$TMPDIR/$NEWNAME" ;;
esac
if test $? -ne 0
then
echo metamail failed
cd $METAMAIL_TMPDIR
rm -rf $TMPDIR
exit 1
fi
if test ! "$NEWNAME" = "$name"
then
echo ""
echo The data just displayed is stored in the file "$TMPDIR/$NEWNAME"
echo "Do you want to delete it?"
rm -i "$TMPDIR/$NEWNAME"
fi
if test ! -r "${TMPDIR}/${NEWNAME}"
then
cd /
cd $METAMAIL_TMPDIR
rmdir $TMPDIR
fi
|