Replace semicolon in recipient list

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Replace semicolon in recipient list

lucas2

Hello Group,

I have configured Postfix as a relay to forward all messages to the AWS SES mail service.

One sending application is sending mail with a From: header containing a semicolon-separated list of addresses. This is not according to the standard (https://tools.ietf.org/html/rfc2822#section-3.6.3) and is rejected by SES:
status=bounced (host email-smtp.eu-west-1.amazonaws.com[52.215.26.159] said: 554 Transaction failed: Illegal semicolon, not in group (in reply to end of DATA command))

Unfortunately I have little influence on the sending application and it is not easy to correct this erratic behavior.

To solve this I was looking for a REPLACE in the header_checks but I did not find a way to replace the original header with a modified version of itself (i.e., the original string with all semicolons replaced by commas).

Is there a solution to replace semicolons with commas in the To: header of incoming mail?
Is it possible to avoid using a milter for this purpose?

Kind regards,
Lucas

Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

Wesley Peng-6
Hi

on 2019/10/23 16:27, [hidden email] wrote:
> One sending application is sending mail with a From: header containing a
> semicolon-separated list of addresses. This is not according to the
> standard (https://tools.ietf.org/html/rfc2822#section-3.6.3) and is
> rejected by SES:

I was just curious, why the From addr is a list of addresses?
Isn't from just a single address?

regards.
Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

lucas2
> I was just curious, why the From addr is a list of addresses?
> Isn't from just a single address?

My bad - I meant to say the "To:" header!

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

Wesley Peng-6


on 2019/10/23 16:40, [hidden email] wrote:
>> I was just curious, why the From addr is a list of addresses?
>> Isn't from just a single address?
>
> My bad - I meant to say the "To:" header!

So, you could rewrite the "To:" list into "," separated.

regards.
Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

lucas2
> So, you could rewrite the "To:" list into "," separated.

That sounds like what I am looking for, thanks!
How do I do that? I did not get it to work with a REPLACE in the
header_checks...
Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

Wesley Peng-6


on 2019/10/23 16:48, [hidden email] wrote:
>> So, you could rewrite the "To:" list into "," separated.
>
> That sounds like what I am looking for, thanks!
> How do I do that? I did not get it to work with a REPLACE in the
> header_checks...

I saw postfix has a address rewrite guide you may want to check with.
http://www.postfix.org/ADDRESS_REWRITING_README.html

regards.
Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

Wietse Venema
In reply to this post by lucas2
[hidden email]:

> Hello Group,
>
> I have configured Postfix as a relay to forward all messages to the AWS
> SES mail service.
>
> One sending application is sending mail with a From: header containing a
> semicolon-separated list of addresses. This is not according to the
> standard (https://tools.ietf.org/html/rfc2822#section-3.6.3) and is
> rejected by SES:
> status=bounced (host email-smtp.eu-west-1.amazonaws.com[52.215.26.159]
> said: 554 Transaction failed: Illegal semicolon, not in group (in reply
> to end of DATA command))
>
> Unfortunately I have little influence on the sending application and it
> is not easy to correct this erratic behavior.
>
> To solve this I was looking for a REPLACE in the header_checks but I did
> not find a way to replace the original header with a modified version of
> itself (i.e., the original string with all semicolons replaced by
> commas).
>
> Is there a solution to replace semicolons with commas in the To: header
> of incoming mail?
> Is it possible to avoid using a milter for this purpose?

Why not extract the sender from the garbage, and output that instead?

/^From: garbage (sender) garbage/ REPLACE From: $1

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Replace semicolon in recipient list

Wietse Venema
In reply to this post by lucas2
[hidden email]:
> > So, you could rewrite the "To:" list into "," separated.
>
> That sounds like what I am looking for, thanks!
> How do I do that? I did not get it to work with a REPLACE in the
> header_checks...

header_checks are based on first-match-wins, so you would need
different regexps for different numbers of ' ;', with the longest
match first, for example:

- one pattern+result for To: headers with 10 ';'
- one pattern+result for To: headers with 9 ';'
..
- one pattern+result for To: headers with 1 ';'

Only one of these rules will match (Postfix header_checks
are not recursive, for safety reasons).

Another possibility is to use smtpd_proxy_filter with a little
smtpprox script that copies SMTP commands from Postfix to Postfix,
while munging some headers on the fly. But this requires careful
code to handle multiline headers correctly, something that header_checks
already does.

Good luck with parsing RFC5322 address syntax.

        Wietse