[exim] Re: Show regex capture group in logs?

Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Jasen Betts
Fecha:  
A: exim-users
Asunto: [exim] Re: Show regex capture group in logs?
On 2023-05-16, MRob via Exim-users <exim-users@???> wrote:
> Hi, I want to capture part of a regex match (capture group) to put in 
> logs. This example using subject header works but is there a better way?
>
> warn set acl_c_temp = ${if match{$h_Subject:}{<regex with capture 
> group>}{$1}{none}}
>       !condition = ${if eq{$acl_c_temp}{none}}
>       logwrite = Notice: subject match is: $acl_c_temp
>
> This also risky because must be careful to make sure "none" could never 
> come from the regex match group


probably better is

      warn 
          set acl_m0 = ${if match{$h_Subject:}{<regex with capture group>}{1$1}{0}}
      # if it matched acl_m0 starts with "1" else with "0"

          condition = ${length_1:$acl_m0}
      # condition understands "1" and "0" so no need for "${if..."

          logwrite = Notice: subject match is: ${substr_1:$acl_m0}
          # need to chop off the first charcter for printing.

 

> PS: is there better local variable to use?


I usually use an acl_m variable in message context, and if it's of
temporary use I use a numbered variable, but that's just a convention
I have adopted.


--
Jasen.
🇺🇦 Слава Україні

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@???
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/