/*
 *            Copyright (c) 1998-2000 by NETsilicon Inc.
 *
 *  This software is copyrighted by and is the sole property of 
 *  NETsilicon.  All rights, title, ownership, or other interests
 *  in the software remain the property of NETsilicon.  This
 *  software may only be used in accordance with the corresponding
 *  license agreement.  Any unauthorized use, duplication, transmission,  
 *  distribution, or disclosure of this software is expressly forbidden.
 *
 *  This Copyright notice may not be removed or modified without prior
 *  written consent of NETsilicon.
 *
 *  NETsilicon, reserves the right to modify this software
 *  without notice.
 *
 *  NETsilicon
 *  411 Waverley Oaks Road                  USA 781.647.1234
 *  Suite 227                               http://www.netsilicon.com
 *  Waltham, MA 02452                       AmericaSales@netsilicon.com
 *
 *************************************************************************
 *
 *     Module Name: mailcapi.h
 *         Version: 1.00
 *   Original Date: 28-Jul-1999
 *	    Author: 
 *	  Language: Ansi C
 * Compile Options: 
 * Compile defines: 
 *	 Libraries: 
 *    Link Options: 
 *
 *    Entry Points: 
 *
 * Description.
 * =======================================================================
 *                                                                        
 *                                                                        
 * Edit Date/Ver   Edit Description
 * ==============  ===================================================
 * LZ   02/10/00   Changed MCStat() to have one argument.
 * JFU  8/2/00     updated file for commonapi
 * GPL  8/4/00	   Modified MCStat with 1 argument for vxWorks and removed 
 *                 gener_os.h
 * PMJ  09/06/00   Removed private functions MC_err_get_*, MC_set_timeout,
 *                 MCSend*Cmd, MCSendData and MCSendLogout commands.
 * ESUN 10/20/00   Added prototype of MCSendSimpleMailWithDomain().
 * PMJ  12/26/00   Added new prototypes for attachment functionality
 * PMJ  01/03/01   Changed MCRetrWithAttachments callback prototype to include
 *                 arguments for size.  Removed PNA reference.
 * ECL  12/18/01   added MCSendMailWithAttachmentsAndDomain
 * ECL   5/6/02    added MC_MORE_TO_COME,MC_OK, and MC_MSG_TOO_BIG 
 * ESUN 08/21/02   Added some error values definitions, attachment structure,
 *                 NASendSimpleMailWithDomain(),and NASendMailWithAttachmentsAndDomain()
 * ESUN 12/6/02    Added NAMCRetr() and NARetrWithAttachments().
 * JZW  1/20/03    REplaced the above two eits that were lost
 *                 between v5 & v6
 * ESUN 01/21/03   Added the protypes of many new functions.
 * JZW  03/07/03   Added defines allowing the removal of magic numbers
 *                 from file allegro_mailc.c
 * JZW  03/19/03   Added new typedef to be used in the functional prototypes
 *                 for callback Register functions. This is used to facilitate
 *                 using comments as documentation
 * ESUN 04/29/03   iso_8859_1 and iso_2022_jp added as constants for use in setting
 *                 character sets
 * JZW  05/14/03   Removed comma from last item of enum list. Eliminates
 *                 compiler warnings
 * JZW  08/17/04   Added two items to support configurable attachment file
 *                 names. Added two manifest constants for users to use when
 *                 calling the new function. Added new function NASmtpSetAttachmentNameType
 *                 that allows users to set how they want attachment file names
 *                 to appear. Reference Vantive 13994
 * JZW  08/17/04   Cleanedup Autodoc issues relating to new function and one
 *                 autodoc misspelling.
 */

#ifndef __NA_MAILCAPI_H
#define __NA_MAILCAPI_H
#ifdef __cplusplus
extern "C"
{
#endif

#include "npttypes.h"


/**
 * Mail attachment file name type flag
 *
 * @category Email_Services
 * @since 6.0
 * @name mc_attach_filename_type	"Mail attachment file name type flag"
 * @external
 *
 * @param  NAMAILC_ATTACHMENT_DEVANDFILE		File name is current format
 *                                              device_directory_filename
 * @param  NAMAILC_ATTACHMENT_FILEONLY		File name is new format
 *                                          filename only
 */

#define NAMAILC_ATTACHMENT_DEVANDFILE 0
#define NAMAILC_ATTACHMENT_FILEONLY 1

/**
 * Mail client enable header flag
 *
 * @category Email_Services
 * @since 6.0
 * @name mc_include_header	"Mail Client Message Header Include Flag"
 * @external
 *
 * @param  NAMAILC_NOHEADER		No header included
 * @param  NAMAILC_HEADER		Header included
 */
#define NAMAILC_NOHEADER	0
#define NAMAILC_HEADER		1

/**
 * Mail Client wait state
 *
 * @category Email_Services
 * @since 6.0
 * @name mc_wait_status "Mail Client API Wait Status"
 * @external
 *
 * @param  NAMAILC_NOWAIT	no wait
 * @param  NAMAILC_WAIT		wait
 */
#define NAMAILC_NOWAIT  0
#define NAMAILC_WAIT    1

/**
 * Mail user client command types
 *
 * @category Email_Services
 * @since 6.0
 * @external
 *
 * @param MC_USER_LOGOUT	Log out a user
 * @param MC_USER_LOGIN		Log in a user
 * @param MC_UNDELETE_MAIL	Undelete mail
 * @param MC_DELETE_MAIL	Delete a mail
 */
typedef enum {
	MC_USER_LOGOUT,
	MC_USER_LOGIN,
	MC_UNDELETE_MAIL,
	MC_DELETE_MAIL
} mc_client_cmd_types;

/**
 * Mail Client Content-Transfer-Encoding type
 *
 * @category Email_Services
 * @since 6.0
 * @name mc_body_type	"Mail Client Body Message Content Types"
 * @external
 *
 * @param  MC_BODYTYPE_BASE64	Base64 Content
 * @param  MC_BODYTYPE_OTHER	other content
 */
#define MC_BODYTYPE_BASE64         1
#define MC_BODYTYPE_OTHER          0


/**
 * Mail attachment name is used to indicate the type of attachment data
 *
 * @category Email_Services
 * @since 6.0
 * @name mc_attach_name	"Mail Attachment Names"
 * @external
 *
 * @param MC_BODY_MESSAGE       Body message of a mail
 * @param MC_ATTACHMENT_MESSAGE File attachment in a mail
 */
#define MC_BODY_MESSAGE       "BODY-MESSAGE"
#define MC_ATTACHMENT_MESSAGE "FILE-ATTACHMENT"

#define POP3 0

/**
 * Mail sending status codes
 *
 * @deprecated 6.0 It's no long used for mail V6.0.
 * @external
 * @category Email_Services
 * @since 3.0
 * @name MC	 "Mail Message Data Status"
 *
 * @param MC_MSG_ERROR		Error reading message
 * @param MC_MORE_TO_COME 	More data is pending
 * @param MC_OK 			Message was read successfully
 * @param MC_MSG_TOO_BIG  	Message was too large
 */
#define MC_MSG_ERROR 		-1
#define MC_MORE_TO_COME 	0
#define MC_OK 				1
#define MC_MSG_TOO_BIG 		2


#define   LIST_ALL                    0
#define ISO_8859_1                    0
#define ISO_2022_JP                   1

/**
 * Error codes from Mail Services 
 *
 * @external
 * @category Email_Services
 * @since 6.0
 * 
 * @name NAMAILC	"Mail Client API Return Status"
 *
 * @param NAMAILC_OK                    Success
 * @param NAMAILC_MISSADDRESS           Missing address
 * @param NAMAILC_INVALIDBODY           Invalid message body
 * @param NAMAILC_NOSERVER              No server
 * @param NAMAILC_NOMAILBOX             No mailbox available
 * @param NAMAILC_TCPERROR              TCP error
 * @param NAMAILC_CANCELLED             Mail has been cancelled
 * @param NAMAILC_SYNTAXERROR           Syntax error
 * @param NAMAILC_MAILBOXBUSY           Mailbaox is busy
 * @param NAMAILC_GENERALERROR          General error
 * @param NAMAILC_BUFFERFULL			Buffer full. Not enough space.
 * @param NAMAILC_FILESYSTEMERROR		File system error
 * @param NAMAILC_INVALIDFILE			Invalid file
 * @param NAMAILC_NOATTACHFILENAME      no attachment 
 * @param NAMAILC_NOATTACHDATA          no attachment data
 * @param NAMAILC_INVALIDATTACHSIZE     Invalid file attachment size
 * @param NAMAILC_TOOMANYATTACH         Too many attachments
 * @param NAMAILC_INVAILDMAILID			Invalid message id
 */

#define NAMAILC_OK                    0
#define NAMAILC_MISSADDRESS           -1
#define NAMAILC_INVALIDBODY           -2
#define NAMAILC_NOSERVER              -4
#define NAMAILC_NOMAILBOX             -5
#define NAMAILC_TCPERROR              -6
#define NAMAILC_CANCELLED             -7
#define NAMAILC_SYNTAXERROR           -8
#define NAMAILC_MAILBOXBUSY           -9
#define NAMAILC_GENERALERROR          -13
#define NAMAILC_BUFFERFULL			  -14
#define NAMAILC_FILESYSTEMERROR		  -15
#define NAMAILC_INVALIDFILE			  -16
#define NAMAILC_NOATTACHFILENAME      -17
#define NAMAILC_NOATTACHDATA          -18
#define NAMAILC_INVALIDATTACHSIZE     -19
#define NAMAILC_TOOMANYATTACH         -20
#define NAMAILC_INVAILDMAILID		  -21



/**
 * Mail attachment structure
 *
 * @deprecated 6.0 This structure is only used on deprescated functions.
 * @category Email_Services
 * @since 6.0
 *
 * @param attachedFileName 	Pointer to attched file name. Maximum file name length is 64 bytes.
 * @param attachedFileType   Pointer to file type. i.e. "text/plain"
 * @param data               pointer to file data
 * @param dataSize           Size in file data
 */
typedef struct attachment
{
    char * attachedFileName; 
    char * attachedFileType; 
    void * data;             
    size_t dataSize;         
}attachments;

/**
 * Pointer to attachment structure.
 *
 * @category Email_Services
 * @since 6.0
 */
typedef  attachments * attachmentPtr;

/**
 * Mail message types
 *
 * @deprecated 6.0 These types are used only on the deprecated functions.
 * @category Email_Services
 * @since 6.0
 *
 * @param MESSAGEHEADER		Mail message header
 * @param MESSAGEBODY		Mail message body
 * @param ATTACHMENT_1		Mail file attachment 1
 * @param ATTACHMENT_2		Mail file attachment 2
 * @param ATTACHMENT_3		Mail file attachment 3
 * @param ATTACHMENT_4		Mail file attachment 4
 * @param ATTACHMENT_5		Mail file attachment 5
 * @param ATTACHMENT_6		Mail file attachment 6
 * @param ATTACHMENT_7		Mail file attachment 7
 * @param ATTACHMENT_8		Mail file attachment 8
 * @param ATTACHMENT_9		Mail file attachment 9
 * @param ATTACHMENT_10		Mail file attachment 10
 * @param ATTACHMENT_11		Mail file attachment 11
 * @param ATTACHMENT_12		Mail file attachment 12
 * @param ATTACHMENT_13		Mail file attachment 13
 * @param ATTACHMENT_14		Mail file attachment 14
 * @param ATTACHMENT_15		Mail file attachment 15
 * @param ATTACHMENT_16		Mail file attachment 16
 * @param ATTACHMENT_17		Mail file attachment 17
 * @param ATTACHMENT_18		Mail file attachment 18
 * @param ATTACHMENT_19		Mail file attachment 19
 * @param ATTACHMENT_20		Mail file attachment 20
 * @param ATTACHMENT_21		Mail file attachment 21
 * @param ATTACHMENT_22		Mail file attachment 22
 * @param ATTACHMENT_23		Mail file attachment 23
 * @param ATTACHMENT_24		Mail file attachment 24
 * @param ATTACHMENT_25		Mail file attachment 25
 * @param ATTACHMENT_26		Mail file attachment 26
 * @param ATTACHMENT_27		Mail file attachment 27
 * @param ATTACHMENT_28		Mail file attachment 28
 * @param ATTACHMENT_29		Mail file attachment 29
 * @param ATTACHMENT_30		Mail file attachment 30
 * @param ATTACHMENT_31		Mail file attachment 31
 * @param ATTACHMENT_32		Mail file attachment 32
 * @param ATTACHMENT_33		Mail file attachment 33
 * @param ATTACHMENT_34		Mail file attachment 34
 * @param ATTACHMENT_35		Mail file attachment 35
 * @param ATTACHMENT_36		Mail file attachment 36
 * @param ATTACHMENT_37		Mail file attachment 37
 * @param ATTACHMENT_38		Mail file attachment 38
 * @param ATTACHMENT_39		Mail file attachment 39
 * @param ATTACHMENT_40		Mail file attachment 40
 */
typedef enum {
    MESSAGEHEADER,
    MESSAGEBODY,
    ATTACHMENT_1,
    ATTACHMENT_2,
    ATTACHMENT_3,
    ATTACHMENT_4,
    ATTACHMENT_5,
    ATTACHMENT_6,
    ATTACHMENT_7,
    ATTACHMENT_8,
    ATTACHMENT_9,
    ATTACHMENT_10,
    ATTACHMENT_11,
    ATTACHMENT_12,
    ATTACHMENT_13,
    ATTACHMENT_14,
    ATTACHMENT_15,
    ATTACHMENT_16,
    ATTACHMENT_17,
    ATTACHMENT_18,
    ATTACHMENT_19,
    ATTACHMENT_20,
    ATTACHMENT_21,
    ATTACHMENT_22,
    ATTACHMENT_23,
    ATTACHMENT_24,
    ATTACHMENT_25,
    ATTACHMENT_26,
    ATTACHMENT_27,
    ATTACHMENT_28,
    ATTACHMENT_29,
    ATTACHMENT_30,
    ATTACHMENT_31,
    ATTACHMENT_32,
    ATTACHMENT_33,
    ATTACHMENT_34,
    ATTACHMENT_35,
    ATTACHMENT_36,
    ATTACHMENT_37,
    ATTACHMENT_38,
    ATTACHMENT_39,
    ATTACHMENT_40
} messagesections;


unsigned long MCCreate(int type, int sport, char *sip, int smtp_port, char *smtp_ip);
int MCClose(unsigned long handle);
int MCReadLogin(unsigned long handle, char *user, char *pass);
int MCReadLogout(unsigned long handle);
int MCStat(unsigned long handle);
int MCList(unsigned long handle, int msg, int raw);
int MCRetr(unsigned long handle, int msg, int raw);
/* REmove later...jzw
 *int NAMCRetr(unsigned long handle, int msg, int raw,char *buf, int *bufsize);
 */
int NAMCRetr(unsigned long handle, int msg, int raw,char *headerbuf, int *headerbufsize, char *bodybuf, int *bodybufsize);
int MCNoop(unsigned long handle);
int MCRset(unsigned long handle);
int MCDele (unsigned long handle, int msg);
int MC_get_msg_count(unsigned long handle);
int MCSendSimpleMail(unsigned long handle, char *from, char *to_addr, char *subject, char *buf, int buflen);
int MCSendSimpleMailWithDomain(unsigned long handle, char *from, char *to_addr, char *subject, char *buf, int buflen, char *domain);

/*
 * New typedefs for callback registration functions - added 03/19/03
 */

/**
 * Callback registration function for listing mail status from MCRegisterLIST
 *
 * @deprecated 6.0 This function type is only used for deprecated function.
 * @external
 * @category Email_Services
 * @since 6.0
 * 
 * @param buffer		Pointer to data returned by the mail server     
 * @param size			Number of bytes in the buffer
 * @param unused1		Not used
 * @param unused2		Not used
 *
 * @return "Return value" The return value is currently not used.
 */
typedef int (* mcFunctionList_t)(char * buffer, unsigned long size, unsigned long unused1, unsigned long unused2);

/**
 * Callback registration function for retrieving mail from MCRegisterRETR
 *
 * @deprecated 6.0 This function type is only used for deprecated function.
 * @external
 * @category Email_Services
 * @since 6.0
 * 
 * @param buffer		Pointer to data returned by the mail server     
 * @param size			Number of bytes in the buffer
 * @param unused1		Not used
 * @param unused2		Not used
 *
 * @return "Return value" The return value is currently not used.
 */
typedef int (* mcFunctionRetr_t)(char * buffer, unsigned long size, unsigned long unused1, unsigned long unused2);

/**
 * Callback registration function for retrieving mail with attachment from 
 * MCRegisterRETRWithAttachments
 *
 * @deprecated 6.0 This function type is only used for deprecated function.
 * @external
 * @category Email_Services
 * @since 6.0
 * 
 * @param bodybuf			Pointer to the message body     
 * @param s2bodybuf	 	Size of the bodybuf buffer
 * @param buf1			Pointer to the first attachment (if any)
 * @param s2buf1			Size of the buf1 buffer
 * @param buf2			Pointer to the second attachment (if any)
 * @param s2buf2			Size of the buf2 buffer
 * @param buf3			Pointer to the third attachment (if any)
 * @param s2buf3			Size of the buf3 buffer
 * @param overflow		Flag set if any of the buffers exceeded the maximum
 *
 * @return "Return value" The return value is currently not used.
 */
typedef int (* mcFunctionRetrAttach_t)(char * bodybuf, int s2bodybuf, char * buf1, int s2buf1, char * buf2, int s2buf2, char * buf3, int s2buf3, int overflow);

/**
 * User send dynamic callback function type for sending mail data dynamically
 *
 * This user callback function is called to obtain body message and attachment 
 * data to be sent.  It's called continuously for sending data to the mail server
 * until it returns zero length of data.
 *
 * @deprecated 6.0 This function type is only used for deprecated function.
 * @category Email_Services
 * @since 6.0
 * 
 * @param buffer		Pointer to memory where data will be copied to and 
 *						sent to the mail server.
 * @param buflen		Maximum size of buffer 
 * @param type			Mail message type indicating the type of data in the buffer
 *						For example: 1 is for the body message and > 1 is number
 *						of attachments.
 *
 * @return >0 			Number of bytes in buffer for mail data which will be sent to
 *						the mail server.
 * @return 0			No more data on this mail message type.
 *
 */
typedef int (* mcFunctionSendDyn_t)(char * buffer, unsigned long buflen, unsigned long type);

/**
 * Callback registration function type for dynamic retrieving mail and file attachment
 *
 * @deprecated 6.0 This function type is only used for deprecated function.
 * @category Email_Services
 * @since 6.0
 * 
 * @param buffer		Pointer to data returned by the mail server     
 * @param buflen		Number of bytes in the buffer
 * @param type			Mail message type indicating the type of data in the buffer
 *
 * @return "Return value" The return value is currently not used.
 *
 * @see @link messagesections
 */
typedef int (* mcFunctionRetrDyn_t)(char * buffer, unsigned long buflen, unsigned long type);

int MCRegisterRETR(unsigned long handle, mcFunctionRetr_t mcFunctionP);
int MCRegisterLIST(unsigned long handle, mcFunctionList_t mcFunctionP);

/*The following New Functions added in August 2002*/
/* 
 * int NAMCRetr(unsigned long handle, int msg, int raw,char *headerbuf, int *headerbufsize, char *bodybuf, int *bodybufsize);int NAMCRetr(unsigned long handle, int msg, int raw,char *headerbuf, int *headerbufsize, char *bodybuf, int *bodybufsize);()  
 * 
 *    Send email with attachments -- with a Domain name.
 *
 * INPUTS                      
  handle    unsigned long type id indicating the mail control block, returned by MCCreate().
 *    from      the sender's email address, NULL terminated string,for example,"abc@wonderful.com" 
 *    to_addr   the message receiver's address. NULL terminated character pointer array,
 *              ,for example,{"abc@wonderful.com", "def@great.edu",NULL}
 *    copy_addr the message recipients' email addresses in the cc field. NULL terminated
 *              character pointer array ,for example,{"abc@wonderful.com", "def@great.edu",NULL}
 *    subject   subject of email message. NULL terminated string like "Don't forget the
 *              subject when you send email"
 *    extraHeader (optional) additional email header information. NULL terminated string ,for example,
 *              "Content-type:text/plain". If you do not want extraHeader, just use NULL. 
 *    bodybuf   character buffer containing the text message body.
 *    buflen    length of the text message body
 *    domain    domain name used in HELO statement.NULL terminated string.
 *
 * RETURNS
 *    0     email message successfully sent out.
 *   -1     the receiver's address, to_addr, is NULL or invalid.
 *   -2     invalid message body, for example, NULL or invalid buffer pointer.
 *   -3     invalid message size,for example,buflen<=0.
 *   -4     No server
 *   -5     no mailbox
 *   -6     TCP layer Error in transmiting message.
 *   -7     email message cancelled (with MCDlete())
 *   -8     mailbox syntax error
 *   -9     mailbox busy
 *   -13    other errors
 */
/*remove later .. jzw int NASendSimpleMailWithDomain(unsigned long handle, char *from, char *to_addr[], char *copy_addr[], char *subject, char *extraHeader,char *buf, int buflen, char *domain);
 */
int NASendSimpleMailWithDomain(unsigned long handle, char *from, char *to_addr[], char *copy_addr[], char *subject, char *extraHeader,char *buf, int buflen, int base64body,char *domain);
/*  New Functions added in Dec 2000 */
int MCRegisterRETRWithAttachments(unsigned long handle, mcFunctionRetrAttach_t mcFunctionP);
int MCRetrWithAttachments(unsigned long handle, int msg, int raw, char *bodybuf, unsigned long bufsize, char *buf1, unsigned int szbuf1, char *buf2, unsigned int szbuf2, char *buf3, unsigned int szbuf3);
int NARetrWithAttachments(unsigned long handle, int msg, int raw, char *buf[], unsigned long *bufsize[], unsigned long bufnumber);
int MCSendMailWithAttachments(unsigned long handle, char *from, char *to_addr, char *subject, char *bodybuf, int buflen, char *buf1, int len1, char *buf2, int len2, char *buf3, int len3);

int MCSendMailWithAttachmentsAndDomain(unsigned long handle, char *from, char *to_addr, char *subject, char *bodybuf, int buflen, char *buf1, int len1, char *buf2, int len2, char *buf3, int len3, char *domain);

/*The following New Function added in August 2002*/
/* 
 * NASendMailWithAttachmentsAndDomain()  
 * 
 *    Send email with attachments -- with a Domain name.
 *
 * INPUTS                      
*    handle    unsigned long type id indicating the mail control block, returned by MCCreate().
 *    from      the sender's email address, zero terminated string ,for example, "abc@wonderful.com" 
 *    to_addr   the message receiver's address. NULL terminated character pointer array ,for example,
 *              {"abc@wonderful.com", "def@great.edu",NULL}
 *    copy_addr the message recipients' email addresses in the cc field. NULL terminated
 *              character pointer array ,for example, {"abc@wonderful.com", "def@great.edu",NULL}
 *    subject   subject of email message. NULL terminated string like "Don't forget the
 *              subject when you send email"
 *    extraHeader (optional) additional email header information. NULL terminated string ,for example,
 *              "Content-type:text/plain". If you do not want extraHeader, just use NULL. 
 *    bodybuf   character buffer containing the text message body.
 *    buflen    length of the text message body
 *    attachment NULL terminated structure pointer array to the attached data file. the attachments
 *              structure is defined above in this file.
 *    domain    domain name used in HELO statement. NULL terminated string.
 * RETURNS
 *    0     email message successfully sent out.
 *   -1     the receiver's address,to_addr, is NULL or invalid.
 *   -2     invalid message body, ,for example, NULL or invalid buffer pointer.
 *   -3     invalid message size. ,for example, buflen <=0.
 *   -4     No server
 *   -5     no mailbox
 *   -6     TCP layer Error in transmiting message.
 *   -7     email message cancelled (with MCDlete())
 *   -8     mailbox syntax error
 *   -9     mailbox busy
 *   -10    no filename for attachment
 *   -11    no attachment data 
 *   -12    invalid attachment data size. for example, the attachment file length is <=0.
 *   -13    other errors
 */
/* remove later .. jzw int NASendMailWithAttachmentsAndDomain(unsigned long handle, char *from, char *to_addr[], char* copy_addr[], char *subject, char *extraHeader,char *bodybuf, int buflen, attachmentPtr attachment[], char *domain);
 */

int NASendMailWithAttachmentsAndDomain(unsigned long handle, char *from, char *to_addr[], char* copy_addr[], char *subject, char *extraHeader,char *bodybuf, int buflen, int base64body,attachmentPtr attachment[], char *domain);
int NARetrWithAttachments(unsigned long handle, int msg, int raw, char *buf[], unsigned long *bufsize[], unsigned long bufnumber);
int NAGetMailHeader(unsigned long handle, int msg, char* buf, int bufsize);
int NAListMail(unsigned long handle, int numbermsg, char *buf, int bufsize);
int NARegisterSendCallback (unsigned long handle, mcFunctionSendDyn_t mcFunctionP);
int NARegisterRetrCallback (unsigned long handle, mcFunctionRetrDyn_t mcFunctionP);
int NADeRegisterSendCallback (unsigned long handle );
int NADeRegisterRetrCallback (unsigned long handle);


/**
 * This mc_list_callback_fn is a callback function prototype for listing mail status
 * information. This is a user's callback function to return a list of mails with 
 * message id, size of the message, and headers (optional).
 *
 * @since 6.0
 * @external
 * @category Email_Services
 *
 * @param   handle        		Identifier of the mail client that is returned by MCCreate.
 * @param   status 				It indicates the status whether a list of mail status information 
 *								has been obtained.
 *          <list type="unordered">
 *				<item> NAMAILC_OK  	</item>
 *				<item> NAMAILC_TCPERROR  </item>
 *				<item> NAMAILC_CANCELLED </item>
 *				<item> NAMAILC_SYNTAXERROR </item>
 *				<item> NAMAILC_GENERALERROR  </item>
 *				<item> NAMAILC_BUFFERFULL </item>
 *          </list>
 * @param	list_buffer		Pointer to the user buffer which will contain the mail status information.
 * @param   user_data    	User data given in MCRegisterListMail
 * 
 * @see @link MCRegisterListMail
 * @see @link MCListMail
 * @see @link NAMAILC
 */
typedef void (* mc_list_callback_fn)(unsigned long handle, int status, char * list_buffer, unsigned long user_data);

/**
 * This mc_file_callback_fn is a callback function prototype for processing file 
 * attachment data. This is a user's callback function for sending or receiving 
 * file attachment. User must called MCRegisterSend_File for sending file attachments
 * and MCRegisterRetr_File for receiving file attachment.
 * 
 * For sending file attachment:
 *
 *		This user callback function is to get file data for each file attachments
 *		and is called continuously until it reaches the end of a file.
 *
 *		The filename argument is the file name given in MCAdd_Attachment.
 *
 *		The readBuffer is pointer to memory where file data will be copied to.
 *		This callback function must copy data into this readBuffer pointer.
 *
 *      The bytesRead is pointer to the size of readBuffer.
 *		This callback needs to update this to the number of bytes has been 
 *		copied into readBuffer
 *
 *		The theCompletionStatusPtr is updated by the callback function indicating
 *		one of the following:
 *  	<list type="unordered">
 *			<item> READPENDING  - It's pending to read the file attachment data.
 *								The callback will be called again.</item>
 *			<item> READCOMPLETE - The readBuffer has data and ready to be sent. 
 *								The callback will be called again for more data.</item>
 *			<item> ENDOFFILE	- It reaches the end of file. 
 *								The callback will not be called again.</item>
 *		</list>
 *
 * For retrieving file attachment:
 *
 *		The user callback is called and given file attachment data.
 *
 *		The filename argument indicates whether the data is body message or file attachment.
 *  	<list type="unordered">
 *			<item> MC_BODY_MESSAGE  - The given data is body message. </item>
 *			<item> MC_ATTACHMENT_MESSAGE - The given data is file attachment data.</item>
 *		</list>
 *
 *		The readBuffer is pointer to buffer which contain file data.
 * 		The bytesRead is pointer to number of bytes in readBuffer. This will 
 *		be updated with the actual number of bytes that has been processed by
 *	 	the callback function.
 *
 *		The theCompletionStatusPtr is updated by the callback function indicating
 *		one to the following:
 *  	<list type="unordered">
 *			<item> ACTIONPENDING  - The data remains pending in the buffer.
 *								  The callback will be called again for the
 *								  data that has not been processed.</item>
 *			<item> ACTIONCOMPLETED  - It finishes processing the data in the buffer.
 *									The callback will be called again for more data 
 *									in the file attachment if any.</item>
 *		</list>
 *
 *		When readBuffer & byteRead are NULL, it indicates it's end of the attachment. 
 *		This callback will be called again for next file attachment if any.
 *
 * @since 6.0
 * @external
 * @category Email_Services
 *
 * @param   handle        	Identifier of the mail client that is returned by MCCreate.
 * @param   filename		Pointer to buffer indicating the name of a file.
 *
 * @param	readBuffer		Pointer to the buffer for file data 
 *							See above for detail on sending or retrieveing file.
 * @param 	byteRead	    Pointer to the size of readBuffer
 *							See above for detail on sending or retrieveing file.
 * @param 	theCompletionStatusPtr	Pointer to completion status.
 * @param   user_data    	User data given in MCRegisterSend_File or MCRegisterRetr_File.
 * 
 * @return	eRpNoError		Data was successfully processed.
 * @return	<0				Data was unsuccessfully processed and error is encountered.
 *
 * @see @link MCRegisterRetr_File
 * @see @link MCRegisterSend_File
 * @see @link MCRetrMail
 * @see @link MCSendMail
 * @see @link MCAdd_Attachment
 * @see @link HttpFileCompletion
 * @see @link HttpFileAction
 * @see @link RpErrorCode
 */
typedef int (* mc_file_callback_fn)(unsigned long handle, char * filename, char * readBuffer, int * byteRead, int * theCompletionStatusPtr, unsigned long user_data);
/**
 * This mc_retr_callback_fn is a callback function prototype for retrieving mail.
 * This is a user's callback and it's called when POP3 has retrieved a mail or error 
 * occurs.
 *
 * @since 6.0
 * @external
 * @category Email_Services
 *
 * @param   handle        		Identifier of the mail client that is returned by MCCreate
 * @param   error_status 		The status of the mail retrieval
 *          <list type="unordered">
 *				<item> NAMAILC_OK  </item> 	               
 *				<item> NAMAILC_MISSADDRESS  </item>
 *				<item> NAMAILC_INVALIDBODY  </item>
 *				<item> NAMAILC_NOSERVER  </item>
 *				<item> NAMAILC_NOMAILBOX </item>
 *				<item> NAMAILC_TCPERROR  </item>
 *				<item> NAMAILC_CANCELLED </item>
 *				<item> NAMAILC_SYNTAXERROR </item>
 *				<item> NAMAILC_MAILBOXBUSY  </item>
 *				<item> NAMAILC_GENERALERROR  </item>
 *				<item> NAMAILC_BUFFERFULL </item>
 *				<item> NAMAILC_FILESYSTEMERROR </item>
 *				<item> NAMAILC_INVALIDFILE </item>
 *				<item> NAMAILC_NOATTACHFILENAME  </item>
 *				<item> NAMAILC_NOATTACHDATA  </item>
 *				<item> NAMAILC_INVALIDATTACHSIZE  </item>
 *				<item> NAMAILC_TOOMANYATTACH </item>
 *				<item> NAMAILC_INVAILDMAILID </item>
 *          </list>
 * @param	message_count	Number of attachments
 * @param	body			Pointer to the body of the email message. This is given
 *							by user when calling MCRetrMail_Read.
 * @param   body_length  	The lenght of the body 
 * @param   userData    	User data
 * 
 * @see @link NAMAILC
 */
typedef void (* mc_retr_callback_fn)(unsigned long handle, int error_status, unsigned int message_count, char * body, int body_length, unsigned long userData);
/**
 * This mc_send_callback_fn is a callback function prototype for sending mail.
 * This is a user's callback and it's called when SMTP has sent a mail or error 
 * occurs.
 * 																			  
 * @since 6.0
 * @external
 * @category Email_Services
 * 
 * @param   handle        		Identifier of the mail client that is returned by MCCreate
 * @param   error_status 		The mail status
 *          <list type="unordered">
 *				<item> NAMAILC_OK  </item> 	               
 *				<item> NAMAILC_MISSADDRESS  </item>
 *				<item> NAMAILC_INVALIDBODY  </item>
 *				<item> NAMAILC_NOSERVER  </item>
 *				<item> NAMAILC_NOMAILBOX </item>
 *				<item> NAMAILC_TCPERROR  </item>
 *				<item> NAMAILC_CANCELLED </item>
 *				<item> NAMAILC_SYNTAXERROR </item>
 *				<item> NAMAILC_MAILBOXBUSY  </item>
 *				<item> NAMAILC_GENERALERROR  </item>
 *				<item> NAMAILC_BUFFERFULL </item>
 *				<item> NAMAILC_FILESYSTEMERROR </item>
 *				<item> NAMAILC_INVAILDMAILID </item>
 *          </list>
 * @param    user_data			User data
 *
 * @see @link NAMAILC
 */
typedef void (* mc_send_callback_fn)(unsigned long handle, int error_status, unsigned long user_data);

/**
 * This mc_client_callback_fn is a callback function prototype for user logging in, 
 * logging out, deleting mail and undeleting mail.
 *
 * @since 6.0
 * @external
 * @category Email_Services
 *
 * @param   handle 		Identifier of the mail client that is returned by MCCreate.
 * @param   status 		The status whether error occurs:  
 *          <list type="unordered">
 *				<item> NAMAILC_OK  </item> 	               
 *				<item> NAMAILC_MISSADDRESS  </item>
 *				<item> NAMAILC_INVALIDBODY  </item>
 *				<item> NAMAILC_NOSERVER  </item>
 *				<item> NAMAILC_NOMAILBOX </item>
 *				<item> NAMAILC_TCPERROR  </item>
 *				<item> NAMAILC_CANCELLED </item>
 *				<item> NAMAILC_SYNTAXERROR </item>
 *				<item> NAMAILC_MAILBOXBUSY  </item>
 *				<item> NAMAILC_GENERALERROR  </item>
 *				<item> NAMAILC_INVAILDMAILID </item>
 *          </list>
 * @param   user_data    User data given in MCRegisterLogin or MCRegisterDel 
 * @param   type		Type of command that was sent to the mail server.
 *          <list type="unordered">
 *				<item> MC_USER_LOGOUT 	User logging out </item>
 *				<item> MC_USER_LOGIN 	User logging in </item>
 *				<item> MC_UNDELETE_MAIL Undeleting mail </item>
 *				<item> MC_DELETE_MAIL 	Deleting mail </item>
 *          </list>
 * 
 * @see @link MCRegisterLogin
 * @see @link MCUserLogin
 * @see @link MCUserLogout
 * @see @link MCRegisterDel
 * @see @link MCDeleteMail
 * @see @link MCUndeleteAll
 * @see @link NAMAILC
 * @see @link mc_client_cmd_types
 */
typedef void (* mc_client_callback_fn)(unsigned long handle, int status, unsigned long user_data, int type);

/**
 * This mc_summary_callback_fn is a callback function prototype to return number  
 * messages for a mailbox.
 *
 * @since 6.0
 * @external
 * @category Email_Services
 *
 * @param   handle 		Identifier of the mail client that is returned by MCCreate.
 * @param   status 		The status whether error occurs:  
 *          <list type="unordered">
 *				<item> NAMAILC_OK  </item> 	               
 *				<item> NAMAILC_MISSADDRESS  </item>
 *				<item> NAMAILC_INVALIDBODY  </item>
 *				<item> NAMAILC_NOSERVER  </item>
 *				<item> NAMAILC_NOMAILBOX </item>
 *				<item> NAMAILC_TCPERROR  </item>
 *				<item> NAMAILC_CANCELLED </item>
 *				<item> NAMAILC_SYNTAXERROR </item>
 *				<item> NAMAILC_MAILBOXBUSY  </item>
 *				<item> NAMAILC_GENERALERROR  </item>
 *				<item> NAMAILC_INVAILDMAILID </item>
 *          </list>
 * @param   message_count	Number of messages in the mailbox.
 * @param   user_data    User data given in MCRegisterListMail
 * 
 * @see @link MCRegisterSummary
 * @see @link MCSummary
 * @see @link NAMAILC
 * @see @link mc_client_cmd_types
 */
typedef void (* mc_summary_callback_fn)(unsigned long handle, int status, int message_count, unsigned long user_data);

unsigned long MCCreate(int type, int sport, char * sip, int smtp_port, char * smtp_ip);
int MCClose(unsigned long handle);
int MCRegisterLogin(unsigned long handle, mc_client_callback_fn callback, 
					unsigned long user_data);
int MCUserLogin(unsigned long handle, char * user, char * pass, int wait);
int MCUserLogout(unsigned long handle, int wait);
int MCNewMail(unsigned long handle, unsigned long * mail_id);
int MCCancelMail(unsigned long handle, unsigned long mail_id);
int MCAdd_ToAddr(unsigned long handle, unsigned long mail_id, char * to_addr[]);
int MCAdd_CopyAddr(unsigned long handle, unsigned long mail_id, char * cc_addr[]);
int MCAdd_ExtraHeaders(unsigned long handle, unsigned long mail_id, char * extra_header);
int MCRegisterSend(unsigned long handle, unsigned long mail_id, mc_send_callback_fn callback, 
					unsigned long user_data);

int MCRegisterSend_File(unsigned long handle, unsigned long mail_id, mc_file_callback_fn callback, 
						unsigned long user_data);

int MCAdd_Attachment(unsigned long handle, unsigned long mail_id, char *filename[], 
					int file_type, unsigned int access_code);

int MCSendMail(unsigned long handle, unsigned long mail_id, char * from_addr, char * to_addr, 
				char * subject, char * bodybuf, int body_type, int wait);

int MCRegisterRetr_Mail(unsigned long handle, mc_retr_callback_fn callback, 
					unsigned long user_data);

int MCRegisterRetr_File(unsigned long handle, mc_file_callback_fn callback, 
						unsigned long user_data);

int MCRetrMail(unsigned long handle, int msgId, char * readBuffer, unsigned long * readLength, 
				BOOLEAN includeHeader, int wait);

int MCRegisterListMail(unsigned long handle, mc_list_callback_fn callback, 
						unsigned long user_data);

int MCListMail(unsigned long handle, int start_id, int end_id, char * buffer, int bufsize, 
				BOOLEAN includeHeader, int wait);

int MCRegisterDel(unsigned long handle, mc_client_callback_fn callback, 
					unsigned long user_data);

int MCDeleteMail(unsigned long handle, int msgId, int wait);
int MCUndeleteAll(unsigned long handle, int wait);

int MCSetSignature(unsigned long handle, char * signature);
char * MCGetSignature(unsigned long handle);
int MCSetDomain(unsigned long handle, char * domain);
char * MCGetDomain(unsigned long handle);
int MCRegisterSummary(unsigned long handle, mc_summary_callback_fn callback, unsigned long user_data);
int MCSummary(unsigned long handle, int wait);
/**
 * Function allowing users to set the file name format of email attachments
 *
 * @category Email_Services
 * @since 6.0
 * @external
 * 
 * @param AttachmentType	Defines whether the current or new format is used    
 *
 * @return "Return value" None
 *
 * @see @link mc_attach_filename_type
 */

void NASmtpSetAttachmentNameType(int AttachmentType);

#ifdef __cplusplus
}
#endif

#endif /* __NA_MAILCAPI_H */
