Replace subject based in email

Discussion in 'Installation/Configuration' started by Peter Oudenes, Jan 18, 2022.

  1. Peter Oudenes

    Peter Oudenes New Member

    Hi There,

    I want create a filter that will check incoming email and replace the subject. I found on net this filter:

    if /^To: [email protected]\.com/
    /^Subject: (.+)$/ REPLACE Subject: [TEST] $1
    endif

    But when I add this in ISPcondig Content filter nothing happen. (I replaced [email protected]\.com with my own email)

    Source code of the email is little different

    To: Firstname Lastname <[email protected]> so tried to change it to:

    if /^To: Firstname Lastename [email protected]\.com/
    /^Subject: (.+)$/ REPLACE Subject: [TEST] $1
    endif

    Didn't work also.

    Can someone help me to crate the right filter to add in ISPcondig?

    Cheers,
    Peter
     
  2. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    I've never tried this before, but in a quick look I don't see any way to enter the if/endif conditional in the ui, how is it you are accomplishing that? I would expect this has to be done manually, directly in postfix config, and not via the ISPConfig ui, but maybe I'm missing something.
     
  3. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

  4. till

    till Super Moderator Staff Member ISPConfig Developer

  5. Peter Oudenes

    Peter Oudenes New Member

    This is for now what I have found. Its do a check but always give the first IF and not the second one.

    Code:
    [email protected]:/home/poudenes# cat test.eml
    From: Nobody <[email protected]>
    Mime-Version: 1.0
    To: <[email protected]>
    Subject: TESSUBJECT
    
    This is a test message
    
    header_checks files have this
    Code:
    if !/^To: [email protected]/i
    /^Subject: (.+)$/i REPLACE Subject: (test1) [$1]
    endif
    if !/^To: [email protected]/i
    /^Subject: (.+)$/i REPLACE Subject: (test2) [$1]
    endif 
    Code:
    [email protected]:/home/poudenes# postmap -vhmq - regexp:/etc/postfix/header_checks < test.eml
    
    postmap: name_mask: all
    postmap: inet_addr_local: configured 2 IPv4 addresses
    postmap: inet_addr_local: configured 2 IPv6 addresses
    postmap: dict_open: regexp:/etc/postfix/header_checks
    postmap: dict_regexp_lookup: /etc/postfix/header_checks: From: Nobody <[email protected]>
    postmap: dict_regexp_lookup: /etc/postfix/header_checks: Mime-Version: 1.0
    postmap: dict_regexp_lookup: /etc/postfix/header_checks: To: <[email protected]>
    postmap: dict_regexp_lookup: /etc/postfix/header_checks: Subject:
    Subject: TESSUBJECT     REPLACE Subject: (test1) [TESSUBJECT]
    
     
  6. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    That sounds correct. As the thread I linked to above explains, header checks work on one header at a time; for any message that comes through, the Subject header will not match your regex that starts with "To:", so the transformation on the subject line will be performed. What you are trying to do can't work.
    @till posted above one possible solution, ie. perform the rewriting in sieve.
     
  7. Peter Oudenes

    Peter Oudenes New Member

    thanks for the info. Changing subject in sieve is not working. I have some email addresses that are aliases and goes to a other.
    All mails that comes in for the alias I want change the subject. So I can see in the mailbox in subject what used receiving email address was used.

    That was the whole idea. But I think im stuck and have to accept that it won't work what I want
     

Share This Page