Connect with your customers

through Web forums, newsgroups, mailing lists, blogs, RSS feeds, and more.

Writing a custom filtering action

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, but custom actions can be used to modify the article before it is saved or take some external action based on the article.

For example, a custom action could add information from specially formatted messages into another database, or could alert the administrator that a new message has been posted.

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 action, you must produce a new class inheriting from the MPS.MPNews.Filtering.Action abstract base class. Override the Execute method to perform the action when a new article is posted.

You should also override the ToString method to return the text that will be displayed in the list of actions 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 action types when adding a new action 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. Full documentation of the MPNews class libraries is also provided as part of the main MPNews help file.

Installing a new action

Once you have written your new action, you need to register it with MPNews for it to be available in the list of types of action 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 action plugin" link to start installing your action.

Select the type of action 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 action type, you will now be shown a list of all the action in the file you have selected. Select the action you want to install and click on "Save".

Your action will now be available for use. When you now create a new filter, you will be able to select your new action type when adding an action to the filter.