Introducing the Messaging Server Plug-in API
Table of Contents | Previous | Next | Index

Messaging Server Plug-in API Guide


Chapter 1
Introducing the Messaging Server Plug-in API

This chapter explains how you can use the Messaging Server Plug-in API, provides some basic definitions, and describes the stages involved in message processing.

The chapter has the following sections:

NOTE: If you want to use existing Messaging Server 3.0 plug-ins in Messaging Server 4.0, see "Converting Messaging Server Plug-in 3.0 Files." §

[Top]

How You Can Use Messaging Server Plug-ins

The Messaging Server Plug-in API plug-in interface allows third-party developers to plug in site-specific message-handling functionality to Netscape Messaging Server. The server plug-ins you write become part of the server address space and are called automatically whenever a new message comes in.

A server plug-in is a shared object or shared library (or dynamic link library (DLL) on Windows NT), written in the C/C++ language, that implements your own functions and behaves as though it is a part of the server.

Here's what you can do with the Messaging Server Plug-in API:

Here's what you cannot do with the plug-in API:

For general information about the functionality and operation of Messaging Server, see the Messaging Server 4.0 Administration Guide.

The UBE plug-in, which was written using the Messaging Server Plug-in API, is installed automatically with Messaging Server 4.0. This plug-in is a versatile filter that removes or redirects unwanted messages. For information about this plug-in, see Chapter 8, "Filtering Unsolicited Bulk Email," in the Messaging Server 4.0 Administration Guide.

Note The Messaging Server Plug-in API 4.0 is available on the Solaris, HP-UX 11.00, and AIX platforms. §
[Top]

How Messaging Server Plug-ins Work

You can write two types of Messaging Server plug-ins. The plug-in type is determined by the stage in message processing at which it is called:

Plug-in message processing goes through several steps. For example, this is the sequence that a PostSmtpAccept plug-in takes with a message:

  1. Since this is a PostSmtpAccept plug-in, the message must first be accepted by the server. After this, the plug-in is called with the message.
  2. The plug-in determines whether the server should continue to process the message or not. How the plug-in actually determines this is up to you.
The Messaging Server Plug-in API operates on messages whose formats conform to the definition in RFC 822: "Standard for the Format of ARPA Internet Text Messages." In addition, the plug-in API uses the control information in the SMTP envelope.

When the message is accepted, the plug-in API creates a Message structure that points to the file that contains the entire message, including the header and body information.

The Message structure is passed into the plug-in through the main plug-in function, which must be based on the pFunc function prototype.

The control data accessed by the Messaging Server Plug-in API is specific to Netscape Messaging Server. Control data is internal to the Messaging Server. It is made up of the SMTP envelope combined with connection data gathered during the accept sequence of Messaging Server.

The control data for a message is passed into the plug-in through the plug-in initialization function, which must be based on the pInitFunc function prototype. Once loaded, the control data is maintained in memory until the plug-in entry point returns to the server. When this happens, the message is written automatically to the disk.

If several entry points for a single plug-in entry stage are cascaded, the server waits to write the control data until after all the entry points return. The server writes the entry points in the order in which they appear in the configuration file. See "The Plug-in Configuration File."

Messaging Server 4.0 is multithreaded. In general, make sure that your plug-in code is thread-safe.

If possible, avoid using global variables in your Messaging Server plug-ins. If you use globals, make sure that they are synchronized to avoid multiple calls to the plug-in. For example, they could be encapsulated in a class that synchronizes access to the globals.

Plug-ins for 4.x servers should handle restartable system calls, such as signals.

[Top]

The Plug-in Configuration File

The Messaging Server plug-in configuration file, plugins.cfg, contains configuration information for all installed server plug-ins. In the configuration file, each plug-in is listed on its own line, in the order in which the plug-ins were installed in Messaging Server. This is the order in which the plug-ins will execute as well.

When the plug-in is initialized, Messaging Server passes this configuration information to the plug-in's pblock structure.

Plug-in configuration information has this format:

stage <pluginPath> funcs=<function>[,function] init=<function>
                  <optionParam>[<optionParam>]
<optionParam>=<param-name>=<param-value>
The parameters have the following descriptions:

stage

The stage in message processing, or entry point, at which the plug-in is called, either:

For more information, see "How Messaging Server Plug-ins Work."

pluginPath

Complete file path to the binary (executable) file of the plug-in library. For more information, see "Building the Plug-in."

funcs

The plug-in's functions in a comma-separated list. When the plug-in runs, Messaging Server calls the functions as they occur in this list. The documentation you supply with your plug-in should describe the contents of this field.

init

The plug-in's initialization function.

optionParam

One or more options that supply additional plug-in functionality, listed in a set of comma-separated name:value pairs. When the plug-in runs, Messaging Server passes it this optional information.

For example, you could use this option to set a path to a temporary file or configuration file.

To get the value part of one of these pairs, you use the pblock_findval function. The documentation you supply with your plug-in should describe the contents of this field.

For example, a plug-in configuration file could call the plug-in libxlate.so at the PostSmtpAccept stage of message processing to decode the message, and at the PreSmtpDeliver to encode it, with these lines:

PostSmtpAccept /foo/bar/libxlate.so funcs=decode-euc init=decode-init 
PreSmtpDeliver /foo/bar/libxlate.so funcs=encode-iso init=encode-init 
                                    no-xlate-domains="*.kr"
In the first line of the example, the plug-in acts at the PostSmtpAccept message processing stage, and gives the full path to its library file, libxlate.so. The funcs list implements the plug-in function decode-euc. The init list implements the plug-in's initialization function, decode-init.

In the second line of the example, the plug-in acts at the PreSmtpDeliver processing stage and gives the full path its library file, libxlate.so. The funcs list implements the plug-in function encode-iso. The init list implements the plug-in's initialization function, encode-init. This line sets a single option, directing the plug-in not to encode messages from the top-level domain .kr.

For more information about the configuration file, including its location in Messaging Server, see Chapter 7, "Working With SMTP Plug-Ins," in the Messaging Server 4.0 Administration Guide.

[Top]

Building the Plug-in

The dynamically loadable executable code that implements the functionality of your plug-in is the shared object (called a shared library on some platforms). The shared object is passed as the pluginPath parameter in the plug-in configuration file, plugins.cfg. For more information about this code, see "The Plug-in Configuration File."

A shared object or plug-in is configured to run at a particular stage of message processing, or entry point. The possible entry points are PostSmtpAccept and PreSmtpDeliver. For more information about entry points, see "How Messaging Server Plug-ins Work."

A message goes through the shared object when it enters the processing stage for which the object is configured. For example, all outbound messages go through any plug-in configured with the PreSmtpDeliver entry point. Messaging Server calls the shared object and waits for a return before calling it again.

You can write a makefile to build your plug-in. The example in this section shows the makefile that builds the sample code in this guide, which you can find in Chapter 4, "Messaging Server Sample Plug-in." Running makefile with the sample code file, sample.c, results in a shared object named sample.o.

NOTE: You can download a zip file, msplugin.zip, that contains the sample plug-in file sample.c and makefile. §
# Sample Makefile for Netscape Messaging Server Plug-in
# Name of the plug-in to build
TARGET=sample
# Use one of the following
SHARED_SUFFIX=so
# Use one of the following
CC=gcc -fPIC -I../include -shared
#CC=cc -KPIC -I../include -G
# Use one of the following
FLAGS = -DXP_UNIX
#FLAGS = -DXP_WIN32
# Use zero or more of the following
#FLAGS += -D_DEBUG
all: $(TARGET).$(SHARED_SUFFIX)
$(TARGET).$(SHARED_SUFFIX): $(TARGET).c ../include/msg4plugins.h
        $(CC) $(FLAGS) -o $(TARGET).$(SHARED_SUFFIX) $(TARGET).c
sample.o
clean:
        rm -f $(TARGET).$(SHARED_SUFFIX)
[Top] [Building the Plug-in]

Installing the Plug-in

When you write a plug-in, you are responsible for writing an installation routine that installs it, along with any additional files it requires, in Messaging Server. You can make the process easier by providing some documentation to help the user install your plug-in.

For information about plug-ins in Messaging Server, see Chapter 7, "Working With SMTP Plug-Ins," in the Messaging Server 4.0 Administration Guide. This chapter describes installing, configuring, deactivating, and deinstalling plug-ins.

[Top]


Table of Contents | Previous | Next | Index

Last Updated: 11/19/98 10:23:53

[an error occurred while processing this directive]