- #pragma once
- /********************************************************************
- created: 2008:9:26 13:41
- author: 李欣
- filename: c:MyProjectSimpleMailSimpleMailReceiveManager.h
- classname: CReceiveManager
- purpose: implement the pop3 protocol to send the mail
- *********************************************************************/
- class CPopReceiveManager
- {
- public:
- CPopReceiveManager(void);
- public:
- ~CPopReceiveManager(void);
- ///<summary>
- /// receive the mails
- ///</summary>
- ///<param name = pSaveMngr>
- /// the object used to save the mails
- ///</param>
- ///<param name = phProgressDlg>
- /// the pointer to the progress dialog
- ///</param>
- ///<param name = arrPos>
- /// the position to locate each mail in the file
- ///</param>
- ///<param name = arrSize>
- /// the size of each mail
- ///</param>
- /// <returns>
- /// the value dictating whether it is successful
- /// </returns>
- HRESULT RecMail(IN CMailSaveMngr* pSaveMngr,
- IN CRecvProgressDlg* pProgressDlg,
- OUT CArray<MAILPOS>& arrPos,
- OUT CArray<UINT>& arrSize);
- ///<summary>
- /// delete the specified mail
- ///</summary>
- ///<param name = arrIndex>
- /// the index of the mail to be deleted
- ///</param>
- /// <returns>
- /// the value dictating whether it is successful
- /// </returns>
- HRESULT DelMail(IN const CArray<UINT>& arrIndex);
- ///<summary>
- /// set the user name
- ///</summary>
- void SetUserName(IN const CString& strUserName);
- ///<summary>
- /// set the password
- ///</summary>
- void SetPassword(IN const CString& strPassword);
- ///<summary>
- /// set the pop3 server address
- ///</summary>
- void SetPopServer(IN const CString& strPopServer);
- ///<summary>
- /// get the last error description
- ///</summary>
- CString GetLastErrorMsg();
- private:
- ///<summary>
- /// basic network functions
- ///</summary>
- BOOL Connect();
- BOOL Disconnect();
- //////////////////////////////////////////////////////////////////////////
- ///<summary>
- /// POP3 commands
- ///</summary>
- ///<summary>
- /// commands in the AUTHORIZATION state, identify the client to the POP3 server
- ///</summary>
- BOOL AuthorizationState();
- ///<summary>
- /// query the number of mails and the size of the maildrop
- ///</summary>
- BOOL CmdStat();
- ///<summary>
- /// query the message-number of the mail and the exact size of the mail
- ///</summary>
- ///<param name = nMsgNumber>
- /// specify the index of the mail which you want to know about if you don't want the all mail information
- ///</param>
- BOOL CmdList(IN const int nMsgNumber = 0);
- ///<summary>
- /// Receive any specified mail
- ///</summary>
- BOOL CmdRetr(IN const int nMsgNumber);
- ///<summary>
- /// Delete a specified mail from the server
- ///</summary>
- BOOL CmdDele(IN const int nMsgNumber);
- ///<summary>
- /// no action other than that the receiver send an OK reply
- ///</summary>
- BOOL CmdNoop();
- ///<summary>
- /// change the mails marked as deleted to be unmarked
- ///</summary>
- BOOL CmdRset();
- ///<summary>
- /// to enter the UPDATE state
- ///</summary>
- BOOL CmdQuit();
- ///<summary>
- /// get certain number of lines of the specified message's body
- ///</summary>
- ///<param name = nMsgNumber>
- /// the mail's index that you want
- ///</param>
- ///<param name = nLength>
- /// the line number you want to get
- ///</param>
- BOOL CmdTop(IN const int nMsgNumber, IN const int nLength);
- //////////////////////////////////////////////////////////////////////////
- ///<summary>
- /// read the response from the network
- ///</summary>
- ///<param name = pszBuf>
- /// the buffer to store the response
- ///</param>
- ///<param name = nBufSize>
- /// the size of the buffer
- ///</param>
- BOOL ReadResponse(INOUT LPSTR pszBuf, IN const int nBufSize);
- ///<summary>
- /// get the response and parse
- ///</summary>
- ///<param name = >
- /// the type of the command whose response you want to check
- ///</param>
- BOOL CheckResponse(IN const int nResponseType);
- ///<summary>
- /// get the first char meaningful in the response
- ///</summary>
- ///<param name = pszData>
- /// the origin data
- ///</param>
- /// <returns>
- /// the result of processing
- /// </returns>
- LPCSTR GetFirstMeaningChar(INOUT LPCSTR pszData) const;
- ///<summary>
- /// parse the response of STAT
- ///</summary>
- ///<param name = szBuf>
- /// the response to be parsed
- ///</param>
- BOOL ParseStatResponse(IN LPCSTR szBuf);
- ///<summary>
- /// parse the response of LIST
- ///</summary>
- ///<param name = szBuf>
- /// the response to be parsed
- ///</param>
- BOOL ParseListResponse(IN LPCSTR szBuf);
- ///<summary>
- /// parse the response of RETR
- ///</summary>
- ///<param name = szBuf>
- /// the response to be parsed
- ///</param>
- BOOL ParseRetrResponse(IN LPCSTR szBuf);
- ///<summary>
- /// parse the response of TOP
- ///</summary>
- ///<param name = szBuf>
- /// the response to be parsed
- ///</param>
- BOOL ParseTopResponse(IN LPCSTR szBuf);
- ///<summary>
- /// return the size of overall mails
- ///</summary>
- int GetTotalMailSize();
- ///<summary>
- /// set socket parameters
- ///</summary>
- BOOL SetNetParams();
- //////////////////////////////////////////////////////////////////////////
- ///<summary>
- /// the size of overall mails
- ///</summary>
- int m_nTotalSize;
- ///<summary>
- /// the current mail content received
- ///</summary>
- CString m_strMsgContents;
- ///<summary>
- /// the size of each mail
- ///</summary>
- CWordArray m_SizeOfMsg;
- ///<summary>
- /// the socket used for transmitting
- ///</summary>
- CSocket m_PopServer;
- ///<summary>
- /// the error description
- ///</summary>
- CString m_strError;
- ///<summary>
- /// the number of mails
- ///</summary>
- int m_nNumMail;
- ///<summary>
- /// the user name
- ///</summary>
- CString m_strUserName;
- ///<summary>
- /// the password
- ///</summary>
- CString m_strPassword;
- ///<summary>
- /// the pop3 server address
- ///</summary>
- CString m_strPopServer;
- ///<summary>
- /// the socket parameters
- ///</summary>
- int m_nRecvTimeout;
- int m_nSendTimeout;
- };