home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / bin / metasend < prev    next >
Encoding:
Text File  |  1993-05-10  |  9.6 KB  |  325 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.  
  15. if (! $?METAMAIL_TMPDIR) then
  16.     set METAMAIL_TMPDIR=/tmp
  17. endif
  18.  
  19. set idctr=0
  20. set MustDelete=0
  21. set batchmode=0
  22. set multipart = 1
  23. set splitsize = 100000
  24. while ($#argv > 0)
  25.     switch ("$1")
  26.         case "-S":
  27.             shift
  28.             if ($#argv == 0) then
  29.                 echo "-S requires a following argument, the SPLIT threshhold"
  30.                 exit
  31.             endif
  32.             set splitsize=$1
  33.             shift
  34.             breaksw
  35.         case "-b":
  36.             # Batch mode -- ALL args must be on command line
  37.             set batchmode = 1
  38.             shift
  39.             breaksw
  40.         case "-c":
  41.             shift
  42.             if ($#argv == 0) then
  43.                 echo "-c requires a following argument, the CC address"
  44.                 exit
  45.             endif
  46.             set cc=$1
  47.             shift
  48.             breaksw
  49.         case "-s":
  50.             shift
  51.             if ($#argv == 0) then
  52.                 echo "-s requires a following argument, the SUBJECT"
  53.                 exit
  54.             endif
  55.             set subject="$1"
  56.             shift
  57.             breaksw
  58.         case "-t":
  59.             shift
  60.             if ($#argv == 0) then
  61.                 echo "-t requires a following argument, the TO address"
  62.                 exit
  63.             endif
  64.             set to="$1"
  65.             shift
  66.             breaksw
  67.         case "-e":
  68.             shift
  69.             if ($#argv == 0) then
  70.                 echo "-e requires a following argument, the ENCODING value"
  71.                 exit
  72.             endif
  73.             set encode=$1
  74.             if ($encode == "base64") then
  75.         set encodingprog = "mimencode -b"
  76.             else if ($encode == "x-uue") then
  77.             set encodingprog = "uuencode mail-body"
  78.             else if ($encode == "7bit") then
  79.             set encodingprog = cat
  80.            else
  81.             set encodingprog = "mimencode -q"
  82.             set encode = "quoted-printable"
  83.            endif 
  84.            shift
  85.             breaksw
  86.         case "-f":
  87.             shift
  88.             if ($#argv == 0) then
  89.                 echo "-f requires a following argument, the DATA FILE"
  90.                 exit
  91.             endif
  92.             set datafile=$1
  93.             if (! -e  $datafile) then
  94.                 echo The file $datafile does not exist.
  95.                 exit
  96.             endif
  97.             shift
  98.             breaksw
  99.         case "-m":
  100.             shift
  101.             if ($#argv == 0) then
  102.                 echo "-m requires a following argument, the MIME CONTENT-TYPE"
  103.                 exit
  104.             endif
  105. #            set ctyperaw = $1
  106. #            set  ctype=`echo $ctyperaw | tr \" \'`
  107.     set ctype = $1
  108.             shift
  109.             breaksw
  110.         case "-z":
  111.             set MustDelete=1
  112.             shift
  113.             breaksw
  114.         case "-n":
  115.     if ( ! $?ctype || ! $?datafile) then
  116.         echo One part is incomplete -- each part needs at least -f and -m
  117.         exit 1
  118.     endif
  119.     if (! $?encode) then
  120.             if ("$ctype" =~ text*) then
  121.                   set encodingprog = "mimencode -q"
  122.         set encode = "quoted-printable"
  123.             else
  124.                 set encode = base64
  125.                 set encodingprog = "mimencode -b"
  126.             endif
  127.     endif
  128.     set ctype${multipart} = $ctype
  129.     set datafile${multipart} = $datafile
  130.     set encode${multipart} = $encode
  131.     set encodingprog${multipart} = "$encodingprog"
  132.     unset ctype
  133.     unset datafile
  134.     unset encode
  135.     unset encodingprog
  136.             @  multipart++
  137.     shift
  138.     breaksw
  139.         default:
  140.             echo UNRECOGNIZED METASEND OPTION: $1
  141.             exit
  142.     endsw
  143. end
  144. if ($batchmode == 0) then
  145.     if (! $?to) then
  146.         echo -n "To: "
  147.         set to = $<
  148.     endif
  149.     if (! $?subject) then
  150.         echo -n "Subject: "
  151.         set subject = $<
  152.     endif
  153.     if (! $?cc) then
  154.         echo -n "CC: "
  155.         set cc = $<
  156.     endif
  157. anotherpart:
  158.     if (! $?ctype) then
  159.         echo -n "Content-type: "
  160. #        set ctyperaw = $<
  161. #        set  ctype=`echo $ctyperaw | tr \" \'`
  162.         set ctype = $<
  163.     endif
  164. #    if ($ctype != $ctyperaw)  echo Double  quotes not allowed, using $ctype
  165.     if (! $?datafile) then
  166.         getfile:
  167.         echo -n "Name of file containing $ctype data: "
  168.         set datafile = $<
  169.         if (! -e  $datafile) then
  170.             echo The file $datafile does not exist.
  171.             goto getfile
  172.         endif
  173.     endif
  174.     if (! $?encode) then
  175.         retry:
  176.         echo "Do you want to encode this data for sending through the mail?"
  177.         echo "  1 -- No, it is already in 7 bit ASCII"
  178.         echo "  2 -- Yes, encode in base64 (most efficient)"
  179.         echo "  3 -- Yes, encode in quoted-printable (less efficient, more readable)"
  180.         echo "  4 -- Yes, encode it using uuencode (not standard, being phased out)"
  181.         set encode=$<
  182.         switch ("$encode")
  183.             case 1:
  184.                 set encodingprog = cat
  185.       set encode = 7bit
  186.                 breaksw
  187.             case 2:
  188.                 set encodingprog = "mimencode -b"
  189.       set encode = base64
  190.                 breaksw
  191.             case 3:
  192.                 set encodingprog = "mimencode -q"
  193.       set encode = quoted-printable
  194.                 breaksw
  195.             case 4:
  196.                 set encodingprog = "uuencode $datafile"
  197.       set encode = x-uue
  198.                 breaksw
  199.             default:
  200.                 echo Unrecognized answer, please try again.
  201.                 goto retry
  202.         endsw
  203.     endif
  204.     echo -n "Do you want to include another file too (y/n) [n] ? "
  205.     set ans=$<
  206.     if  ("$ans" =~ y*) then
  207.     set ctype${multipart} = $ctype
  208.     set datafile${multipart} = $datafile
  209.     set encode${multipart} = $encode
  210.     set encodingprog${multipart} = "$encodingprog"
  211.     unset ctype
  212.     unset datafile
  213.     unset encode
  214.     unset encodingprog
  215.             @  multipart++
  216.             goto anotherpart
  217.      endif
  218. else
  219.     if (! $?to || ! $?subject || ! $?ctype || ! $?datafile) then
  220.         echo metasend: in batch mode, -t, -s, -f, and -m are all required
  221.         exit
  222.     endif
  223.     if (! -e  $datafile) then
  224.         echo metasend:  The file $datafile does not exist
  225.         exit
  226.     endif
  227.     if (! $?cc) set cc=""
  228. #     if ($ctype != $ctyperaw)  echo Double  quotes not allowed, using $ctype
  229.     if (! $?encode) then
  230.         if ("$ctype" =~ text*) then
  231.     set encodingprog = "mimencode -q"
  232.     set encode = "quoted-printable"
  233.         else
  234.             set encodingprog = "mimencode -b"
  235.             set encode = base64
  236.         endif
  237.     else if ($encode == "base64") then
  238.         set encodingprog = "mimencode -b"
  239.     else if ($encode == "x-uue") then
  240.         set encodingprog = "uuencode mail-body"
  241.     else if ($encode == "7bit") then
  242.         set encodingprog = cat
  243.     else
  244.         set encodingprog = "mimencode -q"
  245.         set encode = "quoted-printable"
  246.     endif
  247. endif
  248.  
  249. if (! $?encode) then
  250.         if ("$ctype" =~ text*) then
  251.     set encode = "quoted-printable"
  252.     set encodingprog = "mimencode -q"
  253.         else
  254.             set encode = base64
  255.             set encodingprog = "mimencode -b"
  256.         endif
  257. endif
  258. set ctype${multipart} = $ctype
  259. set datafile${multipart} = $datafile
  260. set encode${multipart} = $encode
  261. set encodingprog${multipart} = "$encodingprog"
  262.  
  263. set fname = ${METAMAIL_TMPDIR}/metasend.$$
  264. echo "To: " "$to" > $fname
  265. echo "Subject: " "$subject" >> $fname
  266. echo "CC: " "$cc" >> $fname
  267. echo "MIME-Version: 1.0" >> $fname
  268. set hname = `hostname`
  269. if ($multipart > 1) then
  270.     set  boundary = ${hname}.$$.`date | tr "  " .`
  271.     set newid=`date | tr " :" "__"`
  272.     echo "Content-ID: <${newid}_$idctr@${hname}>"   >> $fname
  273.     @ idctr++
  274.     echo "Content-type: multipart/mixed;" >> $fname
  275.     echo "    boundary="\"$boundary\" >> $fname
  276.     echo "" >> $fname
  277.     echo "This is  a multimedia message in MIME  format.  If you are reading this" >> $fname
  278.     echo "prefix, your mail reader does  not understand MIME.  You may wish" >> $fname
  279.     echo "to look into upgrading to a newer version of  your mail reader." >> $fname
  280.     set i=1
  281.     set junkfile=${METAMAIL_TMPDIR}/mmjunk.$$
  282.     while  ($multipart >= $i)
  283.     echo --$boundary >> $fname
  284.               set newid=`date | tr " :" "__"`
  285.               echo "Content-ID: <${newid}_$idctr@${hname}>"   >> $fname
  286.     @ idctr++
  287.     echo -n Content-type: >>$fname
  288.     echo echo \$ctype$i \>\>  $fname > $junkfile
  289.     source $junkfile 
  290.     echo -n Content-Transfer-Encoding: >>$fname
  291.     echo echo \$encode$i \>\> $fname > $junkfile
  292.     source $junkfile 
  293.     echo ""  >> $fname
  294.     echo \$encodingprog$i \< \$datafile$i \>\> $fname > $junkfile
  295.     source $junkfile 
  296.     @ i++
  297.     end
  298.     rm $junkfile
  299.     echo --${boundary}-- >> $fname
  300.     echo "" >> $fname
  301. else 
  302.     set newid=`date | tr " :" "__"`
  303.     echo "Content-ID: <${newid}_$idctr@${hname}>"   >> $fname
  304.     @ idctr++
  305.     echo "Content-type: " $ctype >> $fname
  306.     echo "Content-Transfer-Encoding: " $encode >> $fname
  307.     echo  "" >> $fname
  308.     $encodingprog < $datafile >> $fname
  309.     # Ensure last line has trailing carraige return
  310.     echo "" >> $fname
  311. endif
  312. if ($batchmode == 0) echo -n "Delivering mail, please wait...  "
  313. splitmail -s $splitsize -d $fname
  314. if (! $status) then
  315.     if ($batchmode == 0) echo "Mail delivery apparently succeeded."
  316.     rm $fname
  317. else if ($MustDelete == 1) then
  318.     echo Mail delivery failed
  319.     rm $fname
  320. else
  321.     echo Mail delivery failed, draft mail is in $fname
  322. endif
  323.  
  324.