regex syntax for exclusive sender

Use this forum to get help.

regex syntax for exclusive sender

Postby VanguardLH » Thu May 18, 2017 7:29 am

While there is a note in the FAQs that regex can be used to specify on what to match for exclusive sender(s), what regex syntax is used or honored is not mentioned. I've searched through the forum posts but the supported regex syntax was not specified. Is it PCRE (Perl Compatible Regular Expression) syntax?

For example, I want to accept e-mails through a Spamgourmet alias from one sender but that sender has the same domain name but different TLDs (top-level domains) from which they may send messages. One might be something@nonda.co and another is something@nonda.us. I wanted to whitelist both sources for the sender. The regex to check for that domain at only those TLDs would be:

@nonda\.(co|us)$

That is before the at-sign is unknown. It varies depending on from within where inside the company that someone is sending a message. The at-sign anchors the domain on the left. That omits anything from @whatevernonda.co or @yadda.nonda.us. If I wanted to receive from any subdomain at nonda.co or nonda.us then I would use:

@(\S+\.)*nonda\.(co|us)$

\S+ means any one or more non-whitespace characters. The ()* means zero or more of substring(s) that end with a period character, so it would match on @host1.nonda.co, @subhost.host.nonda.co, or just @nonda.co. The backslash is needed in regex to escape the period character which is otherwise a special character used as a placeholder to match on any character (often followed by a repeat qualifier, like ? or 0 or 1 occurences of any character, + for one or more of any character, and * for zero or more of any character). I want to make sure there is a period after the nonda domain to delimit that substring. In the grouping enclosed within the paranthesis (more special chars) for the TLD, I'm looking for co or us, not com or anything longer than co or us. That's why the $ right-end anchor is used to ensure the sender's e-mail address ends with those TLDs. It makes sure the match is anchored at the end of the string. I've got it anchored on the left by looking for the at-sign that separates the left-token from the right-token in an e-mail address. I've got it anchored on the right to prevent matching on any further characters after the specific TLDs.

So far, the sender has not specified a host or subhost in the right-token of their e-mail address, so the first regex should pass their e-mails. Just in case they ever did add a host or subhost to their domain in the right-token, I could use the second regex to cover that syntax.

Will the above regex work to ensure that only e-mails from @nonda.us and @nonda.co are passed through Spamgourmet? Or is Spamgourmet's regex something other than PCRE, like some incomplete implementation of regex? I'm wondering just how full is Spamgourmet's regex support.
VanguardLH
 
Posts: 43
Joined: Sun Oct 11, 2009 10:01 pm

Re: regex syntax for exclusive sender

Postby lwc » Fri May 19, 2017 7:55 pm

I'd use something simpler, like:
Code: Select all
nonda.(co|us)

Although it should probably be "\." and not ".".

It leaves a loophole, but It's not like there's a high chance of something like foobarnona coming your way.
lwc
 
Posts: 341
Joined: Sat Aug 28, 2004 9:09 am

Re: regex syntax for exclusive sender

Postby VanguardLH » Fri May 19, 2017 10:24 pm

nonda\.(co|us)

would match on:

benonda.colgne.com
kenonda.compen@yale.com
someone@bergenonda.com
and lots more.

If I go to the trouble of defining a regular expression, I like to be as narrow as possible to reduce the number of false positives as much as possible. Remember that Spamgourmet only lets you know how many it allowed (forwarded) or blocked (eaten). You don't get to see who sent you a message that got eaten and there is no way to retrieve an eaten message. I don't want to discard (eat) a good message because there's no way for me to get it back. I also don't want something similar to get through.

Did the Spamgourmet owner ever publish information on his regex rules? There is only a tiny mention of regex in his FAQs.
VanguardLH
 
Posts: 43
Joined: Sun Oct 11, 2009 10:01 pm


Return to Support / Hilfe / ayuda / ondersteuning / ...

Who is online

Users browsing this forum: No registered users and 2 guests

cron