Discussion:
regex to block emails while having word bounce before @ sign.
(too old to reply)
Indunil Jayasooriya
2016-03-11 04:50:40 UTC
Permalink
Hi,

I get mails from addresses like these.

Pls pay attention to the *username* part before *@ sign.*

the string* bounce* is present somewhere *before @ sign. *


*bounce*@anydomain.com
list*bounce****@anydoamin.com
list*bounce*s-***@anydoamin.com
*bounce****@me-ss2-qaesx6.domain.com
*bounce*-684_HTML-239103804-572627-1363516-***@rock.info.domain.com
*bounce*-7071912-***@sub.domain.com
*bounce*s+1501722-c815-sam=***@mail.123xyz.com
ml-*bounce*-***@anydomain.com
ab-*bounce*s-***@anydomain.com


I want to block these email address with spam assassin.

I wrote a *from.cf <http://from.cf>* file to match these?


header FROM_BOUNCE From:addr =~* /(bounce)/i*
describe FROM_BOUNCE From address contain the word bounce
score FROM_BOUNCE 3.1

it matches the word *bounce *any where* before and after @ sign.*

e.g -

ml-*bounce*-newsletter@*bounce*.anydomain.com

So, it is NOT the regex I expect since I *DO NOT* want to filter
anything *after
@* sign.

So I am trying like this. But it still does NOT work.

*(bounce)\@* instead of* /(bounce)/i*

header FROM_BOUNCE From:addr =~ */(bounce)\@/i*
describe FROM_BOUNCE From address contain the word bounce and bounces
score FROM_BOUNCE 3.1


I go to below site and see whether it matches.

https://regex101.com/

it does NOT matches.

Can you guys make any comments on this?



-
cat /etc/motd

Thank you
Indunil Jayasooriya
http://www.theravadanet.net/
http://www.siyabas.lk/sinhala_how_to_install.html - Download Sinhala
Fonts
Olivier Nicole
2016-03-11 05:00:36 UTC
Permalink
Indunil
Post by Indunil Jayasooriya
I go to below site and see whether it matches.
https://regex101.com/
I use The Regex Coach (http://weitz.de/files/regex-coach.exe) for that
matter, it works well under Windows or under wine, you can do step by
step on your regex.

Best regards,

Olivier
Indunil Jayasooriya
2016-03-11 07:03:47 UTC
Permalink
I use The Regex Coach (http://weitz.de/files/regex-coach.exe) for that
Post by Olivier Nicole
matter, it works well under Windows or under wine, you can do step by
step on your regex.
Thanks. Downloaded. I loaded the pkg on Ubuntu with wine.

But, I find it difficult to use it.


any way, https://regex101.com/ is okay for me.

I think below regex matches everything up to *@ sign.*

*/(bounce.*@)/i*

it does NOT check anything* after @ sign. This is WHAT I NEED*

something like these.

noreply@*bounce*.domain.com
noreply@*bounce*.com

Now, my file looks like this.

header FROM_BOUNCE From:addr =~ */(bounce.*@)/i*
describe FROM_BOUNCE From address contain the word bounce
score FROM_BOUNCE 3.1


Can anyone out there agree with this?
--
cat /etc/motd

Thank you
Indunil Jayasooriya
http://www.theravadanet.net/
http://www.siyabas.lk/sinhala_how_to_install.html - Download Sinhala
Fonts
Gregory Sloop
2016-03-11 19:15:39 UTC
Permalink
I think below regex matches everything up to @ sign.

/(bounce.*@)/i

it does NOT check anything after @ sign. This is WHAT I NEED

something like these.

***@bounce.domain.com
***@bounce.com


Be exceptionally careful of ".*" [It very, *very* often matches more things than you expected it to.]

I can't think of a specific example of a line that would cause an issue, but your regex, will match something like this too. [Essentially anything with "bounce" with anything in-between, followed by an "@" later in the same line.

blah blah blah ***@bounce.com ***@someotherdomain.com blah blah blah @ blah [In this case, it will match on the second "@", not the first - as an example of how .* works.]

or

blah blah blah ***@somedomain.com freddy-***@someotherdomain.com blah blah blah

or

blah blah blah ***@somedomain.com ***@someotherdomain.com bounce blah blah blah @ blah

Any new regex, I'd monitor it carefully for some time to be sure it does what you expected it to do, especially if it has a .* in it.

-Greg

Loading...