home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / ServiceMail / src / shell / grabexternal < prev    next >
Encoding:
Text File  |  1992-03-25  |  2.0 KB  |  107 lines

  1. #!/bin/csh -f
  2. # based on Nathaniel Borenstein's "showexternal" code
  3. echo $*
  4. if ($#argv <4) then
  5.     echo "Usage: grabexternal newfile access-type name [site [directory [mode]]]"
  6.     exit -1
  7. endif
  8. set newfile=$1
  9. set atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  10. set name=$3
  11. if ($#argv > 3) then
  12.     set site=$4
  13. else 
  14.     set site=""
  15. endif
  16. if ($#argv > 4) then
  17.     set dir=$5
  18. else
  19.     set dir=""
  20. endif
  21. if ($#argv > 5) then
  22.     set mode=$6
  23. else
  24.     set mode=""
  25. endif
  26. set username=""
  27. set pass=""
  28.  
  29. switch ($atype)
  30.     case anon-ftp:
  31.     set username=anonymous
  32.     set pass=`whoami`@`hostname`
  33.     # DROP THROUGH
  34.     case ftp:
  35.     if ("$site" == "") then
  36.         echo -n "Site for ftp access: "
  37.         set site=$<
  38.     endif
  39.     if ("$username" == "") then
  40.         echo -n "User name at site ${site}: "
  41.         set username=$<
  42.     endif
  43.     if ("$pass" == "") then
  44.         echo -n "Password for user $username at site ${site}: "
  45.         stty -echo
  46.         set pass=$<
  47.         stty echo
  48.         echo ""
  49.     endif
  50.     if ("$dir" == "") then
  51.         set DIRCMD=""
  52.     else
  53.         set DIRCMD="cd $dir"
  54.     endif
  55.     if ("$mode" == "") then
  56.         set MODECMD=""
  57.     else
  58.         set MODECMD="type $mode"
  59.     endif
  60.     echo OBTAINING MESSAGE BODY USING FTP
  61.     ftp -n <<!
  62. open $site
  63. user $username $pass
  64. $DIRCMD
  65. $MODECMD
  66. get $name $newfile
  67. quit
  68. !
  69.     if (! -e $newfile) then
  70.         echo FTP failed.
  71.         exit -1
  72.     endif
  73.     breaksw
  74.     case afs:
  75.     case local-file:
  76.     if (! -e $name) then
  77.         echo local file not found
  78.         exit -1
  79.     endif
  80.         cp $name $newfile
  81.     breaksw
  82.     case mail-server:  # A very special case DOESN'T WORK
  83.     if ("$bodyfile" == "") then
  84.         echo mail-server access-type requires a body file
  85.         exit -1
  86.     endif
  87.     echo Subject: Automated Mail server request > $newfile
  88.     echo To: ${name}@${site} >> $newfile
  89.     echo "" >> $newfile
  90.     cat $bodyfile >> $newfile
  91.     /usr/lib/sendmail -t  < $newfile
  92.     if ($status) then
  93.         echo sendmail failed
  94.         rm -rf $TMPDIR
  95.         exit -1
  96.     endif
  97.     rm -rf $TMPDIR
  98.     echo Your $ctype data has been requested from a mail server.
  99.     exit 0
  100.     default:
  101.     echo UNRECOGNIZED ACCESS-TYPE
  102.     exit -1
  103. endsw
  104.  
  105. exit 0
  106.