Attribute VB_Name = "nMail"
Option Explicit

Public Const INVALID_SOCKET = -1

Public Const NMAIL_ATTACHMENT_TEMP_SIZE = 2000

Public Const NMAIL_SMTP_PORT = 25
Public Const NMAIL_SMTP_SUBMISSION_PORT = 587
Public Const NMAIL_SMTP_SSL_PORT = 465
Public Const NMAIL_POP3_PORT = 110
Public Const NMAIL_POP3_SSL_PORT = 995
Public Const NMAIL_IMAP4_PORT = 143
Public Const NMAIL_IMAP4_SSL_PORT = 993

Public Const NMAIL_ERROR_SOCKET = -1
Public Const NMAIL_ERROR_AUTHENTICATE = -2
Public Const NMAIL_ERROR_INVALID_NO = -3
Public Const NMAIL_ERROR_TIMEOUT = -4
Public Const NMAIL_ERROR_FILE_OPEN = -5
Public Const NMAIL_ERROR_PARTIAL = -6
Public Const NMAIL_ERROR_FILE_ALREADY = -7
Public Const NMAIL_ERROR_AUTHENTICATE_NO_SUPPORT = -8
Public Const NMAIL_ERROR_MEMORY = -9
Public Const NMAIL_ERROR = -10

Public Const NMAIL_ERROR_INVALID_PARAMETER = -11
Public Const NMAIL_ERROR_IMAP4_NO = -12
Public Const NMAIL_ERROR_IMAP4_BAD = -13
Public Const NMAIL_ERROR_IMAP4_NO_NAMESPACE = -14
Public Const NMAIL_ERROR_IMAP4_NO_IDLE = -15

Public Const NMAIL_ERROR_SUSPEND_ATTACHMENT_FILE = -20
Public Const NMAIL_ERROR_IMAP4_NO_RESULT = -21

Public Const NMAIL_ERROR_SSL_NO_SUPPORT = -30
Public Const NMAIL_ERROR_STARTTLS_NO_SUPPORT = -31

Public Const NMAIL_ERROR_OAUTH2_NO_CODE = -40
Public Const NMAIL_ERROR_OAUTH2_GET_CODE = -41
Public Const NMAIL_ERROR_OAUTH2_NO_TOKEN = -42
Public Const NMAIL_ERROR_JSON_NO_VALUE = -50

Public Const NMAIL_HTTP_OK = 200
Public Const NMAIL_HTTP_CREATED = 201
Public Const NMAIL_HTTP_ACCEPTED = 202
Public Const NMAIL_HTTP_NO_CONTENT = 204
Public Const NMAIL_HTTP_RESET_CONTENT = 205
Public Const NMAIL_ERROR_HTTP_BAD_REQUEST = -400
Public Const NMAIL_ERROR_HTTP_UNAUTHORIZED = -401
Public Const NMAIL_ERROR_HTTP_FORBIDDEN = -403
Public Const NMAIL_ERROR_HTTP_NOT_FOUND = -404
Public Const NMAIL_ERROR_HTTP_INTERNAL_SERVER_ERROR = -500

Public Const NMAIL_ERROR_SERVICE_NOT_AVAILABLE = -421
Public Const NMAIL_ERROR_MAILBOX_UNAVAILABLE = -450
Public Const NMAIL_ERROR_LOCAL_ERROR = -451
Public Const NMAIL_ERROR_INSUFFICIENT_SYSTEM_STORAGE = -452
Public Const NMAIL_ERROR_SYNTAX_ERROR = -500
Public Const NMAIL_ERROR_PARAMETER = -501
Public Const NMAIL_ERROR_COMMAND_NOT_IMPLEMENTED = -502
Public Const NMAIL_ERROR_BAD_SEQUENCE = -503
Public Const NMAIL_ERROR_USER_UNKOWN = -550
Public Const NMAIL_ERROR_USER_NOT_LOCAL = -551
Public Const NMAIL_ERROR_EXCEEDED_STORAGE_ALLOCATION = -552
Public Const NMAIL_ERROR_MAILBOX_NAME_NOT_ALLOWED = -553
Public Const NMAIL_ERROR_RELAY_OPERATION_REJECTED = -553
Public Const NMAIL_ERROR_TRANSACTION_FAILED = -554

Public Const NMAIL_NO_ATTACHMENT_FILE = -1
Public Const NMAIL_ATTACHMENT_FILE = 0

Public Const NMAIL_SUCCESS = 1

Public Const NMAIL_ADD_DATE_FIELD = 1
Public Const NMAIL_ADD_MESSAGEID_FIELD = 2
Public Const NMAIL_SUSPEND_ATTACHMENT_FILE = 4
Public Const NMAIL_SUSPEND_NEXT = 8
Public Const NMAIL_FILE_NAME_RFC2231 = 16
Public Const NMAIL_ENCODE_UTF8 = 32

Public Const NMAIL_SMTP_HTML = 64
Public Const NMAIL_SMTP_HTML_USE_FILE = 128
Public Const NMAIL_SMTP_HTML_AUTO_PART = 256
Public Const NMAIL_SMTP_HTML_NO_MIXED_PART = 512
Public Const NMAIL_SMTP_HTML_SOFTBANK = 512
Public Const NMAIL_SMTP_HTML_EMOBILE = 512
Public Const NMAIL_SMTP_HTML_WILLCOM = 512
Public Const NMAIL_SMTP_HTML_NO_RELATED_PART = 1024
Public Const NMAIL_SMTP_HTML_AU = 1024
Public Const NMAIL_SMTP_HTML_NO_PLAIN_PART = 2048
Public Const NMAIL_SMTP_HTML_SET_PLAIN_BODY = 4096

Public Const NMAIL_IMAP4_MIME_PART_SAVE_AS_FILE = 2048
Public Const NMAIL_IMAP4_MIME_PART_PEEK = 4096
Public Const NMAIL_IMAP4_MIME_PART_NO_DECODE = 8192
Public Const NMAIL_IMAP4_MIME_PART_HEADER = 16384
Public Const NMAIL_IMAP4_USE_UID As Long = 32768

Public Const NMAIL_PARTIAL_ATTACHMENT_FILE = 1
Public Const NMAIL_GET_TEXT_ONLY = 2

Public Const NMAIL_OPTION_TIMEOUT = 0
Public Const NMAIL_OPTION_HEADER_MAX = 1
Public Const NMAIL_OPTION_BODY_MAX = 2
Public Const NMAIL_OPTION_ALREADY_FILE = 3
Public Const NMAIL_OPTION_DEBUG_MODE = 4
Public Const NMAIL_OPTION_CONNECT_TIMEOUT = 5
Public Const NMAIL_OPTION_SPLIT_CHAR = 6
Public Const NMAIL_OPTION_SUSPEND_SIZE = 7
Public Const NMAIL_OPTION_SLEEP_TIME = 8
Public Const NMAIL_OPTION_FIELD_MAX = 9
Public Const NMAIL_OPTION_SAVE_HTML = 10
Public Const NMAIL_OPTION_DECODE_BODY = 11
Public Const NMAIL_OPTION_DECODE_HEADER = 12
Public Const NMAIL_OPTION_FILENAME_MAX = 13
Public Const NMAIL_OPTION_CHANGE_CHAR = 14
Public Const NMAIL_OPTION_CHANGE_CHAR_MODE = 15
Public Const NMAIL_OPTION_SAVE_RFC822 = 16
Public Const NMAIL_OPTION_TOP_LINE = 17

Public Const NMAIL_FILE_OVERWRITE = 0
Public Const NMAIL_FILE_RENAME = 1
Public Const NMAIL_FILE_ALREADY_ERROR = 2

Public Const NMAIL_GET_ERROR_MESSAGE = 0
Public Const NMAIL_GET_DEBUG_MESSAGE = 1

Public Const NMAIL_DEBUG_START = 1
Public Const NMAIL_DEBUG_END = 0

Public Const NMAIL_GET_UIDL_ALL = 0

Public Const NMAIL_CONNECT_TIMEOUT_ON = 1
Public Const NMAIL_CONNECT_TIMEOUT_OFF = 0

Public Const NMAIL_SMTP_AUTH_NOT_USE = 0
Public Const NMAIL_SMTP_AUTH_PLAIN = 1
Public Const NMAIL_SMTP_AUTH_LOGIN = 2
Public Const NMAIL_SMTP_AUTH_CRAM_MD5 = 4
Public Const NMAIL_SMTP_AUTH_DIGEST_MD5 = 8
Public Const NMAIL_SMTP_AUTH_OAUTH2 = 16

Public Const NMAIL_SAVE_HTML_OFF = 0
Public Const NMAIL_SAVE_HTML_ON = 1

Public Const NMAIL_DECODE_BODY_ON = 0
Public Const NMAIL_DECODE_BODY_ALL_OFF = 1
Public Const NMAIL_DECODE_BODY_TEXT_OFF = 2

Public Const NMAIL_DECODE_HEADER_ON = 0
Public Const NMAIL_DECODE_HEADER_OFF = 1
Public Const NMAIL_DECODE_HEADER_ALL_OFF = 2

Public Const NMAIL_CHANGE_SPLIT_CHAR = 0
Public Const NMAIL_CHANGE_HALF_SPACE = 1
Public Const NMAIL_CHANGE_FULL_SPACE = 2
Public Const NMAIL_CHANGE_ALL_SPACE = 3
Public Const NMAIL_CHANGE_NO_SPLIT_CHAR = 4

Public Const NMAIL_SAVE_RFC822_OFF = 0
Public Const NMAIL_SAVE_RFC822_BODY = 1
Public Const NMAIL_SAVE_RFC822_PART_ALL = 2

Public Const NMAIL_POP3_AUTH_NORMAL = 0
Public Const NMAIL_POP3_AUTH_APOP = 1
Public Const NMAIL_POP3_AUTH_OAUTH2 = 16

Public Const NMAIL_IMAP4_AUTH_PLAIN = 1
Public Const NMAIL_IMAP4_AUTH_LOGIN = 2
Public Const NMAIL_IMAP4_AUTH_CRAM_MD5 = 4
Public Const NMAIL_IMAP4_AUTH_DIGEST_MD5 = 8
Public Const NMAIL_IMAP4_AUTH_OAUTH2 = 16

Public Const NMAIL_IMAP4_MAILBOX_NO_SELECT = 1
Public Const NMAIL_IMAP4_MAILBOX_NO_INFERIOUS = 2
Public Const NMAIL_IMAP4_MAILBOX_MARKED = 4
Public Const NMAIL_IMAP4_MAILBOX_UNMARKED = 8
Public Const NMAIL_IMAP4_MAILBOX_CHILDREN = 16
Public Const NMAIL_IMAP4_MAILBOX_NO_CHILDREN = 32

Public Const NMAIL_IMAP4_MESSAGE_ANSWERED = 1
Public Const NMAIL_IMAP4_MESSAGE_DELETED = 2
Public Const NMAIL_IMAP4_MESSAGE_DRAFT = 4
Public Const NMAIL_IMAP4_MESSAGE_FLAGGED = 8
Public Const NMAIL_IMAP4_MESSAGE_RECENT = 16
Public Const NMAIL_IMAP4_MESSAGE_SEEN = 32

Public Const NMAIL_IMAP4_ADD_MESSAGE_FLAG = 1
Public Const NMAIL_IMAP4_DELETE_MESSAGE_FLAG = 2
Public Const NMAIL_IMAP4_REPLACE_MESSAGE_FLAG = 3

Public Const NMAIL_IMAP4_MAILBOX_MESSAGE = 1
Public Const NMAIL_IMAP4_MAILBOX_RECENT = 2
Public Const NMAIL_IMAP4_MAILBOX_UIDNEXT = 3
Public Const NMAIL_IMAP4_MAILBOX_UIDVALIDITY = 4
Public Const NMAIL_IMAP4_MAILBOX_UNSEEN = 5

Public Const NMAIL_IMAP4_SEARCH_ANSWERED = 1
Public Const NMAIL_IMAP4_SEARCH_UNANSWERED = 2
Public Const NMAIL_IMAP4_SEARCH_DELETED = 3
Public Const NMAIL_IMAP4_SEARCH_UNDELETED = 4
Public Const NMAIL_IMAP4_SEARCH_DRAFT = 5
Public Const NMAIL_IMAP4_SEARCH_UNDRAFT = 6
Public Const NMAIL_IMAP4_SEARCH_FLAGGED = 7
Public Const NMAIL_IMAP4_SEARCH_UNFLAGGED = 8
Public Const NMAIL_IMAP4_SEARCH_RECENT = 9
Public Const NMAIL_IMAP4_SEARCH_OLD = 10
Public Const NMAIL_IMAP4_SEARCH_SEEN = 11
Public Const NMAIL_IMAP4_SEARCH_UNSEEN = 12
Public Const NMAIL_IMAP4_SEARCH_NEW = 13
Public Const NMAIL_IMAP4_SEARCH_ALL = 14
Public Const NMAIL_IMAP4_SEARCH_KEYWORD = 15
Public Const NMAIL_IMAP4_SEARCH_UNKEYWORD = 16
Public Const NMAIL_IMAP4_SEARCH_FROM = 17
Public Const NMAIL_IMAP4_SEARCH_TO = 18
Public Const NMAIL_IMAP4_SEARCH_CC = 19
Public Const NMAIL_IMAP4_SEARCH_BCC = 20
Public Const NMAIL_IMAP4_SEARCH_SUBJECT = 21
Public Const NMAIL_IMAP4_SEARCH_SENTBEFORE = 22
Public Const NMAIL_IMAP4_SEARCH_SENTON = 23
Public Const NMAIL_IMAP4_SEARCH_SENTSINCE = 24
Public Const NMAIL_IMAP4_SEARCH_BEFORE = 25
Public Const NMAIL_IMAP4_SEARCH_ON = 26
Public Const NMAIL_IMAP4_SEARCH_SINCE = 27
Public Const NMAIL_IMAP4_SEARCH_HEADER = 28
Public Const NMAIL_IMAP4_SEARCH_BODY = 29
Public Const NMAIL_IMAP4_SEARCH_TEXT = 30
Public Const NMAIL_IMAP4_SEARCH_LARGER = 31
Public Const NMAIL_IMAP4_SEARCH_SMALLER = 32
Public Const NMAIL_IMAP4_SEARCH_UID = 33

Public Const NMAIL_IMAP4_SEARCH_COMMAND = 256

Public Const NMAIL_IMAP4_SEARCH_NOT = 512
Public Const NMAIL_IMAP4_SEARCH_OR = 1024
Public Const NMAIL_IMAP4_SEARCH_AND = 2048
Public Const NMAIL_IMAP4_SEARCH_FIRST = 4096
Public Const NMAIL_IMAP4_SEARCH_NO_WAIT = 8192
Public Const NMAIL_IMAP4_SEARCH_CHECK = 16384

Public Const NMAIL_IMAP4_NAMESPACE_PERSONAL_ALL = 0
Public Const NMAIL_IMAP4_NAMESPACE_OTHER_ALL = 1
Public Const NMAIL_IMAP4_NAMESPACE_SHARED_ALL = 2

Public Const NMAIL_IMAP4_NAMESPACE_PERSONAL_NO = 256
Public Const NMAIL_IMAP4_NAMESPACE_OTHER_NO = 512
Public Const NMAIL_IMAP4_NAMESPACE_SHARED_NO = 768

Public Const NMAIL_IMAP4_NAMESPACE_PERSONAL_COUNT = 4096
Public Const NMAIL_IMAP4_NAMESPACE_OTHER_COUNT = 8192
Public Const NMAIL_IMAP4_NAMESPACE_SHARED_COUNT = 12288

Public Const NMAIL_IMAP4_MIME_CONTENT_PART = 0
Public Const NMAIL_IMAP4_MIME_CONTENT_TYPE = 1
Public Const NMAIL_IMAP4_MIME_CONTENT_SUBTYPE = 2
Public Const NMAIL_IMAP4_MIME_CONTENT_ID = 3
Public Const NMAIL_IMAP4_MIME_CONTENT_DESCRIPTION = 4
Public Const NMAIL_IMAP4_MIME_CONTENT_TRANSFER_ENCODING = 5
Public Const NMAIL_IMAP4_MIME_CONTENT_FILE_NAME = 6
Public Const NMAIL_IMAP4_MIME_CONTENT_TYPE_AND_SUBTYPE = 7
Public Const NMAIL_IMAP4_MIME_CONTENT_SIZE = 8
Public Const NMAIL_IMAP4_MIME_CONTENT_LINE = 9
Public Const NMAIL_IMAP4_MIME_CONTENT_PARAMETER_COUNT = 10
Public Const NMAIL_IMAP4_MIME_CONTENT_PARAMETER = 11

Public Const NMAIL_MAKE_DATE_TIME_SMTP = 0
Public Const NMAIL_MAKE_DATE_IMAP4 = 32768
Public Const NMAIL_MAKE_DATE_TIME_IMAP4 = 65536
Public Const NMAIL_MAKE_DATE_NOW = 131072
Public Const NMAIL_MAKE_DATE_TIMEZONE_PLUS = 262144
Public Const NMAIL_MAKE_DATE_TIMEZONE_MINUS = 524288
Public Const NMAIL_MAKE_DATE_SIZE = 32

Public Const NMAIL_SSL_IGNORE_NOT_TIME_VALID = 2048
Public Const NMAIL_SSL_ALLOW_UNKNOWN_CA = 1024
Public Const NMAIL_SSL_IGNORE_INVALID_NAME = 64

Public Const NMAIL_SSL_SSL3 = 4096
Public Const NMAIL_SSL_TLS1 = 8192
Public Const NMAIL_SSL_STARTTLS = 16384
Public Const NMAIL_SSL_TLS1_2 = 65536
Public Const NMAIL_SSL_TLS1_3 = 131072

Public Const NMAIL_SSL_ERROR_UNTRUSTED_ROOT = -2146762487
Public Const NMAIL_SSL_ERROR_INTERNAL = -2146893052
Public Const NMAIL_SSL_ERROR_ILLEGAL_MESSAGE = -2146893018
Public Const NMAIL_SSL_ERROR_EXPIRED = -2146893016
Public Const NMAIL_SSL_ERROR_CN_NO_MATCH = -2146762481

Public Const NMAIL_OAUTH2_CODE_CHALLENGE_METHOD_PLAIN = 1
Public Const NMAIL_OAUTH2_HEADER_CLIENT_ID = 2
Public Const NMAIL_OAUTH2_GET_REFRESH_TOKEN = 16
Public Const NMAIL_OAUTH2_GET_ACCESS_TOKEN = 32

Public Const NMAIL_JSON_DECODE_ESCAPE = 128

Public Const NMAIL_HTTP_POST_X_WWW_FORM_URLENCODE = 512
Public Const NMAIL_HTTP_BASE64_AUTHORIZATION_BASIC = 1024
Public Const NMAIL_HTTP_GET = 4096
Public Const NMAIL_HTTP_PUT = 8192
Public Const NMAIL_HTTP_DELETE = 16384

Public Const NMAIL_RANDOM_STRING_ALPHANUMERIC = 1

Public Declare Function NMailGetVersion Lib "nMail" () As Long
Public Declare Function NMailInitializeWinSock Lib "nMail" () As Long
Public Declare Function NMailEndWinSock Lib "nMail" () As Long
Public Declare Function NMailPop3Connect Lib "nMail" (ByVal HostName As String) As Long
Public Declare Function NMailPop3ConnectPortNo Lib "nMail" (ByVal HostName As String, ByVal no As Long) As Long
Public Declare Function NMailPop3Authenticate Lib "nMail" (ByVal s As Long, ByVal Id As String, ByVal Password As String, ByVal ApopFlag As Boolean) As Long
Public Declare Function NMailPop3AuthenticateMode Lib "nMail" (ByVal s As Long, ByVal Id As String, ByVal Password As String, ByVal Mode As Integer) As Long
Public Declare Function NMailPop3Close Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailPop3GetMailSize Lib "nMail" (ByVal s As Long, ByVal no As Long) As Long
Public Declare Function NMailPop3DeleteMail Lib "nMail" (ByVal s As Long, ByVal no As Long) As Long
Public Declare Function NMailPop3GetMailStatus Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal SizeFlag As Long) As Long
Public Declare Function NMailPop3GetMail Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal filename As String) As Long
Public Declare Function NMailPop3GetMailEx Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal filename As String, ByVal temp As String, ByVal flag As Long) As Long
Public Declare Function NMailPop3GetMailPartial Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal filename As String) As Long
Public Declare Function NMailPop3GetUidl Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal Uidl As String, ByVal Max As Long) As Long
Public Declare Function NMailPop3GetAttachmentFileStatus Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal Id As String, ByVal Max As Long) As Long
Public Declare Function NMailSmtpSendMail Lib "nMail" (ByVal HostName As String, ByVal ToStr As String, ByVal Cc As String, ByVal Bcc As String, ByVal from As String, ByVal subject As String, ByVal Body As String, ByVal header As String, ByVal Path As String, ByVal flag As Long) As Long
Public Declare Function NMailSmtpSendMailPortNo Lib "nMail" (ByVal HostName As String, ByVal ToStr As String, ByVal Cc As String, ByVal Bcc As String, ByVal from As String, ByVal subject As String, ByVal Body As String, ByVal header As String, ByVal Path As String, ByVal flag As Long, ByVal PortNo As Long) As Long
Public Declare Function NMailSmtpConnect Lib "nMail" (ByVal HostName As String) As Long
Public Declare Function NMailSmtpConnectPortNo Lib "nMail" (ByVal HostName As String, ByVal no As Long) As Long
Public Declare Function NMailSmtpAuthenticate Lib "nMail" (ByVal s As Long, ByVal HostName As String, ByVal Id As String, ByVal Password As String, ByVal AuthMode As Long) As Long
Public Declare Function NMailSmtpSendMailEx Lib "nMail" (ByVal s As Long, ByVal ToStr As String, ByVal Cc As String, ByVal Bcc As String, ByVal from As String, ByVal subject As String, ByVal Body As String, ByVal header As String, ByVal Path As String, ByVal temp As String, ByVal flag As Long) As Long
Public Declare Function NMailSmtpClose Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailGetHeaderField Lib "nMail" (ByVal Field As String, ByVal header As String, ByVal name As String, ByVal Size As Long) As Long
Public Declare Function NMailDecodeHeaderField Lib "nMail" (ByVal Destination As String, ByVal Source As String, ByVal Size As Long) As Long
Public Declare Function NMailAttachmentFileFirst Lib "nMail" (ByVal temp As String, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal filename As String, ByVal FirstHeader As String, ByVal FirstBody As String) As Long
Public Declare Function NMailAttachmentFileNextVB Lib "nMail" (ByVal temp As String, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal filename As String, ByVal NextHeader As String, ByVal NextBody As String) As Long
Public Declare Function NMailAttachmentFileNext Lib "nMail" (ByVal temp As String, ByVal header As String, ByVal Body As String, ByVal NextHeader As String, ByVal NextBody As String) As Long
Public Declare Function NMailAttachmentFileClose Lib "nMail" (ByVal temp As String) As Long
Public Declare Function NMailAttachmentFileStatus Lib "nMail" (ByVal header As String, ByVal Id As String, ByVal Max As Long) As Long
Public Declare Function NMailSetOption Lib "nMail" (ByVal Opt As Long, ByVal Value As Long) As Long
Public Declare Function NMailGetOption Lib "nMail" (ByVal Opt As Long) As Long
Public Declare Function NMailGetSuspendNumber Lib "nMail" (ByVal Path As String) As Long
Public Declare Sub NMailGetMessage Lib "nMail" (ByVal Mtype As Long, ByVal Message As String, Max As Long)
Public Declare Sub NMailSetParameter Lib "nMail" (ByVal TimeOutSec As Long, ByVal HeaderMax As Long, ByVal BodyMax As Long)
Public Declare Function NMailImap4AppendMail Lib "nMail" (ByVal s As Long, ByVal MailBox As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal MessageFlag As Long, ByVal datestr As String, ByVal flag As Long) As Long
Public Declare Function NMailImap4Authenticate Lib "nMail" (ByVal s As Long, ByVal Id As String, ByVal Password As String, ByVal AuthMode As Long) As Long
Public Declare Function NMailImap4ChangeMessageFlag Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal MessageFlag As Long, ByVal Command As Long, ByVal flag As Long) As Long
Public Declare Function NMailImap4Close Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailImap4CloseMailBox Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailImap4Connect Lib "nMail" (ByVal HostName As String) As Long
Public Declare Function NMailImap4ConnectPortNo Lib "nMail" (ByVal HostName As String, ByVal PortNo As Long) As Long
Public Declare Function NMailImap4CopyMail Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal MailBox As String, ByVal flag As Long) As Long
Public Declare Function NMailImap4CreateMailBox Lib "nMail" (ByVal s As Long, ByVal MailBox As String) As Long
Public Declare Function NMailImap4DeleteMail Lib "nMail" (ByVal s As Long, ByVal no As Long, ByVal flag As Long) As Long
Public Declare Function NMailImap4DeleteMailBox Lib "nMail" (ByVal s As Long, ByVal MailBox As String) As Long
Public Declare Function NMailImap4ExpungeMail Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailImap4GetMail Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByVal Body As String, ByVal Path As String, ByVal filename As String, ByVal flag As Long) As Long
Public Declare Function NMailImap4GetMailBoxList Lib "nMail" (ByVal s As Long, ByVal Refer As String, ByVal MailBox As String, ByVal SubscribeFlag As Boolean) As Long
Public Declare Function NMailImap4GetMailBoxListStatus Lib "nMail" (ByVal s As Long, ByVal ListNo As Long, ByRef MailBoxFlag As Long, ByVal separate As String, ByVal MailBox As String, ByVal Size As Long) As Long
Public Declare Function NMailImap4GetMailBoxStatus Lib "nMail" (ByVal s As Long, ByVal MailBox As String, ByVal StatusType As Long, ByRef data As Long) As Long
Public Declare Function NMailImap4GetMailSize Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal flag As Long) As Long
Public Declare Function NMailImap4GetMailStatus Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal subject As String, ByVal datestr As String, ByVal from As String, ByVal header As String, ByRef MessageFlag As Long, ByVal flag As Long) As Long
Public Declare Function NMailImap4GetMimePart Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal PartNo As Long, ByVal Body As String, ByVal flag As Long) As Long
Public Declare Function NMailImap4GetMimeStructure Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal flag As Long) As Long
Public Declare Function NMailImap4GetMimeStructureStatus Lib "nMail" (ByVal s As Long, ByVal MimeType As Long, ByVal PartNo As Long, ByVal SubNo As Long, ByVal name As String, ByVal data As String, ByVal Size As Long) As Long
Public Declare Function NMailImap4GetNameSpace Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailImap4GetNameSpaceStatus Lib "nMail" (ByVal s As Long, ByVal NameType As Long, ByVal separate As String, ByVal name As String, ByVal Size As Long) As Long
Public Declare Function NMailImap4GetSearchMailResult Lib "nMail" (ByVal s As Long, ByVal ResultNo As Long, ByRef MailNo As Long) As Long
Public Declare Function NMailImap4GetUid Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByRef flag As Long) As Long
Public Declare Function NMailImap4NoOperation Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailImap4RenameMailBox Lib "nMail" (ByVal s As Long, ByVal OldMailBox As String, ByVal NewMailBox As String) As Long
Public Declare Function NMailImap4SaveMimePart Lib "nMail" (ByVal s As Long, ByVal MailNo As Long, ByVal PartNo As Long, ByVal Path As String, ByVal filename As String, ByVal flag As Long) As Long
Public Declare Function NMailImap4SearchMail Lib "nMail" (ByVal s As Long, ByVal SearchType As Long, ByVal text As String, ByVal flag As Long) As Long
Public Declare Function NMailImap4SelectMailBox Lib "nMail" (ByVal s As Long, ByVal MailBox As String, ByVal ReadOnlyFlag As Boolean) As Long
Public Declare Function NMailImap4SubscribeMailBox Lib "nMail" (ByVal s As Long, ByVal MailBox As String) As Long
Public Declare Function NMailImap4UnsubscribeMailBox Lib "nMail" (ByVal s As Long, ByVal MailBox As String) As Long
Public Declare Function NMailImap4StartIdle Lib "nMail" (ByVal s As Long, ByVal wnd As Long, ByVal msg As Long) As Long
Public Declare Function NMailImap4EndIdle Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailMakeDateString Lib "nMail" (ByVal datestr As String, ByVal Year As Long, ByVal Month As Long, ByVal Day As Long, ByVal Hour As Long, ByVal Minute As Long, ByVal Second As Long, ByVal flag As Long) As Long
Public Declare Function NMailPop3ConnectSsl Lib "nMail" (ByVal HostName As String, ByVal no As Long, ByVal flag As Long, ByVal Name As String) As Long
Public Declare Function NMailSmtpConnectSsl Lib "nMail" (ByVal HostName As String, ByVal no As Long, ByVal flag As Long, ByVal Name As String) As Long
Public Declare Function NMailImap4ConnectSsl Lib "nMail" (ByVal HostName As String, ByVal no As Long, ByVal flag As Long, ByVal Name As String) As Long
Public Declare Function NMailSmtpSendMailSsl Lib "nMail" (ByVal HostName As String, ByVal ToStr As String, ByVal Cc As String, ByVal Bcc As String, ByVal from As String, ByVal subject As String, ByVal Body As String, ByVal header As String, ByVal Path As String, ByVal PortNo As Long, ByVal flag As Long, ByVal Name As String) As Long
Public Declare Function NMailOAuth2StartRedirectServer Lib "nMail" (ByVal RedirectUri As String, ByVal ResponseOK As String, ByVal ResponseError As String, ByVal Wnd As Long, ByVal Msg As Long, ByVal Flag As Long) As Long
Public Declare Function NMailOAuth2StartRedirectServerPortNo Lib "nMail" (ByVal PortNo As Integer, ByVal ResponseOK As String, ByVal ResponseError As String, ByVal Wnd As Long, ByVal Msg As Long, ByVal Flag As Long) As Long
Public Declare Function NMailOAuth2RequestAuthorize Lib "nMail" (ByVal AuthUri As String, ByVal ClientId As String, ByVal RedirectUri As String, ByVal Scope As String, ByVal State As String, ByVal Verifier As String, ByVal Param As String, ByVal Flag As Long) As Long
Public Declare Function NMailOAuth2GetAuthorizeCode Lib "nMail" (ByVal s As Long, ByVal Code As String, ByVal CodeLength As Long, ByVal State As String, ByVal StateLength As Integer) As Long
Public Declare Function NMailOAuth2EndRedirectServer Lib "nMail" (ByVal s As Long) As Long
Public Declare Function NMailOAuth2GetRefreshToken Lib "nMail" (ByVal RequestUri As String, ByVal ClientId As String, ByVal ClientSecret As String, ByVal RedirectUri As String, ByVal Code As String, ByVal Verifier As String, ByVal Param As String, ByVal Header As String, ByVal Json As String, ByVal Length As Long, ByVal Flag As Long) As Long
Public Declare Function NMailOAuth2GetAccessToken Lib "nMail" (ByVal RequestUri As String, ByVal ClientId As String, ByVal ClientSecret As String, ByVal RefreshToken As String, ByVal Param As String, ByVal Header As String, ByVal Json As String, ByVal Length As Long, ByVal Flag As Long) As Long
Public Declare Function NMailJsonGetValue Lib "nMail" (ByVal Json As String, ByVal Key As String, ByVal Value As String, ByVal Length As Long, ByVal Flag As Long) As Long
Public Declare Function NMailMakeRandomString Lib "nMail" (ByVal Str As String, ByVal Length As Long, ByVal Flag As Long) As Long
Public Declare Function NMailHttpGetPost Lib "nMail" (ByVal PostUri As String, ByVal PostData As String, ByVal Header As String, ByVal Json As String, ByVal Length As Long, ByVal Flag As Long) As Long

Public Function NMailGetString(Src As String) As String
    If InStr(Src, Chr(0)) > 0 Then
        NMailGetString = Left(Src, InStr(Src, Chr(0)) - 1)
    Else
        NMailGetString = Src
    End If
End Function
