home *** CD-ROM | disk | FTP | other *** search
- #! /LocalApps/perl
- # joinMail
- # Read a bunch of mail messages with headers from stdin, arrange in the
- # correct order based on the Subject lines, and print it to stdout
- # without mail headers.
- #
- # 04-Feb-91 Rob Kedoin rob@lighthouse.com Initial version
- # 15-Feb-91 Rob Kedoin rob@lighthouse.com rewrite
-
- # inData is:
- # 0 before a Subject line
- # 1 after a Subject line
- # 2 when it hits a line beginning with an M.
- $inData = 0;
- $partNum = 0;
- while (<>)
- {
- eachLine:
- {
- ($inData == 0) && (/Subject/o) && do
- {
- ($junk, $subject) = split(/: /);
- chop $subject;
- $subjects[$partNum] = $subject;
-
- $inData = 1;
- last eachLine;
- };
- ($inData == 1) && do
- {
- # the first data line after a Subject
- ((/^begin/o) || (/^M/o && (length($_) == 62))) && do
- {
- $inData = 2;
- push(@mailMsgs,$_);
- $partLines = 1;
- };
- last eachLine;
- };
- ($inData == 2) && do
- {
- # if the line has whitespace for "From " at the beginning
- # of it we are done with the data.
- if ( /^(\s|From |end)/o )
- {
- /^end/o && do
- {
- push(@mailMsgs,$_);
- $partLines += 1;
- };
- $numLines[$partNum] = $partLines;
- $partNum += 1;
- $inData = 0;
- }
- else
- {
- push(@mailMsgs,$_);
- $partLines += 1;
- }
- last eachLine;
- };
- }
- }
-
- #build an assoc array to make it easier to sort.
- for ($index = 0 ; $index <= $#numLines; $index += 1)
- {
- @theSplice = splice(@mailMsgs,0,$numLines[$index]);
- $msg{$subjects[$index]} = join(//,@theSplice);
- }
-
- # sort the subjects as appropriate and print the message bodies to
- # standard out.
- if ($purdue == 0)
- {
- foreach $key (sort(keys %msg))
- {
- print $msg{$key};
- }
- }
- else
- {
- # use special sorting routine for purdue files
- foreach $key (sort purdue (keys %msg))
- {
- print $msg{$key};
- }
- }
-
- sub numeric
- # numeric is used to sort in numerical rather than string order
- {
- $a > $b;
- }
-
- sub purdue
- # the subject line on files from purdue looks like:
- # 1/11 of next/demos/Diagram.tar.Z
- # use the number before the first '/' and sort numerically
- {
- ($aNum,@rest) = split(/\//,$a);
- ($bNum,@rest) = split(/\//,$b);
- $aNum > $bNum;
- }
-