[PLUG] Perl is EVIL!!

AthlonRob AthlonRob at axpr.net
Fri Oct 31 17:08:02 UTC 2003


...too bad it's just the right tool for some jobs.

I'm trying to extract rfc/822 attachments out of emails.  Forwards. 
Easier said than done, I'm finding.

I'm making progress, but have hit a major stumbling block, I can't get
the last boundary to NOT print.  It just absolutely wants to print, no
matter what.  Well, that isn't accurate.  It wants to print, no matter
what, if the attached message uses MIME, itself.  If the attached
message is all plaintext, then the bottom boundary does *not* print, as
it should be.

I'm stumped.  Any ideas?  This is the *first* perl script I've ever
written, so be gentle.  :-)

It's still rough around the edges with a few things that need to be
worked out, but as it stands now it is usable, just adding whitespace at
the top and the bottom boundary if there's extra MIME in there.  It also
assumes Content-Type is the last line in the MIME header - these will be
fixed, I have ideas... if I can get the blasted last boundry to stop
printing.  :-)

Any thoughts?

#!/usr/bin/perl

$bound = 1;		#Unless this is false, keep checking for tbound
$tbound = "No Boundry";	#True boundary - need for begining and ending
$lastline = "";		#The line before the current one.

while (<>) {
  chomp $_;

  if ($_ =~ /^--=-/ && $bound){   #that regex isn't going to work 
				  #outside of testing
     $tbound = $_;	#When we have a boundry before bound is set (rfc822)
			#tbound is set to it.  After we hit the rfc822 line,
			#we won't be defining it any more.
  }

  if ($lastline =~ /^Content-Type: message\/rfc822/){
     $bound = 0;	#Set bound to false so we start printing
  }

  if ($tbound =~ /--/ && !($bound)) {
        print "$_\n" unless ($_ =~ $tbound); #Should print all lines not 
					     #matching $tbound after $bound 
					     #is set to 0
  }

  $lastline = $_;	#Defining lastline so we don't print the Content line
}





More information about the PLUG mailing list