home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1559 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  5.7 KB

  1. From: csu@alembic.acs.com (Dave Mack)
  2. Newsgroups: alt.personals,alt.sources,comp.lang.perl
  3. Subject: Anonymous Contact Service Software Posted
  4. Message-ID: <1990Jul7.182135.19069@alembic.acs.com>
  5. Date: 7 Jul 90 18:21:35 GMT
  6.  
  7. Immediately following this article, I will post the ACS software to
  8. alt.sources. It will be in three parts. The source is in a uuencoded,
  9. compressed tar file. This annpouncement has been crossposted to comp.lang.perl
  10. because most of the ACS code is written in Perl and may be of interest
  11. to Perl hackers, but the source itself will only be posted to alt.sources.
  12.  
  13. This distribution also includes the complete source for smail2.5,
  14. because I had to make a minor modification to it to get things to
  15. work properly. You can build a completely vanilla smail2.5 using the
  16. instructions and Makefile in the "mailer" subdirectory. Building the
  17. ACS version is automatic when you invoke the Makefile in the ACS
  18. toplevel directory, or when you use "make -f Makefile.acs install" in
  19. the "mailer" subdirectory.
  20.  
  21. To assist in unpacking this distribution, I'm enclosing a Perl script
  22. I wrote called uumerge, which will take a split uuencoded file, strip
  23. headers and trailers off, and uudecode the concatenated chunks.
  24. Simply save the ACS software articles in files (acs.part[1-3], for
  25. example), then say "uumerge acs.part*". Make sure that the pieces
  26. on the command line are in the right order. This should result in
  27. the production of a file called "acs1.0.tar.Z", which you should be
  28. able to uncompress and untar. Please do the latter in a new directory,
  29. as the tar file doesn't provide an acs toplevel directory.
  30.  
  31. --------------------------uumerge: cut here --------------------------------
  32. #! /usr/local/bin/perl
  33. #
  34. # Combine split uuencoded files into a single data stream with
  35. # e-mail garbage removed and pipe into uudecode. The uuencoded
  36. # files must be in the correct order on the command line - in
  37. # particular the first file must contain the "begin" line and
  38. # the last file must contain the "end" line.
  39. #
  40. # WARNING: this code relies on uuencode putting out all lines
  41. # of the form "M[61 ASCII characters]\n" for every line of the
  42. # file except the last few before the "end" line. If you come
  43. # across a uuencoded file that doesn't do this, you'll need to
  44. # modify the code to handle it.
  45. #
  46. # DISCLAIMER: You use this code at your own risk. Also, don't
  47. # take this is as a sterling example of Perl programming. Corrections
  48. # and improvements welcome. You may do whatever you like with this
  49. # code as long as you leave in some reminder of who the original
  50. # culprit^H^H^H^H^H^H^Hauthor was.
  51. #
  52. # Usage: uumerge filename [filename...]
  53. # Requires Perl 3.0 - my copy is at patchlevel 18
  54. #
  55. # Dave Mack csu@alembic.ACS.COM
  56. #
  57. # TODO: modify to allow more than one collection of files on
  58. #    command line.
  59. #
  60. # KNOWN BUGS: 
  61. #
  62. # If some bozo puts a line beginning with "M" in the body of one
  63. # of the intermediate/last chunks, uumerge will assume that uuencoded
  64. # part starts there.
  65. #
  66. # If the last chunk only contains the last two or three lines of
  67. # the uuencoded file (the ones that don't start with "M"), uumerge
  68. # will die.
  69. #
  70. # CHANGES
  71. #
  72. # PATCH 1:
  73. # It appears that some versions of uudecode are too stupid to skip
  74. # past the lines preceding the "begin" line, so feeding a one-part
  75. # uuencoded file to uumerge will bomb.
  76. #
  77. if ($#ARGV < 0 ) {
  78.     print "Usage: uumerge filename [filename...]\n";
  79.     exit 1;
  80. }
  81.  
  82. $| = 1;
  83. # open a pipe into uudecode
  84. open(DECO,"|uudecode") || die "Can't pipe into uudecode\n";
  85.  
  86. # if we only have one file, pump it straight into uudecode and die
  87. if ( $#ARGV == 0 ) {
  88.     open(FIRST,"<$ARGV[0]") || die "Can't open $ARGV[0] for input\n";
  89.  
  90.     while ( <FIRST> ) {
  91.         # skip past everything before the "begin" line
  92.         next unless /^begin [0-9]/;
  93.         last;
  94.     }
  95.     die "$ARGV[0] doesn't contain \"begin\"\n" if eof(FIRST);
  96.     
  97.     print DECO $_; # the begin line
  98.  
  99.     while ( <FIRST> ) {
  100.         print DECO $_ unless /^end/;
  101.         if ( /^end/ ) {
  102.             print DECO $_;
  103.             last;
  104.         }
  105.         die "$ARGV[0] doesn't contain \"end\"\n" if eof(FIRST);
  106.     }
  107.  
  108.     # done with file
  109.     close(FIRST);
  110.     exit 0;
  111. }
  112.  
  113. # process the first file - make sure we have a "begin" line
  114.  
  115. open(FIRST,"<$ARGV[0]") || die "Can't open $ARGV[0] for input\n";
  116.  
  117. while ( <FIRST> ) {
  118.     # skip past everything before the "begin" line
  119.     next unless /^begin [0-9]/;
  120.     last;
  121. }
  122. die "First file on command line doesn't contain \"begin\"\n" if eof(FIRST);
  123.     
  124. print DECO $_; # the begin line
  125.  
  126. # the remaining "real" uuencoded lines in this file should begin with "M"
  127. while ( <FIRST> ) {
  128.     if ( /^M/ ) {
  129.         print DECO $_;
  130.     }
  131.     else {
  132.         last;
  133.     }
  134. }
  135.  
  136. # done with the first file
  137. close(FIRST);
  138.  
  139. # do all except the last file
  140. $maxindex = $#ARGV;
  141. $curr = 1;
  142.  
  143. while ( $curr < $maxindex ) {
  144.     open(CURR,"<$ARGV[$curr]") || die "Can't open $ARGV[$curr]\n";
  145.     # skip the header junk
  146.     while ( <CURR> ) {
  147.         next unless /^$/;
  148.         last;
  149.     }
  150.     # at the body of the message - start looking for /^M/
  151.     while ( <CURR> ) {
  152.         next unless /^M/;
  153.         last;
  154.     }
  155.     die "$ARGV[$curr] isn't a uuencoded file\n" if eof(CURR);
  156.     # OK, we're at the start of the good stuff (probably)
  157.     print DECO $_;
  158.     while ( <CURR> ) {
  159.         if (/^M/) {
  160.             print DECO $_;
  161.         }
  162.         else {
  163.             last;
  164.         }
  165.     }
  166.     # done with current file
  167.     close(CURR);
  168.     $curr++;
  169. }
  170.  
  171. # time to do the last file in the set
  172. $curr = $maxindex;
  173. open(CURR,"<$ARGV[$curr]") || die "Can't open $ARGV[$curr]\n";
  174. # skip the header junk
  175. while ( <CURR> ) {
  176.     next unless /^$/;
  177.     last;
  178. }
  179. # at the body of the message - start looking for /^M/
  180. while ( <CURR> ) {
  181.     next unless /^M/;
  182.     last;
  183. }
  184. # OK, we're at the start of the good stuff (probably)
  185. print DECO $_;
  186. while ( <CURR> ) {
  187.     print DECO $_ unless /^end/;
  188.     if ( /^end/ ) {
  189.         print DECO $_;
  190.         last;
  191.     }
  192.     die "Last file on command line doesn't contain \"end\"\n" if eof(CURR);
  193. }
  194. # done with final file
  195. close(CURR);
  196. # close the pipe to uudecode and exit
  197. close(DECO);
  198. exit(0);
  199.