On Wed, Jun 12, 2002 at 12:06:13PM -0500, Derrick 'dman' Hudson wrote: > Does perl have a MULTILINE mode like python's p-c implementation has?
Perl in general doesn't care about lines, it cares about strings. There are some regex chars (^, $, and . specifically) that pay attention to "lines" which may require overriding with the m (multiline string, ^ and $ work inside the string) or s (single line, . will also match \n) flags on the regex. So I would probably do something like: /^(X-Spam-Status:.+\n(?:\s+.+\n)*)/m I haven't actually tried that, but it ought to grab the whole header, folding whitespace and all and stick it in $1. You could then do something like: ( $xss = $1 ) =~ s/\n\s+/ /g and unfold into a single line. $xss =~ /\btests=(\S+)/ $tests = $1 and you should have your tests. There are also perl modules available to deal with mail formats that could get the header out for you. I use Mail::Internet for this stuff generally. my $msg = new Mail::Internet( \@msg, Modify => 0 ); my $head = $msg->head(); my $SAstatus = $head->get("X-Spam-Status") || "No, tests=\n"; my ( $status, $tests ) = ( $SAstatus =~ /^(\w+).+?tests=(\S*).*$/i ); $status =~ tr/A-Z/a-z/; $tests =~ tr/ //sd; foreach ( $tests, $from, $subject ) { $_ =~ tr/\040-\176//cd; # remove non-printables, newline, tab, etc ... } This works for 2.20. I forget whether or not Mail::Internet does unfolding for you or not, so I wonder if I'll have to change my code for 2.30 ... :| -- Randomly Generated Tagline: "A softball is like a foot. Don't try to lick it when it's traveling unusually fast towards your face." - a proverb from the Book of Mike
msg06250/pgp00000.pgp
Description: PGP signature