(Original based on Kids SafeGuard script here: https://www.hmailserver.com/forum/viewt ... =14&t=4317 but with extra resilience and effective operation eliminating several flaws.)
This script will search all emails prior to delivery for words that you deem to be blacklisted and replaced accordingly. The words are maintained in a CSV file (to which you point the script to) It fully appreciates and ignores any leading and trailing characters, along with placement within the live (being the first word, last word or anything in between), allowing for full find/replace of your search word. It will search and replace your words in the banned list irrespective of any preceding or superseding punctuation (eliminating the flaw highlighted in the original script).
Note of warning: The script works on INCOMING messages which is distinguished by having a non-authenticated connection from the sending server (to HMS) for email delivery (as if an external email server was passing an email INBOUND for delivery to a local account). However, if you use a local email client without authentication to send out emails, this email will also be subject to sanitising before being sent out for delivery.
1, Create a CSV file called "filter.csv", and enter the full path/location in the script under the "Location=" variable.
"Filter.csv" file format should be:
Code: Select all
Bugger, B*g**r,1 Bloody, Blooming,1 shit,poo,0
This is the foul word you want to disallow/mask
This is the clean word/pattern you want the foul word to be shown as
STRICT is either ON (1) or OFF (0) on a per word basis, it works as follows:
eg, If you have "SHIT" in your csv and it changes to "****" and STRICT is off ("0") then "BULLSHIT" would be also be caught and changed to "BULL****". If you have STRICT on ("1") then the script would be restricted to "SHIT" and BULLSHIT would not be caught or changed.
2, Copy the following script in to your EVENTHANDLERS.VBS script (following normal hmailserver 'script enabling procedure').
Code: Select all
Sub OnAcceptMessage(oClient, oMessage) If (oClient.Username = "") Then Dim Location Location = "C:\Program Files (x86)\hMailServer\Events\Filter.csv" Dim objFSO Dim objTextFile Dim strWords,i Dim restrict Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile(Location, 1) Dim objRegEx Set objRegEx = CreateObject("VBScript.RegExp") objRegEx.Global = True objRegEx.IgnoreCase = True Do While objTextFile.AtEndOfStream <> True strWords = split(objTextFile.Readline, ",") restrict = strWords(2) if restrict = 1 then objRegEx.Pattern = "(\s|_|\W|[0-9])" & strWords(0) & "(\s|_|\W|[0-9])" oMessage.Body = objRegEx.Replace(oMessage.Body, "$1" & strWords(1) & "$2" ) oMessage.HTMLBody = objRegEx.Replace(oMessage.HTMLBody, "$1" & strWords(1) & "$2" ) else oMessage.Body = Replace(oMessage.Body,strWords(0),strWords(1),1,-1,1) oMessage.HTMLBody = Replace(oMessage.HTMLBody,strWords(0),strWords(1),1,-1,1) end if Loop oMessage.Save() End If End Sub