ChrisP,
I re-ran my tests using your examples and it sort of works. The problem is that the rule appears to modify other parts of the header. Specifically, it appears to strip the white space character (in this case a horizontal tab) from the header. This results in the email client not being able to fully interpret the To header.
Example: "To:" header NOT changed by replace.
To: "someone@domain1.tld" <someone@domain1.tld>, "support@n2net.net"
<support@n2net.net>, "someone@domain2.tld" <someone@domain2.tld>
Example: "To:" header changed by replace.
To: "someone@domain1.tld" <someone@domain1.tld>, "support@n2net.net"
<support@n2net.net>, "someone@domain2.tld" <someone@domain2.tld>
Is there any way to prevent replace from mangling long header lines?
Thank you,
Jim L
-----Original Message-----
From: Surgemail Support <surgemail-support@netwinsite.com>
Sent: Thursday, January 17, 2019 3:58 PM
To: surgemail-list@netwin.co.nz
Subject: Re: [SurgeMail List] mfilter replace email address
Use this:
if (isin("to","support@n2net.com")) then call replace("to","*support@n2net.com*","%1support@n2net.net%2")
call replace("to","*support@n2net.com*","%1support@n2net.net%2")
end if
In brief:
1) replace needs 'call' in front of it.
2) don't use recipients, that is a loop for each envelope recipient, whereas you want to do this for the header which is not related to the recipients.
3) do it twice, so that it picks up two instances in the single header.
ChrisP.
On 18/01/2019 3:59 AM, Jim Lohiser wrote:
> SurgeMail List,
>
> We have a need to rewrite an email address in message headers. I am attempting to write an mfilter rule to make this happen. I have created the following rules.
>
> recipients
> if (isin("recipient","support@n2net.com")) then
> replace("to","support@n2net.com","support@n2net.net")
> end if
> end recipients
>
> This works. It replaces both the email address and the "name" portion in the To address (see below).
>
> To: "support@n2net.net" <support@n2net.net>
>
> HOWEVER, if the message has multiple recipients, then the rule does not work.
>
> To: "johndoe@domain1.tld" <johndoe@domain1.tld>, "support@n2net.com"
> <support@n2net.com>, "janedoe@domain2.tld" <janedoe@domain2.tld>
>
> I know the isin() test is working because I added a "call report()" to the rule block and it sends me a report email. I have tried adding wildcards to the rule (see below), but this also does not work.
>
> replace("to","*support@n2net.com*","%1support@n2net.net%2")
>
> Is there any way to replace all instances of an email address in a header?
>
> Thanks in advance,
>
> Jim Lohiser
> N2Net
>
|