Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: exim: users

need to rewrite _ characters in MAIL FROM domain part

 

 

exim users RSS feed   Index | Next | Previous | View Threaded


dlugo at etherboy

Nov 22, 2011, 5:36 AM

Post #1 of 10 (761 views)
Permalink
need to rewrite _ characters in MAIL FROM domain part

Hi,

I seem to have some apps that are sending with a underscore in
the domain part. Searching the exim-user archives suggests that
I can work around this by rewriting the MAIL FROM address,
replacing the domain part _ chars with . chars.

Can anyone offer a rewrite rule that will do this? I'm going
to try to figure it out myself now, but for someone more versed
in rewriting rules, this may be trivial.

Thanks,

Dave

--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


dlugo at etherboy

Nov 22, 2011, 6:35 AM

Post #2 of 10 (747 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, 22 Nov 2011, Dave Lugo wrote:
>
> Hi,
>
> I seem to have some apps that are sending with a underscore in
> the domain part. Searching the exim-user archives suggests that
> I can work around this by rewriting the MAIL FROM address,
> replacing the domain part _ chars with . chars.
>
> Can anyone offer a rewrite rule that will do this? I'm going
> to try to figure it out myself now, but for someone more versed
> in rewriting rules, this may be trivial.
>
> Thanks,
>
> Dave
>

I decided to try to be simple - any MAIL FROM with a domain part
ending in example.com, that is preceeded by an element containing
an underscore, gets replaced with example.com.

eg:

user [at] asd ---> user [at] example

But trying to go with this:

\N^(.*)@*_*.example.com(.*)$\N $1 [at] example$4 SF

yields:

[root [at] ews-pgh1-exmp exim]# /usr/sbin/exim -C exim.conf.tst -brw
user [at] asd
2011-11-22 09:34:00 Rewrite of user [at] asd yielded
unparseable address: malformed address: _asd_asd [at] example may not
follow user [at] asd in address user [at] asd@example.com
Syntax error in user [at] asd
Malformed address: _asd_asd.example.com may not follow user [at] asd

adding Rq to the rewrite flags didn't help.

Suggestions gratefully appreciated...


--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


dlugo at etherboy

Nov 22, 2011, 7:10 AM

Post #3 of 10 (756 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, 22 Nov 2011, Dave Lugo wrote:
>
> eg:
>
> user [at] asd ---> user [at] example
>
> But trying to go with this:
>
> \N^(.*)@*_*.example.com(.*)$\N $1 [at] example$4 SF
>
> yields:
>
> [root [at] ews-pgh1-exmp exim]# /usr/sbin/exim -C exim.conf.tst -brw
> user [at] asd
> 2011-11-22 09:34:00 Rewrite of user [at] asd yielded
> unparseable address: malformed address: _asd_asd [at] example may not follow
> user [at] asd in address user [at] asd@example.com
> Syntax error in user [at] asd
> Malformed address: _asd_asd.example.com may not follow user [at] asd
>
> adding Rq to the rewrite flags didn't help.
>
> Suggestions gratefully appreciated...
>

closer...

\N^(.*)@.*_.*\.example.com(.*)$\N $1 [at] example$4 SF

works, but not very well - depending on whether or not the sender
correctly uses < > characters, it breaks.

Ideas? Should i break this out into multiple rewrite lines?

--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


tlyons at ivenue

Nov 22, 2011, 7:17 AM

Post #4 of 10 (746 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, Nov 22, 2011 at 6:35 AM, Dave Lugo <dlugo [at] etherboy> wrote:
>> I seem to have some apps that are sending with a underscore in
>> the domain part.  Searching the exim-user archives suggests that
>> I can work around this by rewriting the MAIL FROM address,
>> replacing the domain part _ chars with . chars.
> I decided to try to be simple - any MAIL FROM with a domain part
> ending in example.com, that is preceeded by an element containing
> an underscore, gets replaced with example.com.

That's not what your regex has below. Let's analyze it.

> user [at] asd  --->  user [at] example
> But trying to go with this:
> \N^(.*)@*_*.example.com(.*)$\N    $1 [at] example$4        SF

Wrapping the regex with \N is good. That means you don't have to do
do all kinds of ugly escaping.

What is messing you up is the @*_*. That literally means "zero or
more @ signs followed by zero or more _ signs". What you meant was
"@.*_.*\.example.com". You were thinking shell style or sendmail
style wildcard instead of regex.

Second, you said "with a domain part ending in example.com". But your
regex searches for "example.com(.*). That means that example.com
could match anywhere in the hostname.

Finally, drop the $4 from the rewrite part.

CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
\N^(.*)@.*_.*.example.com.*$\N $1 [at] example SF
CentOS56[root [at] ivwm5 ~]# exim -C /etc/exim/exim_TEST.conf -brw
user [at] asd
SMTP: user [at] example

Regards.... Todd
--
If Americans could eliminate sugary beverages, potatoes, white bread,
pasta, white rice and sugary snacks, we would wipe out almost all the
problems we have with weight and diabetes and other metabolic
diseases. -- Dr. Walter Willett, Harvard School of Public Health

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


dlugo at etherboy

Nov 22, 2011, 7:23 AM

Post #5 of 10 (749 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

Thanks very much for your reply, my followup below...


On Tue, 22 Nov 2011, Todd Lyons wrote:
>
> On Tue, Nov 22, 2011 at 6:35 AM, Dave Lugo <dlugo [at] etherboy> wrote:
>>> I seem to have some apps that are sending with a underscore in
>>> the domain part.  Searching the exim-user archives suggests that
>>> I can work around this by rewriting the MAIL FROM address,
>>> replacing the domain part _ chars with . chars.
>> I decided to try to be simple - any MAIL FROM with a domain part
>> ending in example.com, that is preceeded by an element containing
>> an underscore, gets replaced with example.com.
>
> That's not what your regex has below. Let's analyze it.
>
>> user [at] asd  --->  user [at] example
>> But trying to go with this:
>> \N^(.*)@*_*.example.com(.*)$\N    $1 [at] example$4        SF
>
> Wrapping the regex with \N is good. That means you don't have to do
> do all kinds of ugly escaping.
>
> What is messing you up is the @*_*. That literally means "zero or
> more @ signs followed by zero or more _ signs". What you meant was
> "@.*_.*\.example.com". You were thinking shell style or sendmail
> style wildcard instead of regex.
>
> Second, you said "with a domain part ending in example.com". But your
> regex searches for "example.com(.*). That means that example.com
> could match anywhere in the hostname.
>
> Finally, drop the $4 from the rewrite part.
>
> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
> \N^(.*)@.*_.*.example.com.*$\N $1 [at] example SF
> CentOS56[root [at] ivwm5 ~]# exim -C /etc/exim/exim_TEST.conf -brw
> user [at] asd
> SMTP: user [at] example
>

that works great for -brw, but when wrapped in <>, it fails:

mail from:<user [at] a_sd>
LOG: Rewrite of <user [at] a_sd> yielded unparseable
address: '>' missing at end of address in address <user [at] example
LOG: SMTP syntax error in "mail from:<user [at] a_sd>"
H=localhost (ad) [127.0.0.1] malformed address:
_sd.asd_asdasd.example.com> may not follow <user@a
501 <user [at] a_sd>: malformed address:
_sd.asd_asdasd.example.com> may not follow <user@a

I can't unfortunately guarantee that clients will do the right
thing, or not, with regards to < > usage.

Can both cases be done in the same rewrite rule? Should I use
two rewrite rules instead?

Thanks,

Dave

--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------


tlyons at ivenue

Nov 22, 2011, 7:24 AM

Post #6 of 10 (746 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

> \N^(.*)@.*_.*\.example.com(.*)$\N    $1 [at] example$4        SF
> works, but not very well - depending on whether or not the sender correctly
> uses < > characters, it breaks.

Ok, I see why you are having issues if you are passing < > characters
around it. According to the docs, it looks to me like it will already
have been stripped, so you shouldn't have to worry about it, but if
you really want to account for it:

CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
\N^<?(.*)@.*_.*.example.com>?$\N $1 [at] example SF

Regards... Todd
--
If Americans could eliminate sugary beverages, potatoes, white bread,
pasta, white rice and sugary snacks, we would wipe out almost all the
problems we have with weight and diabetes and other metabolic
diseases. -- Dr. Walter Willett, Harvard School of Public Health

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


tlyons at ivenue

Nov 22, 2011, 7:28 AM

Post #7 of 10 (745 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, Nov 22, 2011 at 7:24 AM, Todd Lyons <tlyons [at] ivenue> wrote:
>
> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
> \N^<?(.*)@.*_.*.example.com>?$\N    $1 [at] example        SF

Oops, make sure to escape the dot before "example.com" :

CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
\N^<?(.*)@.*_.*\.example.com>?$\N $1 [at] example SF

Regards...             Todd
--
If Americans could eliminate sugary beverages, potatoes, white bread,
pasta, white rice and sugary snacks, we would wipe out almost all the
problems we have with weight and diabetes and other metabolic
diseases. -- Dr. Walter Willett, Harvard School of Public Health

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


dlugo at etherboy

Nov 22, 2011, 7:30 AM

Post #8 of 10 (747 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, 22 Nov 2011, Todd Lyons wrote:
>
> Ok, I see why you are having issues if you are passing < > characters
> around it. According to the docs, it looks to me like it will already
> have been stripped, so you shouldn't have to worry about it, but if
> you really want to account for it:
>
> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
> \N^<?(.*)@.*_.*.example.com>?$\N $1 [at] example SF
>

that seems to work, though I need to test some more, just to
be paranoid.

thanks very much!


--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


dlugo at etherboy

Nov 22, 2011, 7:31 AM

Post #9 of 10 (746 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, 22 Nov 2011, Todd Lyons wrote:
>
> On Tue, Nov 22, 2011 at 7:24 AM, Todd Lyons <tlyons [at] ivenue> wrote:
>>
>> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
>> \N^<?(.*)@.*_.*.example.com>?$\N    $1 [at] example        SF
>
> Oops, make sure to escape the dot before "example.com" :
>
> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
> \N^<?(.*)@.*_.*\.example.com>?$\N $1 [at] example SF
>
> Regards...             Todd
>

will do, thanks again!


--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------


dlugo at etherboy

Nov 22, 2011, 7:33 PM

Post #10 of 10 (745 views)
Permalink
Re: need to rewrite _ characters in MAIL FROM domain part [In reply to]

On Tue, 22 Nov 2011, Todd Lyons wrote:
>
> On Tue, Nov 22, 2011 at 7:24 AM, Todd Lyons <tlyons [at] ivenue> wrote:
>>
>> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
>> \N^<?(.*)@.*_.*.example.com>?$\N    $1 [at] example        SF
>
> Oops, make sure to escape the dot before "example.com" :
>
> CentOS56[root [at] ivwm5 ~]# grep example.com /etc/exim/exim_TEST.conf
> \N^<?(.*)@.*_.*\.example.com>?$\N $1 [at] example SF
>

Followup..

had to add (?i) after the ^ :

\N^(?i)<?(.*)@.*_.*\.example.com>?$\N $1 [at] example SF

Section 31.5 states:

Domains in patterns should be given in lower case. Local parts in patterns
are case-sensitive. If you want to do case-insensitive matching of local
parts, you can use a regular expression that starts with ^(?i).


Per the above, it sounds like the domain part of a pattern isn't
case-sensitive, but my testing shows it is. Passing:

asd [at] asd_as@EXAMPLE.COM

... fails to match the pattern.

Deficiency in docs with regards to the domain part in a pattern, or
deficiency in the exim code? Dunno which. Adding the case-insensitive
bits to the pattern lets it match both lower and upper case domain
variants.


--
--------------------------------------------------------
Dave Lugo dlugo [at] etherboy No spam, thanks.
Are you the police? . . . No ma'am, we're sysadmins.
--------------------------------------------------------

exim users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.