POP.CPP
上传用户:chenhai826
上传日期:2007-04-11
资源大小:72k
文件大小:1k
- // Pop.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "Pop.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////////
- // CPop Class
- //////////////////////////////////////////////////////////////////////
- CPop::CPop()
- {
- m_PopServer.Create();
- }
- CPop::~CPop()
- {
- m_PopServer.Close();
- }
- int CPop::Connect(CString & Host, CString & User, int Password)
- {
- CString str;
- int err;
- if (!m_PopServer.Connect(Host))
- return REPORT_CONNECT_ERROR;
- if((err = CheckResponse())!=1)
- return (err==0)?REPORT_CONNECT_ERROR:REPORT_BAD_OTHER;
- str.Format("USER %srn",User);
- m_PopServer.Send(str.GetBuffer(100),str.GetLength());
- if((err=CheckResponse())!=1)
- return (err==0)?REPORT_BAD_USER:REPORT_BAD_OTHER;
- str.Format("PASS %drn",Password);
- m_PopServer.Send(str.GetBuffer(100),str.GetLength());
- if ((err=CheckResponse())!=1)
- return (err==0)?REPORT_BAD_PASSWORD:REPORT_BAD_OTHER;
- return REPORT_SUCCEED;
- }
- int CPop::CheckResponse()
- {
- char buf [512];
- int i = m_PopServer.Receive(buf, sizeof(buf));
- if(i == SOCKET_ERROR)
- return REPORT_BAD_OTHER;
- return buf[0] != '-';
- }
- void CPop::Disconnect(void)
- {
- m_PopServer.Send("QUIT rn", strlen("QUIT rn"));
- }