Writing a custom filtering rule
Introduction
MPNews provides a powerful automated filtering system that allows you to set up filters containing one or more "rules". These rules are applied to each incoming message and, if all of them match, the "actions" associated with the filter are executed. This normally results in the message being rejected.
The facility to combine the rules supplied with MPNews in any combination, and to change various properties of each rule, allow for very precise filters to be applied as needed. However, only a limited number of rules are available for use. While these should cover the majority of cases, you may need to write your own rules or have us write one for you to pick up the exact messages you want.
For example, a custom rule could detect messages in a particular format ready to be added directly to another database, such as spam or virus definitions, or any number of netiquette-related rules such as top posting or quoting style.
Supported languages
Rules can be written in VB.NET, JScript.NET or any compiled .NET language such as C# or Managed C++.
For help on using these languages, please refer to MSDN.
Technical details
To write a new rule, you must produce a new class inheriting from the MPS.MPNews.Filtering.Rule abstract base class. Override the Match method to perform the checks to see if a new article matches your rule; return true if the filter should be applied to the article, and false if not.
You should also override the ToString method to return the text that will be displayed in the list of rules in the Edit Filter screen. You can also provide a System.ComponentModel.DescriptionAttribute attribute for your class to define the text that will be displayed in the list of available rule types when adding a new rule to a filter.
Examples
Rather than trying to present a full introduction on programming with these languages, a number of examples are provided with MPNews in the C:\Program Files\MPNews5\Plugin Samples folder.
Installing a new rule
Once you have written your new rule, you need to register it with MPNews for it to be available in the list of types of rules to add to a filter.
In the main MPNews administration site, select the main "Filtering" item and click the "plugins" link. Click on the "Add new rule plugin" link to start installing your rule.
Select the type of rule you have created. If you have written your rule as a C#, VB.NET or JScript.NET script, select the corresponding option. If you have used a compiled language, select the "Assembly" option. VB.NET scripts must be saved with a ".vbs" extension, JScript.NET scripts must be saved with a ".js" extension, and other languages must be compiled into an assembly with a ".dll" extension.
Select the file containing your rule.
If you have used a scripting language, you will also be prompted to select the assemblies that your script references. You will typically need to select the MPS.MPNews.Common and MPS.MPNews.Filtering assemblies from the GAC, but you may also need to select additional assemblies depending on the classes your script uses.
Once you have added all the required references, click on "Save". Any missing references or errors in your script will cause a message to be displayed describing the error, and you will be returned to the previous screen. Correct any errors in your script or add any additional required references and click on "Save" again.
If your script or assembly contains more than one rule type, you will now be shown a list of all the rules in the file you have selected. Select the rule you want to install and click on "Save".
Your rule will now be available for use. When you now create a new filter, you will be able to select your new rule type when adding a rule to the filter.