procmail
[Top] [All Lists]

Re: filtering headers

1997-11-05 18:37:05
W. Wesley Groleau x4923 wrote:   ...
So what's wrong with my latest try (below)?
...
# discard our internal routing
:0 fhw
|perl  -ne 'if(/^\s/) {'                   \
        -e '    $h .= $_;'                 \
        -e '} else {'                      \
        -e '    if($h =~ /^Received:/) {'  \
        -e '        print $h unless $saw;' \
        -e '        $saw=1 if $h =~ /gw1.hughes-defense-comm.com/;' \
        -e '    } else {'                  \
        -e '        print $h;'             \
        -e '    }'                         \
        -e '    $h = $_;'                  \
        -e '  }'                           \
        -e '}'

If it isn't obvious, here's that resulting log:
...

I only looked at the perl part since I don't know anything about
procmail. :)  The perl compiler's error messages say the problem is:
Unmatched right bracket at -e line 12, at end of line
which causes a
syntax error at -e line 12, near ";}"
and this results in
Execution of -e aborted due to compilation errors.

In other words, your final } is extra.  You can debug more easily if you
put the perl into a file of its own.  Suppose you put:

#!/usr/bin/perl  -n
if(/^\s/) {
    $h .= $_;    print ' matched ^\s';
} else {
    if($h =~ /^Received:/) {
        print $h unless $saw;
        $saw=1 if $h =~ /gw1.hughes-defense-comm.com/;
    } else {
        print $h;
    }
    $h = $_;
  }

into "hughes.pl",  with your own path to perl substituted, and you make
hughes.pl executable.  Then use " | hughes.pl " instead of the inline
perl code in your .procmailrc.  To test if your perl code is working,
make a file "t-hu" with some "Received: ...gw1.hughes-defense-comm.com"
lines in it, and say  "./hughes.pl < t-hu" and see if it filters as you
desire.  For example, with t-hu containing the 5 lines:

1  Received: gw1.hughes-defense-comm.com
 line 2 has a space to match ^\s
Received: etc etc gw1.hughes-defense-comm.com etc etc 3
Received: gw1.hughes-defense-comm.com 4
5Received: gw1.hughes-defense-comm.com

the result I get from ./hughes.pl < t-hu is the three lines:

1  Received: gw1.hughes-defense-comm.com
 line 2 has a space to match ^\s
Received: etc etc gw1.hughes-defense-comm.com etc etc 3

which I assume might or might not be what you wanted it to do.

<Prev in Thread] Current Thread [Next in Thread>