OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
Re: Rewrite with Pattern

From: Noel Jones (njonesmegan.vbhcs.org)
Date: Tue Dec 02 2008 - 21:23:14 CST


Fat Bear Mail Services wrote:
> Hi Noel,
> The issue here is that these e-mail addresses are in use for QE purposes
> such as testing new account signups for a given service. What happens
> is that during a "signup test", some 10,000 e-mails will be sent out to
> addresses matching the pattern such as:
>
> pat-acme-*mycompany.com
>
> with the desired result that these are delivered to:
>
> patacmedesign.com
>
> (Of course the names acme, mycompany, and acmedesign.com are actually
> different)

are the "pat", "acme", "mycompany.com", and "acmedesign.com"
parts static, or do they vary? All discussions below assume
they are static.

>
> It would be unreasonable to have a 1:1 mapping of names in the virtual
> file because there are (1) so many of them;

Size is largely irrelevant. Hash tables scale very well to
hundreds of thousands entries, cdb to millions.

> and, (2) because the
> automated scripts that are sending out the e-mails might be testing
> different numbers of recipients with different characters being allowed
> in the "*" part above.

You're willing to throw away the "*" part above in your
regexp, why can't you throw it away in a pre-process awk?

> I'll emphasize that this need is not about
> sending spam or bulk e-mail. It is all about the need to do load and
> performance testing.
>
> So, under this specific need, I'm wondering what the right approach
> would be to do the remapping... and wanting it to be as much "production
> quality" as possible. The solution I wrote:
>
> /^pat-acme(-[^]+)mycompany.com/ patacmedesign.com
>
> in the regexp:/etc/postfix/virtual.regexp

/^pat-acme-[^]+mycompany\.com$/ patacmedesign.com
is a better expression; does it really do what you want?

BTW, use pcre rather than regexp if your postfix supports it
(postconf -m to check). Pcre is faster, dramatically so on
some platforms.

>
> does work, but is it as good as it can be under the circumstances?
> E.g., will it fail to match recipients under conditions such as an
> address formatted as:
>
> "Any Old Text Here" <pat-acme-abcdef1234mycompany.com>

virtual_alias_maps processes the envelope address, so there
won't ever be comments such as you see in a To: header.

If you need to fix the To: (or From:) header also, use
header_checks with IGNORE to remove it. It's possible to use
REWRITE to transform it, but that gets pretty tricky.

--
Noel Jones