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

Messaging Server Plug-in API Guide


Chapter 3
Messaging Server Plug-in API Reference

This chapter is a reference to Messaging Server Plug-in API functions, data structures, and result codes that you can call in your own SMTP plug-ins.

The chapter has the following sections:

The Messaging Server Plug-in API is defined in the msg4plugins.h header file. You can see this file in HTML format or download the file.

[Top]

Functions

The Messaging Server Plug-in API includes the following functions. Table 3.1 lists API functions and any data structures on which they operate.

Table 3.1 Messaging Server SMTP plug-in API functions  
Function

Description

Structure

AddControlInfo

Adds control items to a message.

Message

AddRecipient

Adds a recipient to the message.

Message
Recipient

DupMessage

Duplicates the message.

Message

FreeControlData

Frees message control data.

Message

FreeMessage

Frees the resources associated with a message.

Message

GetControlData

Returns the control data for an incoming message.

Message

GetFirstRecipient

Gets the first recipient to the message.

Message

GetMessageFile

Gets the path and filename to the message file on disk.

Message

GetNextRecipient

Gets all subsequent recipients to the message.

Message
Recipient

GetPostOfficePath

Gets the path to the post office directory where the message resides.

Message

GetRecipientAddress

Gets the address of the specified recipient.

Recipient

pblock_findval

Finds the entry with the given name.

pblock

pFunc

Passes the configuration when the plug-in function is called at MTA start-up.

pblock
Message

pInitFunc

Initializes the SMTP plug-in.

pblock

RemoveControlInfo

Removes control items from a message.

Message

RemoveRecipient

Deletes recipients from the message.

Message
Recipient

[Top]

AddControlInfo

New in Messaging Server Plug-in API 4.0

Adds control items to a message.

Syntax

#include <msg4plugins.h>
int AddControlInfo(
Message*pMessage,
                   const char *key,
                   const char *data,
                   int delete_original);

Parameters

The function has the following parameters:

pMessage

Pointer to the Message structure.

key

Pointer to the control item to add.

data

Pointer to the control data to add.

delete_original

Flag indicating whether to delete the original message when adding control data. Values:

Returns

Description

This function adds name:value pairs to the control data for a message. This change is reflected in any future call to GetControlData.

The control data accessed by the Messaging Server Plug-in API is specific to Netscape Messaging Server. Some of the data in the control data is gathered during the accept sequence of Messaging Server; some is gathered from the SMTP protocol. Control data includes the SMTP envelope.

For information about using this function, see "Add the control data."

See Also

GetControlData, FreeControlData, RemoveControlInfo, Message

[Top] [Functions]

AddRecipient

Adds the specified recipient to a message.

Syntax

#include <msg4plugins.h> 
int AddRecipient (
Message *pMessage, Recipient *pRecipient);

Parameters

The function has the following parameters:

pMessage

Pointer to the name of the Message structure.

pRecipient

Pointer to the address of the Recipient structure.

Returns

Description

This function adds recipients to the recipient list encapsulated in the Message structure. You also use this function to create a new recipient. AddRecipient succeeds if both input parameters are valid and no memory errors occur.

To add a recipient, you must define the magic value 0xdeadbeef. For an example that shows how to define this value, see "Add and remove recipients." To see how AddRecipient is used in a sample SMTP plug-in DLL, see Chapter 4, "Sample SMTP Plug-in."

To delete recipients from the recipient list, use RemoveRecipient.

See Also

GetFirstRecipient, GetNextRecipient, GetRecipientAddress, RemoveRecipient, Recipient, Message

[Top] [Functions]

DupMessage

Duplicates the specified message.

Syntax

#include <msg4plugins.h> 
Message *DupMessage (
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Pointer to the name of the Message structure.

Returns

Description

This function duplicates the incoming message, creating a separate, identical instance of the message. Messaging Server automatically does the following:

Messaging Server frees any pointer returned by DupMessage in the OutMessage output parameter of the plug-in function (the function based on the function prototype, pFunc). If the SMTP plug-in decides not to return the message it created after calling DupMessage, it should call FreeMessage for that pointer. For information about the plug-in function, see "How SMTP Plug-ins Work."

For more information, see "Duplicate the message."

See Also

FreeMessage, Message, pFunc

[Top] [Functions]

FreeControlData

New in Messaging Server Plug-in API 4.0

Frees message control data.

Syntax

#include <msg4plugins.h>
void FreeControlData(char *controldata);

Parameters

The function has the following parameter:

controldata

Pointer to the control data to free.

Description

This function frees the message control data retrieved by GetControlData. Any call to GetControlData should be followed by a call to FreeControlData.

The control data accessed by the Messaging Server Plug-in API is specific to Netscape Messaging Server. Some of the data in the control data is gathered during the accept sequence of Messaging Server; some is gathered from the SMTP protocol. Control data includes the SMTP envelope.

For information about using this function, see "Free the control data."

See Also

GetControlData, AddControlInfo, RemoveControlInfo, Message

[Top] [Functions]

FreeMessage

Frees the resources associated with a message.

Syntax

#include <msg4plugins.h>
void FreeMessage (
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Pointer to the Message structure.

Description

This function frees all of the resources allocated to the Message structure indicated in the pMessage parameter. It operates only on the in-memory copy of a message, and does not touch anything on the disk.

If a SMTP plug-in decides not to return a message it created after calling DupMessage, it should call FreeMessage for that message. For more information, see "Free the message."

See Also

DupMessage, Message

[Top] [Functions]

GetControlData

New in Messaging Server Plug-in API 4.0

Returns the control data for an incoming message.

Syntax

#include <msg4plugins.h>
char *GetControlData(
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Pointer to the Message structure.

Returns

Description

This function returns the control data for an incoming message. Any call to this function should be followed by a call to FreeControlData.

The control data is returned in the form of a character string that contains the full path name to the control data for the message. The character string contains name:value pairs with the elements separated by LFs.

The control data accessed by the Messaging Server Plug-in API is specific to Netscape Messaging Server. Some of the data in the control data is gathered during the accept sequence of Messaging Server; some is gathered from the SMTP protocol. Control data includes the SMTP envelope.

For information about using this function, see "Get the control data."

See Also

FreeControlData, AddControlInfo, RemoveControlInfo, Message

[Top] [Functions]

GetFirstRecipient

Gets a pointer to the first recipient in the message structure.

Syntax

#include <msg4plugins.h>
Recipient *GetFirstRecipient (
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Pointer to the name of the Message structure.

Returns

Description

This function returns a pointer to the first recipient in the recipient list encapsulated in the Message structure. Any subsequent call to GetFirstRecipient resets the retrieval of recipients so that calls to GetNextRecipient return the second, third, and all subsequent recipients.

To traverse the recipient list of the input message, use the GetFirstRecipient and GetNextRecipient pair. The functions do not allocate any storage; both return null if the message is empty or malformed.

For more information, see "Get message recipients." To see how this function is used in a sample SMTP plug-in DLL, see Chapter 4, "Sample SMTP Plug-in."

See Also

AddRecipient, GetNextRecipient, GetRecipientAddress, RemoveRecipient, Message

[Top] [Functions]

GetMessageFile

New in Messaging Server Plug-in API 4.0

Gets the path and filename to the message file on disk.

Syntax

#include <msg4plugins.h> 
char *GetMessageFile(
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Pointer to the name of the Message structure.

Returns

Description

This helper function retrieves the entire message file represented by the Message parameter. In the 4.0 API, the message, including the header and body files, are maintained in the same file. The GetMessageFile function, new in Messaging Server 4.0, combines the two 3.0 functions, GetHeaderFile and GetBodyFile. These two functions are retained in the API to provide backward compatibility. For more information, see "Get the message file." To see how this function is used in a sample SMTP plug-in DLL, see Chapter 4, "Sample SMTP Plug-in."

See Also

Message

[Top] [Functions]

GetNextRecipient

Gets the second, third, and all subsequent recipients in the message.

Syntax

#include <msg4plugins.h>
Recipient *GetNextRecipient (
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Pointer to the list of recipients in the Message structure.

Returns

Description

Call this function after GetFirstRecipient to return the second, third, and all subsequent recipients in the recipient list encapsulated in the Message structure.

To traverse the recipient list of the input message, use the GetFirstRecipient and GetNextRecipient pair. These functions do not allocate any storage; both return null if the message is empty or malformed.

For more information, see "Get message recipients."

See Also

AddRecipient, GetFirstRecipient, GetRecipientAddress, RemoveRecipient, Message

[Top] [Functions]

GetPostOfficePath

New in Messaging Server Plug-in API 4.1

Returns the path to the post office directory where the physical message resides.

Syntax

#include <msg4plugins.h>
char *GetPostOfficePath(
Message *pMessage);

Parameters

The function has the following parameter:

pMessage

Message for which to find the post office path.

Returns

Description

Also see "Return the post office directory."

See Also

Message

[Top] [Functions]

GetRecipientAddress

Gets the address of the specified recipient.

Syntax

#include <msg4plugins.h> 
char *GetRecipientAddress (
Recipient *pRecipient);

Parameters

The function has the following parameter:

pRecipient

Pointer to the address of the Recipient structure.

Returns

Description

This function gets the address of the specified recipient in the recipient list encapsulated in the Message structure.

This function returns the RFC 821 address string contained in the Recipient structure pointed to by pRecipient, for example, <foo@somewhere.org>.

For more information, see "Get the recipient's address." To see how this function is used in a sample SMTP plug-in DLL, see Chapter 4, "Sample SMTP Plug-in." For the address definition, see RFC 821: "Simple Mail Transfer Protocol."

See Also

AddRecipient, GetFirstRecipient, GetNextRecipient, RemoveRecipient, Recipient

[Top] [Functions]

pblock_findval

Finds the name:value pair with the given name.

Syntax

#include <msg4plugins.h> 
char *pblock_findval(char *name,
pblock *pb);

Parameters

The function has the following parameters:

name

Pointer to the name of the name:value pair to find.

pb

Pointer to the pblock structure used to search for the specified the name:value pair.

Returns

Description

This helper function walks the parameter block specified in the pb parameter, searching for the key specified in the name parameter, and returns the value associated with it. The parameter block, or pblock structure, is a linked list of name:value pairs that contains the configuration information for the SMTP plug-in.

You can use this function to find the value of the name=value parameter in the SMTP plug-in entry point code described in "How SMTP Plug-ins Work." This parameter represents name:value pairs that are passed to the function.

For more information, see "Find a Messaging Server entry" and "The Parameter Block Structure."

See Also

pblock

[Top] [Functions]

pFunc

New in Messaging Server Plug-in API 4.0

Passes the configuration when the plug-in function is called at MTA start-up.

Syntax

#include <msg4plugins.h> 
typedef int (*pFunc) (
pblock *Config,
                      struct Message **InMessage,
                      struct Message ***OutMessage);

Parameters

The function has the following parameters:

Config

Pointer to the pblock structure that contains the configuration information for the SMTP plug-in (the name:value pairs that contain all the optional parameters on the configuration command line).

InMessage

Pointer to the pointer to the incoming message. Can point to an array of pointers to structures of type Message, terminated by a null pointer. Every pointer represents a separate message. Usually, there is only one pointer in this array.

OutMessage

Pointer to the pointer to the pointer to the outgoing message. This message is the result of the execution of the SMTP plug-in code. Required only if the plug-in generates more than one message from a single input message. The plug-in should return null in this parameter when:

Not needed if the plug-in code does not split the input message (for example, if it encodes the message for all the recipients).

Returns

Description

This function is one of the two prototypes that the SMTP plug-in must export in order to load. It is called for each message that is accepted. The configuration is passed once again, through the Config parameter block. The details of the incoming message are stored in the InMessage message. If the SMTP plug-in creates an outgoing message, it should be set in the OutMessage message.

For more information, see "Writing the Plug-in Function." To see how this function is used in a sample SMTP plug-in DLL, see Chapter 4, "Sample SMTP Plug-in."

See Also

pInitFunc, pblock, Message, pblock_findval

[Top] [Functions]

pInitFunc

New in Messaging Server Plug-in API 4.0

Initializes the SMTP plug-in.

Syntax

#include <msg4plugins.h> 
typedef int (*pInitFunc)(
pblock *Config);

Parameters

The function has the following parameter:

Config

Pointer to the pblock structure that contains the configuration information for the SMTP plug-in.

Returns

Description

This function initializes the SMTP plug-in and returns an integer that indicates whether the initialization completed. It is one of the two function prototypes that the SMTP plug-in must export in order to load.

This function is called once at MTA start-up to initialize local server data, declare global variables, and load configuration information off the disk. This results in a boost to performance, because the SMTP plug-in function is relieved of this task.

If you construct global variables in the SMTP plug-in, remember that if the variables are changed when the SMTP plug-in is called with incoming or outgoing messages, you must synchronize access to them.

The configuration defined in plugins.cfg (the optional parameters) is passed in through the Config parameter block, a pblock structure that contains SMTP plug-in control information.

For more information, see "Writing the Initialization Function." To see how this function is used in a sample SMTP plug-in DLL, see Chapter 4, "Sample SMTP Plug-in."

See Also

pFunc, pblock, pblock_findval

[Top] [Functions]

RemoveControlInfo

New in Messaging Server Plug-in API 4.0

Removes control items from a message.

Syntax

#include <msg4plugins.h>
int RemoveControlInfo (
Message *pMessage, char *key;

Parameters

The function has the following parameters:

pMessage

Pointer to the Message structure.

key

Pointer to the control item to remove.

Returns

Description

This function removes name:value pairs from the control data. This change is reflected in any future call to GetControlData.

The control data accessed by the Messaging Server Plug-in API is specific to Netscape Messaging Server. Some of the data in the control data is gathered during the accept sequence of Messaging Server; some is gathered from the SMTP protocol. Control data includes the SMTP envelope.

For information about using this function, see "Remove the control data."

See Also

GetControlData, FreeControlData, AddControlInfo, Message

[Top] [Functions]

RemoveRecipient

Deletes recipients from the message.

Syntax

#include <msg4plugins.h>
int RemoveRecipient (
Message *pMessage,
                     Recipient *pRecipient);

Parameters

The function has the following parameters:

pMessage

Pointer to the name of the Message structure.

pRecipient

Pointer to the address of the Recipient structure.

Returns

Description

This function deletes recipients from the recipient list encapsulated in the Message structure.

The AddRecipient and RemoveRecipient functions are used to add and delete recipients in the recipient list. RemoveRecipient always succeeds. For more information, see "Add and remove recipients."

See Also

AddRecipient, GetFirstRecipient, GetNextRecipient, GetRecipientAddress, Recipient, Message

[Top] [Functions]

Return Values for Functions

Messaging Server Plug-in API functions that return pointers to structures or to strings return null on error. Functions that return an integer return 0 on success and a negative value on error.

All input parameters are validity checked for memory corruption and return an appropriate error if necessary.

[Top] [Functions]

Data Structures

This section lists the data structures used in Messaging Server Plug-in API functions.

Table 3.2 Messaging Server SMTP plug-in data structures  
Structure Description

Address

Represents the address of the message.

AddressList

Represents an address list.

Message

Represents the message.

pblock

Contains plug-in control information.

WARNING: The type definitions are described in this section for informational purposes only. Although your SMTP plug-in should be able to reference the members of these structures, it should make all changes through the API, to accommodate future API changes. §
[Top]

Address

Represents the address in the message.

Syntax

#include <msg4plugins.h>
typedef struct addresstag
            long magic;
            
N821Address Addr821;
            SMTPExt Ext;
            int flags;
) Address;

Fields

The structure has the following fields:

magic

Magic value required by AddRecipient. Value: 0xdeadbeef

Addr821

N821Address address.

Ext

Extension for a recipient.

flags

Flags for a recipient.

Description

The Address structure provides the type definition of the Recipient and Sender parameters that are part of the Message structure.

To access this structure, you use the functions that manipulate the Message structure. You should make changes to the Recipient list only through the API. The SMTP plug-in can read the recipient list through plug-in API structures. For more information, see "The Message Recipient and the Address Structure."

WARNING: This type definition is for informational purposes only. Although your plug-in should be able to reference the members of these structures, it should make all changes through the API, to accommodate future API changes. §

See Also

Message, AddressList, N821Address, SMTPExt, Sender, Recipient

[Top] [Data Structures]

AddressList

Represents an address list.

Syntax

#include <msg4plugins.h>
typedef struct addr_list
            long magic;
            void *context;
            Address Addr;
            struct addr_list *pNext;
) AddressList;

Fields

The structure has the following fields:

magic

Magic value required by AddRecipient. Value: 0xdeadbeef

context

Pointer to the context of the message.

Addr

Address of a recipient.

pNext

Pointer to the next address list structure.

Description

The AddressList structure is a linked list of addresses. This structure provides the type definition of the RecipientList parameter that is part of the Message structure.

To access this structure, you use the functions that manipulate the Message structure. You should only make changes to the recipient list through the API. The SMTP plug-in can read the recipient list through plug-in API structures. For more information, see "The Message RecipientList and the AddressList Structure."

WARNING: This type definition is for informational purposes only. Although your plug-in should be able to reference the members of these structures, it should make all changes through the API, to accommodate future API changes. §

See Also

Message, Address, RecipientList

[Top] [Data Structures]

Message

Represents a message.

Syntax

#include <msg4plugins.h>
typedef struct message {
               long magic;
               char *BaseMsgName;
               char *MsgFileName;
               
RecipientList *recipList;
               Sender *sender;
               const char *stage;
               int flags;
               void *context;
               void *control;
               char *PostOfficePath;
} Message;

Fields

The structure has the following fields:

magic

Magic cookie for the message. Use only this value: 0xdeadbeef.

BaseMsgName

Pointer to base message file name (does not include file path).

MsgFileName

Pointer to message file name, including the path.

recipList

Pointer to list of addresses of the recipients of a message. RecipientList of type AddressList.

sender

Pointer to envelope sender, of type Address.

stage

Pointer to stage in message processing at which the SMTP plug-in should be called. Values:

flags

Flags for the message. Used internally.

context

Pointer to internal context for things like getNext routines.

control

Pointer to the ControlFile, which is accessible through plug-in API functions.

PostOfficePath

Pointer to the path to the post office directory where the physical message resides.

Description

The Message structure stores all attributes that define a single message. This includes both header and body information. Most of the other structures and type definitions of the API provide the parameters that make up the Message structure.

The header of the message is made up of fields in name:value pair format that include all header or envelope information, such as sender, recipients, sender and per-recipient extensions, and so on. The body of the message refers to the lines of text that make up the content of the message.

Control information is made up of the SMTP envelope, combined with data gathered during the accept sequence of Messaging Server. For more information, see "Accessing Control Data."

The Message structure is passed into the SMTP plug-in through the main pFunc function.

To set or access message attributes, use the functions that operate on the Message structure, which are listed in "See Also."

For more information, see "Using Messaging Server Plug-in Data Structures" and "The Message Structure." For details about message definition, see RFC 822: "Standard for the Format of ARPA Internet Text Messages."

WARNING: This type definition is for informational purposes only. Although your plug-in should be able to reference the members of these structures, it should make all changes through the API, to accommodate future API changes. §

See Also

AddRecipient, DupMessage, FreeMessage, GetFirstRecipient, GetMessageFile, GetNextRecipient, RemoveRecipient, pFunc, AddControlInfo, GetControlData, FreeControlData, RemoveControlInfo, GetPostOfficePath, Sender, Recipient, RecipientList, AddressList, Address

[Top] [Data Structures]

pblock

Contains SMTP plug-in control information.

Syntax

#include <msg4plugins.h>
typedef struct p_block
            char *name;
            char *value;
            struct p_block *next;
) pblock;

Fields

The structure has the following fields:

name

Pointer to the name portion of the pair.

value

Pointer to the value portion of the pair.

next

Pointer to the next entry in the linked list of name:value pairs.

Description

The pblock structure is an array of name:value pairs in a linked list that you can use to set and retrieve control information for a message.

Both of the functions exported by the SMTP plug-in, pInitFunc and pFunc, use this structure to pass the plug-in configuration data in the plugins.cfg file to the plug-in.

To access the fields in the pblock structure, use the pblock_findval function.

For more information, see "The Parameter Block Structure."

See Also

pblock_findval, pInitFunc, pFunc

[Top] [Data Structures]

Definitions

This section lists the definitions you can use when using Messaging Server Plug-in API functions.

Table 3.3 Messaging Server SMTP plug-in definitions  
Definition Description

N821Address

Address, of character type, that conforms to Address definition in RFC 821. New in 4.0.

Recipient

Address of the recipient of a message. Of type Address.

RecipientList

List of addresses of the recipients of a message. Of type AddressList.

Sender

Address of the sender of a message. Of type Address. New in 4.0.

SMTPExt

Extension, of character type, for an SMTP recipient.

[Top]

Result Codes

The SMTP plug-in's main function should return one of these codes to Messaging Server.

Table 3.4 SMTP plug-in result codes  
Code Description

MSG_CONTINUE

The SMTP plug-in succeeded. Messaging Server should continue to process the resulting messages. This code can occur at any stage of Messaging Server processing.

MSG_NOACTION

The SMTP plug-in did not do anything. Continue to process the message.

[Top]


Table of Contents | Previous | Next | Index

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

Copyright © 1999 Netscape Communications Corporation.