home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / alt / hackers / 1391 < prev    next >
Encoding:
Internet Message Format  |  1992-09-09  |  3.6 KB

  1. Path: sparky!uunet!wupost!darwin.sura.net!utkcs2!cs.utk.edu!moore
  2. From: moore@cs.utk.edu (Keith Moore)
  3. Newsgroups: alt.hackers
  4. Subject: MIME-compatible SHAR program
  5. Date: 10 Sep 92 04:26:40 GMT
  6. Organization: Univ. of Tenn. Computer Science, Knoxville
  7. Lines: 120
  8. Approved: moore@cs.utk.edu
  9. Distribution: world
  10. Message-ID: <latjk0INNb34@utkcs2.cs.utk.edu>
  11. Reply-To: moore@cs.utk.edu
  12. NNTP-Posting-Host: wilma.cs.utk.edu
  13. Content-type: multipart/mixed ; boundary = "MIME-shar-964"
  14. MIME-Version: 1.0
  15.  
  16. Here is a version of SHAR that generates MIME messages.  A MIME mail
  17. reader can understand these and extract them.  If the reader lacks a
  18. MIME mail reader, the header can be stripped off and the result fed to
  19. the Bourne shell like any other SHAR file.  Obviously this is pretty
  20. rudimentary, but I wanted to see how it could be done.
  21.  
  22. (MIME really needs an application/text content-type...)
  23.  
  24. Teaching awk or sed to understand base64 and quoted-printable are
  25. left as exercises to the reader...
  26.  
  27. #!/bin/sh
  28. #
  29. # this is a MIME-compatible .shar file.  If you have a MIME-smart
  30. # mail reader, it will offer to extract files for you.  Otherwise,
  31. # you can treat this message as any other .shar file -- strip off
  32. # the message headers (everything before the #!/bin/sh line above)
  33. # and feed them as input to /bin/sh -- to extract the files.
  34. #
  35. awk 'BEGIN {
  36.     state=0;
  37. }
  38. /^--MIME-shar-964-- *$/ && (state == 2) {
  39.     printf ("EndOfFile\n");
  40.     printf ("exit 0\n");
  41.     next;
  42. }
  43. /^--MIME-shar-964 *$/ && (state == 0 || state == 2) {
  44.     if (state == 2) 
  45.         printf ("EndOfFile\n");
  46.     filename=""
  47.     state = 1;
  48.     next;
  49. }
  50. /^ *$/ && (state == 1) {
  51.     printf ("sed -e '"'"'s/^X//'"'"' << \"EndOfFile\" > %s\n", filename);
  52.     state = 2;
  53.     next;
  54. }
  55. /^Content-type: application\/octet-stream; name=/ && (state == 1) {
  56.     split($0,a,"\"");
  57.     filename=a[2];
  58.     next;
  59. }
  60. { if (state == 2) { printf("X%s\n", $0); }}' << "EndOfAwkInput"
  61. --MIME-shar-964
  62. Content-type: application/octet-stream; name="mime-shar"
  63.  
  64. #!/bin/sh
  65. #
  66. # mime-shar version 1.0
  67. # Keith Moore
  68. # Copyright (c) 1992 Keith Moore
  69. #
  70. # This program generates a MIME message which contains one or more files.
  71. # The MIME message is also a shell script; the headers can be removed and
  72. # the result fed to a UNIX shell for extraction.
  73. #
  74. case $# in
  75.     0) echo 'usage: '$0' filename...' ; exit ;;
  76. esac
  77. BOUNDARY=MIME-shar-$$
  78. sed -e 's/BOUNDARY/'"$BOUNDARY"'/' << "EndOfSedInput"
  79. Content-type: multipart/mixed ; boundary = "BOUNDARY"
  80. MIME-Version: 1.0
  81.  
  82.  
  83. #!/bin/sh
  84. #
  85. # this is a MIME-compatible .shar file.  If you have a MIME-smart
  86. # mail reader, it will offer to extract files for you.  Otherwise,
  87. # you can treat this message as any other .shar file -- strip off
  88. # the message headers (everything before the #!/bin/sh line above)
  89. # and feed them as input to /bin/sh -- to extract the files.
  90. #
  91. awk 'BEGIN {
  92.     state=0;
  93. }
  94. /^--BOUNDARY-- *$/ && (state == 2) {
  95.     printf ("EndOfFile\n");
  96.     printf ("exit 0\n");
  97.     next;
  98. }
  99. /^--BOUNDARY *$/ && (state == 0 || state == 2) {
  100.     if (state == 2) 
  101.         printf ("EndOfFile\n");
  102.     filename=""
  103.     state = 1;
  104.     next;
  105. }
  106. /^ *$/ && (state == 1) {
  107.     printf ("sed -e '"'"'s/^X//'"'"' << \"EndOfFile\" > %s\n", filename);
  108.     state = 2;
  109.     next;
  110. }
  111. /^Content-type: application\/octet-stream; name=/ && (state == 1) {
  112.     split($0,a,"\"");
  113.     filename=a[2];
  114.     next;
  115. }
  116. { if (state == 2) { printf("X%s\n", $0); }}' << "EndOfAwkInput"
  117. EndOfSedInput
  118. for file in $* ; do
  119.     echo '--'$BOUNDARY
  120.     echo 'Content-type: application/octet-stream; name="'$file'"'
  121.     echo ''
  122.     cat $file
  123. done
  124. echo '--'$BOUNDARY'--'
  125. echo 'EndOfAwkInput'
  126. echo 'exit 0'
  127.  
  128. --MIME-shar-964--
  129. EndOfAwkInput
  130. exit 0
  131.  
  132.  
  133. --
  134. Keith Moore / U.Tenn CS Dept / 107 Ayres Hall / Knoxville TN  37996-1301
  135. Internet: moore@cs.utk.edu      BITNET: moore@utkvx
  136.