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

  1. #!/bin/csh -f
  2.  
  3. if (! $?METAMAIL_TMPDIR) then
  4.     set METAMAIL_TMPDIR=/tmp
  5. endif
  6.  
  7. set TREEROOT=${METAMAIL_TMPDIR}/message-parts-`whoami`
  8. if ($#argv < 3 || $#argv > 4) then
  9.     echo "Usage:  showpartial file id partnum totalnum"
  10.     exit -1
  11. endif
  12. set file=$1
  13. # This next line is because message-id can contain weird chars
  14. set id=`echo $2 | tr -d  \!\$\&\*\(\)\|\'\"\;\/\<\>\\` 
  15. @ partnum = $3
  16. if ($#argv == 3 || $4 == "") then
  17.     set totalnum=-1
  18. else
  19.     @ totalnum = $4
  20. endif
  21.  
  22. if (! -d  $TREEROOT)  then
  23.     mkdir $TREEROOT
  24.     if ($status) then 
  25.         echo mkdir $TREEROOT failed
  26.         exit -1
  27.     endif
  28. endif
  29. if (! -d ${TREEROOT}/$id) then 
  30.     mkdir ${TREEROOT}/$id
  31.     if ($status) then 
  32.         echo mkdir ${TREEROOT}/$id failed
  33.         exit -1
  34.     endif
  35. endif
  36. cp $file ${TREEROOT}/$id/$partnum
  37. if ($status) then 
  38.     echo cp $file ${TREEROOT}/$id/$partnum failed
  39.     exit -1
  40. endif
  41. if ($totalnum == -1) then
  42.     if (-e ${TREEROOT}/$id/CT) then
  43.     set totalnum=`cat ${TREEROOT}/$id/CT`
  44.     else
  45.         set totalnum=-1  #GROSS HACK
  46.     endif
  47. else
  48.     echo $totalnum >! ${TREEROOT}/$id/CT
  49. endif
  50. # Slightly bogus here -- the shell messes up the newlines in the headers
  51. # If you put $MM_HEADERS in quotes, it doesn't help.
  52. # if ($partnum == 1) then
  53. #     echo $MM_HEADERS > ${TREEROOT}/$id/HDRS
  54. # endif
  55. set found=0
  56. set ix=1
  57. set list=""
  58. set limit=$totalnum
  59. if ($limit == -1) set limit=25
  60. while ($ix <= $limit)
  61.     if (-e ${TREEROOT}/$id/$ix) then
  62.     set list="$list $ix"
  63.     @ found ++
  64.     endif
  65.     @ ix ++
  66. end
  67. if ($found == $totalnum) then
  68.     cd ${TREEROOT}/$id
  69.     cat $list > ${TREEROOT}/$id/FULL
  70. #    cat ${TREEROOT}/$id/HDRS $list > ${TREEROOT}/$id/FULL
  71.     rm $list
  72.     echo All parts of this ${totalnum}-part message have now been read.
  73.     metamail -d  ${TREEROOT}/$id/FULL
  74.     echo WARNING:  To save space, the full file is now being deleted.  
  75.     echo You will have to read all $totalnum parts again to see the full message again.
  76.     rm ${TREEROOT}/$id/FULL
  77.     rm ${TREEROOT}/$id/CT
  78. #    rm ${TREEROOT}/$id/HDRS
  79.     cd
  80.     rmdir ${TREEROOT}/$id
  81.     rmdir ${TREEROOT} >& /dev/null
  82. else
  83.     if (${totalnum} == -1) then
  84.         echo So far you have only read $found of the several parts of this message.
  85.     else
  86.         echo So far you have only read $found of the $totalnum parts of this message.
  87.     endif
  88.     echo When you have read them all, then you will see the message in full.
  89. endif
  90.     
  91.