Short TLD filter for .top .xyz & other crap domains

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
NoahVail
New user
New user
Posts: 5
Joined: 2010-11-11 21:03

Short TLD filter for .top .xyz & other crap domains

Post by NoahVail » 2016-09-23 03:48

I started with this: viewtopic.php?f=20&t=28725

However it wasn't catching emails with return addresses like crap.crap@crapity.crap.top
I assume the problem was Instr() reading R to L and stopping at the first dot.

A friend debugged it for me and his modification works great.
It's short & sweet. I just had to paste it in and reload scripts.

Code: Select all

Sub OnSMTPData(oClient, oMessage)

Const BlackList=" TOP XYZ STREAM CH BID DATE WIN TR INFO BIZ MEN "
arr=Split(oMessage.FromAddress, ".")

TLD=arr(UBound(arr))
    if Instr(Blacklist," "&uCase(TLD)&" ")>0 then
          Eventlog.Write("OnSMTPdata: TLD in Blacklist " & oMessage.FromAddress & ". 542 Rejected" )
          result.value=1
    End if   
End Sub 

User avatar
jimimaseye
Moderator
Moderator
Posts: 8632
Joined: 2011-09-08 17:48

Re: Short TLD filter for .top .xyz & other crap domains

Post by jimimaseye » 2016-09-23 10:18

Thanks for sharing.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

thorntonBGB
New user
New user
Posts: 3
Joined: 2016-10-27 12:50

Re: Short TLD filter for .top .xyz & other crap domains

Post by thorntonBGB » 2016-12-13 05:29

In my instance I'm accepting empty sender addresses. The script needed to be tweaked to allow it. Thanks Noah for your revised version, put me on the right track.

Code: Select all

Public Const blacklisted_domains = " top "
Public Const blacklisted_domains_log = true

Sub OnSMTPData(oClient, oMessage)
	Dim from_array
	Dim top_level_domain
	
	' Verify email address contains tld.
	If InStr(oMessage.FromAddress, ".") > 0 Then
		from_array = Split(oMessage.FromAddress, ".")
		top_level_domain = from_array(UBound(from_array))
		If InStr(blacklisted_domains, " "& LCase(top_level_domain) &" ") > 0 Then
			If blacklisted_domains_log Then
				EventLog.Write("SMTPData:" & oMessage.FromAddress & ". 542 Rejected" )
			End If
			Result.Value = 1
		End If
	End If
End Sub

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: Short TLD filter for .top .xyz & other crap domains

Post by SorenR » 2016-12-13 15:05

This is what I would use... I already filter on "oClient.HELO", "oMessage.From", "oMessage.Subject" and "oMessage.Body" in Sub OnAcceptMessage(oClient, oMessage) ...

Code: Select all

   Function Lookup(strRegEx, strMatch)
      With CreateObject("VBScript.RegExp")
         .IgnoreCase = True
         .Global = False
         .Pattern = strRegEx
         If .Test(strMatch) Then
            Lookup = True
         Else
            Lookup = False
         End If
      End With
   End Function


   Sub OnSMTPData(oClient, oMessage)
      Dim strRegEx
      strRegEx = ".\top$|.\xyz$|.\stream$|.\bid$|.\date$|.\win$|.\men$"
      If Lookup(strRegEx, oMessage.FromAddress) Then
         Result.Value = 2
         Result.Message = "5.7.1 Your access to this mail system has been rejected due to the " &_
                          "sending MTA's poor reputation. If you believe that this failure is " &_
                          "in error, please contact the intended recipient via alternate means."
         Exit Sub
      End If
   End Sub
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
jimimaseye
Moderator
Moderator
Posts: 8632
Joined: 2011-09-08 17:48

Re: Short TLD filter for .top .xyz & other crap domains

Post by jimimaseye » 2016-12-13 15:47

SorenR wrote:

Code: Select all

         Result.Value = 2
         Result.Message = "5.7.1 Your access to this mail system has been rejected due to the " &_
                          "sending MTA's poor reputation. If you believe that this failure is " &_
                          "in error, please contact the intended recipient via alternate means."
         Exit Sub
      End If
   End Sub
:lol:

Ooh....cheeky!
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

NoahVail
New user
New user
Posts: 5
Joined: 2010-11-11 21:03

Re: Short TLD filter for .top .xyz & other crap domains

Post by NoahVail » 2017-03-01 19:02

SorenR wrote:This is what I would use...

Code: Select all

  
   Sub OnSMTPData(oClient, oMessage)
      Dim strRegEx
      strRegEx = ".\top$|.\xyz$|.\stream$|.\bid$|.\date$|.\win$|.\men$"
 
Is your escape sequence reversed or am I missing something? (ie: |.\tld$ vs |\.tld$ )

User avatar
SorenR
Senior user
Senior user
Posts: 3620
Joined: 2006-08-21 15:38
Location: Denmark

Re: RE: Re: Short TLD filter for .top .xyz & other crap domains

Post by SorenR » 2017-03-01 19:54

NoahVail wrote:
SorenR wrote:This is what I would use...

Code: Select all

  
   Sub OnSMTPData(oClient, oMessage)
      Dim strRegEx
      strRegEx = ".\top$|.\xyz$|.\stream$|.\bid$|.\date$|.\win$|.\men$"
 
Is your escape sequence reversed? (ie: |.\tld$ vs |\.tld$ )
It seems so... wonder when that happened 'cos my script has it right.
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

Post Reply