зеркало из https://github.com/mozilla/pjs.git
adding msg sdk sources
This commit is contained in:
Родитель
a6f6580246
Коммит
41d87a89cb
|
@ -0,0 +1,480 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MIME_H
|
||||
#define MIME_H
|
||||
|
||||
#include "nsmail.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MIME_OK 0
|
||||
#define MIME_ERR_UNINITIALIZED -1 /* don't modify */
|
||||
#define MIME_ERR_INVALIDPARAM -2
|
||||
#define MIME_ERR_OUTOFMEMORY -3
|
||||
#define MIME_ERR_UNEXPECTED -4
|
||||
#define MIME_ERR_IO -5
|
||||
#define MIME_ERR_IO_READ -6
|
||||
#define MIME_ERR_IO_WRITE -7
|
||||
#define MIME_ERR_IO_SOCKET -8
|
||||
#define MIME_ERR_IO_SELECT -9
|
||||
#define MIME_ERR_IO_CONNECT -10
|
||||
#define MIME_ERR_IO_CLOSE -11
|
||||
#define MIME_ERR_PARSE -12
|
||||
#define MIME_ERR_TIMEOUT -13
|
||||
#define MIME_ERR_INVALID_INDEX -14
|
||||
#define MIME_ERR_CANTOPENFILE -15
|
||||
#define MIME_ERR_CANT_SET -16
|
||||
#define MIME_ERR_ALREADY_SET -17
|
||||
#define MIME_ERR_CANT_DELETE -18
|
||||
#define MIME_ERR_CANT_ADD -19
|
||||
/* reserved by nsmail.h codes -20 through -30 */
|
||||
|
||||
#define MIME_ERR_EOF -82
|
||||
#define MIME_ERR_EMPTY_DATASINK -83
|
||||
#define MIME_ERR_ENCODE -84
|
||||
#define MIME_ERR_NO_SUCH_HEADER -85
|
||||
#define MIME_ERR_NO_HEADERS -86
|
||||
#define MIME_ERR_NOT_SET -87
|
||||
#define MIME_ERR_NO_BODY -88
|
||||
#define MIME_ERR_NOT_FOUND -89
|
||||
#define MIME_ERR_NO_CONTENT_SUBTYPE -90
|
||||
#define MIME_ERR_INVALID_ENCODING -91
|
||||
#define MIME_ERR_INVALID_BASICPART -92
|
||||
#define MIME_ERR_INVALID_MULTIPART -93
|
||||
#define MIME_ERR_INVALID_MESSAGEPART -94
|
||||
#define MIME_ERR_INVALID_MESSAGE -95
|
||||
#define MIME_ERR_INVALID_CONTENTTYPE -96
|
||||
#define MIME_ERR_INVALID_CONTENTID -97
|
||||
#define MIME_ERR_NO_DATA -98
|
||||
#define MIME_ERR_NOTIMPL -99
|
||||
#define MIME_ERR_EMPTY_BODY -100
|
||||
#define MIME_ERR_EMPTY_BODY -100
|
||||
#define MIME_ERR_UNSUPPORTED_PARTIAL_SUBTYPE -101
|
||||
#define MIME_ERR_MAX_NESTED_PARTS_REACHED -102
|
||||
|
||||
#define MIME_BUFSIZE 1024
|
||||
|
||||
struct mimeDataSink;
|
||||
|
||||
/* ----------------------------- */
|
||||
typedef enum mime_encoding_type
|
||||
{
|
||||
MIME_ENCODING_UNINITIALIZED = -1, /* don't modify */
|
||||
MIME_ENCODING_BASE64 = 1,
|
||||
MIME_ENCODING_QP,
|
||||
MIME_ENCODING_7BIT, /* 7 bit data with NO transfer encoding */
|
||||
MIME_ENCODING_8BIT, /* 8 bit data with NO transfer encoding */
|
||||
MIME_ENCODING_BINARY /* Binary data with NO transfer encoding */
|
||||
|
||||
} mime_encoding_type;
|
||||
|
||||
|
||||
typedef enum mime_disp_type
|
||||
{
|
||||
MIME_DISPOSITION_UNINITIALIZED = -1, /* don't modify */
|
||||
MIME_DISPOSITION_INLINE = 1,
|
||||
MIME_DISPOSITION_ATTACHMENT
|
||||
|
||||
} mime_disp_type;
|
||||
|
||||
|
||||
typedef enum mime_content_type
|
||||
{
|
||||
MIME_CONTENT_UNINITIALIZED = -1, /* don't modify */
|
||||
MIME_CONTENT_TEXT,
|
||||
MIME_CONTENT_AUDIO,
|
||||
MIME_CONTENT_IMAGE,
|
||||
MIME_CONTENT_VIDEO,
|
||||
MIME_CONTENT_APPLICATION,
|
||||
MIME_CONTENT_MULTIPART,
|
||||
MIME_CONTENT_MESSAGEPART
|
||||
|
||||
} mime_content_type;
|
||||
|
||||
|
||||
|
||||
typedef struct mime_header
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
struct mime_header *next;
|
||||
|
||||
} mime_header_t;
|
||||
|
||||
|
||||
|
||||
/* Common structure for leaf parts: Text, Audio, Video, Image and Application */
|
||||
typedef struct mime_basicPart
|
||||
{
|
||||
char * content_description;
|
||||
mime_disp_type content_disposition;
|
||||
char * content_disp_params; /* content disposition parameters */
|
||||
mime_content_type content_type;
|
||||
char * content_subtype;
|
||||
char * content_type_params;
|
||||
char * contentID;
|
||||
mime_header_t * extra_headers; /* additional X- and Content- headers */
|
||||
char * contentMD5; /* MD5 CRC code */
|
||||
mime_encoding_type encoding_type;
|
||||
void *pInternal; /* Stuff that client can not directly manipulate */
|
||||
|
||||
} mime_basicPart_t;
|
||||
|
||||
|
||||
|
||||
typedef struct mime_messagePart
|
||||
{
|
||||
char * content_description;
|
||||
mime_disp_type content_disposition;
|
||||
char * content_disp_params; /* content disposition parameters */
|
||||
mime_content_type content_type;
|
||||
char * content_subtype;
|
||||
char * content_type_params;
|
||||
char * contentID;
|
||||
mime_header_t * extra_headers; /* additional X- and Content- headers */
|
||||
mime_encoding_type encoding_type;
|
||||
mime_header_t * extern_headers; /* for extern-body */
|
||||
void *pInternal; /* Stuff that client can not directly manipulate */
|
||||
|
||||
} mime_messagePart_t;
|
||||
|
||||
|
||||
|
||||
typedef struct mime_multiPart
|
||||
{
|
||||
char * content_description;
|
||||
mime_disp_type content_disposition;
|
||||
char * content_disp_params; /* content disposition parameters */
|
||||
mime_content_type content_type;
|
||||
char * content_subtype;
|
||||
char * content_type_params;
|
||||
mime_encoding_type encoding_type;
|
||||
char * contentID;
|
||||
mime_header_t * extra_headers; /* additional X- and Content- headers */
|
||||
char * preamble;
|
||||
void *pInternal; /* Stuff that client can not directly manipulate */
|
||||
|
||||
} mime_multiPart_t;
|
||||
|
||||
|
||||
typedef struct mime_message
|
||||
{
|
||||
mime_header_t * rfc822_headers; /* message headers */
|
||||
void *pInternal; /* Stuff that client can not directly manipulate */
|
||||
|
||||
} mime_message_t;
|
||||
|
||||
|
||||
typedef struct file_mime_type
|
||||
{
|
||||
mime_content_type content_type;
|
||||
char * content_subtype;
|
||||
char * content_params;
|
||||
mime_encoding_type mime_encoding;
|
||||
/* char * file_extn; */
|
||||
/* char * file_shortname; */
|
||||
} file_mime_type;
|
||||
|
||||
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/** BASIC (LEAF) BODY PART TYPES **/
|
||||
/*************************************************************************/
|
||||
|
||||
/* Set the body-data for this part from an input stream.
|
||||
* This can only be done on a (new) mime_basicPart with empty bodydata.
|
||||
*/
|
||||
int mime_basicPart_setDataStream (mime_basicPart_t * in_pBasicPart,
|
||||
nsmail_inputstream_t *in_pTheDataStream,
|
||||
BOOLEAN in_fCopyData);
|
||||
|
||||
/* Set the body-data for this part from a buffer.
|
||||
* This can only be done on a (new) mime_basicPart with empty bodydata.
|
||||
*/
|
||||
int mime_basicPart_setDataBuf (mime_basicPart_t * in_pBasicPart,
|
||||
unsigned int in_size,
|
||||
const char * in_pDataBuf,
|
||||
BOOLEAN in_fCopyData);
|
||||
|
||||
/* Deletes the bodyData for this part. */
|
||||
int mime_basicPart_deleteData (mime_basicPart_t * in_pBasicPart);
|
||||
|
||||
/* gives the size of the body-data in bytes */
|
||||
int mime_basicPart_getSize (mime_basicPart_t * in_pBasicPart,
|
||||
unsigned int * out_pSize);
|
||||
|
||||
/* returns the body-data after any decoding in an input stream */
|
||||
/* If in_pFileName is NULL returns a memory based input-stream */
|
||||
/* If in_pFileName is not NULL, returns the specified file based */
|
||||
/* input-stream to the data */
|
||||
int mime_basicPart_getDataStream (mime_basicPart_t *in_ppBasicPart,
|
||||
char * in_pFileName,
|
||||
nsmail_inputstream_t **out_ppDataStream);
|
||||
|
||||
/* returns the body-data after any decoding in a buffer */
|
||||
int mime_basicPart_getDataBuf (mime_basicPart_t * in_pBasicPart,
|
||||
unsigned int * out_pSize,
|
||||
char **out_ppDataBuf );
|
||||
|
||||
/* Writes out byte stream for this part with MIME headers and encoded body-data */
|
||||
int mime_basicPart_putByteStream (mime_basicPart_t * in_pBasicPart,
|
||||
nsmail_outputstream_t *in_pOutput_stream);
|
||||
|
||||
/* Frees up the basic-part and all internal structures. User should set in_pBasicPart = NULL up on return*/
|
||||
int mime_basicPart_free_all (mime_basicPart_t * in_pBasicPart);
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/** COMPOSITE BODY PART TYPES **/
|
||||
/*************************************************************************/
|
||||
|
||||
/*=========================== MULTI PART =================================*/
|
||||
|
||||
/* Adds a file as basic part to the multi-part. */
|
||||
/* If in_pref_file_encoding > 0 attempts to use the encoding */
|
||||
/* for the file-attachment. If encoding is not valid for the */
|
||||
/* file-type overrides with the correct value. */
|
||||
int mime_multiPart_addFile (mime_multiPart_t * in_pMultiPart,
|
||||
char * in_pFileFullName,
|
||||
mime_encoding_type in_pref_file_encoding,
|
||||
int * out_pIndex_assigned);
|
||||
|
||||
/* Adds a basic part to the multi-part. */
|
||||
int mime_multiPart_addBasicPart (mime_multiPart_t * in_pMultiPart,
|
||||
mime_basicPart_t * in_pBasicPart,
|
||||
BOOLEAN in_fClone,
|
||||
int * out_pIndex_assigned);
|
||||
|
||||
/* Adds a message part to the multi-part. */
|
||||
int mime_multiPart_addMessagePart (mime_multiPart_t * in_pMultiPart,
|
||||
mime_messagePart_t * in_pMessagePart,
|
||||
BOOLEAN in_fClone,
|
||||
int * out_pIndex_assigned);
|
||||
|
||||
/* Adds a message part to the multi-part. */
|
||||
int mime_multiPart_addMultiPart (mime_multiPart_t * in_pMultiPart,
|
||||
mime_multiPart_t * in_pMultiPartToAdd,
|
||||
BOOLEAN in_fClone,
|
||||
int * out_pIndex_assigned);
|
||||
|
||||
/* Deletes the bodyPart at the requested index from this multi-part */
|
||||
int mime_multiPart_deletePart (mime_multiPart_t * in_pMultiPart,
|
||||
int in_index);
|
||||
|
||||
/* returns the count of the body parts in this multi-part */
|
||||
int mime_multiPart_getPartCount (mime_multiPart_t * in_pMultiPart,
|
||||
int * out_count);
|
||||
|
||||
/* returns the body part at the specified index */
|
||||
int mime_multiPart_getPart (mime_multiPart_t * in_pMultiPart,
|
||||
int in_index,
|
||||
mime_content_type * out_pContentType,
|
||||
void **out_ppTheBodyPart /* Client can cast based on pContentType */
|
||||
);
|
||||
|
||||
/* Writes out byte stream for this part with MIME headers and encoded body-data */
|
||||
int mime_multiPart_putByteStream (mime_multiPart_t * in_pMultiPart,
|
||||
nsmail_outputstream_t *in_pOutput_stream);
|
||||
|
||||
/* Frees up the multi-part and all internal structures. User should set in_pMultiPart = NULL up on return*/
|
||||
int mime_multiPart_free_all (mime_multiPart_t * in_pMultiPart);
|
||||
|
||||
|
||||
/*=========================== MESSAGE PART =================================*/
|
||||
|
||||
/* creates a message part from a message structure */
|
||||
int mime_messagePart_fromMessage (mime_message_t * in_pMessage,
|
||||
mime_messagePart_t ** out_ppMessagePart);
|
||||
|
||||
/* retrieves the message from the message part */
|
||||
int mime_messagePart_getMessage (mime_messagePart_t * in_pMessagePart,
|
||||
mime_message_t ** out_ppMessage);
|
||||
|
||||
/* deletes the mime message that is the body of this part */
|
||||
int mime_messagePart_deleteMessage (mime_messagePart_t * in_pMessagePart);
|
||||
|
||||
/* Sets the passed message as body of this message-part. It is error to set message
|
||||
when it is already set. */
|
||||
int mime_messagePart_setMessage (mime_messagePart_t * in_pMessagePart,
|
||||
mime_message_t * in_pMessage);
|
||||
|
||||
/* Writes out byte stream for this part to the output stream */
|
||||
int mime_messagePart_putByteStream (mime_messagePart_t * in_pMessagePart,
|
||||
nsmail_outputstream_t *in_pOutput_stream);
|
||||
|
||||
/* Frees up the message-part and all internal structures. User should set in_pMessagePart = NULL up on return*/
|
||||
int mime_messagePart_free_all (mime_messagePart_t * in_pMessagePart);
|
||||
|
||||
/*============================== MESSAGE ===================================*/
|
||||
|
||||
/* Creates a message given text-data and a file to attach. */
|
||||
/* The file-name supplied must be fully-qualified file-name. */
|
||||
/* If either in_pText or in_pFileFullName are NULL creates a */
|
||||
/* MIME message with the non-NULL one. It is an error to pass */
|
||||
/* NULL for both text and file-name parameters. */
|
||||
/* If in_pref_file_encoding > 0 attempts to use the encoding */
|
||||
/* for the file-attachment. If encoding is not valid for the */
|
||||
/* file-type overrides with the correct value. */
|
||||
/* Returns MIME_OK on success and an error code otherwise. */
|
||||
/* */
|
||||
/* Copies the data in in_pText. User responsible for freeing */
|
||||
/* in_pText up on return as needed. in_pFileFullName can also */
|
||||
/* be free'd up on return. */
|
||||
int mime_message_create (char * in_pText,
|
||||
char * in_pFileFullName,
|
||||
mime_encoding_type in_pref_file_encoding,
|
||||
mime_message_t ** out_ppMessage);
|
||||
|
||||
/* Adds a basic part as the body of the message. */
|
||||
/* Error if Body is already present. */
|
||||
/* Sets content-type accordingly. */
|
||||
int mime_message_addBasicPart (mime_message_t * in_pMessage,
|
||||
mime_basicPart_t * in_pBasicPart,
|
||||
BOOLEAN in_fClone);
|
||||
|
||||
/* Adds the message part as the body of the message. */
|
||||
/* Error if Body is already present. */
|
||||
/* Sets content-type accordingly. */
|
||||
int mime_message_addMessagePart (mime_message_t * in_pMessage,
|
||||
mime_messagePart_t * in_pMessagePart,
|
||||
BOOLEAN in_fClone);
|
||||
|
||||
/* Adds the multipart as the body of the message */
|
||||
/* Error if Body is already present. */
|
||||
/* Sets content-type accordingly. */
|
||||
int mime_message_addMultiPart (mime_message_t * in_pMessage,
|
||||
mime_multiPart_t * in_pMultiPart,
|
||||
BOOLEAN in_fClone);
|
||||
|
||||
/* Deletes the bodyPart that constitutes the body of this message */
|
||||
int mime_message_deleteBody (mime_message_t * pMessage);
|
||||
|
||||
/* returns the content_type of this message */
|
||||
int mime_message_getContentType (mime_message_t * in_pMessage,
|
||||
mime_content_type * out_content_type);
|
||||
|
||||
/* returns the content_subtype of this message */
|
||||
int mime_message_getContentSubType (mime_message_t * in_pMessage,
|
||||
char ** out_ppSubType);
|
||||
|
||||
/* returns the content_type params of this message */
|
||||
int mime_message_getContentTypeParams (mime_message_t * in_pMessage,
|
||||
char ** out_ppParams);
|
||||
|
||||
/* gets the value of the specified header.*/
|
||||
int mime_message_getHeader (mime_message_t * in_pMessage,
|
||||
char * in_pName,
|
||||
char ** out_ppValue);
|
||||
|
||||
|
||||
/* Returns the body part at the specified index */
|
||||
/* Client to free the returned body-part. See: */
|
||||
/* mime_basicPart_free_all() */
|
||||
/* mime_multiPart_free_all() and */
|
||||
/* mime_messagePart_free_all() */
|
||||
int mime_message_getBody (mime_message_t * pMessage,
|
||||
mime_content_type * out_pContentType,
|
||||
void ** out_ppTheBodyPart /* Client to cast this based on pContentType */
|
||||
);
|
||||
|
||||
/* Writes out byte stream for this part to the output stream */
|
||||
int mime_message_putByteStream (mime_message_t * in_pMessage,
|
||||
nsmail_outputstream_t *in_pOutput_stream);
|
||||
|
||||
/* Frees up the message and all internal structures. User should set in_pMessage = NULL up on return*/
|
||||
int mime_message_free_all (mime_message_t * in_pMessage);
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/** UTILITY ROUTINES */
|
||||
/*************************************************************************/
|
||||
|
||||
/* Builds and returns a mime_header given name and value */
|
||||
/* Returns NULL if either name or value is a NULL */
|
||||
mime_header_t * mime_header_new (char * in_pName, char * in_pValue);
|
||||
|
||||
/* Frees a mime_header_t structure. User should set in_pHdr = NULL up on return */
|
||||
int mime_header_free (mime_header_t * in_pHdr);
|
||||
|
||||
/* Encode a header string per RFC 2047. The encoded string can be used as the
|
||||
value of unstructured headers or in the comments section of structured headers.
|
||||
Below, encoding must be one of 'Q' or 'B' */
|
||||
int mime_encodeHeaderString (char * in_pString,
|
||||
char * in_charset, /* charset the input string is in */
|
||||
char in_encoding,
|
||||
char ** out_ppString);
|
||||
|
||||
/* If the input string is not encoded (per RFC 2047), returns the same.
|
||||
Otherwise, decodes and returns the decoded string */
|
||||
int mime_decodeHeaderString (char * in_pString,
|
||||
char ** out_ppString);
|
||||
|
||||
/* Base64 encodes the data from input_stream and writes to output_stream */
|
||||
int mime_encodeBase64 (nsmail_inputstream_t * in_pInput_stream,
|
||||
nsmail_outputstream_t * in_pOutput_stream);
|
||||
|
||||
/* QuotedPrintable encodes the data from input_stream and writes to output_stream */
|
||||
int mime_encodeQP (nsmail_inputstream_t * in_pInput_stream,
|
||||
nsmail_outputstream_t * in_pOutput_stream);
|
||||
|
||||
/* Base64 decodes the data from input_stream and writes to output_stream */
|
||||
int mime_decodeBase64 (nsmail_inputstream_t * in_pInput_stream,
|
||||
nsmail_outputstream_t * in_pOutput_stream);
|
||||
|
||||
/* QuotedPrintable decodes the data from input_stream and writes to output_stream */
|
||||
int mime_decodeQP (nsmail_inputstream_t * in_pInput_stream,
|
||||
nsmail_outputstream_t * in_pOutput_stream);
|
||||
|
||||
/* Returns file's MIME type info based on file's extension. */
|
||||
/* By default returns application/octet-stream. */
|
||||
/* If filename_ext is null returns application/octet-stream.*/
|
||||
int getFileMIMEType (char * in_pFilename_ext, file_mime_type * in_pFileMIMEType);
|
||||
|
||||
/* Allocates memory of specified size. Recommended to be used instead of
|
||||
malloc() for memory allocated to use with mime API. Avoids heap space
|
||||
conflicts when the application links with two or more libraries that
|
||||
support malloc / free. Internally simply invokes malloc() and hence the
|
||||
simantics and usage are identical to malloc(). */
|
||||
void * mime_malloc (unsigned int in_size);
|
||||
|
||||
/* To be used for freeing any memory allocated by the sdk.
|
||||
Example: Data buffer returned by mime_basicPart_getDataBuf().
|
||||
Another example: Memory allocated using mime_malloc().
|
||||
Internally simply invokes free() and hence the simantics and
|
||||
usage are identical to free().*/
|
||||
void mime_memfree (void * in_pMem);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MIME_H */
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
/**** mime_internal.h ****/
|
||||
|
||||
#ifndef MIME_INTERNAL_H
|
||||
#define MIME_INTERNAL_H
|
||||
|
||||
#include "nsmail.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define MIME_INFO 1
|
||||
#define MIME_HEADER 2
|
||||
#define MIME_XHEADER 3
|
||||
#define MIME_MESSAGE_DATA 4
|
||||
#define MIME_PARAM 5
|
||||
#define MIME_BOUNDARY 6
|
||||
#define MIME_CRLF 7
|
||||
|
||||
#define MIME_MESSAGE 20
|
||||
#define MIME_BASICPART MIME_CONTENT_TEXT
|
||||
#define MIME_MULTIPART MIME_CONTENT_MULTIPART
|
||||
#define MIME_MESSAGEPART MIME_CONTENT_MESSAGEPART
|
||||
#define MIME_PARSE_ALL 30
|
||||
#define MIME_MP_MAX_PARTS 50 /* Max 50 parts in a multi-part */
|
||||
#define BUFFER_INCREMENT 1024 /* buffer increases by this when it runs out of space */
|
||||
|
||||
|
||||
|
||||
/* used by parser to store general message information */
|
||||
typedef struct mimeInfo
|
||||
{
|
||||
int nType; /* mimeInfo type */
|
||||
int nContentType; /* current message content type */
|
||||
char *szName; /* name */
|
||||
char *szValue; /* value */
|
||||
Vector *pVectorParam; /* extra parameters */
|
||||
|
||||
} mimeInfo_t;
|
||||
|
||||
|
||||
typedef struct mime_mp_partInfo
|
||||
{
|
||||
mime_content_type nContentType; /* content type of the part */
|
||||
char *contentID; /* content ID */
|
||||
void *pThePart; /* pointer to actual part */
|
||||
|
||||
} mime_mp_partInfo_t;
|
||||
|
||||
|
||||
typedef struct mime_basicPart_internal
|
||||
{
|
||||
nsmail_inputstream_t *pTheDataStream; /* pointer to bodydata STREAM! */
|
||||
char *szMessageBody; /* message body data */
|
||||
long nMessageSize; /* size of decoded message body data */
|
||||
long nRawMessageSize; /* size of raw message body data */
|
||||
int nStartMessageDataIndex; /* start of message vector index */
|
||||
int nEndMessageDataIndex; /* end of message vector index */
|
||||
BOOLEAN bDecodedData; /* TRUE if data has been decoded */
|
||||
int nDynamicBufferSize; /* dynamic buffer size, only 4 callbacks */
|
||||
void *pUserObject; /* user object */
|
||||
|
||||
} mime_basicPart_internal_t;
|
||||
|
||||
|
||||
typedef struct mime_multiPart_internal
|
||||
{
|
||||
int nPartCount;
|
||||
mime_mp_partInfo_t partInfo [MIME_MP_MAX_PARTS];
|
||||
char *szBoundary;
|
||||
void *pUserObject;
|
||||
BOOLEAN fParsedPart;
|
||||
|
||||
} mime_multiPart_internal_t;
|
||||
|
||||
|
||||
typedef struct mime_messagePart_internal
|
||||
{
|
||||
struct mime_message *pTheMessage;
|
||||
void *pUserObject;
|
||||
|
||||
} mime_messagePart_internal_t;
|
||||
|
||||
|
||||
typedef struct mime_message_internal
|
||||
{
|
||||
mime_basicPart_t *pMimeBasicPart;
|
||||
mime_multiPart_t *pMimeMultiPart;
|
||||
mime_messagePart_t *pMimeMessagePart;
|
||||
|
||||
/* callback support */
|
||||
void *pUserObject; /* user object */
|
||||
struct mimeDataSink *pDataSink; /* user's datasink. NULL if not using dynamic parsing */
|
||||
|
||||
} mime_message_internal_t;
|
||||
|
||||
|
||||
|
||||
/* ---------------- BasicPart ---------------- */
|
||||
struct mime_basicPart * mime_basicPart_new();
|
||||
int mime_basicPart_free (struct mime_basicPart *p);
|
||||
struct mime_basicPart * mime_basicPart_clone (struct mime_basicPart *p);
|
||||
|
||||
mime_basicPart_internal_t * mime_basicPart_internal_new();
|
||||
int mime_basicPart_internal_free (mime_basicPart_internal_t *p);
|
||||
mime_basicPart_internal_t * mime_basicPart_internal_clone (mime_basicPart_internal_t *p);
|
||||
|
||||
|
||||
/* ---------------- Multi-part ---------------- */
|
||||
struct mime_multiPart * mime_multiPart_new();
|
||||
int mime_multiPart_free (struct mime_multiPart *p);
|
||||
struct mime_multiPart * mime_multiPart_clone (struct mime_multiPart *p);
|
||||
|
||||
int mime_multiPart_addPart (struct mime_multiPart *pMultiPart,
|
||||
void *pMessage,
|
||||
mime_content_type nContentType,
|
||||
int *index_assigned );
|
||||
|
||||
int mime_multiPart_addPart_clonable( struct mime_multiPart *pMultiPart,
|
||||
void * pMessage,
|
||||
mime_content_type nContentType,
|
||||
BOOLEAN clone,
|
||||
int * pIndex_assigned);
|
||||
|
||||
int mime_multiPart_getPart2 (struct mime_multiPart *pMultiPart,
|
||||
int index,
|
||||
char *contentID,
|
||||
mime_content_type *pContentType,
|
||||
void **ppTheBodyPart );
|
||||
|
||||
mime_multiPart_internal_t * mime_multiPart_internal_new();
|
||||
int mime_multiPart_internal_free (mime_multiPart_internal_t *p);
|
||||
mime_multiPart_internal_t * mime_multiPart_internal_clone (mime_multiPart_internal_t *p);
|
||||
|
||||
|
||||
/* ---------------- MessagePart ---------------- */
|
||||
struct mime_messagePart * mime_messagePart_new();
|
||||
int mime_messagePart_free (struct mime_messagePart *p);
|
||||
struct mime_messagePart * mime_messagePart_clone (struct mime_messagePart *p);
|
||||
BOOLEAN mime_messagePart_isEmpty (struct mime_messagePart *pMessage);
|
||||
|
||||
mime_messagePart_internal_t * mime_messagePart_internal_new();
|
||||
int mime_messagePart_internal_free (mime_messagePart_internal_t *p);
|
||||
mime_messagePart_internal_t * mime_messagePart_internal_clone (mime_messagePart_internal_t *p);
|
||||
|
||||
|
||||
/* ---------------- Message ---------------- */
|
||||
mime_message_internal_t * mime_message_internal_new();
|
||||
int mime_message_internal_free (mime_message_internal_t *p);
|
||||
mime_message_internal_t * mime_message_internal_clone (mime_message_internal_t *p);
|
||||
|
||||
|
||||
/* common constructor for both regular and dynamic parsing versions
|
||||
* pass in a NULL parameter means regular parsing
|
||||
* pass in a proper datasink to turn on dynamic parsing
|
||||
*/
|
||||
mime_message_t * mime_message_new (struct mimeDataSink *pDataSink);
|
||||
int mime_message_free (struct mime_message *p);
|
||||
struct mime_message * mime_message_clone (struct mime_message *p );
|
||||
int mime_message_addBasicPart_clonable (struct mime_message * pMessage,
|
||||
struct mime_basicPart * pBasicPart,
|
||||
BOOLEAN clone );
|
||||
int mime_message_addMultiPart_clonable (struct mime_message * pMessage,
|
||||
struct mime_multiPart * pMultiPart,
|
||||
BOOLEAN clone );
|
||||
int mime_message_addMessagePart_clonable (struct mime_message * pMessage,
|
||||
struct mime_messagePart * pMessagePart,
|
||||
BOOLEAN clone );
|
||||
BOOLEAN mime_message_isEmpty (struct mime_message *pMessage);
|
||||
|
||||
|
||||
/* ---------------- Header ---------------- */
|
||||
/*struct mime_header * mime_header_new (char *szName, char *szValue); */
|
||||
int mime_header_add (struct mime_header *pStart, char *szName, char *szValue);
|
||||
int mime_header_apend( mime_header_t *pStart, char *szName, char *szValue );
|
||||
/*int mime_header_free (struct mime_header *p); */
|
||||
int mime_header_freeAll (struct mime_header *pStart);
|
||||
struct mime_header * mime_header_clone (struct mime_header *pMimeHeader);
|
||||
|
||||
|
||||
|
||||
/* -------------- Generic -------------- */
|
||||
int mime_getStructType (void *pStruct);
|
||||
|
||||
void * mime_clone_any_part (void * pThePart, mime_content_type nContentType);
|
||||
|
||||
int mime_translateMimeInfo (char *name, char *value);
|
||||
int mime_translateMimeEncodingType (char *s);
|
||||
int mime_translateDispType (char *s, char **ppParam);
|
||||
|
||||
struct mimeInfo *mimeInfo_new();
|
||||
int mimeInfo_free (struct mimeInfo *p);
|
||||
int mimeInfo_init (struct mimeInfo *p, int nType1, char *szName1);
|
||||
int mimeInfo_init2 (struct mimeInfo *p, int nType1, char *szName1, char *szValue1);
|
||||
struct mimeInfo *mimeInfo_clone (struct mimeInfo *p);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MIME_INTERNAL_H */
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/*
|
||||
* mimeparser.h
|
||||
* carsonl, jan 8,97
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MIMEPARSER_H
|
||||
#define MIMEPARSER_H
|
||||
|
||||
#include "nsmail.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------------------------------------------- mimeDataSink ------------------------------------------- */
|
||||
|
||||
/* forward declaration */
|
||||
struct mime_basicPart;
|
||||
struct mime_multiPart;
|
||||
struct mime_messagePart;
|
||||
struct mime_message;
|
||||
|
||||
/* Forward declaration of the MIME data sink. */
|
||||
typedef struct mimeDataSink * mimeDataSinkPtr_t;
|
||||
|
||||
|
||||
typedef struct mimeDataSink
|
||||
{
|
||||
/* Client data Opaque to the API. allocated / freed and managed by the client*/
|
||||
void * pOpaqueData;
|
||||
|
||||
void (*header)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value ); /* mime headers */
|
||||
void (*addHeader)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value); /* additional header value */
|
||||
void (*endMessageHeader)(mimeDataSinkPtr_t pSink, void *pCallbackObject); /* end of message hdrs */
|
||||
void (*contentType)(mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentType ); /* content type */
|
||||
void (*contentSubType)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentSubType );/* content sub type */
|
||||
void (*contentTypeParams)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentTypeParams );/* content type parameters */
|
||||
void (*contentID)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentID ); /* content ID */
|
||||
void (*contentMD5)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentMD5 ); /* content MD5 */
|
||||
void (*contentDisposition)(mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentDisposition ); /* content disposition */
|
||||
void (*contentDispParams)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentDispParams ); /* content disposition parameters */
|
||||
void (*contentDescription)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentDescription );/* content description */
|
||||
void (*contentEncoding)(mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentEncoding ); /* content encoding */
|
||||
void *(*startMessage)(mimeDataSinkPtr_t pSink); /* signal start of message */
|
||||
void (*endMessage)(mimeDataSinkPtr_t pSink, void *pCallbackObject ); /* signal end of message */
|
||||
|
||||
void *(*startBasicPart)(mimeDataSinkPtr_t pSink); /* signal start of basicpart */
|
||||
void (*bodyData)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char bodyData[], int len ); /* message data */
|
||||
void (*endBasicPart)(mimeDataSinkPtr_t pSink, void *pCallbackObject ); /* signal end of basicpart */
|
||||
|
||||
void *(*startMultiPart)(mimeDataSinkPtr_t pSink); /* signal start of multipart */
|
||||
void (*boundary)(mimeDataSinkPtr_t pSink, void *pCallbackObject, char * boundary ); /**/
|
||||
void (*endMultiPart)(mimeDataSinkPtr_t pSink, void *pCallbackObject ); /* signal end of multipart */
|
||||
|
||||
void *(*startMessagePart)(mimeDataSinkPtr_t pSink); /* signal start of messagepart */
|
||||
void (*endMessagePart)(mimeDataSinkPtr_t pSink, void *pCallbackObject ); /* signal end of messagepart */
|
||||
|
||||
} mimeDataSink_t;
|
||||
|
||||
|
||||
|
||||
int mimeDataSink_new (mimeDataSink_t ** out_ppDataSink); /* constructor */
|
||||
void mimeDataSink_free (mimeDataSink_t ** in_ppDataSink); /* destructor */
|
||||
|
||||
|
||||
/* ---------------------------------------------- mimeParser ------------------------------------------- */
|
||||
|
||||
|
||||
struct mimeParser;
|
||||
|
||||
/* constructor */
|
||||
int mimeDynamicParser_new (mimeDataSink_t * in_pDataSink,
|
||||
struct mimeParser ** out_ppParser);
|
||||
|
||||
/* destructor */
|
||||
void mimeDynamicParser_free (struct mimeParser ** in_ppParser);
|
||||
|
||||
/* begin parsing new message */
|
||||
int beginDynamicParse (struct mimeParser * in_pParser);
|
||||
|
||||
/* parse more data (given as an input-stream) */
|
||||
int dynamicParseInputstream (struct mimeParser * in_pParser,
|
||||
struct nsmail_inputstream *in_pInput);
|
||||
|
||||
/* parse more data (given as a data-buffer) */
|
||||
int dynamicParse (struct mimeParser * in_pParser, char * in_pData, int in_nLen);
|
||||
|
||||
/* Tell the parser no more data to parse */
|
||||
int endDynamicParse (struct mimeParser * in_pParser);
|
||||
|
||||
/* Parse an entire message in one shot. Data given as an input-stream */
|
||||
int parseEntireMessageInputstream (struct nsmail_inputstream * in_pInput,
|
||||
struct mime_message ** out_ppMimeMessage);
|
||||
|
||||
/* Parse an entire message in one shot. Data given as data-buffer */
|
||||
int parseEntireMessage (char * in_pData, int in_nLen,
|
||||
struct mime_message ** in_ppMimeMessage);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MIMEPARSER_H */
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* mimeparser_internal.h
|
||||
* carsonl, jan 8,97
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MIMEPARSER_INTERNAL_H
|
||||
#define MIMEPARSER_INTERNAL_H
|
||||
|
||||
#include "nsmail.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define BOOLEAN int
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_MULTIPART 40 /* maximum number of multipart per message */
|
||||
#define START_BOUNDARY 11 /* start of boundary */
|
||||
#define END_BOUNDARY 21 /* end of boundary */
|
||||
#define NOT_A_BOUNDARY 31 /* not a boundary */
|
||||
#define UNINITIALIZED -1 /* uninitialized */ /* don't modify */
|
||||
#define BUFFER_SIZE 1024 /* base64 buffer size */
|
||||
#define SUBTYPE_RFC822 1
|
||||
#define SUBTYPE_EXTERNAL_BODY 2
|
||||
|
||||
|
||||
|
||||
typedef struct currentParent
|
||||
{
|
||||
int type;
|
||||
void *p;
|
||||
|
||||
} currentParent_t;
|
||||
|
||||
|
||||
|
||||
typedef struct mimeParser
|
||||
{
|
||||
/* parser related */
|
||||
Vector *pVectorMimeInfo; /* mimeInfo, preparse storage */
|
||||
Vector *pVectorMessageData; /* message data */
|
||||
int bStartData; /* TRUE if next line is message data */
|
||||
|
||||
/* api related */
|
||||
mime_content_type nMessageType; /* message type for entire message */
|
||||
mime_content_type nCurrentMessageType; /* for current message */
|
||||
void *pCurrentMessage; /* current message structure */
|
||||
mime_message_t *pMimeMessage; /* mimeMessage structure where all data will reside */
|
||||
BOOLEAN bDeleteMimeMessage; /* FALSE if you want the data to persist outside the parser */
|
||||
int nEmptyLineNo; /* number of consecutive blank lines */
|
||||
|
||||
/* callback fields */
|
||||
mimeDataSink_t *pDataSink; /* user's datasink, NULL for no callbacks */
|
||||
char *pLeftoverBuffer; /* base64 left over buffer */
|
||||
char *pInputBuffer; /* base64 input buffer */
|
||||
int nLeftoverBytes; /* base64 left over bytes */
|
||||
int out_byte; /* base64 output byte */
|
||||
int out_bits; /* base64 output bits */
|
||||
BOOLEAN bParseEntireFile; /* TRUE to parse entire file, which means no dynamic parsing, */
|
||||
/* data is treated as the entire mimeMessage each time it's parsed */
|
||||
int nLineType; /* line type */
|
||||
|
||||
int QPNoOfLeftOverBytes; /* number of lefted over QP bytes */
|
||||
char achQPLeftOverBytes[4]; /* lefted over QP bytes */
|
||||
|
||||
currentParent_t aCurrentParent[MAX_MULTIPART]; /* current message parent */
|
||||
int nCurrentParent; /* current parent index */
|
||||
mime_message_t *pCurrentMimeMessage; /* current mime message */
|
||||
|
||||
BOOLEAN bDecodeData; /* TRUE to turn on decoding before sending it to user */
|
||||
BOOLEAN bLocalStorage; /* TRUE to let parser manage storage */
|
||||
|
||||
mime_message_t *pNextMimeMessage;
|
||||
int nLastBoundry;
|
||||
Vector *pMimeInfoQueue;
|
||||
Vector *pHeaderQueue;
|
||||
BOOLEAN bQPEncoding;
|
||||
BOOLEAN bReadCR;
|
||||
currentParent_t tHeaderParent;
|
||||
currentParent_t tNextHeaderParent;
|
||||
void *szPreviousHeaderName;
|
||||
int nMessagePartSubType;
|
||||
BOOLEAN fSeenBoundary;
|
||||
BOOLEAN fEndMessageHeader;
|
||||
|
||||
} mimeParser_t;
|
||||
|
||||
|
||||
|
||||
/* ------------------- internal routines ---------------------- */
|
||||
|
||||
mimeParser_t *mimeParser_new_internal(); /* internal constructor */
|
||||
mimeParser_t *mimeParser_new_internal2( mime_message_t * pMimeMessage ); /* internal constructor */
|
||||
int mimeParser_checkForLineType( mimeParser_t *pp, char *s, int len ); /* check for line type */
|
||||
int mimeParser_parseLine( mimeParser_t *pp, char *s, int len, BOOLEAN lastLine ); /* parse a line */
|
||||
|
||||
int mimeParser_parseMimeInfo( mimeParser_t *pp, mimeInfo_t *pmi ); /* parse mimeInfo structure */
|
||||
mime_content_type mimeParser_nGetContentType( char *s, char *szSubtype, char **ppParam ); /* get content type */
|
||||
char *mimeParser_parseForBoundary( char *s ); /* parse a line for boundary */
|
||||
int nNewMessageStructure( mimeParser_t *p, char *s ); /* create a new message structure */
|
||||
int nAddMessage( mimeParser_t *p, void *pMessage, mime_content_type nContentType ); /* add a new message */
|
||||
|
||||
int mimeParser_setData( mimeParser_t *p, mimeInfo_t *pMimeInfo ); /* extra data from mimeInfo structure and set fields */
|
||||
int mimeParser_parseMimeMessage( mimeParser_t *p, nsmail_inputstream_t *pInput, char *pData, int nLen, int nContentType, void **ppReturn ); /* core parser routine */
|
||||
void decodeDataBuffer( mimeParser_t *p ); /* decode message data */
|
||||
char *mimeParser_getCurrentBoundary( mimeParser_t *p ); /* get current boundary */
|
||||
int mimeParser_bIsStartBoundary( mimeParser_t *p, char *s ); /* TRUE if current line is a starting boundary */
|
||||
|
||||
int mimeParser_nBoundaryCheck( mimeParser_t *p, char *s, int len ); /* type of boundary */
|
||||
void setUserObject( void *pMessage, int nType, void *pUserObject ); /* set user object */
|
||||
void *getUserObject( void *pMessage, int nType ); /* get user object */
|
||||
void *getUserObject2 ( void *pMessage, int nType ); /* get user object version 2 */
|
||||
BOOLEAN IsLocalStorage( mimeParser_t *p ); /* TRUE for local storage, default to TRUE for non callbacks */
|
||||
BOOLEAN IsDecodeData( mimeParser_t *p ); /* TRUE to decode message data, default to TRUE */
|
||||
|
||||
void saveBodyData( mimeParser_t *p, char *pBuffer, int nLen, mime_basicPart_t *pMimeBasicPart ); /* save body data to message structure */
|
||||
char *decodeBase64LeftOverBytes( int out_bits, int out_byte, int *pLen ); /* base64, leftover decoding */
|
||||
|
||||
int nGetCurrentParentType( mimeParser_t *p );
|
||||
void *pGetCurrentParent( mimeParser_t *p );
|
||||
void vAddCurrentParent( mimeParser_t *p, int nType, void *pParent );
|
||||
void mimeParser_unwindCurrentBoundary( mimeParser_t *p, char *s, BOOLEAN bDelete );
|
||||
|
||||
void addHeader( mimeParser_t *p, char *name, char *value, BOOLEAN addToQueue );
|
||||
BOOLEAN checkForEmptyMessages( mimeParser_t *p, void *pMessage, int type );
|
||||
int setCurrentMessage( mimeParser_t *p, void *pMessage, int nMessageType );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MIMEPARSER_INTERNAL_H */
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/*
|
||||
* nsmail_inputstream.h
|
||||
* prasad jan 8,98
|
||||
*
|
||||
* basic inputstream implementation for file i/o
|
||||
*/
|
||||
|
||||
#ifndef NSMAIL_INPUTSTREAM_H
|
||||
#define NSMAIL_INPUTSTREAM_H
|
||||
|
||||
#include "nsmail.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* carson's additions -------------------------------------- */
|
||||
|
||||
|
||||
typedef struct fileRock /* my custom rock for persisting to a file */
|
||||
{
|
||||
char *filename;
|
||||
FILE *f;
|
||||
char *buffer;
|
||||
int offset;
|
||||
|
||||
} fileRock_t;
|
||||
|
||||
|
||||
|
||||
int fileRock_new( char *filename, fileRock_t **ppRock ); /* constructor */
|
||||
void fileRock_free( fileRock_t **ppRock ); /* destructor */
|
||||
int fileRock_read( void *pRock, char *buf, unsigned size ); /* read */
|
||||
void fileRock_rewind( void *pRock ); /* rewind */
|
||||
void fileRock_close( void *pRock ); /* close */
|
||||
|
||||
int nsmail_inputstream_new( char *filename, nsmail_inputstream_t **ppInput ); /* constructor */
|
||||
void nsmail_inputstream_free( nsmail_inputstream_t **ppInput ); /* destructor */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* NSMAIL_INPUTSTREAM_H */
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/*
|
||||
* util.h
|
||||
* prasad
|
||||
* carsonl, oct 10,97
|
||||
*/
|
||||
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define null NULL
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#define LOG_FILE "error.log"
|
||||
#define BASE64_NOFIT -1
|
||||
#define BASE64_SOMELEFT -2
|
||||
|
||||
|
||||
|
||||
/* log structure */
|
||||
typedef struct errorLog
|
||||
{
|
||||
FILE *m_pFile; /* file pointer */
|
||||
char m_achFilename[128]; /* log filename */
|
||||
BOOLEAN m_bActive; /* TRUE if you want output to log file */
|
||||
|
||||
} errorLog_t;
|
||||
|
||||
|
||||
typedef struct buf_instream_tracker
|
||||
{
|
||||
char * pDataBuf; /* data buffer */
|
||||
long total_size; /* totoal buffer size */
|
||||
long bytes_read; /* number of bytes read */
|
||||
char * pNext;
|
||||
|
||||
} buf_instream_tracker_t;
|
||||
|
||||
|
||||
typedef struct file_instream_tracker
|
||||
{
|
||||
FILE * fp;
|
||||
char * file_name;
|
||||
long bytes_read;
|
||||
|
||||
} file_instream_tracker_t;
|
||||
|
||||
typedef struct file_outstream_tracker
|
||||
{
|
||||
FILE * fp;
|
||||
char * file_name;
|
||||
long bytes_written;
|
||||
|
||||
} file_outstream_tracker_t;
|
||||
|
||||
|
||||
|
||||
/* string utilities */
|
||||
int bStringEquals( char *s1, char *s2 ); /* equals */
|
||||
char *szTrim( char *s ); /* all trim */
|
||||
char *szRTrim( char *s ); /* right trim */
|
||||
char *szLTrim( char *s ); /* left trim */
|
||||
char *szStringClone( char *s ); /* clone */
|
||||
BOOLEAN bIsBasicPart( int nType ); /* test if type is a basicpart */
|
||||
|
||||
|
||||
/* base64 utilities */
|
||||
int decodeBase64 (char *szInput, char *szOutput,
|
||||
int nInputBufferSize, int nMaxBufferSize,
|
||||
int *pOut_byte, int *pOut_bits);
|
||||
|
||||
int decodeBase64Vector (int nStart, int nEnd, Vector *v,
|
||||
char **szDecodedBuffer, int nRawMessageSize,
|
||||
int *pOut_byte, int *pOut_bits );
|
||||
|
||||
/* quoted printable utilities */
|
||||
int decodeQP (char *szInput, char *szOutput, int nMaxBufferSize);
|
||||
int decodeQPVector (int nStart, int nEnd, Vector *v,
|
||||
char **szDecodedBuffer, int nRawMessageSize, char *szLeftOverBytes,
|
||||
int *nNoOfLeftOverBytes);
|
||||
|
||||
/* misc */
|
||||
char *decodeHeader (char *szInputString);
|
||||
int nConvertHexToDec (int nFirstByte, int nSecondByte);
|
||||
char * generateBoundary();
|
||||
int append_str (char * dest, char * src);
|
||||
|
||||
/* If s1 equals s2, returns TRUE, FALSE otherwise. */
|
||||
BOOLEAN equalsIgnoreCase (char * s1, char * s2);
|
||||
|
||||
char * getFileExtn (char * fileName);
|
||||
char * getFileShortName (char * fileName);
|
||||
|
||||
/* inputstream utilities */
|
||||
long get_inputstream_size (struct nsmail_inputstream * pTheStream);
|
||||
int buf_instream_create (char * pDataBuf, long data_size,
|
||||
struct nsmail_inputstream ** ppRetInputStream);
|
||||
int buf_instream_read (void * rock, char *buf, int size);
|
||||
void buf_instream_rewind (void * rock);
|
||||
void buf_instream_close (void * rock);
|
||||
|
||||
int file_instream_create (char * fileName, struct nsmail_inputstream ** ppRetInputStream);
|
||||
void file_instream_close (void * rock);
|
||||
void file_instream_rewind (void * rock);
|
||||
int file_instream_read (void * rock, char *buf, int size);
|
||||
|
||||
int file_outstream_create (char * fileName, nsmail_outputstream_t ** ppRetOutputStream);
|
||||
void file_outstream_close (void * rock);
|
||||
|
||||
|
||||
/* log utilities */
|
||||
errorLog_t *errorLog_new( char *szFilename ); /* constructor */
|
||||
void errorLog_free( errorLog_t *pLog ); /* destructor, calls closeLog() automatically */
|
||||
void initErrorLog( char *szFilename ); /* init */
|
||||
void closeErrorLog(); /* close log */
|
||||
void errorLog (char *szOwner, int nError); /* report error to log */
|
||||
void errorLog2 (errorLog_t *pLog, char *szOwner, int nError); /* report error to log */
|
||||
void errorLogMsg( char *szMsg ); /* display custom error message */
|
||||
void errorLogMsg2 (errorLog_t *pLog, char *szMsg); /* display custom error message */
|
||||
void errorLogOn(); /* turn log on */
|
||||
void errorLogOff(); /* turn log off */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* UTIL_H */
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/* vector.h
|
||||
*
|
||||
* carsonl, oct 1,97
|
||||
*/
|
||||
|
||||
#ifndef VECTOR_H
|
||||
#define VECTOR_H
|
||||
|
||||
#include "nsmail.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define INITIAL_SIZE 16
|
||||
#define VECTOR_TYPE_STRING 1
|
||||
#define VECTOR_TYPE_MIMEINFO 2
|
||||
|
||||
|
||||
/* private */
|
||||
typedef struct Vector
|
||||
{
|
||||
int nMaxSize; /* max size */
|
||||
int nSize; /* current size */
|
||||
int nType; /* content type */
|
||||
void **pt; /* pointer to object */
|
||||
|
||||
} Vector;
|
||||
|
||||
|
||||
Vector *Vector_new( int nType1 );
|
||||
int Vector_free( Vector *v );
|
||||
int Vector_size( Vector *v );
|
||||
int Vector_addElement( Vector *v, void *pObject, int nObjectSize );
|
||||
void *Vector_elementAt( Vector *v, int nIndex );
|
||||
Vector *Vector_clone( Vector *v );
|
||||
int Vector_deleteAll( Vector *v );
|
||||
void *Vector_deleteLastElement (Vector *v);
|
||||
void *Vector_popLastElement (Vector *v);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* VECTOR_H */
|
|
@ -0,0 +1,76 @@
|
|||
|
||||
# GNU Makefile for MIME
|
||||
#
|
||||
|
||||
MSGSDK_ROOT = ../../../../C
|
||||
CONFIG_ROOT = ../../../../CONFIG
|
||||
BUILD_ROOT = ../../../../C
|
||||
MKDIR = mkdir -p
|
||||
|
||||
LIBDIR = $(OBJDIR)/lib
|
||||
OBJDEST = $(LIBDIR)/libmime
|
||||
LIBNAME = libmime
|
||||
|
||||
include $(CONFIG_ROOT)/msgsdk.mk
|
||||
|
||||
LOCAL_INCDIR = ../include
|
||||
GLOBAL_INCDIR = ../../../include
|
||||
CFLAGS += -I$(LOCAL_INCDIR) -I$(GLOBAL_INCDIR)
|
||||
|
||||
ifeq ($(ARCH), AIX)
|
||||
LIBNAME = libmime
|
||||
DLL_SUFFIX = a
|
||||
endif
|
||||
|
||||
|
||||
#
|
||||
# Build full target library file and path
|
||||
#
|
||||
ifeq ($(ARCH), AIX)
|
||||
LIBTARGET = $(addsuffix _shr.a, \
|
||||
$(addprefix $(LIBDIR)/, $(LIBNAME)))
|
||||
else
|
||||
LIBTARGET = $(addsuffix .$(DLL_SUFFIX), \
|
||||
$(addprefix $(LIBDIR)/, $(LIBNAME)))
|
||||
endif
|
||||
|
||||
MIME_OBJS= mime.o mime_internal.o mimeparser.o util.o vector.o mimeDataSink.o
|
||||
|
||||
OBJS = $(addprefix $(OBJDEST)/, $(MIME_OBJS))
|
||||
|
||||
all: $(OBJDEST) $(LIBDIR) $(LIBTARGET)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDEST)*
|
||||
rm -rf $(OBJDEST)/*
|
||||
|
||||
$(LIBDIR):
|
||||
echo creating $(LIBDIR)
|
||||
$(MKDIR) $(LIBDIR)
|
||||
|
||||
$(OBJDEST):
|
||||
echo creating $(OBJDEST)
|
||||
$(MKDIR) $(OBJDEST)
|
||||
|
||||
ifeq ($(ARCH), WINNT)
|
||||
$(LIBTARGET): $(OBJS)
|
||||
$(PURIFY) $(LINK_DLL) /DEF:mime.def $(OBJS)
|
||||
else
|
||||
ifeq ($(ARCH), AIX)
|
||||
$(LIBTARGET): $(OBJS)
|
||||
$(LD) -o $(LIBTARGET) $(OBJS) $(DLL_LDFLAGS) -bE:mime.exp -lc_r
|
||||
else
|
||||
ifeq ($(ARCH), IRIX)
|
||||
$(LIBTARGET): $(OBJS)
|
||||
$(LD) $(DLL_LDFLAGS) -exports_file mime.exp -soname $(LIBNAME).so -o $(LIBTARGET) $(OBJS)
|
||||
else
|
||||
ifeq ($(ARCH), IRIX64)
|
||||
$(LIBTARGET): $(OBJS)
|
||||
$(LD) $(DLL_LDFLAGS) -exports_file mime.exp -soname $(LIBNAME).so -o $(LIBTARGET) $(OBJS)
|
||||
else
|
||||
$(LIBTARGET): $(OBJS)
|
||||
$(LD) $(DLL_LDFLAGS) -o $(LIBTARGET) $(OBJS)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,87 @@
|
|||
LIBRARY LIBMIME
|
||||
DESCRIPTION "MIME Client exported functions."
|
||||
EXPORTS
|
||||
mime_basicPart_setDataStream @1
|
||||
mime_basicPart_setDataBuf @2
|
||||
mime_basicPart_deleteData @3
|
||||
mime_basicPart_getSize @4
|
||||
mime_basicPart_getDataStream @5
|
||||
mime_basicPart_getDataBuf @6
|
||||
mime_basicPart_putByteStream @7
|
||||
mime_basicPart_free_all @8
|
||||
mime_multiPart_addBasicPart @9
|
||||
mime_multiPart_addMessagePart @10
|
||||
mime_multiPart_addMultiPart @11
|
||||
mime_multiPart_deletePart @12
|
||||
mime_multiPart_getPartCount @13
|
||||
mime_multiPart_getPart @14
|
||||
mime_multiPart_putByteStream @15
|
||||
mime_multiPart_free_all @16
|
||||
mime_messagePart_fromMessage @17
|
||||
mime_messagePart_getMessage @18
|
||||
mime_messagePart_deleteMessage @19
|
||||
mime_messagePart_setMessage @20
|
||||
mime_messagePart_putByteStream @21
|
||||
mime_messagePart_free_all @22
|
||||
mime_message_new @23
|
||||
mime_message_addBasicPart @24
|
||||
mime_message_addMessagePart @25
|
||||
mime_message_addMultiPart @26
|
||||
mime_message_deleteBody @27
|
||||
mime_message_getContentType @28
|
||||
mime_message_getContentSubType @29
|
||||
mime_message_getContentTypeParams @30
|
||||
mime_message_getBody @31
|
||||
mime_message_putByteStream @32
|
||||
mime_message_free_all @33
|
||||
mime_encodeHeaderString @34
|
||||
mime_decodeHeaderString @35
|
||||
mime_encodeBase64 @36
|
||||
mime_encodeQP @37
|
||||
mime_decodeBase64 @38
|
||||
mime_decodeQP @39
|
||||
mimeDynamicParser_new @40
|
||||
mimeDynamicParser_free @41
|
||||
beginDynamicParse @42
|
||||
dynamicParseInputstream @43
|
||||
dynamicParse @44
|
||||
endDynamicParse @45
|
||||
parseEntireMessageInputstream @46
|
||||
parseEntireMessage @47
|
||||
decodeBase64 @48
|
||||
decodeQP @49
|
||||
decodeHeader @50
|
||||
nConvertHexToDec @51
|
||||
generateBoundary @52
|
||||
get_inputstream_size @53
|
||||
buf_instream_create @54
|
||||
buf_instream_read @55
|
||||
buf_instream_rewind @56
|
||||
buf_instream_close @57
|
||||
file_instream_create @58
|
||||
file_instream_close @59
|
||||
file_instream_rewind @60
|
||||
file_instream_read @61
|
||||
append_str @62
|
||||
errorLog_new @63
|
||||
errorLog_free @64
|
||||
initErrorLog @65
|
||||
closeErrorLog @66
|
||||
errorLog @67
|
||||
errorLog2 @68
|
||||
errorLogMsg @69
|
||||
errorLogMsg2 @70
|
||||
errorLogOn @71
|
||||
errorLogOff @72
|
||||
file_outstream_create @73
|
||||
mime_message_create @74
|
||||
file_outstream_close @75
|
||||
mime_multiPart_addFile @76
|
||||
mimeDataSink_new @77
|
||||
mimeDataSink_free @78
|
||||
mime_message_getHeader @79
|
||||
mime_header_new @80
|
||||
mime_header_free @81
|
||||
mime_malloc @82
|
||||
mime_memfree @83
|
||||
getFileMIMEType @84
|
|
@ -0,0 +1,84 @@
|
|||
mime_basicPart_setDataStream
|
||||
mime_basicPart_setDataBuf
|
||||
mime_basicPart_deleteData
|
||||
mime_basicPart_getSize
|
||||
mime_basicPart_getDataStream
|
||||
mime_basicPart_getDataBuf
|
||||
mime_basicPart_putByteStream
|
||||
mime_basicPart_free_all
|
||||
mime_multiPart_addBasicPart
|
||||
mime_multiPart_addMessagePart
|
||||
mime_multiPart_addMultiPart
|
||||
mime_multiPart_deletePart
|
||||
mime_multiPart_getPartCount
|
||||
mime_multiPart_getPart
|
||||
mime_multiPart_putByteStream
|
||||
mime_multiPart_free_all
|
||||
mime_messagePart_fromMessage
|
||||
mime_messagePart_getMessage
|
||||
mime_messagePart_deleteMessage
|
||||
mime_messagePart_setMessage
|
||||
mime_messagePart_putByteStream
|
||||
mime_messagePart_free_all
|
||||
mime_message_new
|
||||
mime_message_addBasicPart
|
||||
mime_message_addMessagePart
|
||||
mime_message_addMultiPart
|
||||
mime_message_deleteBody
|
||||
mime_message_getContentType
|
||||
mime_message_getContentSubType
|
||||
mime_message_getContentTypeParams
|
||||
mime_message_getBody
|
||||
mime_message_putByteStream
|
||||
mime_message_free_all
|
||||
mime_encodeHeaderString
|
||||
mime_decodeHeaderString
|
||||
mime_encodeBase64
|
||||
mime_encodeQP
|
||||
mime_decodeBase64
|
||||
mime_decodeQP
|
||||
mimeDynamicParser_new
|
||||
mimeDynamicParser_free
|
||||
beginDynamicParse
|
||||
dynamicParseInputstream
|
||||
dynamicParse
|
||||
endDynamicParse
|
||||
parseEntireMessageInputstream
|
||||
parseEntireMessage
|
||||
decodeBase64
|
||||
decodeQP
|
||||
decodeHeader
|
||||
nConvertHexToDec
|
||||
generateBoundary
|
||||
get_inputstream_size
|
||||
buf_instream_create
|
||||
buf_instream_read
|
||||
buf_instream_rewind
|
||||
buf_instream_close
|
||||
file_instream_create
|
||||
file_instream_close
|
||||
file_instream_rewind
|
||||
file_instream_read
|
||||
append_str
|
||||
errorLog_new
|
||||
errorLog_free
|
||||
initErrorLog
|
||||
closeErrorLog
|
||||
errorLog
|
||||
errorLog2
|
||||
errorLogMsg
|
||||
errorLogMsg2
|
||||
errorLogOn
|
||||
errorLogOff
|
||||
file_outstream_create
|
||||
mime_message_create
|
||||
file_outstream_close
|
||||
mime_multiPart_addFile
|
||||
mimeDataSink_new
|
||||
mimeDataSink_free
|
||||
mime_message_getHeader
|
||||
mime_header_new
|
||||
mime_header_free
|
||||
mime_malloc
|
||||
mime_memfree
|
||||
getFileMIMEType
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* mimeparser.c
|
||||
* carsonl, Jan 8,97
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "nsmail.h"
|
||||
#include "vector.h"
|
||||
#include "util.h"
|
||||
#include "mime.h"
|
||||
#include "mime_internal.h"
|
||||
#include "mimeparser.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 7,97
|
||||
* default do nothing callback methods
|
||||
*
|
||||
* NOTE : by default all callbacks do nothing, it's up to the user to override the methods they're interested in
|
||||
*/
|
||||
void mimeDataSink_header(mimeDataSink_t *pSink, void *pCallbackObject, char *name, char *value ) { return; }
|
||||
void mimeDataSink_contentType(mimeDataSink_t *pSink, void *pCallbackObject, int nContentType ) { return; }
|
||||
void mimeDataSink_contentSubType(mimeDataSink_t *pSink, void *pCallbackObject, char * contentSubType ) { return; }
|
||||
void mimeDataSink_contentTypeParams(mimeDataSink_t *pSink, void *pCallbackObject, char * contentTypeParams ) { return; }
|
||||
void mimeDataSink_contentID(mimeDataSink_t *pSink, void *pCallbackObject, char * contentID ) { return; }
|
||||
void mimeDataSink_contentMD5(mimeDataSink_t *pSink, void *pCallbackObject, char * contentMD5 ) { return; }
|
||||
void mimeDataSink_contentDisposition(mimeDataSink_t *pSink, void *pCallbackObject, int nContentDisposition ) { return; }
|
||||
void mimeDataSink_contentDispParams(mimeDataSink_t *pSink, void *pCallbackObject, char * contentDispParams ) { return; }
|
||||
void mimeDataSink_contentDescription(mimeDataSink_t *pSink, void *pCallbackObject, char * contentDescription ) { return; }
|
||||
void mimeDataSink_contentEncoding(mimeDataSink_t *pSink, void *pCallbackObject, int nContentEncoding ) { return; }
|
||||
|
||||
void *mimeDataSink_startMessage(mimeDataSink_t *pSink) { return NULL; }
|
||||
void mimeDataSink_endMessage(mimeDataSink_t *pSink, void *pCallbackObject ) { return; }
|
||||
|
||||
void *mimeDataSink_startBasicPart(mimeDataSink_t *pSink) { return NULL; }
|
||||
void mimeDataSink_bodyData(mimeDataSink_t *pSink, void *pCallbackObject, char bodyData[], int len ) { return; }
|
||||
void mimeDataSink_endBasicPart(mimeDataSink_t *pSink, void *pCallbackObject ) { return; }
|
||||
|
||||
void *mimeDataSink_startMultiPart(mimeDataSink_t *pSink) { return NULL; }
|
||||
void mimeDataSink_boundary(mimeDataSink_t *pSink, void *pCallbackObject, char * boundary ) { return; }
|
||||
void mimeDataSink_endMultiPart(mimeDataSink_t *pSink, void *pCallbackObject ) { return; }
|
||||
|
||||
void *mimeDataSink_startMessagePart(mimeDataSink_t *pSink) { return NULL; }
|
||||
void mimeDataSink_endMessagePart(mimeDataSink_t *pSink, void *pCallbackObject ) { return; }
|
||||
|
||||
void mimeDataSink_addHeader(mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value) { return; }
|
||||
void mimeDataSink_endMessageHeader(mimeDataSinkPtr_t pSink, void *pCallbackObject) { return; }
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 7,97
|
||||
* datasink constructor
|
||||
*
|
||||
* parameter : none
|
||||
*
|
||||
* returns : instance of newly created datasink
|
||||
*
|
||||
* NOTE : by default all callbacks do nothing, it's up to the user to override the methods they're interested in
|
||||
*/
|
||||
int mimeDataSink_new( mimeDataSink_t **pp )
|
||||
{
|
||||
if ( pp == NULL )
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
|
||||
*pp = (mimeDataSink_t *) malloc( sizeof( mimeDataSink_t ) );
|
||||
|
||||
if ( *pp == NULL )
|
||||
{
|
||||
return MIME_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
(*pp)->pOpaqueData = NULL;
|
||||
(*pp)->header = &mimeDataSink_header;
|
||||
(*pp)->addHeader = &mimeDataSink_addHeader;
|
||||
(*pp)->endMessageHeader = &mimeDataSink_endMessageHeader;
|
||||
(*pp)->contentType = &mimeDataSink_contentType;
|
||||
(*pp)->contentSubType = &mimeDataSink_contentSubType;
|
||||
(*pp)->contentTypeParams = &mimeDataSink_contentTypeParams;
|
||||
(*pp)->contentID = &mimeDataSink_contentID;
|
||||
(*pp)->contentMD5 = &mimeDataSink_contentMD5;
|
||||
(*pp)->contentDisposition = &mimeDataSink_contentDisposition;
|
||||
(*pp)->contentDispParams = &mimeDataSink_contentDispParams;
|
||||
(*pp)->contentDescription = &mimeDataSink_contentDescription;
|
||||
(*pp)->contentEncoding = &mimeDataSink_contentEncoding;
|
||||
|
||||
(*pp)->startMessage = &mimeDataSink_startMessage;
|
||||
(*pp)->endMessage = &mimeDataSink_endMessage;
|
||||
|
||||
(*pp)->startBasicPart = &mimeDataSink_startBasicPart;
|
||||
(*pp)->bodyData = &mimeDataSink_bodyData;
|
||||
(*pp)->endBasicPart = &mimeDataSink_endBasicPart;
|
||||
|
||||
(*pp)->startMultiPart = &mimeDataSink_startMultiPart;
|
||||
(*pp)->boundary = &mimeDataSink_boundary;
|
||||
(*pp)->endMultiPart = &mimeDataSink_endMultiPart;
|
||||
|
||||
(*pp)->startMessagePart = &mimeDataSink_startMessagePart;
|
||||
(*pp)->endMessagePart = &mimeDataSink_endMessagePart;
|
||||
|
||||
return MIME_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 7,97
|
||||
* datasink destructor
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* mimeDataSink_t *p : instance of datasink
|
||||
*
|
||||
* returns : nothing
|
||||
*/
|
||||
void mimeDataSink_free( mimeDataSink_t **pp )
|
||||
{
|
||||
if ( pp != NULL && *pp != NULL )
|
||||
{
|
||||
free( *pp );
|
||||
*pp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* nsmail_inputstream.c
|
||||
* carsonl, jan 8,98
|
||||
*
|
||||
* simple routines for a file inputstream implementation
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "nsmail.h"
|
||||
#include "vector.h"
|
||||
#include "util.h"
|
||||
#include "mime.h"
|
||||
#include "mime_internal.h"
|
||||
#include "mimeparser.h"
|
||||
#include "mimeparser_internal.h"
|
||||
#include <nsmail_inputstream.h>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* constructor
|
||||
*
|
||||
* parameter : filename
|
||||
*
|
||||
* returns : new rock
|
||||
*/
|
||||
int fileRock_new( char *filename, fileRock_t **ppRock )
|
||||
{
|
||||
if ( filename == NULL || ppRock == NULL )
|
||||
{
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
*ppRock = (fileRock_t *) malloc( sizeof( fileRock_t ) );
|
||||
|
||||
if ( *ppRock == NULL )
|
||||
{
|
||||
return MIME_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
(*ppRock)->filename = filename;
|
||||
(*ppRock)->offset = 0;
|
||||
|
||||
(*ppRock)->buffer = (char *) malloc( BUFFER_SIZE );
|
||||
|
||||
if ( (*ppRock)->buffer == NULL )
|
||||
{
|
||||
free( *ppRock );
|
||||
*ppRock = NULL;
|
||||
|
||||
return MIME_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
(*ppRock)->f = fopen( filename, "r" );
|
||||
|
||||
if ( (*ppRock)->f == NULL )
|
||||
{
|
||||
free( (*ppRock)->buffer );
|
||||
free( *ppRock );
|
||||
*ppRock = NULL;
|
||||
|
||||
return MIME_ERR_CANTOPENFILE;
|
||||
}
|
||||
|
||||
return MIME_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* free rock
|
||||
*
|
||||
* parameter : rock
|
||||
*
|
||||
* returns : nothing
|
||||
*/
|
||||
void fileRock_free( fileRock_t **ppRock )
|
||||
{
|
||||
if ( ppRock == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( *ppRock == NULL )
|
||||
return;
|
||||
|
||||
if ( (*ppRock)->f != NULL )
|
||||
fclose( (*ppRock)->f );
|
||||
|
||||
if ( (*ppRock)->buffer != NULL )
|
||||
free( (*ppRock)->buffer );
|
||||
|
||||
free( *ppRock );
|
||||
*ppRock = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* read
|
||||
*
|
||||
* parameter : rock, input buffer, size of buffer
|
||||
*
|
||||
* returns : number of bytes read
|
||||
*/
|
||||
int fileRock_read( void *rock, char *buf, unsigned size )
|
||||
{
|
||||
fileRock_t *pRock;
|
||||
|
||||
if ( rock == NULL || buf == NULL )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pRock = (fileRock_t *) rock;
|
||||
|
||||
if ( pRock->f == NULL )
|
||||
return 0;
|
||||
|
||||
return fread( buf, sizeof(char), size, pRock->f );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* rewind
|
||||
*
|
||||
* parameter : rock
|
||||
*
|
||||
* returns : nothing
|
||||
*/
|
||||
void fileRock_rewind( void *rock )
|
||||
{
|
||||
fileRock_t *pRock;
|
||||
|
||||
if ( rock == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pRock = (fileRock_t *) rock;
|
||||
|
||||
if ( pRock->f != NULL )
|
||||
{
|
||||
fseek( pRock->f, 0, SEEK_END );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* close
|
||||
*
|
||||
* parameter : rock
|
||||
*
|
||||
* returns : nothing
|
||||
*/
|
||||
void fileRock_close( void *rock )
|
||||
{
|
||||
fileRock_t *pRock;
|
||||
|
||||
if ( rock == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pRock = (fileRock_t *) rock;
|
||||
|
||||
if ( pRock->f != NULL )
|
||||
{
|
||||
fclose( pRock->f );
|
||||
pRock->f = NULL;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* constructor
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* char *filename : filename
|
||||
*
|
||||
* returns : new inputstream or NULL if failed
|
||||
*/
|
||||
int nsmail_inputstream_new( char *filename, nsmail_inputstream_t **ppInput )
|
||||
{
|
||||
int nRet;
|
||||
|
||||
if ( filename == NULL || ppInput == NULL )
|
||||
{
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
*ppInput = (nsmail_inputstream_t *) malloc( sizeof( nsmail_inputstream_t ) );
|
||||
|
||||
if ( *ppInput == NULL )
|
||||
{
|
||||
return MIME_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
nRet = fileRock_new( filename, (fileRock_t **) &(*ppInput)->rock );
|
||||
|
||||
if ( nRet == MIME_OK )
|
||||
{
|
||||
(*ppInput)->read = &fileRock_read;
|
||||
(*ppInput)->rewind = &fileRock_rewind;
|
||||
(*ppInput)->close = &fileRock_close;
|
||||
}
|
||||
|
||||
return nRet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* destructor
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* nsmail_inputstream_t *in : inputstream
|
||||
*
|
||||
* returns : NSMAIL_OK, NSMAIL_ERR_INVALIDPARAM
|
||||
*/
|
||||
void nsmail_inputstream_free( nsmail_inputstream_t **ppInput )
|
||||
{
|
||||
if ( ppInput == NULL )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( *ppInput == NULL )
|
||||
return;
|
||||
|
||||
if ( (*ppInput)->rock != NULL )
|
||||
fileRock_free( (fileRock_t **) &(*ppInput)->rock );
|
||||
|
||||
free( *ppInput );
|
||||
*ppInput = NULL;
|
||||
}
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,398 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
/* vector.c
|
||||
*
|
||||
* simple vector class
|
||||
* carsonl, oct 1,97
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "nsmail.h"
|
||||
#include "vector.h"
|
||||
#include "util.h"
|
||||
#include "mime.h"
|
||||
#include "mime_internal.h"
|
||||
#include "mimeparser.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* constructor
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* int type1 : content type
|
||||
*
|
||||
* returns : new instance of vector
|
||||
*/
|
||||
Vector *Vector_new( int nType )
|
||||
{
|
||||
Vector *v = (Vector *) malloc( sizeof( Vector ) );
|
||||
|
||||
if ( v == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v->nSize = 0;
|
||||
v->nMaxSize = INITIAL_SIZE;
|
||||
v->nType = nType;
|
||||
|
||||
v->pt = (void **) malloc( INITIAL_SIZE * sizeof( void * ) );
|
||||
|
||||
if ( v->pt == NULL )
|
||||
{
|
||||
free( v );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* clone
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* Vector *v : original vector
|
||||
*
|
||||
* returns : new instance of vector, or NULL if incorrect parameters or out of memory
|
||||
*/
|
||||
Vector *Vector_clone( Vector *v )
|
||||
{
|
||||
int i, len;
|
||||
Vector *v2;
|
||||
|
||||
if ( v == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v2 = (Vector *) malloc( sizeof( Vector ) );
|
||||
|
||||
if ( v2 == NULL )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v2->nMaxSize = v->nMaxSize;
|
||||
v2->nSize = v->nSize;
|
||||
v2->nType = v->nType;
|
||||
|
||||
/* clone pointer array */
|
||||
v2->pt = (void **) malloc( v->nMaxSize * sizeof( void* ) );
|
||||
|
||||
if ( v2->pt == NULL )
|
||||
{
|
||||
free( v2 );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy( v2->pt, v->pt, v->nSize * sizeof( void* ) );
|
||||
|
||||
/* clone each element */
|
||||
for ( i=0; i < v->nSize; i++ )
|
||||
{
|
||||
if ( v->pt[i] != NULL )
|
||||
{
|
||||
switch ( v->nType )
|
||||
{
|
||||
case VECTOR_TYPE_STRING:
|
||||
len = strlen( (char *) v->pt[i] ) + 1;
|
||||
v2->pt[i] = (char *) malloc( len );
|
||||
|
||||
if ( v2->pt[i] != NULL )
|
||||
{
|
||||
memcpy( v2->pt[i], v->pt[i], len );
|
||||
}
|
||||
break;
|
||||
|
||||
case VECTOR_TYPE_MIMEINFO:
|
||||
v2->pt[i] = (void *) mimeInfo_clone( (mimeInfo_t *) v->pt[i] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return v2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* destructor
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* Vector *v : vector
|
||||
*
|
||||
* returns : MIME_OK if successful
|
||||
*/
|
||||
int Vector_free( Vector *v )
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( v == NULL )
|
||||
{
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
if ( v->pt != NULL )
|
||||
{
|
||||
for ( i=0; i < v->nSize; i++ )
|
||||
{
|
||||
if ( v->pt[i] != NULL )
|
||||
{
|
||||
switch ( v->nType )
|
||||
{
|
||||
case VECTOR_TYPE_STRING:
|
||||
free( v->pt[i] );
|
||||
break;
|
||||
|
||||
case VECTOR_TYPE_MIMEINFO:
|
||||
mimeInfo_free( v->pt[i] );
|
||||
break;
|
||||
|
||||
default:
|
||||
free( v->pt[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free( v->pt );
|
||||
}
|
||||
|
||||
free( v );
|
||||
|
||||
return MIME_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* delete all elements
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* Vector *v : original vector
|
||||
*
|
||||
* returns : MIME_OK if successful
|
||||
*/
|
||||
int Vector_deleteAll( Vector *v )
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( v == NULL )
|
||||
{
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
if ( v->pt != NULL )
|
||||
{
|
||||
for ( i=0; i < v->nSize; i++ )
|
||||
{
|
||||
if ( v->pt[i] != NULL )
|
||||
{
|
||||
switch ( v->nType )
|
||||
{
|
||||
case VECTOR_TYPE_STRING:
|
||||
free( v->pt[i] );
|
||||
break;
|
||||
|
||||
case VECTOR_TYPE_MIMEINFO:
|
||||
mimeInfo_free( v->pt[i] );
|
||||
break;
|
||||
|
||||
default:
|
||||
free( v->pt[i] );
|
||||
}
|
||||
|
||||
v->pt[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
v->nSize = 0;
|
||||
}
|
||||
|
||||
return MIME_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* add a new element
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* Vector *v : original vector
|
||||
* void *pObject : user's object
|
||||
* int nObjectSize : object size
|
||||
*
|
||||
* returns : return a negative error code if failed, return the vector index if successful
|
||||
*/
|
||||
int Vector_addElement( Vector *v, void *pObject, int nObjectSize )
|
||||
{
|
||||
if ( v == NULL || pObject == NULL || v->pt == NULL )
|
||||
{
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
/* reallocate more space */
|
||||
if ( v->nSize >= v->nMaxSize )
|
||||
{
|
||||
void *ptOld = v->pt;
|
||||
v->nMaxSize += INITIAL_SIZE;
|
||||
|
||||
v->pt = (void **) malloc( v->nMaxSize * sizeof( void* ) );
|
||||
|
||||
if ( v->pt == NULL )
|
||||
{
|
||||
return MIME_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
memcpy( v->pt, ptOld, v->nSize * sizeof( void* ) );
|
||||
|
||||
if ( ptOld != NULL )
|
||||
free( ptOld );
|
||||
}
|
||||
|
||||
/* copy content */
|
||||
switch ( v->nType )
|
||||
{
|
||||
case VECTOR_TYPE_MIMEINFO:
|
||||
v->pt[ v->nSize ] = (void **) mimeInfo_clone( (mimeInfo_t *) pObject );
|
||||
break;
|
||||
|
||||
default:
|
||||
/* store object */
|
||||
v->pt[ v->nSize ] = (void **) malloc( nObjectSize + 1 );
|
||||
|
||||
/* out of memory */
|
||||
if ( v->pt[ v->nSize ] == NULL )
|
||||
{
|
||||
return MIME_ERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
memcpy( v->pt[v->nSize], pObject, nObjectSize + 1 );
|
||||
break;
|
||||
}
|
||||
|
||||
/* add element */
|
||||
v->nSize++;
|
||||
|
||||
return v->nSize - 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* return the vector at nIndex
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* Vector *v : original vector
|
||||
* int nIndex : element index
|
||||
*
|
||||
* returns : object at index
|
||||
*/
|
||||
void *Vector_elementAt( Vector *v, int nIndex )
|
||||
{
|
||||
if ( v != NULL && nIndex < v->nSize )
|
||||
return v->pt[ nIndex ];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void *Vector_deleteLastElement (Vector *v)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (v != NULL && v->nSize > 0)
|
||||
{
|
||||
i = v->nSize;
|
||||
free(v->pt[i-1] );
|
||||
v->pt[i-1] = NULL;
|
||||
v->nSize--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void *Vector_popLastElement (Vector *v)
|
||||
{
|
||||
int i;
|
||||
void * p;
|
||||
|
||||
if (v != NULL && v->nSize > 0)
|
||||
{
|
||||
i = v->nSize;
|
||||
p = v->pt[i-1];
|
||||
v->pt[i-1] = NULL;
|
||||
v->nSize--;
|
||||
return p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* carsonl, jan 8,98
|
||||
* return # of elements in the vector class
|
||||
*
|
||||
* parameter :
|
||||
*
|
||||
* Vector *v : original vector
|
||||
*
|
||||
* returns : size of vector
|
||||
*/
|
||||
int Vector_size( Vector *v )
|
||||
{
|
||||
if ( v == NULL )
|
||||
{
|
||||
return MIME_ERR_INVALIDPARAM;
|
||||
}
|
||||
|
||||
return v->nSize;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,346 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/* * Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Example program to demonstrate the use of the MIME dynamic parser
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "stdio.h"
|
||||
#include "nsmail.h"
|
||||
#include "mime.h"
|
||||
#include "mimeparser.h"
|
||||
#include "nsStream.h"
|
||||
#include "testdynamic.h"
|
||||
|
||||
|
||||
char achTemp[512];
|
||||
int messageNo = 0;
|
||||
int basicPartNo = 0;
|
||||
int multiPartNo = 0;
|
||||
int messagePartNo = 0;
|
||||
nsmail_outputstream_t *pBodyDataStream;
|
||||
|
||||
#define outmsg(x) (fprintf(stderr,"%s:%d>%s\n",__FILE__,__LINE__,x))
|
||||
#define outmsg2(x, y) (fprintf(stderr,"%s:%d>%s%s\n",__FILE__,__LINE__,x,y))
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define BASICPART_FILE "/tmp/bodypart.out"
|
||||
#define BODYDATA_FILE "/tmp/boddata.out"
|
||||
#define BASICPART_BYTESTREAM "/tmp/basicpart.bstream"
|
||||
#else
|
||||
#define BASICPART_FILE "C:\\temp\\bodypart.out"
|
||||
#define BODYDATA_FILE "C:\\temp\\boddata.out"
|
||||
#define BASICPART_BYTESTREAM "C:\\temp\\basicpart.bstream"
|
||||
#endif
|
||||
|
||||
/* allocate and return the callback object */
|
||||
char * getCBObject (char * s, int num)
|
||||
{
|
||||
char * CBObj = (char *) mime_malloc (20);
|
||||
|
||||
memset (CBObj, 0, 20);
|
||||
|
||||
sprintf (CBObj, "%s%d", s, num);
|
||||
return CBObj;
|
||||
}
|
||||
|
||||
void freeCBObject (void * pCBObj)
|
||||
{
|
||||
mime_memfree (pCBObj);
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************/
|
||||
/* ------ datasink methods ---------- */
|
||||
/************************************************************************************/
|
||||
|
||||
|
||||
void mimeDataSink2_header (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value)
|
||||
{
|
||||
if (name != NULL && value != NULL)
|
||||
sprintf( achTemp, "> header() name = [%s] value = [%s]\n", name, value);
|
||||
else if (name != NULL && value == NULL)
|
||||
sprintf( achTemp, "> header() name = [%s] value = [%s]\n", name, "null");
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_addHeader (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value)
|
||||
{
|
||||
sprintf( achTemp, "> addHeader() name = [%s] value = [%s]\n", name, value);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMessageHeader (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
sprintf( achTemp, "> endMessageHeader()");
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentType (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentType)
|
||||
{
|
||||
sprintf( achTemp, "> contentType() = [%d]\n", nContentType);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentSubType (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentSubType)
|
||||
{
|
||||
sprintf( achTemp, "> contentSubType() = [%s]\n", contentSubType);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentTypeParams (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentTypeParams)
|
||||
{
|
||||
sprintf( achTemp, "> contentTypeParams() = [%s]\n", contentTypeParams);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentID (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *contentID)
|
||||
{
|
||||
sprintf( achTemp, "> contentID() = [%s]\n", contentID);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentMD5 (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentMD5)
|
||||
{
|
||||
sprintf( achTemp, "> contentMD5() = [%s]\n", contentMD5);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentDisposition (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentDisposition)
|
||||
{
|
||||
sprintf( achTemp, "> contentDisposition() = [%d]\n", nContentDisposition);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentDispParams (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentDispParams)
|
||||
{
|
||||
sprintf( achTemp, "> contentDispParams() = [%s]\n", contentDispParams);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentDescription (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *contentDescription)
|
||||
{
|
||||
sprintf( achTemp, "> contentDescription() = [%s]\n", contentDescription);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentEncoding (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentEncoding)
|
||||
{
|
||||
sprintf( achTemp, "> contentEncoding() = [%d]\n", nContentEncoding);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
|
||||
void *mimeDataSink2_startMessage (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * msgCB = getCBObject ("Message", ++messageNo);
|
||||
outmsg2("startMessage() ", msgCB);
|
||||
return msgCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMessage (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endMessage()");
|
||||
/*outmsg( "endMessage()\n");*/
|
||||
}
|
||||
|
||||
|
||||
void *mimeDataSink2_startBasicPart (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * basicCB = getCBObject ("BasicPart", ++basicPartNo);
|
||||
outmsg2("startBasicPart() ", basicCB);
|
||||
return basicCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_bodyData (mimeDataSinkPtr_t pSink, void *pCallbackObject, char bodyData[], int len)
|
||||
{
|
||||
outmsg((char *)pCallbackObject);
|
||||
outmsg( "bodyData() = [");
|
||||
outmsg( "]\n");
|
||||
if (pBodyDataStream != NULL)
|
||||
{
|
||||
pBodyDataStream->write (pBodyDataStream->rock, bodyData, len);
|
||||
}
|
||||
}
|
||||
|
||||
void mimeDataSink2_endBasicPart (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endBasicPart()");
|
||||
}
|
||||
|
||||
void *mimeDataSink2_startMultiPart (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * mpCB = getCBObject ("MultiPart", ++multiPartNo);
|
||||
outmsg2("startMultiPart() ", mpCB);
|
||||
return mpCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_boundary (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * boundary)
|
||||
{
|
||||
sprintf( achTemp, "> boundary() = [%s]\n", boundary);
|
||||
outmsg2((char*)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMultiPart (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endMultiPart()");
|
||||
}
|
||||
|
||||
void *mimeDataSink2_startMessagePart (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * msgpCB = getCBObject ("MessagePart", ++messagePartNo);
|
||||
outmsg2("startMessagePart() ", msgpCB);
|
||||
return msgpCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMessagePart (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endMessagePart()");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dynamicParseEntireFile (char *szFilename)
|
||||
{
|
||||
int len, ret;
|
||||
char buffer[BUFFER_SIZE2];
|
||||
struct mimeParser *p;
|
||||
mimeDataSink_t *pDataSink;
|
||||
nsmail_inputstream_t *pInStream;
|
||||
|
||||
/* Create a new data-sink */
|
||||
ret = mimeDataSink_new (&pDataSink);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "mimeDataSink_new failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* initialize the data-sink */
|
||||
pDataSink->header = &mimeDataSink2_header;
|
||||
pDataSink->addHeader = &mimeDataSink2_addHeader;
|
||||
pDataSink->endMessageHeader = &mimeDataSink2_endMessageHeader;
|
||||
pDataSink->contentType = &mimeDataSink2_contentType;
|
||||
pDataSink->contentSubType = &mimeDataSink2_contentSubType;
|
||||
pDataSink->contentTypeParams = &mimeDataSink2_contentTypeParams;
|
||||
pDataSink->contentID = &mimeDataSink2_contentID;
|
||||
pDataSink->contentMD5 = &mimeDataSink2_contentMD5;
|
||||
pDataSink->contentDisposition = &mimeDataSink2_contentDisposition;
|
||||
pDataSink->contentDispParams = &mimeDataSink2_contentDispParams;
|
||||
pDataSink->contentDescription = &mimeDataSink2_contentDescription;
|
||||
pDataSink->contentEncoding = &mimeDataSink2_contentEncoding;
|
||||
|
||||
pDataSink->startMessage = &mimeDataSink2_startMessage;
|
||||
pDataSink->endMessage = &mimeDataSink2_endMessage;
|
||||
|
||||
pDataSink->startBasicPart = &mimeDataSink2_startBasicPart;
|
||||
pDataSink->bodyData = &mimeDataSink2_bodyData;
|
||||
pDataSink->endBasicPart = &mimeDataSink2_endBasicPart;
|
||||
|
||||
pDataSink->startMultiPart = &mimeDataSink2_startMultiPart;
|
||||
pDataSink->boundary = &mimeDataSink2_boundary;
|
||||
pDataSink->endMultiPart = &mimeDataSink2_endMultiPart;
|
||||
|
||||
pDataSink->startMessagePart = &mimeDataSink2_startMessagePart;
|
||||
pDataSink->endMessagePart = &mimeDataSink2_endMessagePart;
|
||||
|
||||
/* create a new parser instance */
|
||||
ret = mimeDynamicParser_new (pDataSink, &p);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
mimeDataSink_free( &pDataSink);
|
||||
fprintf (stderr, "mimeDynamicParser_new failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* open an input-stream to the file with MIME message to parse */
|
||||
ret = file_inputStream_create (szFilename, &pInStream);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "file_inputStream_create failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
ret = file_outputStream_create (BODYDATA_FILE, &pBodyDataStream);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "file_outputStream_create on %s failed! ret = %d\n", BODYDATA_FILE, ret);
|
||||
pBodyDataStream = NULL;
|
||||
}
|
||||
|
||||
beginDynamicParse (p);
|
||||
|
||||
/* You can also pass the entire stream to the parser */
|
||||
/* ret = dynamicParseInputstream (p, pInStream); */
|
||||
|
||||
for (len = pInStream->read (pInStream->rock, buffer, BUFFER_SIZE2);
|
||||
len > 0;
|
||||
len = pInStream->read (pInStream->rock, buffer, BUFFER_SIZE2))
|
||||
{
|
||||
if (dynamicParse (p, buffer, len) != MIME_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
ret = endDynamicParse (p);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "file_inputStream_create failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* close and free the inputStream created */
|
||||
pInStream->close (pInStream->rock);
|
||||
nsStream_free (pInStream);
|
||||
|
||||
/* free the parser and data-sink */
|
||||
mimeDynamicParser_free (&p);
|
||||
mimeDataSink_free (&pDataSink);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s <filename> \n", argv[0]);
|
||||
#ifdef XP_UNIX
|
||||
fprintf (stderr, "example: %s /tmp/TestCases_MIME/Messages/mime1.txt\n", argv[0]);
|
||||
#else
|
||||
fprintf (stderr, "example: %s e:\\share\\MIME_Test\\Messages\\mime1.txt\n", argv[0]);
|
||||
#endif
|
||||
exit (1);
|
||||
}
|
||||
|
||||
dynamicParseEntireFile (argv[1]);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Example dynamic parsing program
|
||||
*/
|
||||
|
||||
#ifndef TESTAPP_H
|
||||
#define TESTAPP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define BUFFER_SIZE2 256
|
||||
|
||||
|
||||
void dynamicParseEntireFile (char *szFilename);
|
||||
|
||||
void mimeDataSink2_header (mimeDataSinkPtr_t pSink,void *pCallbackObject, char *name, char *value);
|
||||
void mimeDataSink2_addHeader (mimeDataSinkPtr_t pSink,void *pCallbackObject, char *name, char *value);
|
||||
void mimeDataSink2_contentType (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentType);
|
||||
void mimeDataSink2_contentSubType (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentSubType);
|
||||
void mimeDataSink2_contentTypeParams (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentTypeParams);
|
||||
void mimeDataSink2_contentID (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *contentID);
|
||||
void mimeDataSink2_contentMD5 (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentMD5);
|
||||
void mimeDataSink2_contentDisposition (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentDisposition);
|
||||
void mimeDataSink2_contentDispParams (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentDispParams);
|
||||
void mimeDataSink2_contentDescription (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *contentDescription);
|
||||
void mimeDataSink2_contentEncoding (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentEncoding);
|
||||
void *mimeDataSink2_startMessageLocalStorage (mimeDataSinkPtr_t pSink, mime_message_t *m);
|
||||
void *mimeDataSink2_startMessage (mimeDataSinkPtr_t pSink);
|
||||
void mimeDataSink2_endMessage (mimeDataSinkPtr_t pSink, void *pCallbackObject);
|
||||
void *mimeDataSink2_startBasicPartLocalStorage (mimeDataSinkPtr_t pSink, mime_basicPart_t *m);
|
||||
void *mimeDataSink2_startBasicPart (mimeDataSinkPtr_t pSink);
|
||||
void mimeDataSink2_bodyData (mimeDataSinkPtr_t pSink, void *pCallbackObject, char bodyData[], int len);
|
||||
void mimeDataSink2_endBasicPart (mimeDataSinkPtr_t pSink, void *pCallbackObject);
|
||||
void *mimeDataSink2_startMultiPartLocalStorage (mimeDataSinkPtr_t pSink, mime_multiPart_t *m);
|
||||
void *mimeDataSink2_startMultiPart (mimeDataSinkPtr_t pSink);
|
||||
void mimeDataSink2_boundary (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * boundary);
|
||||
void mimeDataSink2_endMultiPart (mimeDataSinkPtr_t pSink, void *pCallbackObject);
|
||||
void *mimeDataSink2_startMessagePartLocalStorage (mimeDataSinkPtr_t pSink, mime_messagePart_t *m);
|
||||
void *mimeDataSink2_startMessagePart (mimeDataSinkPtr_t pSink);
|
||||
void mimeDataSink2_endMessagePart (mimeDataSinkPtr_t pSink, void *pCallbackObject);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* TESTAPP_H */
|
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/* * Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Example program to demonstrate the use of the MIME dynamic parser
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "stdio.h"
|
||||
#include "nsmail.h"
|
||||
#include "mime.h"
|
||||
#include "mimeparser.h"
|
||||
#include "nsStream.h"
|
||||
#include "testdynamic.h"
|
||||
|
||||
|
||||
char achTemp[512];
|
||||
int messageNo = 0;
|
||||
int basicPartNo = 0;
|
||||
int multiPartNo = 0;
|
||||
int messagePartNo = 0;
|
||||
nsmail_outputstream_t *pBodyDataStream;
|
||||
|
||||
#define outmsg(x) (fprintf(stderr,"%s:%d>%s\n",__FILE__,__LINE__,x))
|
||||
#define outmsg2(x, y) (fprintf(stderr,"%s:%d>%s%s\n",__FILE__,__LINE__,x,y))
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#define BASICPART_FILE "/tmp/bodypart.out"
|
||||
#define BODYDATA_FILE "/tmp/boddata.out"
|
||||
#define BASICPART_BYTESTREAM "/tmp/basicpart.bstream"
|
||||
#else
|
||||
#define BASICPART_FILE "C:\\temp\\bodypart.out"
|
||||
#define BODYDATA_FILE "C:\\temp\\boddata.out"
|
||||
#define BASICPART_BYTESTREAM "C:\\temp\\basicpart.bstream"
|
||||
#endif
|
||||
|
||||
/* allocate and return the callback object */
|
||||
char * getCBObject (char * s, int num)
|
||||
{
|
||||
char * CBObj = (char *) mime_malloc (20);
|
||||
|
||||
memset (CBObj, 0, 20);
|
||||
|
||||
sprintf (CBObj, "%s%d", s, num);
|
||||
return CBObj;
|
||||
}
|
||||
|
||||
void freeCBObject (void * pCBObj)
|
||||
{
|
||||
mime_memfree (pCBObj);
|
||||
}
|
||||
|
||||
/************************************************************************************/
|
||||
/* ------ datasink methods ---------- */
|
||||
/************************************************************************************/
|
||||
|
||||
|
||||
void mimeDataSink2_header (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value)
|
||||
{
|
||||
if (name != NULL && value != NULL)
|
||||
sprintf( achTemp, "> header() name = [%s] value = [%s]\n", name, value);
|
||||
else if (name != NULL && value == NULL)
|
||||
sprintf( achTemp, "> header() name = [%s] value = [%s]\n", name, "null");
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_addHeader (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *name, char *value)
|
||||
{
|
||||
sprintf( achTemp, "> addHeader() name = [%s] value = [%s]\n", name, value);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMessageHeader (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
sprintf( achTemp, "> endMessageHeader()");
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentType (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentType)
|
||||
{
|
||||
sprintf( achTemp, "> contentType() = [%d]\n", nContentType);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentSubType (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentSubType)
|
||||
{
|
||||
sprintf( achTemp, "> contentSubType() = [%s]\n", contentSubType);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentTypeParams (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentTypeParams)
|
||||
{
|
||||
sprintf( achTemp, "> contentTypeParams() = [%s]\n", contentTypeParams);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentID (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *contentID)
|
||||
{
|
||||
sprintf( achTemp, "> contentID() = [%s]\n", contentID);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentMD5 (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentMD5)
|
||||
{
|
||||
sprintf( achTemp, "> contentMD5() = [%s]\n", contentMD5);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentDisposition (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentDisposition)
|
||||
{
|
||||
sprintf( achTemp, "> contentDisposition() = [%d]\n", nContentDisposition);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentDispParams (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * contentDispParams)
|
||||
{
|
||||
sprintf( achTemp, "> contentDispParams() = [%s]\n", contentDispParams);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentDescription (mimeDataSinkPtr_t pSink, void *pCallbackObject, char *contentDescription)
|
||||
{
|
||||
sprintf( achTemp, "> contentDescription() = [%s]\n", contentDescription);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_contentEncoding (mimeDataSinkPtr_t pSink, void *pCallbackObject, int nContentEncoding)
|
||||
{
|
||||
sprintf( achTemp, "> contentEncoding() = [%d]\n", nContentEncoding);
|
||||
outmsg2((char *)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void *mimeDataSink2_startMessage (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * msgCB = getCBObject ("Message", ++messageNo);
|
||||
outmsg2("startMessage() ", msgCB);
|
||||
return msgCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMessage (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endMessage()");
|
||||
/*outmsg( "endMessage()\n");*/
|
||||
}
|
||||
|
||||
|
||||
void *mimeDataSink2_startBasicPart (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * basicCB = getCBObject ("BasicPart", ++basicPartNo);
|
||||
outmsg2("startBasicPart() ", basicCB);
|
||||
return basicCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_bodyData (mimeDataSinkPtr_t pSink, void *pCallbackObject, char bodyData[], int len)
|
||||
{
|
||||
outmsg((char *)pCallbackObject);
|
||||
outmsg( "bodyData() = [");
|
||||
outmsg( "]\n");
|
||||
|
||||
if (pBodyDataStream != NULL)
|
||||
{
|
||||
pBodyDataStream->write (pBodyDataStream->rock, bodyData, len);
|
||||
}
|
||||
/*
|
||||
outmsg( "bodyData() = [");
|
||||
outmsg( bodyData);
|
||||
outmsg( "]\n");
|
||||
*/
|
||||
}
|
||||
|
||||
void mimeDataSink2_endBasicPart (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endBasicPart()");
|
||||
}
|
||||
|
||||
|
||||
void *mimeDataSink2_startMultiPart (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * mpCB = getCBObject ("MultiPart", ++multiPartNo);
|
||||
outmsg2("startMultiPart() ", mpCB);
|
||||
return mpCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_boundary (mimeDataSinkPtr_t pSink, void *pCallbackObject, char * boundary)
|
||||
{
|
||||
sprintf( achTemp, "> boundary() = [%s]\n", boundary);
|
||||
outmsg2((char*)pCallbackObject, achTemp);
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMultiPart (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endMultiPart()");
|
||||
}
|
||||
|
||||
void *mimeDataSink2_startMessagePart (mimeDataSinkPtr_t pSink)
|
||||
{
|
||||
char * msgpCB = getCBObject ("MessagePart", ++messagePartNo);
|
||||
outmsg2("startMessagePart() ", msgpCB);
|
||||
return msgpCB;
|
||||
}
|
||||
|
||||
void mimeDataSink2_endMessagePart (mimeDataSinkPtr_t pSink, void *pCallbackObject)
|
||||
{
|
||||
outmsg2((char*)pCallbackObject, "> endMessagePart()");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dynamicParseEntireFile (char *szFilename)
|
||||
{
|
||||
int len, ret;
|
||||
char buffer[BUFFER_SIZE2];
|
||||
struct mimeParser *p;
|
||||
mimeDataSink_t *pDataSink;
|
||||
nsmail_inputstream_t *pInStream;
|
||||
|
||||
/* Create a new data-sink */
|
||||
ret = mimeDataSink_new (&pDataSink);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "mimeDataSink_new failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* initialize the data-sink */
|
||||
pDataSink->header = &mimeDataSink2_header;
|
||||
pDataSink->addHeader = &mimeDataSink2_addHeader;
|
||||
pDataSink->endMessageHeader = &mimeDataSink2_endMessageHeader;
|
||||
pDataSink->contentType = &mimeDataSink2_contentType;
|
||||
pDataSink->contentSubType = &mimeDataSink2_contentSubType;
|
||||
pDataSink->contentTypeParams = &mimeDataSink2_contentTypeParams;
|
||||
pDataSink->contentID = &mimeDataSink2_contentID;
|
||||
pDataSink->contentMD5 = &mimeDataSink2_contentMD5;
|
||||
pDataSink->contentDisposition = &mimeDataSink2_contentDisposition;
|
||||
pDataSink->contentDispParams = &mimeDataSink2_contentDispParams;
|
||||
pDataSink->contentDescription = &mimeDataSink2_contentDescription;
|
||||
pDataSink->contentEncoding = &mimeDataSink2_contentEncoding;
|
||||
|
||||
pDataSink->startMessage = &mimeDataSink2_startMessage;
|
||||
pDataSink->endMessage = &mimeDataSink2_endMessage;
|
||||
|
||||
pDataSink->startBasicPart = &mimeDataSink2_startBasicPart;
|
||||
pDataSink->bodyData = &mimeDataSink2_bodyData;
|
||||
pDataSink->endBasicPart = &mimeDataSink2_endBasicPart;
|
||||
|
||||
pDataSink->startMultiPart = &mimeDataSink2_startMultiPart;
|
||||
pDataSink->boundary = &mimeDataSink2_boundary;
|
||||
pDataSink->endMultiPart = &mimeDataSink2_endMultiPart;
|
||||
|
||||
pDataSink->startMessagePart = &mimeDataSink2_startMessagePart;
|
||||
pDataSink->endMessagePart = &mimeDataSink2_endMessagePart;
|
||||
|
||||
/* create a new parser instance */
|
||||
ret = mimeDynamicParser_new (pDataSink, &p);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
mimeDataSink_free( &pDataSink);
|
||||
fprintf (stderr, "mimeDynamicParser_new failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* open an input-stream to the file with MIME message to parse */
|
||||
ret = file_inputStream_create (szFilename, &pInStream);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "file_inputStream_create failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
ret = file_outputStream_create (BODYDATA_FILE, &pBodyDataStream);
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "file_outputStream_create on %s failed! ret = %d\n", BODYDATA_FILE, ret);
|
||||
pBodyDataStream = NULL;
|
||||
}
|
||||
|
||||
beginDynamicParse (p);
|
||||
|
||||
ret = dynamicParseInputstream (p, pInStream);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "dynamicParseInputstream failed! ret = %d\n", ret);
|
||||
}
|
||||
#if (0)
|
||||
for (len = pInStream->read (pInStream->rock, buffer, BUFFER_SIZE2);
|
||||
len > 0;
|
||||
len = pInStream->read (pInStream->rock, buffer, BUFFER_SIZE2))
|
||||
{
|
||||
if (dynamicParse (p, buffer, len) != MIME_OK)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = endDynamicParse (p);
|
||||
|
||||
if (ret != MIME_OK)
|
||||
{
|
||||
fprintf (stderr, "endDynamicParse failed! ret = %d\n", ret);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* close and free the inputStream created */
|
||||
pInStream->close (pInStream->rock);
|
||||
nsStream_free (pInStream);
|
||||
|
||||
/* free the parser and data-sink */
|
||||
mimeDynamicParser_free (&p);
|
||||
mimeDataSink_free (&pDataSink);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s <filename> \n", argv[0]);
|
||||
#ifdef XP_UNIX
|
||||
fprintf (stderr, "example: %s /tmp/TestCases_MIME/Messages/mime1.txt\n", argv[0]);
|
||||
#else
|
||||
fprintf (stderr, "example: %s e:\\share\\MIME_Test\\Messages\\mime1.txt\n", argv[0]);
|
||||
#endif
|
||||
exit (1);
|
||||
}
|
||||
|
||||
dynamicParseEntireFile (argv[1]);
|
||||
|
||||
return 0;
|
||||
}
|
Загрузка…
Ссылка в новой задаче