john mickler wrote:
On Sun, Nov 30, 2008 at 12:18 AM, Victor Duchovni
<[EMAIL PROTECTED]> wrote:
It should work if the newline is part of a ${n} sub-pattern match:

   # ${3} matches Newline + folding white-space
   /^(Received): (.*?)(\n[\t\x20])(.*)$/
           ${1}: ${2}${3}(my comment)${3}${4}

With test.pcre containing the above, "postmap -q" yields:

   $ postmap -q "$(printf "Received: %s\n\t%s\n" abc def)" pcre:test.pcre
   Received: abc
           (my comment)
           def

showing the insertion of an additional line into the header. What is not
possible is the insertion of a literal newline in the Postfix replacement
text in indexed file, regexp table or policy service lookups.

The pcre example above indeed passes the newline through as mentioned.
 Here's an adjusted expression to fit my situation, as well as an
example header after the replacement:

main.cf:
header_checks = /usr/local/etc/postfix/maps/header_checks.pcre

header_checks.pcre:
/^(Received): (.*?)(\n[\t\x20])(.*)$/ REPLACE ${1}: from smtp-auth
(smtp-auth.mycompany.com [55.55.55.55]${3}${4}


resulting replaced header-

Received: from smtp-auth (smtp-auth.mycompany.com [55.55.55.55]
        (using TLSv1 with cipher AES128-SHA (128/128 bits))
        (No client certificate requested)
        (Authenticated sender: [EMAIL PROTECTED])
        by smtp.mycompany.com (Postfix) with ESMTPSA id EA8E9B879
        for <[EMAIL PROTECTED]>; Sun, 30 Nov 2008 11:58:51
-0500 (EST)



The beauty is that all other header information besides the actual
remote host is kept intact - in my eyes making this a perfect solution
for my situation.

Thanks Victor, and thanks to everyone else for their input.

Following one from John's success, I'm failing. One difference between John's setup and mine is my header_checks directive. It was defined in master.cf:

 -o header_checks=pcre:/usr/local/etc/postfix/obscure_smtp_auth

I know I'm putting this directive into the direct Postfix daemon becuase the remove of the following directive, from within the same declaration, affects the email headers:

 -o smtpd_sasl_authenticated_header=yes


I had to move this header_checks directive into main.cf to get the REPLACE working.

The expression I'm using does the following:
- replaces the authenticated user
- replaces the host/ip address of the origin host
- retains the original spacing/newlines

/^Received: from (.* \([-._[:alnum:]]+ \[[.[:digit:]]{7,15}\]\))(.*)\(Authenticated sender: ([^)]+)\)(.*)(by nyi\.unixathome\.org) \(([^)]+)\) with (E?SMTPS?A?) id ([A-F[:digit:]]+)(.*)/ REPLACE Received: from smtp-auth.unixathome.org (smtp-auth.unixathome.org [10.4.7.7])$2(Authenticated sender: hidden)$4$5 ($6) with $7 id $8 $9

Thanks.

Reply via email to