In <
slrnjieqmt...@tadbox.sbcglobal.net>, on 01/30/2012
at 10:07 PM, Tad McClellan <ta...@seesig.invalid> said:
>Nobody knows what string is in $testheader (because it is not loaded
>up in Real Perl Code) so we cannot help with matching it...
Okay, this time I'll provide a complete program instead of snippets.
Where I'm stuck is in the discrepancy between the first and second
test of $testheader
[1] /(\) $RecByPat? $RecWithPat? $RecIdPat? $RecForPat?) /imx
[2] /((?<FOR>$RecForPat))/imx
#!/usr/bin/perl -W
use 5.010;
use Data::Dumper;
use Regexp::Common qw /net URI/;
use Socket;
use strict;
my $decOctetPat = qr/ \d |
[1-9] \d |
1 \d \d |
2 [0-4] \d |
25 [0-5]
/x;
my $IPv4addressPat = qr/ (?:$decOctetPat\.){3} $decOctetPat /x;
my $IPv6h16 = qr/[[:xdigit:]]{1,4}/;
my $IPv6ls32 = qr/ $IPv6h16 \: $IPv6h16 | $IPv4addressPat /x;
my $IPv6AddrPat = qr/ (?: (?: $IPv6h16 \: ){6} $IPv6ls32 ) |
(?: \:\: (?: $IPv6h16 \: ){5} $IPv6ls32 ) |
(?: (?: $IPv6h16 )? \:\: (?: $IPv6h16 \: ){4} $IPv6ls32 ) |
(?: (?: $IPv6h16 \: $IPv6h16 )? \:\: (?: $IPv6h16 \: ){3} $IPv6ls32 ) |
(?: (?: (?: $IPv6h16 \: ){2} $IPv6h16 )? \:\: (?: $IPv6h16 \: ){2} $IPv6ls32 ) |
(?: (?: (?: $IPv6h16 \: ){3} $IPv6h16 )? \:\: $IPv6h16 \: $IPv6ls32 ) |
(?: (?: (?: $IPv6h16 \: ){5} $IPv6h16 )? \:\: $IPv6ls32 ) |
(?: (?: (?: $IPv6h16 \: ){6} $IPv6h16 )? \:\: )
/x;
my $domainPat = qr/[[:alnum:]]+
[[:alnum:]-]*
(?:\. [[:alnum:]]+ [[:alnum:]-]*)*
/x;
my $addressLiteralPat = qr/\[
(?:$IPv4addressPat |
$IPv6AddrPat
)
\]
/x;
my $atextPat = qr"(?:[\w!#\$%&'*+/=?^`{|}~-]+)";
#y $FWS = qr/ (?:[ \t]*\15?\12)? [ \t]+ /mx;
my $FWS = qr/ (?:[ \t]*\15?\n)? [ \t]+ /mx;
my $atomPat = qr/\s* $atextPat+ \s*/x;
my $ctext = '[\x21-\x27\x2A-\x5B\x5D-\x7E]';
my $dotStringPat = qr/$atextPat+ (?:\. $atextPat)*/x;
my $LinkPat = qr/TCP | $atomPat/xi;
my $dtextPat = '[\x21-\x50\x54-\x7E]';
my $idLeftPat = qr/$dotStringPat/;
my $noFoldLiteralPat = qr/\[ $dtextPat* \]/x;
my $idRightPat = qr/$dotStringPat | $noFoldLiteralPat/x;
my $msgIdPat = qr/\s* \< $idLeftPat \@ $idRightPat \> \s*/x;
my $quotedPairPat = qr/ \\ [\x20-\x7E] /x;
my $qtextPat = '[\x20-\x21\x23-\x5B\x5d-\x7E]';
my $QcontentPat = qr/$qtextPat | $quotedPairPat/x;
my $QuotedStringPat = qr/"$QcontentPat*"/;
my $commentPat =qr/
\(
(?:$FWS?
(?:$ctext | $quotedPairPat | (?R))
)*
$FWS?
\)
/x;
my $CFWS = qr/
(?: (?:$FWS+ $commentPat)+ $FWS?) |
$FWS
/mx;
my $localPartPat = qr/$dotStringPat | $QuotedStringPat/x;
my $MailboxPat = qr/(?<LOCAL_PART>$localPartPat) \@ (?<DOMAIN>$domainPat | $addressLiteralPat)/x;
my $RecPathPat = qr/
\<
(?:\@ $domainPat (?:, \@ $domainPat)* :)?
$MailboxPat
\>
/x;
my $RecByPat = qr!$CFWS
BY
$FWS
(?<BY1>
(?:$domainPat |
\[ $RE{net}{IPv4} \]
)
)
(?:
\s*
\(
(?<BY2>[\s\w\./-]+)
\)
)?
!mxi;
my $RecForPat = qr/$CFWS FOR $FWS (?: $RecPathPat | $MailboxPat)/imx;
my $RecIdPat = qr/$CFWS ID $FWS (?:$atomPat | $msgIdPat)/imx;
my $RecViaPat = qr/$CFWS VIA $FWS $LinkPat/imx;
my $RecWithMS = qr/Microsoft \s+ (?:ESMTP|SMTP) (?:\s+ Server | SVC\(\d+(?:\.\d+)*\))/ix;
my $RecWithPat = qr/$CFWS
WITH $FWS
(?:
(?:ESMTP|SMTP) |
$RecWithMS |
NNFMP # Yahoo
)
/imx;
my $RecOptInfo = qr/
(?<VIA>$RecViaPat)?
(?<WITH>$RecWithPat)?
(?:$RecIdPat)?
(?<FOR>$RecForPat)?
/imx;
my $testheader = <<'EOF';
EOF
msg("\n\$testheader= $testheader\n");
msg("\n\$testheader= ".unpack('H*',$testheader)."\n");
if ($testheader =~ /(\) $RecByPat? $RecWithPat? $RecIdPat? $RecForPat?) /imx) {
print STDERR "\n\$testheader matched FWS\n";
print STDERR "\n";
print STDERR "\n\$PREMATCH =$`\n";
print STDERR "\n\$POSTMATCH=$'\n";
msg("\nDumper(\%+):\n");
msg(Dumper(%+),"\n");
msg("\nDumper(\%-):\n");
msg(Dumper(%-),"\n");
foreach (sort keys %+) {
print STDERR "\$+{$_}=$+{$_}\n";
}
print STDERR "\n";
} else {
print STDERR "\n\$testheader did not match FWS\n";
}
# if ($testheader =~ /(?<WITH>$RecWithPat)/im) {
# if ($testheader =~ /$RecOptInfo?/) {
# if ($testheader =~ /($CFWS FOR $FWS (?: $RecPathPat | $MailboxPat))/imx) {
if ($testheader =~ /((?<FOR>$RecForPat))/imx) {
print STDERR "\n\$testheader matched\n";
msg("\nDumper(\%+):\n");
msg(Dumper(%+),"\n");
msg("\nDumper(\%-):\n");
msg(Dumper(%-),"\n");
foreach (sort keys %+) {
print STDERR "\$+{$_}=$+{$_}\n";
}
print STDERR "\n";
} else {
print STDERR "\n\$testheader did not match\n";
}
sub msg {
print STDERR @_;
}
1;
__END__