locked
POP3/IMAP mailserver/client application RRS feed

  • Question

  • hi everyone

    I'e created the class structure for the application as follows


    //class for creating socket,initilize socket,send and receive data
    class socket
    {
    public:
     socket();//constructor decalre
     virtual ~socket();//destructot delcare
     int Create(char* pszHostName, int nPort) ;
     int ConnectSocket(LPCSTR pszUser, LPCSTR pszPassword , BOOL bAPOPAuthentication);//Attempt connection to remote addr
     void Disconnect() ;
     int Close() ;
     int GetReceiveBufSize(long *lSize) ;
     int SetReceiveBufSize(long lSize) ;
     int GetMailList(char* strResult) ;
     int GetMailHeader(int nMailIndex , char* strMailHeader) ;
     int GetLastError(char* msg) ;
     int GetMailSize(int nMailIndex, long *lSize) ;
     int GetStat(char* strStat) ;
     int GetMailDate(int nMailIndex, char* strDate) ;
     int GetMailReceiver(int nMailIndex, char* strReceiver) ;
     int GetMailSender(int nMailIndex, char* strSender) ;
     int GetMailSubject(int nMainIndex, char* strSubject) ;
     int GetMail(int nMailIndex, char* tmpfilename) ;
     int DeleteMail(int nMailIndex) ;
     int ResetMail() ;
     int UpdateMailbox() ;
     int IsConnected() ;


     
    private:

     int   m_hEventWaitingRespond; 
     int   m_hEventExitThread; 
     long  m_lReceiveBufSize; 
     char*  m_dwTimeout;
     int   m_dwThreadId; 
     int   m_hThreadHandle; 
     BOOL  m_bSocketOK; 
     BOOL  m_bConnected;
     apr_socket_t  *m_sPop3Socket; 
     BOOL  m_bReceiving;
     char*  m_szReceiveBuf; 
     char*  m_strEnd; 
     char*  m_strLastError; 
     apr_file_t *m_fpTmp;
     apr_size_t lSize ;
     char*  *m_szReceive;
     long  m_lReceive;


     BOOL CheckMessage();
     void WaitForThreadExit();
     BOOL GetSocketResult(char* msg , char* EndFlag);
     BOOL SetLastError(char* msg);
     
    };


    I'm using the apache (apr) library functions for the development of the application.

    I need suggestions and the modifications to be done in the class structure so that the commandline tool will be efficient and easy to implement.

    thanX & regards 
    anilF
     

    Friday, September 16, 2005 8:57 AM

Answers

  • What's the problem with this implementation, anyway? Did you try it?

    I would use std::string rather than char*. It doesn't look like you avoid using CRT, because APR uses, AFAIK. So, for instance, I would use std::vector for mail list (I guess you mean UIDL.

    On the other hand, try to spare distinct concepts. What I mean is that a socket class is not an email client. socket class can be a base (or a member for a HAS-A [pimpl] implementation) for, say, POP3Socket class, which has methods dealing with retriving emails. You can also write another class, say, MIMEHeader that has GetSender, etc; to extract information from email header. You can also have a POP3Mail class that contains header, parts for multi-part messages, etc. Start with sparing concepts, and I strongly recommend you to use C++ classes rather than pointers.

    Ismail
    Friday, September 16, 2005 12:34 PM