Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CPopProxyMT - A multi-threaded POP3 proxy skeleton

0.00/5 (No votes)
9 Oct 2002 1  
CPopProxyMT is a skeletal class that wraps a multi-threaded POP3 proxy. You can further modify this class to suite your needs.

Introduction

CPopProxyMT is a multi-threaded POP3 proxy server class that is a skeleton for you to work on and modify to suite your own purposes. In its bare condition, it is a simple POP3 proxy that can be installed and run on any Windows machine. Obviously some of you might have further uses for it, in which case you can expand on the class - for example you might want to filter out certain mails or you might want to log every mail that's received.

Class structure

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);
};

Sample usage

//...


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;

//...

Features

  • Multi-threaded (any number of POP clients can connect)
  • No MFC required

POP client configuration

  • POP3 server - This should be the domain name or IP address of your POP3 proxy server
  • Username - This should be the format :- username/POP3 server
  • Password - Your POP3 password

A sample configuration is shown below for Outlook Express 6

Credits

Well I wouldn't have written this class if not for Colin Davies who had asked me whether I'd mind writing such a class for him (he is a man with the most amazing ideas and I reckon this one is for one such idea of his). Thanks Colin, this one is for you :-)

History

  • October 10th 2002 - Although most of the code was written somewhere in mid-2001, this class was written only on 10-10-02

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here