Introducing the Messaging Access SDK
Table of Contents | Previous | Next | Index

Messaging Access SDK Guide
Part 1. Using the Messaging Access SDK


Chapter 1
Introducing the Messaging Access SDK

The Netscape Messaging Access software development kit (SDK) provides a set of Protocol Level APIs that the developer can use to write messaging applications and extend applications with messaging services. This chapter is an overview of the Messaging Access SDK, version 3.5.

The Messaging Access SDK provides SMTP, MIME, POP3, and IMAP4 APIs in the Java and C programming languages, for a variety of platforms.

The Messaging Access SDK Guide provides developers with a complete set of software libraries, sample code, and documentation for building mail-enabled applications.

[Top]

How the Protocol APIs Work Together

The Messaging Access SDK provides implementations of the Internet messaging protocols, SMTP, IMAP4, MIME, and POP3. These Protocol APIs are designed to work together, yet have the ability to operate independently of each other.

SMTP (Simple Mail Transfer Protocol). SMTP sends plain text or MIME-encoded messages. You can use MIME to prepare to send messages in formats other formats than text, to encode messages, and to include attachments. For more information, see Chapter 2, "Sending Mail with SMTP."

MIME (Multipurpose Internet Mail Extension). MIME builds and encodes messages with attachments for sending over SMTP, and parses and decodes received messages. The encoded MIME message is passed to SMTP.

The MIME API consists of the MIME encoder and the MIME parser. The MIME encoder is used to build MIME messages with attachments and encode them for sending over SMTP. You can use the MIME API to parse and decode messages when they are received through IMAP4 or POP3. For more information, see Chapter 3, "Building and Parsing MIME Messages."

IMAP4 (Internet Message Access Protocol, version 4). IMAP4 is used to retrieve and manage messages remotely. The user can save messages on the server or locally. In addition, the user can manipulate items on the server (for example, create or delete mailboxes). IMAP4 supports multiuser mailboxes. For more information, see Chapter 4, "Receiving Mail with IMAP4."

POP3 (Post Office Protocol, version 3). POP3 connects to the server and retrieves messages. POP3 is simpler than IMAP4 and provides a subset of its capabilities. It supports one user per mailbox. For more information, see Chapter 5, "Receiving Mail with POP3."

For a quick reference to the Internet Protocol commands called by Messaging Access SDK methods, see Chapter 7, "Reference to Protocols."

The Protocol APIs are designed to co-exist in the same client environment and match each other's interfaces where applicable. For example, the message data chunks returned by POP3 and IMAP4 APIs can be fed to the MIME SDK API to parse the message contents. In the same way, the encoded message byte-stream returned by the MIME API can be passed to the SMTP API to transmit the message. At the same time, the APIs are designed to allow customers to use only the API required by their application.

Applications written with the Messaging Access SDK Protocol APIs can work with any messaging system that implements the Internet messaging protocols, primarily the Netscape Messaging Servers. Protocol APIs are self-contained and are intended to coexist with all other SuiteSpot SDKs; they are independent of Netscape Server releases.

Each Messaging Access SDK Protocol API is designed to follow its Internet standard specification. API invocations result in the exchange of standard protocol elements with the server. Any information exchange with the server conforms to one of the standard protocols.

Figure 1.1   Messaging Access API Architecture

The Messaging Access SDK is designed to parse and format protocol elements and make these available to the programmer through Java classes or C data structures and the methods and functions that access them.

The Messaging Access SDK Protocol APIs are built to be thin and are optimized for performance and memory. Each Protocol API includes a sendCommand (or pass-through) interface, which programmers can use to send protocol elements that are not directly supported by the API. The IMAP4 API has further conveniences, such as transparently handling unilateral and unsolicited responses from the server and making these available at the API level through a callback mechanism.

For more information about the sendCommand API, see the reference entries for smtp_sendCommand, imap4_sendCommand, and pop3_sendCommand.

For more information about using callbacks, see the section about callback mapping in each of these chapters: Sending Mail with SMTP, Receiving Mail with IMAP4, Receiving Mail with POP3, and Building and Parsing MIME Messages.

[Top]

The Messaging Access SDK, C Version

The Messaging Access SDK (Software Development Kit) comes in a zip file on Unix and a self-extracting executable on MS Windows.

You can download the SDK at this URL.

For the latest installation information, see the ReadMe file for the SDK.

The Messaging Access SDK download file contains the following directories and files:

On Unix, unzip the downloaded file using a utility that preserves the file hierarchy, for example, gzip. On MS Windows, simply execute the self-extracting executable. For links to the latest information about installation, see ReadMeC.htm, included in the SDK.

[Top]

Supported Platforms

The Messaging Access SDK supports the MS Windows and Unix platforms listed in Table 1.1.

Table 1.1 Supported Platforms

Platforms Supported Versions

Solaris

2.5.1, 2.6

Windows NT

4.0 with SP 3

Windows 95

AIX

4.21

IRIX

6.2

DEC Unix

4.0d

HP-UX

11.0

[Top]


SDK Response Sinks for C

The SMTP, IMAP4, and POP3 response sinks and the MIME data sink are C structures made up of function prototypes and opaque data.

For example, the SMTP response sink, smtpSink_t, defines opaque data and provides function prototypes for response functions.

typedef struct smtpSink 
   /* User data. */
    void * pOpaqueData;
/* Notification for the response to the connection to the server. */
   void (*connect)( smtpSink_t * in_psmtpSink, 
         int in_responseCode,
         const char * in_responseMessage );
   ...
} smtpSink_t;
Each function prototype is a callback that is associated with one or more functions in the SDK implementation of the protocol.

Functions with multi-line responses map to more than one callback, as shown in the table for smtp_expand. The second callback provides a notification that the operation is complete.

Function Callback, Defined in smtpSink_t
smtp_expand
void (*expand)(SMTPSinkPtr_t in_psmtpSink, 
   int in_responseCode,
   const char * in_emailAddress );
smtp_expand
void (*expandComplete)(SMTPSinkPtr_t in_psmtpSink); 

For easy reference, each protocol chapter includes a table that shows how functions are mapped to callbacks. See the individual protocol chapters under "Function Callback Mapping."

The developer implements the response sink by supplying the functionality for each method and associating each method implementation with its prototype. You can use any function name, but you must assign the same number and types of parameters. If you do not want to implement a function prototype, you can assign the function the value of null, as follows:

smtpSink_t.expand = null;
When you start a session with SMTP, IMAP4, or POP3, you first create (initialize) the sink. Then you create the client, which calls the sink functions. The sink receives and processes all the available server response data whenever processResponses is called. This call reads in responses from the server and invokes the appropriate callback function for all responses that are available at the time of execution.

You can create more than one response sink, based on what you want the messaging application to do. In SMTP, IMAP4, and POP3, you can change the response sink in use with the setResponseSink function.

When you start a session with the MIME dynamic parser, you first create and initialize the data sink, and then you create the parser. The parser makes callbacks to its data sink based on the kind of data it finds in the input stream. For example, if it finds a header, it makes the header callback. For the other protocols, the callback comes from the server and callbacks tend to be tied to individual functions.

For MIME, the kind of callback is dependent upon the kind of data that is in the input stream. There are no particular correspondences between functions and data sink callback prototypes, as there are in the other protocols.

For more information, see the section about implementing the response sink in each of these chapters: Sending Mail with SMTP, Receiving Mail with IMAP4, Receiving Mail with POP3, and Building and Parsing MIME Messages.

NOTE: POP3, IMAP4, and POP3 commands are asynchronous. After sending a command, the application does not have to wait to issue the next one, but can do something else. §
[Top]

SDK Error Codes for C

The Messaging Access SDK Protocol implementations for SMTP, MIME, IMAP4, and POP3 return information about command operation using the set of standard SDK error codes defined in nsmail.h. For a complete list of SDK error codes, see Error Definitions.

Table 1.2 Messaging Access SDK Errors

Error Value Description
0

NSMAIL_OK: Successful completion.

<0

Various error messages: Failure. Interpret the error and take appropriate action. See Error Definitions for the error types in this category.

>0

The intended action did not occur, but you can recover. For example, if the data is not returned or processed, you may still be able to go on processing.

NSMAIL_ERR_IO_SOCKET

Socket I/O error. As serious as other errors, but you can get more information about this type. On Unix, query the Unix errno. On Windows NT, call GetlLastError().

NSMAIL_ERR_TIMEOUT

Time-out. Recoverable condition; the application can wait and reissue the function.

NOTE: Error codes and other definitions to apply to all protocols are defined in Shared C Definitions. §
[Top]

Compiling with the C SDK

This section provides general information for including libraries and compiling with the SDK on the Unix and MS Windows platforms.

[Top]

Including C Header Files

The protocol APIs in the Messaging Access SDK include libraries that implement the API functions. When you write messaging applications that use one or more of the SDK protocols, be sure to include the header files required by the APIs that you use.

When you install the Netscape C version of the Messaging Access SDK, the installation process creates an include directory and a lib directory under the install root.

In your source files, include the Messaging Access SDK common header files <nsmail.h> and <nsstream.h>, along with any Protocol API include files: <mime.h> <mimeparser.h>, <smtp.h>, <pop3.h>, and <imap4.h>, that you need.

The lib directory contains the library files for the different protocol APIs: libmime.*, libsmtp.*, libpop3.*, and libimap4.*. The lib directory also contains the library that is common to all protocol APIs, libcomm.*. Here, the extension * represents the platform-specific extensions for the libraries: .dll or .lib on MS Windows; .so on Solaris and IRIX; .sl on HPUX; and _shr.a on AIX.

The libmime library contains the implementation of the MIME encoder as well as the MIME parser API. You must link with the libmime library if you intend to use the MIME encoder API, the MIME parser API, or both.

[Top] [Compiling with the C SDK]

Compiling on Unix

Follow these steps to compile the C version of the Messaging Access SDK on the Unix platform:

  1. Copy the SDK API library files libmime.*, libsmtp.*, libpop3.* , libimap4.* and libcomm.* to your work directory, for example: /usr/lib/msgsdk
  2. When compiling, be sure to include the library path in your link statement, for example: -L/usr/lib/msgsdk -lmime -lsmtp -lcomm
  3. On Unix platforms, specify the -DXP_UNIX flag in your compilation (cc) step.
  4. On the AIX platform only, also specify the -DAIX flag in your compilation step.
  5. If you are using the POP3, SMTP, and IMAP4 protocols, you may also need to link with the additional libraries -lsocket and -lnsl.
  6. When you run your client program, be sure to include the msgsdk library path in the LD_LIBRARY_PATH (on Solaris) or the equivalent on other platforms. This way, the clients can find the msgsdk shared libraries at run time.

[Top] [Compiling with the C SDK]

Compiling on MS Windows

Follow these steps to compile the C version of the Messaging Access SDK on MS Windows (NT/95) platforms:

  1. On MS Windows platforms, you must link with the libcomm.lib and with one or more of the protocol-specific libraries libmime.lib, libsmtp.lib, libpop3.lib, and libimap4.lib.
  2. Be sure to specify the directory where Messaging Access SDK lib files are located, for example, by using /libpath or by setting the LIB environment variable.
  3. If required by your environment, specify the -DWIN32 flag in your compilation (cl) step.
  4. To ensure that the client you build with the Messaging Access SDK can find the dynamic link libraries, copy the .dll files to one of these locations:
During run time, the Messaging Access SDK client looks for the dynamic link libraries in the following places:

[Top] [Compiling with the C SDK]


Table of Contents | Previous | Next | Index

Last Updated: June 3, 1998

Copyright © 1998 Netscape Communications Corporation