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

Top Page
Delete this message
Reply to this message
Author: Heiko Schlittermann
Date:  
To: exim-users
Subject: Re: [exim] Remove header lines matching a specific pattern?
Hello Phil,

Phil Pennock <exim-users@???> (Mo 13 Jul 2009 15:51:45 CEST):
> 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.


Thank you for your response. I missed the fact, that $message_headers*
just contains the RFC2822 header part of the message, _unaltered_.

> 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}{}}


Now I implented it like this:

    MESSAGE_HEADERS = \
              # replace "\n" with the default list separator ":" and
              # and lowercase everything
              ${lc:${sg\
               # fix continuation lines and extract the header names
               # replace every "\n" followed by a number of whitespaces
               # with a single whitespace
               {${map\
                 { <\n ${sg {$message_headers_raw}{\N\n\s+\N}{ }} }\
                 {${extract{1}{:}{$item}}}\
                 }\
               }\
               {\N\n\N}\
               {:}\
               }}


Later in the ACL (I did it in the ACL because we have several
processing policies and it seems more straight forward to me to do it
there.)

    acl_check_data:


          warn    set acl_m_headers_remove \
                       = ${filter {MESSAGE_HEADERS}{match{$item}{\N^x-(?:ius|hh)\N}}}
          log_message  = DEBUG-X: $acl_m_headers_remove


          ...


And all transports look similar to this one:

    lmtp:
        driver = smtp
        ...
        headers_remove = $acl_m_headers_remove



(Would be great to have the counterpart of add_header in the ACL ...)

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

                                              ~~
                                              Thank you for
this. Didn't know it. But now I found the reference in perlre(1).



Thanks and
    best regards from Dresden/Germany
    Heiko Schlittermann
-- 
 SCHLITTERMANN.de ---------------------------- internet & unix support -
 Heiko Schlittermann HS12-RIPE -----------------------------------------
 gnupg encrypted messages are welcome - key ID: 48D0359B ---------------
 gnupg fingerprint: 3061 CFBF 2D88 F034 E8D2  7E92 EE4E AC98 48D0 359B -