00001
00002
00003 #ifndef UNmailAPIH
00004 #define UNmailAPIH
00005
00006
00007 #include "MimeDec.hpp"
00008 #include "Pop3Prot.hpp"
00009 #include "SmtpProt.hpp"
00010 #include "WSocket.hpp"
00011
00012 #include <vector.h>
00013 #include <map.h>
00014
00015 #define CMD_NONE 0
00016
00017 #define CMD_POP3_GET_ALL 1
00018 #define CMD_POP3_GET_MSG 2
00019 #define CMD_POP3_GET_LIST 4
00020 #define CMD_POP3_CONNECT 8
00021 #define CMD_POP3_DISCONNECT 16
00022 #define CMD_POP3_LIST 32
00023 #define CMD_POP3_LIST_IDS 64
00024 #define CMD_POP3_UNDEL 128
00025 #define CMD_POP3_DEL_LIST 256
00026 #define CMD_POP3_ABORT 512
00027 #define CMD_POP3_TOP_ALL 1024
00028 #define CMD_POP3_TOP_MSG 2048
00029 #define CMD_POP3_TOP_LIST 4096
00030 #define CMD_POP3_PARSE_ALL 8192
00031
00032 #define CMD_SMTP_CONNECT 16384
00033 #define CMD_SMTP_DISCONNECT 32768
00034 #define CMD_SMTP_ABORT 65536
00035
00036 enum MailState {connected, disconnected, listed, sendfinished, getfinished, delfinished};
00037
00038 struct Pop3MailInfo
00039 {
00040 int num;
00041 AnsiString uidl;
00042 int size;
00043 bool deleted;
00044
00045 AnsiString from;
00046 AnsiString dest;
00047 AnsiString date;
00048 AnsiString reply;
00049 AnsiString subject;
00050 AnsiString contentType;
00051 };
00052
00053 class Pop3MailInfos
00054 {
00055 map<int, Pop3MailInfo, less<int> > container;
00056
00057 public:
00058
00059 bool __fastcall clear() { container.clear(); return true; }
00060 int __fastcall count() { return container.size(); }
00061 Pop3MailInfo * __fastcall at(int _num);
00062 Pop3MailInfo * __fastcall find(int _num);
00063 bool __fastcall add(Pop3MailInfo _sum) { container.insert(pair<int, Pop3MailInfo>(_sum.num, _sum)); return true; }
00064 bool __fastcall remove(int _num);
00065 };
00066
00067 class IcsMail
00068 {
00069
00070 void __fastcall onPop3ListBegin(TObject * Sender);
00071 void __fastcall onPop3ListLine(TObject * Sender);
00072 void __fastcall onPop3ListEnd(TObject * Sender);
00073 void __fastcall onPop3MessageBegin(TObject * Sender);
00074 void __fastcall onPop3MessageLine(TObject * Sender);
00075 void __fastcall onPop3MessageEnd(TObject * Sender);
00076 void __fastcall onPop3RequestDone(TObject *Sender, TPop3Request RqType, WORD Error);
00077 void __fastcall onPop3Response(TObject *Sender, AnsiString _message);
00078 void __fastcall onPop3UidlBegin(TObject * Sender);
00079 void __fastcall onPop3UidlLine(TObject * Sender);
00080 void __fastcall onPop3UidlEnd(TObject * Sender);
00081 void __fastcall onPop3SessionConnected(TObject * Sender, WORD Error);
00082 void __fastcall onPop3SessionClosed(TObject * Sender, WORD Error);
00083 void __fastcall onPop3Display(TObject * Sender, AnsiString _message);
00084 void __fastcall onPop3StateChange(TObject * Sender);
00085
00086
00087 void __fastcall onSmtpAttachContentType(TObject * Sender, int _fileNumber, AnsiString & _fileName, AnsiString & _contentType);
00088 void __fastcall onSmtpAttachHeader(TObject * Sender, int _fileNumber, AnsiString _fileName, TStrings * _hdrLines);
00089 void __fastcall onSmtpCommand(TObject * Sender, AnsiString _msg);
00090 void __fastcall onSmtpGetData(TObject * Sender, int _lineNum, void * _msgLine, int _maxLen, bool & _more);
00091 void __fastcall onSmtpHeaderLine(TObject * Sender, void * _msg, int _size);
00092 void __fastcall onSmtpProcessHeader(TObject * Sender, TStrings * _hdrLines);
00093 void __fastcall onSmtpRequestDone(TObject * Sender, TSmtpRequest RqType, WORD Error);
00094 void __fastcall onSmtpResponse(TObject * Sender, AnsiString _msg);
00095 void __fastcall onSmtpSessionClosed(TObject * Sender, WORD Error);
00096 void __fastcall onSmtpSessionConnected(TObject * Sender, WORD Error);
00097 void __fastcall onSmtpDisplay(TObject * Sender, AnsiString _msg);
00098
00099
00100 void __fastcall onMimeDecodeHeaderBegin(TObject *Sender);
00101 void __fastcall onMimeDecodeHeaderEnd(TObject *Sender);
00102 void __fastcall onMimeDecodeHeaderLine(TObject *Sender);
00103 void __fastcall onMimeDecodeInlineDecodeBegin(TObject *Sender, AnsiString Filename);
00104 void __fastcall onMimeDecodeInlineDecodeEnd(TObject *Sender, AnsiString Filename);
00105 void __fastcall onMimeDecodeInlineDecodeLine(TObject *Sender, void * Line, int Len);
00106 void __fastcall onMimeDecodePartBegin(TObject *Sender);
00107 void __fastcall onMimeDecodePartEnd(TObject *Sender);
00108 void __fastcall onMimeDecodePartHeaderBegin(TObject *Sender);
00109 void __fastcall onMimeDecodePartHeaderEnd(TObject *Sender);
00110 void __fastcall onMimeDecodePartHeaderLine(TObject *Sender);
00111 void __fastcall onMimeDecodePartLine(TObject *Sender, void * Data, int DataLen);
00112
00113 bool __fastcall initialize();
00114 bool __fastcall deInitialize();
00115
00116
00117 TStrings * mLog;
00118 TMemoryStream * mPop3memoryStream;
00119
00120 int mPop3callCommand;
00121
00122 int mPop3msgPosition;
00123 int mPop3msgLength;
00124
00125 vector<int> mPop3toGetList;
00126 vector<int> mPop3toDelList;
00127
00128
00129
00130 bool __fastcall pop3getMessage(int _num);
00131 bool __fastcall pop3deleteMessage(int _num);
00132
00133 bool __fastcall pop3processAttachments();
00134 bool __fastcall pop3processAttachments(TStream * _src, AnsiString _dstLocation);
00135 bool __fastcall pop3processAttachments(TStrings * _src, AnsiString _dstLocation);
00136
00137 bool __fastcall pop3list();
00138 bool __fastcall pop3top();
00139 bool __fastcall pop3listIDs();
00140
00141
00142 int mSmtpCallCommand;
00143 int mSmtpMsgPosition;
00144 TStrings * mSmtpBody;
00145
00146
00147 TMemoryStream * mMimeMemoryStream;
00148 AnsiString mMimeAttachmentDirectory;
00149
00150
00151 bool __fastcall mimeParseStream(TStream * _stream, AnsiString _attachmentsDir);
00152 bool __fastcall mimeParseFile(AnsiString _fileName, AnsiString _attachmentsDir);
00153
00154
00155 void __fastcall log(AnsiString msg);
00156
00157 TPop3Cli * mPop3cli;
00158 TMimeDecode * mMimeDecode;
00159 TSmtpCli * mSmtpCli;
00160
00161
00162 public:
00163
00164
00165 AnsiString mPop3inboxDirectory;
00166 Pop3MailInfos mPop3mailInfos;
00167
00168
00169 IcsMail();
00170 IcsMail(TPop3Cli * _pop3cli, TSmtpCli * _smtpCli, TMimeDecode * _mimeDecode);
00171 IcsMail(TPop3Cli * _pop3cli, TSmtpCli * _smtpCli, TMimeDecode * _mimeDecode, TStrings * _log);
00172
00173 ~IcsMail() { deInitialize(); }
00174
00175
00176 bool __fastcall setPop3cli(TPop3Cli * _pop3cli);
00177 bool __fastcall setSmtpCli(TSmtpCli * _smtpcli);
00178 bool __fastcall setMimeDecode(TMimeDecode * _mimeDecode);
00179 bool __fastcall setLog(TStrings * _sl);
00180
00181
00182 bool __fastcall pop3connect(AnsiString _hostName, AnsiString _userName, AnsiString _password, int _port = 110);
00183 bool __fastcall pop3disconnect();
00184
00185 bool __fastcall pop3parseMessage(int _num);
00186 bool __fastcall pop3parseAllMessages();
00187
00188 bool __fastcall pop3getMessage(int _num, AnsiString _inboxDir);
00189 bool __fastcall pop3getMessages(vector<int> & _listMailNumber, AnsiString _inboxDir);
00190 bool __fastcall pop3getAllMessages(AnsiString _inboxDir);
00191
00192 bool __fastcall pop3delMessage(int _num);
00193 bool __fastcall pop3delMessages(vector<int> & _listMailNumber);
00194 bool __fastcall pop3delAllMessages();
00195 bool __fastcall pop3undelMessages();
00196
00197 void __fastcall pop3abort();
00198
00199
00200
00201 bool __fastcall smtpConnect(AnsiString _hostName, AnsiString _userName, int _port = 25);
00202 bool __fastcall smtpDisconnect();
00203
00204 bool __fastcall smtpSendMessage(AnsiString _dest, TStrings * _recipients, AnsiString _subject, TStrings * _body, TStrings * _attachements, AnsiString _from = "", AnsiString _fromName = "");
00205
00206 bool __fastcall smtpAbort();
00207
00208
00209
00210 void ( __closure __fastcall *onPop3state )(MailState);
00211 void ( __closure __fastcall *onPop3progress )(int _position, int _read, int _total);
00212
00213 void ( __closure __fastcall *onSmtpState )(MailState);
00214 void ( __closure __fastcall *onSmtpProgress )(int _position, int _read, int _total);
00215 };
00216
00217 #endif
00218