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 SMTP plug-ins, provides some basic definitions, and describes the stages involved in message processing.

SMTP (Simple Mail Transport Protocol) allows clients to deliver mail messages to SMTP servers. Servers also use SMTP to move messages from one server to another before delivering them to a mailbox.

A Messaging Server SMTP plug-in, called a shared object or shared library on Unix and a dynamic link library (DLL) on Windows NT, is written in the C/C++ language, using the Messaging Server Plug-in API. Your SMTP plug-in becomes part of the server address space and implements the functions you determine. Whenever a new message comes in, the plug-in is called automatically at one of two stages in SMTP processing: either immediately after the message is received or just before the message is handed off to another host.

The chapter has the following sections:

NOTE: If you want to use existing Messaging Server 3.0 or 4.0 plug-ins in Messaging Server 4.1, see Appendix A, "Converting Messaging Server Plug-in Files to 4.1." §
[Top]

How You Can Use Messaging Server SMTP Plug-ins

The Messaging Server plug-in interface allows third-party developers to write SMTP plug-ins that add site-specific message-handling functionality to Netscape Messaging Server 4.1. Here's what you can do with the Messaging Server Plug-in API:

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

For general information about the functionality and operation of Messaging Server, the way that plug-ins work in it, the plug-ins supplied with the server, and the way that users can manipulate them through Netscape Console, see the Messaging Server 4.1 Administration Guide.

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

Note The Messaging Server Plug-in API 4.1 is available on the Solaris, HP-UX 11.00, DEC UX, SGI IRIX, AIX, and Windows NT platforms. §
[Top]

How SMTP Plug-ins Work

The type of Messaging Server SMTP plug-in you write is determined by the stage in SMTP message processing when you want it to be called.

PostSMTPAccept plug-ins are called immediately after the message is received, at the PostSMTPAccept entry point. This is the most common, and most useful, type of plug-in.

At the PostSMTPAccept point in processing, Messaging Server has not touched either the message body or the envelope, and the message may not be fully standards compliant. In addition, the recipient and sender addresses are not yet verified or expanded. The plug-in developer is responsible for handling this.

PreSMTPDeliver plug-ins are called just before the message is handed off to another host, at the PreSMTPDeliver entry point. These SMTP plug-ins are best for adding or removing message recipients.

NOTE: You can also write plug-ins that act at the PreSMTPAccept stage, before SMTP has accepted the incoming message and written it to disk. For more information, see the Protocol Level Plug-in Programmer's Guide. §
You set the processing stage in the configuration file. For more information, see "Configuring SMTP Plug-ins." The user can also set the processing stage through the Netscape Console user interface. For information about this, see the Messaging Server 4.1 Administration Guide.

There are several steps in SMTP plug-in processing. For example, this is the sequence that a PostSMTPAccept plug-in takes with a message:

  1. For a PostSMTPAccept plug-in, the message must first be accepted by the server. After this, the SMTP plug-in is called with the message.
  2. The SMTP 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.
SMTP plug-ins written using the Messaging Server Plug-in API operate on message that conform to the format 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 SMTP plug-in through the main plug-in function, which must be based on the pFunc function prototype.

The configuration data accessed by the Messaging Server Plug-in API is specific to Netscape Messaging Server. This data is stored in the plugins.cfg file in serverroot/instance/smtp-bin/plugins/.

Configuration data for a message is passed to the SMTP plug-in through the plug-in initialization function, which must be based on the pInitFunc function prototype. Once loaded, the configuration data should be maintained by the plug-in. If several "function" entry points for a single plug-in exist, the server calls them in the order in which they appear in the plugins.cfg configuration file. See "Configuring SMTP Plug-ins."

Messaging Server 4.1 is multithreaded; make sure that your plug-in code is thread-safe. If possible, avoid using global variables. If you do, make sure that they are synchronized to avoid multiple calls to the plug-in. For example, the globals could be encapsulated in a class that synchronizes access.

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

[Top]

Configuring SMTP Plug-ins

You can install and configure SMTP plug-ins by editing the SMTP plug-in configuration file, plugins.cfg, in serverroot/instance/smtp-bin/plugins/. This file contains the configuration data for all installed SMTP plug-ins. You can also change plug-in configuration or deactivate an installed plug-in by editing this file.

Each plug-in is listed with its configuration information on its own line in the file, in the order in which it was installed in Messaging Server. The plug-ins will execute in this order as well. When an SMTP plug-in is initialized, Messaging Server passes the configuration information, which includes the path to the executable code, to the plug-in's pblock structure.

To deactivate an installed plug-in, place a number sign character (#) at the beginning of its line to comment it out.

SMTP plug-in configuration data 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 SMTP plug-in is called, either:

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

pluginPath

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

funcs

The SMTP 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 SMTP plug-in's initialization function.

optionParam

One or more options that supply additional SMTP 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. You could use this option to set a path to a temporary file or configuration file.

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

Unix
For example, an SMTP plug-in configuration file could use these lines to call the plug-in libxlate.so at the PostSMTPAccept stage of message processing to decode the message, and at the PreSMTPDeliver stage to encode it:

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 SMTP 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 SMTP plug-in acts at the PreSMTPDeliver stage and calls the plug-in by giving 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.

Windows NT
For example, an SMTP plug-in configuration file could use these lines to call the SMTP plug-in libxlate.dll at the PostSMTPAccept stage of message processing to decode the message, and at the PreSMTPDeliver stage to encode it:

PostSMTPAccept d:\plugins\libxlate.dll funcs=decode-euc 
                                 init=decode-init
PreSMTPDeliver d:\plugins\libxlate.dll funcs=encode-iso 
                  init=encode-init no-xlate-domains="*.kr"
In the first line of the example, the SMTP plug-in acts at the PostSMTPAccept message processing stage, and gives the full path to its library file, libxlate.dll. 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 SMTP plug-in acts at the PreSMTPDeliver stage and calls the plug-in by giving the full path of its library file, libxlate.dll. 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.

NOTE: 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.1 Administration Guide. §
[Top]

Building the SMTP Plug-in

Unix
To build your SMTP plug-in, you can write a makefile or use the one supplied with this document. The example in this section shows the makefile that builds the sample code in this guide, which you can find in Chapter 4, "Sample SMTP Plug-in." Running this Unix makefile with the sample code file, sample.c, results in a shared object named sample.o.

NOTE: You can download a zip file, uplugin.zip, that contains the sample plug-in file sample.c and makefile. §
# Sample Makefile for Netscape Messaging Server SMTP 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)
Windows NT
When you build your SMTP plug-in, link to libns.lib as well as libstore.lib. You can find these in the Messaging Server installation in this directory: serverroot\plugins\lib. The result of building the sample code file, sample.c, results in a shared object named sample.dll.

NOTE: You can download a zip file, wplugin.zip, that contains the sample plug-in file sample.c. §
[Top] [Building the SMTP Plug-in]

Installing the SMTP Plug-in

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

Users of SMTP plug-ins have two options for installing, configuring, activating and deactivating SMTP plug-ins.

[Top]


Table of Contents | Previous | Next | Index

Last Updated: 05/13/99 11:41:54

Copyright © 1999 Netscape Communications Corporation.