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

Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Karl Fischer
Fecha:  
A: exim-users, hs
Asunto: Re: [exim] Remove header lines matching a specific pattern?
Heiko Schlittermann schrieb:
> 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}\
>                {:}\
>                }}



Heiko,

I followed this thread with interest and I'm still a little puzzled with the
specific exim syntax, but in terms of regex and just extracting the header
names, this perl regex should be more efficient: s/:.*?\n(\s+.*?\n)*/:/g

This saves looping through map/extract by getting rid of the unwanted 1st.

In exim syntax I'd assume this to be (not tested yet):

MESSAGE_HEADERS = ${lc:${sg {$message_headers_raw}{\N:.*?\n(\s+.*?\n)*\N}{:}}}

my .02.

- Karl