Library Module Definition
=========================

The mail server lets you create your own library modules you can use in
several areas such as the Executables, Static Routes, Content Filters and Static filters.

A library module is a standard dynamic linked library file which can be written in any programming
tool such as Microsoft Visual C++, Delphi or Borland C++ Builder. The whole library has to fully
support multi threaded calls and be stable.


There are two functions your library can export for the mail server to use it. The function names
are case sensitive. A library file should export either of them.

DWord MerakFilterProc(TExternalFilter* ExternalFilter)

DWord MerakFilterProc2(byte* szData; byte* pResult; DWord* dwResultSize)

The function inteface used is the Cdecl. If a function is present in the library it is called
by the mail server with the proper parameters. The library module can perform any operations and actions
and finally has to return a result value.

Results:

0 - Accept the message
1 - Reject the message
2 - Delete the message
3 - Mark as spam
4 - None


MerakFilterProc
===============

This is the simplest function to be implemented. The only one required parameter is a pointer to the TExternalFilter 
structure variable.

ExternalFilter [in] A pointer to the session's data

struct TExternalFilter {
  static char szOriginalAddress[0x100];
  static char szRecipientAddress[0x100];
  static char szFileName[0x100];
}

szOriginalAddress The sender's email adress
szRecipientAddress - The recipient's email address
szFileName - A full filename to a text file holding the message data

The TExternalFilter structure is filled by the mail server and passed to your function call. 


MerakFilterProc2
================

This function is more advanced and requires a certain level of knowledge how to fill the parameters.

szData [in] The parameters to be sent to the function
pResult [out] Pointer to allocated string for the result parameters to be returned to
dwResultSize [in/out] The maximum length of the result to accept, the length of the returned data

The szData and pResult are specially constructed data packages. Each package contains a data ID and a data value.
Data IDs are variable types and data values the actual content of the variable.

Data IDs:

define MTYPE_END 0
define MTYPE_CLIENTIP 1
define MTYPE_MAILFROM 2
define MTYPE_RCPTTO 3
define MTYPE_RCPTTO_DOMAIN_FOLDER 4
define MTYPE_RCPTTO_ACCOUNT_FOLDER 5
define MTYPE_HELO_STRING 6
define MTYPE_MAIL_FILE 7
define MTYPE_AUTH = 8
define MTYPE_HOST = 9
define MTYPE_IS_LOCAL_IP = 10
define MTYPE_SSL = 11

define MTYPE_SMTP_STATUS_CODE 500
define MTYPE_SMTP_EXTENDED_STATUS_CODE 501
define MTYPE_SMTP_MESSAGE 502
define MTYPE_LOG_MESSAGE 503
define MTYPE_FILE_MODIFIED 504
define MTYPE_ADD_SCORE 505

define MTYPE_REQUEST_OPTIONS 1000
define TYPE_RESULT_BUFFER_DESIRED 1001
define MTYPE_FIELD_DESIRED 1002

A package has the following format:

DataID[2] ValueLength[2] ValueZeroTerminated[N+1]

Multiple packages are merged together in the following way:

PackageA PackageB PackageC PackageEnd

The PackageEnd uses the MTYPE_END data ID. Each sentence has to be ended using the end package.

By default the mail server passes most of the data from the Data ID definions above in the szData parameter.

The function has to return a result value and also fill the pResult and dwResultSize with the proper values. 
pResult contains the result sentence constructed of packages and dsResultSize the complete length of the result.

pResult data types processed by Merak:
MTYPE_SMTP_STATUS_CODE
MTYPE_SMTP_EXTENDED_STATUS_CODE
MTYPE_SMTP_MESSAGE

Example of a simple parameter sentence:

[ID     ] [Length ] [Value         ]  [ID     ] [Length ]
0x01 0x00 0x0B 0x00 '127.0.0.1' 0x00  0x00 0x00 0x00 0x00