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: Fat Bear Mail Services (postfixfatbear.com)
Date: Tue Dec 02 2008 - 18:02:40 CST


Hi Noel,
> Fat Bear Mail Services wrote:
>> Noel Jones wrote:
>>> Fat Bear Mail Services wrote:
>>>> How would one setup Postfix that uses /etc/passwd for
>>>> authentication so that e-mails of the pattern:
>>>>
>>>> username-companyID-anyStringdomain1.com
>>>>
>>>> is delivered to:
>>>>
>>>> usernamecompanyDomain.com
>>>>
>>>> where there is a 1:1 mapping between companyID and companyDomain?
>>>> For example:
>>>>
>>>> pat-acme-beta123mycompany.com >>> patacmedesign.com
>>>>
>>>> Note above that "acme" maps to "acmedesign.com".
>>>
>>> One would use an awk or perl script to generate a virtual_alias_map
>>> from the input file.
>> The virtual_alias_map could not be hash:/etc/postfix/virtual because
>> that could not handle e-mail addresses where "anyString" is
>> discarded, right? I would think that we'd need to have
>> regexp:/etc/postfix/virtual that can handle transformations such as:
>
> I'm glad to see you've done some homework before asking.
> The point I'm making is that while you *can* use a regexp for
> virtual_alias_maps, you shouldn't.
>
> Whatever matches in virtual_alias_maps is considered a valid address,
> so a regexp map is (usually) not appropriate. It's important for
> postfix to know valid addresses so that invalid ones can be rejected
> during SMTP - before they are accepted and cause backscatter bounces.
>
> So, as I said earlier, use awk or perl to generate a hash table with
> the proper 1-1 transformations in it, using the your password file as
> the data source. You can automate this with a Makefile and cron so
> that a new table is periodically rebuilt automatically, but only when
> there are changes.
>
> If you think a regexp map is appropriate, explain why.
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)

It would be unreasonable to have a 1:1 mapping of names in the virtual
file because there are (1) so many of them; 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. 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

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>

or is there a more efficient way to do it?

I really appreciate your rapid responses!!

Thanks,
Steve Amerige
Fat Bear