edit/modify ESMTPSA LMTP ESMTP

Discussion in 'Server Operation' started by ptroms, Jun 9, 2021.

  1. ptroms

    ptroms Member

    How to edit postfix conf in order to have more officiant details in message view source. Basically remove all the scanner amavisd and localhost details and having only public IP and mail domain name to keep it simple and nifty.
     
    Last edited: Jun 9, 2021
  2. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Is that like writing a new postfix that logs less info?
    You could write a filter script to remove the lines you do not want from the log and use the result.
     
  3. ptroms

    ptroms Member

    Well
    My point is having a nice email headers before the mail could be send away.
    So far I have managed ESMTPSA by editing /etc/postfix/header_check by adding:
    Code:
    /^Received:(.*?)with ESMTPSA(.*?)/ REPLACE Received: from domain.com (domain.com [1.1.1.1]) by mail.domain.com (Postfix) with ESMTPSA$2
    it seems like adding two lines to to /etc/amavis/conf.d/50-user
    Code:
    $smtpd_greeting_banner = 'mail.domain.com ESMTP';
    $localhost_name = 'main.domain.com';
    Helped LMTP and ESMTP but getting hands on ([127.0.0.1]) require a bit more digging in the documentation.
     
  4. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    Do you mean in your email program? Changing how the message info is pretended would best be done in the mail client, not by removing nearly all the info so your client can't show it to you. There are times that info is quite useful to have.
     
    Last edited: Jun 10, 2021
  5. Steini86

    Steini86 Active Member

    I clean my outgoing mails a bit (for example, hiding the senders IP address and mailing program). With a little manual reading, you should be able to adjust this to your needs: http://www.postfix.org/header_checks.5.html
    In /etc/postfix/main.cf:
    Code:
    smtp_header_checks = pcre:/etc/postfix/header_cleanup_outgoing
    In /etc/postfix/header_cleanup_outgoing
    Code:
    /^\s*(Received: from)[^\n]*(.*)/ REPLACE $1 127.0.0.1 (localhost [127.0.0.1])$2
    /^(Received: from)(.*\(.*\))(\s*)((\(.*\)\s*){3})(by.* with ESMTPSA id.*\s*.*)/ REPLACE $1 localhost (localhost [127.0.0.1]) $3$4$6
    /^\s*User-Agent/ IGNORE
    /^\s*X-Enigmail/ IGNORE
    /^\s*X-Mailer/ IGNORE
    /^\s*X-Originating-IP/ IGNORE
    /^\s*Mime-Version/ IGNORE

    [edit]
    Get a mail header you want to change and use https://regex101.com/ to create your regex until you get the desired result. Then test with postfix.
     
    ptroms likes this.
  6. ptroms

    ptroms Member

    Works as a charm.
    Thank you
     
    Steini86 likes this.
  7. ptroms

    ptroms Member

    A small question regarding editing only a small fraction of it. I get that regex does the line match but how to replace a fraction of it. As far as I'm guessing here trick is in perl syntax that corresponding with the right section such as $1,$2. Where can I find does structure and put my hand on it?
     
  8. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    The $1, $2, etc. are called back references, and refer to what the regex matched inside sets of parenthesis. So eg. if you had:
    Code:
    /^\s*(Test): (.*)/ REPLACE $1-Reply: I got your $2
    A header of "Test: hello world" should be changed to "Test-Reply: I got your hello world". The $1 refers to the content matched in the first parenthesis, and $2 refers to the second match.
     
  9. ptroms

    ptroms Member

    So another example:
    header "Test: hello world Test1: not such hello" it would be:
    Code:
    /^\s*(Test): (.*)/^\s*(Test1): (.*)/ REPLACE $1-Reply: I got your $2-Reply:I got your1 $3
    Is my conclusion right?
     
  10. Steini86

    Steini86 Active Member

    1. Go to https://regex101.com/
    2. On the left side choose "substitution"
    3. Everything between the first / and / goes to "REGULAR EXPRESSION" on the top
    4. Everything after REPLACE goes to SUBSTITUTION
    5. Your Header to change goes to "TEST STRING"
    Looks like in the screen shot below. Easy to do with good explanations. Play and have fun. (Was it really so hard?)
    Screenshot_2021-06-11_21-05-41.png
     
    ptroms likes this.
  11. ptroms

    ptroms Member

    I am guessing not the last one question. Where is the dkim-signature structure saved. I have one position to add (BIMI) before signing. And the I will post full guide how to add BIMI to ispconfig.
     
    Last edited: Jun 16, 2021
  12. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    I'm not positive I understand the question, but outgoing mail is signed by amavisd (or rspamd if you're using that).
     
  13. ptroms

    ptroms Member

    What I mean is that. Amavisd creates the dkim verification. What I want to do is add into h= one selector. So the mail will change (current version):
    Code:
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=domain.com; h=content-type:content-type:mime-version:user-agent:date:date:message-id:subject:subject:from:from;....
    to:
    Code:
    DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=domain.com; h=BIMI-Selector:content-type:content-type:mime-version:user-agent:date:date:message-id:subject:subject:from:from;....

    of course it doesn't have to be in this particular order.
    Another words how to add let say another component passing by requires by BIMI:
    https://tools.ietf.org/id/draft-blank-ietf-bimi-00.html#bimi-selector
    I think I have got it. Some additional software needs to be install
     
    Last edited: Jun 16, 2021
  14. Jesse Norell

    Jesse Norell ISPConfig Developer Staff Member ISPConfig Developer

    In a quick look at amavisd-new settings, I see this in /etc/amavis/conf.d/50-user:
    Code:
    $signed_header_fields{'received'} = 0;  # turn off signing of Received
    
    I'd guess that setting $signed_header_fields{'bimi-selector'} = 1; would cause amavis to additionally sign that header.
     

Share This Page