/*
 *            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.
 * JZW  11/16/05   Vantive 17262. Autodoc changes. A number of APIs that 
 *                  were obsoleted in V6.3 were marked as obsoleted in V7.0.
 *                 V6.3 was originally called V7.0. The change updates the autodoc
 *                 document to show that these APIs are obsoleted in V6.3
 * JZW  03/06/06   Vantive 18030. Updated autodoc description of bytesRead for
 *                 attachment style mail callback function. Cleared up some
 *                 confusion.
 */

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

#include "Npttypes.h"
#include "AsExtern.h"

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

#define NAMAILC_ATTACHMENT_DEVANDFILE 0
#define NAMAILC_ATTACHMENT_FILEONLY 1

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

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

/*ad*
 * Mail user client command types
 *
 * @category Email_Services
 * @since 6.0
 * @include			"mailcapi.h"
 * @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
*ad*/
typedef enum {
    MC_USER_LOGOUT,
    MC_USER_LOGIN,
    MC_UNDELETE_MAIL,
    MC_DELETE_MAIL
} mc_client_cmd_types;

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


/*ad*
 * 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"
 * @include			"mailcapi.h"
 * @external
 *
 * @param MC_BODY_MESSAGE       Body message of a mail
 * @param MC_ATTACHMENT_MESSAGE File attachment in a mail
*ad*/
#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
 * @include			"mailcapi.h"
 * @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

/*ad*
 * Error codes from Mail Services 
 *
 * @external
 * @include			"mailcapi.h"
 * @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
 * @param NAMAILC_INVALIDUSERNAME       Invalid user name
 * @param NAMAILC_INVALIDAUTHTYPE       Invalid authentication type
 * @param NAMAILC_INVALIDLENGTH         Invalid length field
 * @param NAMAILC_NOMEMORY				Out of memory
 * @param NAMAILC_NOTCONNECTED			Not connect or login to the server
 * @param NAMAILC_NOMESSAGE			    No Message in the mailbox
*ad*/

#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
#define NAMAILC_INVALIDUSERNAME       -22
#define NAMAILC_INVALIDAUTHTYPE       -23
#define NAMAILC_INVALIDLENGTH         -24
#define NAMAILC_NOMEMORY			  -25
#define NAMAILC_NOTCONNECTED		  -26
#define NAMAILC_NOMESSAGE             -27

#ifdef MC_VERSION_3_1
/**
 * Mail attachment structure
 *
 * @obsolete 6.3 This structure is only used on deprecated 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.
 *
 * @obsolete 6.3 This structure is only used on deprescated functions.
 * @category Email_Services
 * @since 6.0
**/
typedef  attachments * attachmentPtr;

/**
 * Mail message types
 *
 * @obsolete 6.3 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;

#endif

/*ad*
 * Mail authentication type
 *
 * @category Email_Services
 * @include			"mailcapi.h"
 * @external
 * @since 6.1
 *
 * @param MC_SMTP_AUTH_NONE       No Authentication
 * @param MC_SMTP_AUTH_DIGESTMD5  Digest MD5 only, authentication fails if 
 *                                server doesn't support Digest MD5
 * @param MC_SMTP_AUTH_CRAMMD5    Cram MD5 only, authentication fails if 
 *                                server doesn't support Cram MD5
 * @param MC_SMTP_AUTH_LOGIN      Login only, authentication fails if 
 *                                server doesn't support Login
 * @param MC_SMTP_AUTH_PLAIN      Plain only, authentication fails if 
 *                                server doesn't support Plain
 * @param MC_SMTP_AUTH_ANY        Checks the server ehlo response for the 
 *                                server supported authentication in the 
 *                                following order:
 *                                <list type="ordered">
 *                                  <item> Digest-MD5 </item>
 *                                  <item> CRAM-MD5 </item>
 *                                  <item> LOGIN </item>
 *                                  <item> PLAIN </item>
 *                                </list>
 *
 * @see @link MCSetSmtpAuthentication 
 * 
 * @note Separate entry for MC_SMTP_AUTH_CRAMMD5, MC_SMTP_AUTH_LOGIN and 
 *       MC_SMTP_AUTH_PLAIN are added in NET+OS 7.3
 *
*ad*/

typedef enum
{
    MC_SMTP_AUTH_NONE,
    MC_SMTP_AUTH_DIGESTMD5,
    MC_SMTP_AUTH_CRAMMD5,
    MC_SMTP_AUTH_LOGIN,
    MC_SMTP_AUTH_PLAIN,
    MC_SMTP_AUTH_ANY
} MC_SMTP_AUTH_T;

unsigned long MCCreate(int type, int sport, char *sip, int smtp_port, char *smtp_ip);
int MCClose(unsigned long handle);

#ifdef MC_VERSION_3_1
/**
 * Callback registration function for listing mail status from MCRegisterLIST
 *
 * @obsolete 6.3 This function type is only used for deprecated function.
 * @external
 * @include			"mailcapi.h"
 * @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
 *
 * @obsolete 6.3 This function type is only used for deprecated function.
 * @include			"mailcapi.h"
 * @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
 *
 * @obsolete 6.3 This function type is only used for deprecated function.
 * @include			"mailcapi.h"
 * @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.
 *
 * @obsolete 6.3 This function type is only used for deprecated function.
 * @include			"mailcapi.h"
 * @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
 *
 * @obsolete 6.3 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);

/*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);

#endif /* MC_VERSION_3_1 */

/*ad*
 * 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
 * @include			"mailcapi.h"
 * @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
*ad*/
typedef void (* mc_list_callback_fn)(unsigned long handle, int status, char * list_buffer, unsigned long user_data);

/*ad*
 * 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 a file as an 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 parameter bytesRead is pointer to the size of readBuffer.
 *      This callback needs to update this parameter with the number of bytes that
 *      this callback function copied into readBuffer. When the callback function is
 *      called, bytesRead contains the size of the buffer (readbuffer as described 
 *      immediately above). Prior to the callback function exiting, 
 *      the callback function is required to update bytesRead with the number of 
 *      bytes actually copied into readBuffer. That number can be less than or 
 *      equal to the value of bytesRead passed into the callback function. This number 
 *      must never exceed the number originally passed into the callback function.  
 *
 *      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
 * @include			"mailcapi.h"
 * @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.
 * @param   fileInfo        File informtion includes file data type and access code.
 * 
 * @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
*ad*/
typedef int (* mc_file_callback_fn)(unsigned long handle, char * filename, char * readBuffer, int * byteRead, int * theCompletionStatusPtr, unsigned long user_data, FILEINFO fileInfo);
/*ad*
 * 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
 * @include			"mailcapi.h"
 * @category Email_Services
 *
 * @param   handle              Identifier of the mail client that is returned by MCCreate
 * @param   error_status        The status of the mail retrievel
 *          <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
*ad*/
typedef void (* mc_retr_callback_fn)(unsigned long handle, int error_status, unsigned int message_count, char * body, int body_length, unsigned long userData);
/*ad*
 * 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
 * @include			"mailcapi.h"
 * @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
*ad*/
typedef void (* mc_send_callback_fn)(unsigned long handle, int error_status, unsigned long user_data);

/*ad*
 * This mc_client_callback_fn is a callback function prototype for user logging in, 
 * logging out, deleting mail and undeleting mail.
 *
 * @since 6.0
 * @include			"mailcapi.h"
 * @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
*ad*/
typedef void (* mc_client_callback_fn)(unsigned long handle, int status, unsigned long user_data, int type);

/*ad*
 * This mc_summary_callback_fn is a callback function prototype to return number  
 * messages for a mailbox.
 *
 * @since 6.0
 * @include			"mailcapi.h"
 * @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
*ad*/
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_File(unsigned long handle, unsigned long mail_id, char * filename[]);

int MCAdd_Attachment(unsigned long handle, unsigned long mail_id, char *filename[], 
                    rpDataType file_type, unsigned int access_code);
int MCAdd_SpecialAttachment(unsigned long handle, unsigned long mail_id, 
					char * filename[], char *mime_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_CapturedAttachmentName(unsigned long handle, int file_index, char ** capture_name);

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

int MCRetrMailFileSystem(unsigned long handle, int msgId, char * prefix, 
						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);

int MCSetSmtpAuthentication(unsigned long handle, char * user, char * password, MC_SMTP_AUTH_T authFlag);

int NAMCSetCharsetandMailername(unsigned int charset, char const * mailername);

/*ad*
 * Function allowing users to set the file name format of email attachments
 *
 * @category Email_Services
 * @since 6.0
 * @include			"mailcapi.h"
 * @external
 * 
 * @param AttachmentType	Defines whether the current or new format is used    
 *
 * @see @link mc_attach_filename_type
*ad*/

void NASmtpSetAttachmentNameType(int AttachmentType);

#ifdef __cplusplus
}
#endif

#endif /* __NA_MAILCAPI_H */


