If this is OT, someone holler, it does apply to spamassassin
directly but is actually more perl questions.

Theo posted an answer[1] to this query already, but it largely flew
over my thick skull. (Sorry Theo).

  See this message for the above reference[1]: 
  From: Theo Van Dinter <[EMAIL PROTECTED]>
  Subject: Re: [SAtalk] Re: [Q perl regex] X-Spam-Status:
  To: [EMAIL PROTECTED]
  Date: Wed, 12 Jun 2002 16:15:29 -0400
  Message-ID: <[EMAIL PROTECTED]>

Tony also posted a nifty way to do this inside procmail[2].  It works
and is being employed in that way.  (Thanks Tony)

  See this message for the reference[2]
  From: "Tony L. Svanstrom" <[EMAIL PROTECTED]>
  Subject: Re: [SAtalk] [Q perl regex] X-Spam-Status:
  To: [EMAIL PROTECTED]
  cc: [EMAIL PROTECTED]
  Date: Wed, 12 Jun 2002 20:59:05 +0200 (CEST)
  Message-ID: <[EMAIL PROTECTED]>

To cut to the chase here:  I'm still looking for a way to do
something similar, although my original query is now satisfied.

An example will explain:
I want to capture this style of header:
  X-Spam-Status: No, hits=-106.4 required=5.0
     tests=Spama,BUGZILLA_BUG,NO_REAL_NAME,UNIFIED_PATCH
     version=2.21
(the leading white space is \t)

what I want to do with it isn't really important to the query at
hand. But in general.. reassemble it into a single line for further
processing.

I have worked out a painstaking way that will work (at least in my
tests so far), but wanted to see a better way with some of that
obfuscated but powerfull code perl is famous for.  Only problem is it
needs to be heavily commented else it will probably be like ancient
hebrew to me.

So, although its asking quite a lot of list readers patience and any
respondants good will, I'm pretty sure there are at least a few other
dopes like me who would benefit.

The following code is a start at a planned script that will check
score totals against some other homeboy scripts.  That is, this is a
debugging script for other work.

Its aim is limited here to just grabbing those lines of folded data.
That is not the final aim but I need to get that in hand first.
The final bit will be to compare the line to a similar line aquired
with another script.  The idea being to see if its working properly.

I'm reading a directory of numbered files, finding the target line
and reassembling it in a single line.  But I suspect this can be
done in much less coding.

#!/usr/local/bin/perl -w
## Make sure we have a cmdline arg
if(!$ARGV[0]){
   print "No cmdline argument given.. we need a directory name\n";
   exit;
}
## Establish a target
$dir = shift;
## Open our target dir and scoop all numberd filenames into an array
opendir(DIR,"$dir")|| die "Cannot open directory $dir: $!";
@files = grep {/^[0-9]+$/} readdir(DIR);

## Step thru the files 
for(@files){
   $message = $_;
   open(FILE,"<$dir/$message");
   while(<FILE>){
      chomp;
## If we see a blank line, join our captured lines into a single line
## And stuff into a hash indexed by filename 
      if(/^$/){
         $my_str = join(' ',@lines_we_want);
         $output{"$dir/$message"} = $my_str;
## Zero out our array and break out of the while loop
         @lines_we_want = '';
         last;
      }
## If we see our target line, turn on grab mode
      if(/^X-Spam-Status: /){
         $grab = "true";
      }
## If we see a line beginning with a Cap, and it isn't
## or target line, turn grab mode off.
      if(!/^X-Spam-Status:/ && /^[A-Z]/){
         $grab = '';
      }
## While in grab mode, massage the grabbed line by removing
## leading white space
      if($grab){
        ($str = $_) =~ s/^\s+//g;
        push @lines_we_want,$str;
      }   
   }     
}
## Print out our findings in an orderly fashion
foreach $key (keys %output){
   print "$key\n";
   print "$output{$key}\n\n";
}


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - 
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

_______________________________________________
Spamassassin-talk mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/spamassassin-talk

Reply via email to