home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / bin / showexternal < prev    next >
Encoding:
Text File  |  1993-05-18  |  5.8 KB  |  239 lines

  1. #!/bin/csh -f
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. onintr cleanup
  15. if (! $?METAMAIL_TMPDIR) then
  16.     set METAMAIL_TMPDIR=/tmp
  17. endif
  18. if (! $?FTP) then
  19.     set FTP=ftp
  20. endif
  21.  
  22. if ($#argv <3) then
  23.     echo "Usage: showexternal body-file access-type name [site [directory [mode [server]]]]"
  24.     exit -1
  25. endif
  26. set bodyfile=$1
  27. set atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  28. set name=$3
  29. if ($#argv > 3) then
  30.     set site=$4
  31. else 
  32.     set site=""
  33. endif
  34. if ($#argv > 4) then
  35.     set dir=$5
  36. else
  37.     set dir=""
  38. endif
  39. if ($#argv > 5) then
  40.     set mode=$6
  41. else
  42.     set mode=""
  43. endif
  44. if ($#argv > 6) then
  45.     set server=$7
  46. else
  47.     set server=""
  48. endif
  49.  
  50. if ("$server" == "" && $atype == "mail-server") then
  51. # Backward compatibility with some broken stuff
  52.     set server=${name}@${site}
  53.     echo WARNING -- old style mailserver syntax, using server $server
  54. endif
  55.  
  56. set ctype="`grep -i content-type: $bodyfile | sed -e 's/............: //'`"
  57. if ("$ctype" == "") set ctype="text/plain"
  58. set cenc=`grep -i content-transfer-encoding: $bodyfile | sed -e 's/.........................: //'`
  59. set username=""
  60. set pass=""
  61. set TMPDIR=${METAMAIL_TMPDIR}/XXXternal.$$
  62. mkdir $TMPDIR
  63. pushd $TMPDIR
  64. set NEWNAME="mm.ext.$$"
  65. set NEEDSCONFIRMATION=1
  66. switch ("$atype")
  67.     case anon-ftp:
  68.     echo "This mail message contains a POINTER (reference) to data that is "
  69.     echo not included in the message itself.  Rather, the data can be retrieved 
  70.     echo automatically using  anonymous FTP to a site on the network.
  71.     breaksw
  72.     case ftp:
  73.     echo "This mail message contains a POINTER (reference) to data that is "
  74.     echo not included in the message itself.  Rather, the data can be retrieved 
  75.     echo automatically using  the FTP protocol to a site on the network.
  76.     breaksw
  77.     case mail-server:  
  78.     cat > ${METAMAIL_TMPDIR}/ext.junk.$$ <<!
  79. This mail message contains a POINTER (reference) to data that is 
  80. not included in the message itself.  Rather, the data can be retrieved 
  81. by sending a special mail message to a mail server on the network.
  82. However, doing this automatically is slightly dangerous, because  someone
  83. might be using this mechanism to cause YOU to send obnoxious mail.
  84. For that reason, the mail message that WOULD be sent is being shown to you
  85. first for your approval.
  86.  
  87. This is the message that will be sent if you choose to go ahead and
  88. retreive the external data:
  89.  
  90. To: ${server}
  91. Subject: Automated Mail Server Request
  92.  
  93. !
  94.     cat $bodyfile >> ${METAMAIL_TMPDIR}/ext.junk.$$
  95.     more ${METAMAIL_TMPDIR}/ext.junk.$$
  96.     rm ${METAMAIL_TMPDIR}/ext.junk.$$
  97.     breaksw
  98.     default:
  99.     # IGNORE ALL THE OTHERS -- AUTOMATIC FOR LOCAL-FILE, AFS.
  100.     set NEEDSCONFIRMATION=0
  101. endsw
  102.  
  103. if ($NEEDSCONFIRMATION) then
  104.     echo ""
  105.     echo -n "Do you want to proceed with retrieving the external data [y] ? "
  106.     set ANS=$<
  107.     if ("$ANS" =~ n* ||  "$ANS" =~ N* ) then
  108.         rm -rf $TMPDIR
  109.         exit 0
  110.     endif
  111. endif
  112.  
  113. switch ("$atype")
  114.     case anon-ftp:
  115.     set username=anonymous
  116.     set pass=`whoami`@`hostname`
  117.     # DROP THROUGH
  118.     case ftp:
  119.     if ("$site" == "") then
  120.         echo -n "Site for ftp access: "
  121.         set site=$<
  122.     endif
  123.     if ("$username" == "") then
  124.         echo -n "User name at site ${site}: "
  125.         set username=$<
  126.     endif
  127.     if ("$pass" == "") then
  128.         echo -n "Password for user $username at site ${site}: "
  129.         stty -echo
  130.         set pass=$<
  131.         stty echo
  132.         echo ""
  133.     endif
  134.     if ("$dir" == "") then
  135.         set DIRCMD=""
  136.     else
  137.         set DIRCMD="cd $dir"
  138.     endif
  139.     if ("$mode" == "") then
  140.         set MODECMD=""
  141.     else
  142.         set MODECMD="type $mode"
  143.     endif
  144.     echo OBTAINING MESSAGE BODY USING FTP
  145.     echo SITE: $site USER $username
  146.     $FTP -n <<!
  147. open $site
  148. user $username $pass
  149. $DIRCMD
  150. $MODECMD
  151. get $name $NEWNAME
  152. quit
  153. !
  154.     if (! -e $NEWNAME) then
  155.         echo FTP failed.
  156.         rm -rf $TMPDIR
  157.         exit -1
  158.     endif
  159.     breaksw
  160.     case afs:
  161.     case local-file:
  162.     if (! -e $name) then
  163.         echo local file not found
  164.         rm -rf $TMPDIR
  165.         exit -1
  166.     endif
  167.         set NEWNAME=$name
  168.     echo GETTING BODY FROM FILE NAMED: $NEWNAME
  169.     breaksw
  170.     case mail-server:  # A very special case
  171.     if ("$bodyfile" == "") then
  172.         echo mail-server access-type requires a body file
  173.         rm -rf $TMPDIR
  174.         exit -1
  175.     endif
  176.     echo Subject: Automated Mail Server Request > $NEWNAME
  177.     echo To: ${server} >> $NEWNAME
  178.     echo "" >> $NEWNAME
  179.     cat $bodyfile >> $NEWNAME
  180.     /usr/lib/sendmail -t  < $NEWNAME
  181.     if ($status) then
  182.         echo sendmail failed
  183.         cd ${METAMAIL_TMPDIR}
  184.         rm -rf $TMPDIR
  185.         exit -1
  186.     endif
  187.     cd ${METAMAIL_TMPDIR}
  188.     rm -rf $TMPDIR
  189.     echo Your $ctype data has been requested from a mail server.
  190.     exit 0
  191.     default:
  192.     echo UNRECOGNIZED ACCESS-TYPE
  193.     rm -rf $TMPDIR
  194.     exit -1
  195. endsw
  196. if ($cenc == base64) then
  197.     mimencode -u -b < $NEWNAME > OUT
  198.     mv OUT $NEWNAME
  199. else if ($cenc == quoted-printable) then
  200.     mimencode -u -q < $NEWNAME > OUT
  201.     mv OUT $NEWNAME
  202. endif
  203.  
  204. popd
  205. if ($atype == "local-file") then
  206.     metamail -b -c "$ctype" $NEWNAME
  207. else
  208.     metamail -b -c "$ctype" $TMPDIR/$NEWNAME
  209. endif
  210.  
  211. if ($status) then
  212.     echo metamail failed
  213.     cd ${METAMAIL_TMPDIR}
  214.     rm -rf $TMPDIR
  215.     exit -1
  216. endif
  217.  
  218. if ($NEWNAME != $name) then
  219.     echo ""
  220.     echo The data just displayed is stored in the file $TMPDIR/$NEWNAME
  221.     echo "Do you want to delete it?"
  222.     rm -i $TMPDIR/$NEWNAME
  223. endif
  224.  
  225. if (! -e ${TMPDIR}/${NEWNAME}) then
  226.     cd ${METAMAIL_TMPDIR}
  227.     rmdir $TMPDIR
  228. endif
  229. exit 0
  230.  
  231. cleanup:
  232. cd ${METAMAIL_TMPDIR}
  233. if (-e $TMPDIR) then    
  234.     rmdir $TMPDIR
  235. endif
  236. exit -1
  237.