Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

libmime content type handlers

Warning: The content of this article may be out of date. It was imported from mozilla.org and last updated in 2001.



This page has been flagged by editors or users as needing technical review. Until it is fully reviewed, it may contain inaccurate or incorrect information.

by Richard H. Pizzarro <[email protected]>

Contents

Overview
The libmime module implements a general-purpose MIME parser and one of the primary methods provided by the parser is the ability to emit an HTML representation of an input stream. The primary use of  libmime is to parse and render RFC822 messages for use by the Messenger component of Seamonkey.

A necessary capability of this module is to dynamically add the ability to decode and render various content types. This functionality will be accomplished via Content Type Handler Plugins for libmime. libmime has a homegrown object system written in C, and since the content type handler plugins need to exist in this module, a description of the libmime object system should be reviewed and understood.

API's
Content Type Handler Plugins are dynamically loaded and need to access internal pointers, functions that are part of the C based object system. The following XP-COM interface is implemented by libmime and is necessary for Content Type Handler Plugin development.

/*
 * This interface is implemented by content type handlers that will be
 * called upon by libmime to process various attachments types. The primary
 * purpose of these handlers will be to represent the attached data in a
 * viewable HTML format that is useful for the user
 *
 * Note: These will all register by their content type prefixed by the
 *       following:  mimecth:text/vcard
 *
 *       libmime will then use nsComponentManager::ContractIDToCLSID() to
 *       locate the appropriate Content Type handler
 */
#ifndef nsIMimeContentTypeHandler_h_
#define nsIMimeContentTypeHandler_h_

typedef struct {
  PRBool      force_inline_display;
} contentTypeHandlerInitStruct;

#include "prtypes.h"
#include "nsISupports.h"
#include "mimecth.h"

// {20DABD99-F8B5-11d2-8EE0-00A024A7D144}
#define NS_IMIME_CONTENT_TYPE_HANDLER_IID \
      { 0x20dabd99, 0xf8b5, 0x11d2,   \
      { 0x8e, 0xe0, 0x0, 0xa0, 0x24, 0xa7, 0xd1, 0x44 } }

class nsIMimeContentTypeHandler : public nsISupports {
public:
  static const nsIID& GetIID() { static nsIID iid = NS_IMIME_CONTENT_TYPE_HANDLER_IID; return iid; }

  NS_IMETHOD    GetContentType(char **contentType) = 0;

  NS_IMETHOD    CreateContentTypeHandlerClass(const char *content_type,
                                              contentTypeHandlerInitStruct *initStruct,
                                              MimeObjectClass **objClass) = 0;
};

#endif /* nsIMimeContentTypeHandler_h_ */

Plugin Installation/Location
The installation of these modules will be similar to the that of any XPCOM component (i.e. the components directory for the bin directory).

Sample Content Type Handler Plugin
To see an example of a Content Type Handler Plugin, the source for the handler of the content type "text/calendar" can be viewed at the following link: Calendar plugin Note: This plugin simply creates a blue table in the output stream to identify the fact that it is operational, but the basic constructs of what is needed to build a functional content type handler can be seen. The UUID for this component is:

// {20DABDA1-F8B5-11d2-8EE0-00A024A7D144}
#define NS_VCARD_CONTENT_TYPE_HANDLER_CID \
      { 0x20dabda1, 0xf8b5, 0x11d2, \
      { 0x8e, 0xe0, 0x0, 0xa0, 0x24, 0xa7, 0xd1, 0x44 } }

Document Tags and Contributors

 Contributors to this page: chrisdavidmills, Steffen, jenzed
 Last updated by: chrisdavidmills,