65.9K
CodeProject 正在变化。 阅读更多。
Home

CPopProxyMT - 多线程POP3代理骨架

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.69/5 (12投票s)

2002年10月10日

CPOL

1分钟阅读

viewsIcon

173792

downloadIcon

1805

CPopProxyMT 是一个多线程 POP3 代理的骨架类。您可以根据需要进一步修改此类。

引言

CPopProxyMT 是一个多线程 POP3 代理服务器类,作为您工作和修改的基础。在最基本的状态下,它是一个简单的 POP3 代理,可以安装并运行在任何 Windows 机器上。显然,有些人可能对它有进一步的用途,在这种情况下,您可以扩展该类 - 例如,您可能希望过滤掉某些邮件,或者您可能希望记录每封收到的邮件。

类结构

class CPopProxyMT
{
public:
    CPopProxyMT(void);
    ~CPopProxyMT(void);
private:
    SOCKET m_PopServerSocket;
    HANDLE m_ServerThread;
    // The thread that listens for connections
    static DWORD ServerThread(DWORD arg);
    int m_port;
    DWORD MServerThread(void); 
    static char* MakeCaps(char* str);
public:
    // This starts the multi-threaded POP proxy server
    int StartProxy(int port); 
private:
    // Flag that's set if the proxy is running
    BOOL bRunning;
    static DWORD ClientThread(DWORD arg); 
    void StartClientThread(SOCKET sock);
    static void StartDataThread(DWORD parm);
    static DWORD DataThread(DWORD parm);
public:
    BOOL IsRunning(void);
    void StopProxy(void);
};

使用示例

//...

CPopProxyMT pop_proxy;

//...

case WM_COMMAND: 
    switch (LOWORD(wParam)) 
    {
    case IDOK:
        // This is a sorta toggle button
        // It starts/stops the proxy alternatively
        if(pop_proxy.IsRunning())
        {
            pop_proxy.StopProxy();
            SetDlgItemText(hwnd,IDOK,"Start");
            SetDlgItemText(hwnd,IDC_EDIT1,"POP Proxy stopped");
        }
        else
        {               
            pop_proxy.StartProxy(3110);
            SetDlgItemText(hwnd,IDOK,"Stop");
            SetDlgItemText(hwnd,IDC_EDIT1,"POP Proxy running");
        }
        return TRUE;

//...

特点

  • 多线程(可以连接任意数量的 POP 客户端)
  • 不需要 MFC

POP 客户端配置

  • POP3 服务器 - 这应该是您的 POP3 代理服务器的域名或 IP 地址
  • 用户名 - 这应该是以下格式:用户名/POP3 服务器
  • 密码 - 您的 POP3 密码

下面显示了 Outlook Express 6 的示例配置

致谢

如果没有 Colin Davies 提出要求让我编写此类,我本不会编写它(他是一个拥有最棒想法的人,我认为这个想法也是他其中一个想法)。感谢 Colin,这个献给你 :-)

历史

  • 2002年10月10日 - 虽然大部分代码是在 2001 年年中左右编写的,但该类仅在 02-10-10 编写完成
© . All rights reserved.