Re: [exim] Remove header lines matching a specific pattern?

Góra strony
Delete this message
Reply to this message
Autor: Phil Pennock
Data:  
Dla: exim-users
Temat: Re: [exim] Remove header lines matching a specific pattern?
On 2009-07-13 at 15:03 +0200, Heiko Schlittermann wrote:
> Heiko Schlittermann <hs@???> (Mo 13 Jul 2009 14:00:26 CEST):
> > Hello,
> >
> > I'd like to use something like:
> >
> >     transport:
> >         driver = ....
> >         headers_remove = NX-Spam.*

> >
>
> Hm. Something like
>
>     transport:
>         ...
>         headers_remove = <\n ${filter \
>                 {<\n ${map{<\n$message_headers_raw} {${extract{1}{:}{$item}}}}} \
>                 {match{$item}{(?i:^X-)}}}


The ${map{<\n$message_headers_raw} {${extract{1}{:}{$item}}}} takes no
account of continuation lines.

This is somewhat more accurate:
${map{<\n${filter{<\n$message_headers_raw}{match{$item}{^(?i:[a-z_-]+\s*:)}}}} {${extract{1}{:}{$item}}}}
but still prone to false-positives; the problem is more visible if you
do:
${map{<\n$message_headers_raw} {[$item]}}
and see that the leading tabs on the follow-on lines have been lost as
part of whitespace folding.

This shouldn't have false positives but leaves you with some extra
whitespace in the form of blank lines:
${sg{$message_headers_raw}{\N(?m)(?:^\s|\s*:).*$\N}{}}

So this gets you all the actual headers:
${filter{<\n${sg{$message_headers_raw}{\N(?m)(?:^\s|\s*:).*$\N}{}}}{!eq{$item}{}}}

Or this for just the X-* headers:
${filter{<\n${sg{$message_headers_raw}{\N(?m)(?:^\s|\s*:).*$\N}{}}}{match{$item}{\N^(?i)X-\N}}}

Regards,
-Phil