Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rewrite To field using regex

28 views
Skip to first unread message

Stephen Braswell

unread,
May 1, 2006, 6:40:48 PM5/1/06
to
Hello,

I have an old mailing service that processes alphanumeric pager
email addresses that I'm trying to move to a sort of alias-based
service on another server. The problem I have is the old service
allows users to send mail to a sort of wildcard email address which
in turn has some software that deals with the translating of the
email address. I need to be able to maintain this backwards
compatibility but am having a difficult time coming up with a
solution.

I had originally planned to write a perl script and pipe some
aliases to that but I think it might be simpler to try and solve
this with some regex local rules in sendmail, if possible. I've
looked at Andrzej Filip's examples in previous posts and the basic
examples in the 'Sendmail Cookbook' but I haven't been able to come
up with the right regular expression(s) and rules to make this
work.

Can someone please help get me going in the right direction? Is
there an easier solution that I've overlooked?

Here is an explanation of the email address madness I'm dealing
with.

1. Someone sends an email to 123456...@host1.edu
2. I need to rewrite it to 91912...@host2.com
3. Forward the email to the rewritten email address

Thanks for any assistance you can provide.


Regards,

-Stephen

Andrzej Adam Filip

unread,
May 2, 2006, 5:42:01 AM5/2/06
to
Stephen Braswell <sbra...@email.unc.edu> writes:
> I have an old mailing service that processes alphanumeric pager
> email addresses that I'm trying to move to a sort of alias-based
> service on another server. The problem I have is the old service
> allows users to send mail to a sort of wildcard email address which
> in turn has some software that deals with the translating of the
> email address. I need to be able to maintain this backwards
> compatibility but am having a difficult time coming up with a
> solution.
>
> I had originally planned to write a perl script and pipe some
> aliases to that but I think it might be simpler to try and solve
> this with some regex local rules in sendmail, if possible.

IF you want to investigate "perl option" further THEN take a look at
* socket map protocol, sample scripts are provided in contrib directory
of sendmail distribution [will require also a few custom *.mc lines]
*OR*
* MIMEDefang (perl based) milter, it can rewrite envelope recipients

It may be an overkill in your case unless you want to introduce much
more sophisticated checks than you seem to suggest later
(e.g. checks against full list of valid pager numbers).

> I've looked at Andrzej Filip's examples in previous posts and the
> basic examples in the 'Sendmail Cookbook' but I haven't been able to
> come up with the right regular expression(s) and rules to make this
> work.
>
> Can someone please help get me going in the right direction? Is
> there an easier solution that I've overlooked?
>
> Here is an explanation of the email address madness I'm dealing
> with.
>
> 1. Someone sends an email to 123456...@host1.edu
> 2. I need to rewrite it to 91912...@host2.com
> 3. Forward the email to the rewritten email address
>
> Thanks for any assistance you can provide.

*I HAVE NOT TESTED IT PROPERLY. USE AT YOUR OWN RISK*

Take a look at the sample below

LOCAL_CONFIG
Kd7 regex ^[0-9]{7}$$
LOCAL_RULE_0
# Canonify (in case of DNS resolution problems)
R$+ <@host1.edu> $: $1 <@host1.edu.>
# do the regex lookup
R$-.pager <@host1.edu.> $: <$(d7 $1 $: NOMATCH $)> $1.pager <@host1.edu.>
# rewrite as it was in case of no match
R<$+> $-.pager <@host1.edu.> $: $2.pager<@host1.edu.>
# rewrite matching addresses
R<> $-.pager <@host1.edu.> $: $(dequote 919 "" $1 $) <@host2.com.>

For testing use the commands below (simple check, detailed check):
echo '3,0 123456...@host1.edu' | sendmail -bt
echo '3,0 123456...@host1.edu' | sendmail -bt -d21.12 -d60.1


--
[pl>en: Andrew] Andrzej Adam Filip : an...@priv.onet.pl : an...@xl.wp.pl
http://anfi.homeunix.net/sendmail/ http://www.linkedin.com/in/andfil
Before You Ask: http://anfi.homeunix.net/sendmail/B4UAsk-Sendmail.html

Stephen Braswell

unread,
May 3, 2006, 12:31:55 PM5/3/06
to
Andrzej Adam Filip wrote:

> IF you want to investigate "perl option" further THEN take a look at
> * socket map protocol, sample scripts are provided in contrib directory
> of sendmail distribution [will require also a few custom *.mc lines]
> *OR*
> * MIMEDefang (perl based) milter, it can rewrite envelope recipients

I'm actually already using MIMEDefang for something else on this server
but I didn't want to have to deal with the extra overhead, since MIMEDefang
is already doing other processing, if I didn't have to. Thanks for the
tip about using it, though. It gives me some ideas for some other things
I need to get done.

> Take a look at the sample below
>
> LOCAL_CONFIG
> Kd7 regex ^[0-9]{7}$$
> LOCAL_RULE_0
> # Canonify (in case of DNS resolution problems)
> R$+ <@host1.edu> $: $1 <@host1.edu.>
> # do the regex lookup
> R$-.pager <@host1.edu.> $: <$(d7 $1 $: NOMATCH $)> $1.pager <@host1.edu.>
> # rewrite as it was in case of no match
> R<$+> $-.pager <@host1.edu.> $: $2.pager<@host1.edu.>
> # rewrite matching addresses
> R<> $-.pager <@host1.edu.> $: $(dequote 919 "" $1 $) <@host2.com.>

Awesome! This works perfectly! Thanks so much for rule.


Regards,

-Stephen

Taylor, Grant

unread,
May 3, 2006, 1:00:32 PM5/3/06
to
I in no way shape or form claim to understand sendmail rule sets. However that being said I am curious how they work. I know that I could crack open my ""Bat book, and some day will. In the interest of time and brief interest of the matter at hand I'm curious if any one has a quick 30 second explanation of how the various parts of the rule set(s) work. If no one can give an answer in 30 seconds (including hitting send) then just tell me to look in the ""Bat book and I will do so at a later point in time. Thus far I have been able to do everything I needed to with Sendmail via the MC file and compilation of the various binary from source, I have not had to delve in to custom rule sets yet.

> LOCAL_CONFIG
> Kd7 regex ^[0-9]{7}$$
> LOCAL_RULE_0
> # Canonify (in case of DNS resolution problems)
> R$+ <@host1.edu> $: $1 <@host1.edu.>
> # do the regex lookup
> R$-.pager <@host1.edu.> $: <$(d7 $1 $: NOMATCH $)> $1.pager <@host1.edu.>
> # rewrite as it was in case of no match
> R<$+> $-.pager <@host1.edu.> $: $2.pager<@host1.edu.>
> # rewrite matching addresses
> R<> $-.pager <@host1.edu.> $: $(dequote 919 "" $1 $) <@host2.com.>


Thanks for putting up with my lazy question.

Grant. . . .

Andrzej Adam Filip

unread,
May 3, 2006, 1:03:47 PM5/3/06
to
Stephen Braswell <sbra...@email.unc.edu> writes:

> Andrzej Adam Filip wrote:
>
>> IF you want to investigate "perl option" further THEN take a look at
>> * socket map protocol, sample scripts are provided in contrib directory
>> of sendmail distribution [will require also a few custom *.mc lines]
>> *OR*
>> * MIMEDefang (perl based) milter, it can rewrite envelope recipients
>
> I'm actually already using MIMEDefang for something else on this server
> but I didn't want to have to deal with the extra overhead, since MIMEDefang
> is already doing other processing, if I didn't have to. Thanks for the
> tip about using it, though. It gives me some ideas for some other things
> I need to get done.

IMHO the extra would be negligible.

>> Take a look at the sample below
>>
>> LOCAL_CONFIG
>> Kd7 regex ^[0-9]{7}$$
>> LOCAL_RULE_0
>> # Canonify (in case of DNS resolution problems)
>> R$+ <@host1.edu> $: $1 <@host1.edu.>
>> # do the regex lookup
>> R$-.pager <@host1.edu.> $: <$(d7 $1 $: NOMATCH $)> $1.pager <@host1.edu.>
>> # rewrite as it was in case of no match
>> R<$+> $-.pager <@host1.edu.> $: $2.pager<@host1.edu.>
>> # rewrite matching addresses
>> R<> $-.pager <@host1.edu.> $: $(dequote 919 "" $1 $) <@host2.com.>
>
> Awesome! This works perfectly! Thanks so much for rule.

As I wrote *TEST IT* :-)

P.S.
Do you know how to make trn support non ascii charsets?
I know somebody needing it. Reply off the newsgroup

0 new messages