Click here to Skip to main content
15,889,266 members
Articles / Desktop Programming / ATL
Article

Mail Monitor++

Rate me:
Please Sign up or sign in to vote.
4.82/5 (13 votes)
8 Nov 2004CPOL 143.8K   5.4K   71   36
A POP3 Monitor application.

Sample Image - MailMonitor.jpg

Introduction

This article describes a Pop3 Monitor application.

Features

The mailmonitor++ has the following features:

  • Fast email check.
  • Animation and sound to notify incoming messages.
  • Starts you favorite email client.

Sample screenshot

Email account configuration.

Main protocol:

void CPop3Check::ParseMsg()
{
  CString s;
  strstream str;
  string check;
  str <<(LPCSTR)lastMsg;
  str >> check;

  if (check == "-ERR")
  {
    error = "Error -ERR from server :"+lastMsg;
    Close();
    return;
  }
  switch (state)
  {
    case FIRST:
      fromUltMensaje = "";
      newmsgs =0;
      numnewmsg = 0;
      ((DLG)m_pWnd)->Dispatch(S_RECEIVE); 
      s.Format("user %s%c%c", user, 13, 10);
      Send((LPCSTR)s, s.GetLength()); 
      state = USER;
      break;
    
    case USER:
      ((DLG)m_pWnd)->Dispatch(S_RECEIVE);
      s.Format("pass %s%c%c", pass, 13, 10); 
      Send((LPCSTR)s, s.GetLength()); 
      state = PASS;
      break;
    
    case PASS:
      ((DLG)m_pWnd)->Dispatch(S_RECEIVE);
      s.Format("stat%c%c", 13, 10);
      Send((LPCSTR)s, s.GetLength()); 
      state = STAT; 
      break;
    
    case STAT:
      {
        ud->initRegMsgs();
        string s1;
        str.seekg(0);
        str >> s1 >> numMsg >> sizeMsg; 
        flush(str);
        ((DLG)m_pWnd)->Dispatch(S_GETNUMMSGS);
        ((DLG)m_pWnd)->Dispatch(S_GETSIZEMSGS);
        if (numMsg>0)
        {
          state = UIDL;
          s.Format("uidl 1%c%c", 13, 10);
          bufmail = "";
          retrMsg = 1;
          Send((LPCSTR)s, s.GetLength()); 
        }
        else 
        {
          error = "No new messages.";
          Close();
        }
      }
      break;
    case UIDL:
      {
        string s1, s2;
        int p1;
        CString uidl;
        str.seekg(0);
        str >> s1 >> p1 >> s2;
        uidl = s2.data();
        if (ud->IsNewMail(uidl))
        {
          newmsgs += 1;
          numnewmsg = retrMsg;
        }

        if (retrMsg < numMsg) 
        {
          retrMsg++;
          state = UIDL;
          s.Format("uidl %d%c%c", retrMsg, 13, 10);
          Send((LPCSTR)s, s.GetLength());
        }
        else
        {
          if (newmsgs == 1)
          {
            state = RETR;
            s.Format("top %d %d%c%c", numnewmsg, MAX_TOPLINES_EMAIL, 13, 10); 
            bufmail = "";
            Send((LPCSTR)s, s.GetLength()); 
          }
          else
          {
            state = ENDRETR;
            ((DLG)m_pWnd)->Dispatch(S_ENDRETR);
            error = "Session closed";
            s.Format("quit%c%c", 13, 10);
            Send((LPCSTR)s, s.GetLength());
            Close();
          }
        }
      }
      break;

    case RETR:
      {
        bufmail += lastMsg;

        int where = bufmail.Find("From:");
        if (where >= 0 && where + 80 < bufmail.GetLength())
        {
          fromUltMensaje = "";
          ReadLn(where + 5, bufmail, fromUltMensaje);

          char *sfrom = (char*)calloc(fromUltMensaje.GetLength()+1, sizeof(char));
          strcpy(sfrom, fromUltMensaje);
          fromUltMensaje = MimeDecodeMailHeaderField(sfrom);
          free(sfrom);

          state = ENDRETR;
          ((DLG)m_pWnd)->Dispatch(S_ENDRETR);
          error = "Session closed";
          s.Format("quit%c%c", 13, 10);
          Send((LPCSTR)s, s.GetLength());
          Close();
        }
      }
      break;
    case GOON: // default
    default:
      ((DLG)m_pWnd)->Dispatch(S_RECEIVE);
      break;
  }
}

Credits

History

  • 05/04/2004 - Initial version.
  • 03/11/2004 – UserName suffix bug – Fixed.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Current Version doesn't work Pin
bryce1-Nov-04 16:04
bryce1-Nov-04 16:04 
GeneralRe: Current Version doesn't work Pin
sergiols3-Nov-04 13:22
sergiols3-Nov-04 13:22 
GeneralUnable to open maildrop Pin
enjoywithme23-Jul-04 1:14
enjoywithme23-Jul-04 1:14 
GeneralRe: Unable to open maildrop Pin
sergiols3-Nov-04 13:23
sergiols3-Nov-04 13:23 
QuestionHow to use it with Proxy Pin
ritzi16-Jun-04 0:37
ritzi16-Jun-04 0:37 
GeneralRegistry Problem win98 win2k Pin
bobeth13-May-04 0:21
bobeth13-May-04 0:21 
GeneralRe: Registry Problem win98 win2k Pin
sergiols3-Nov-04 13:23
sergiols3-Nov-04 13:23 
GeneralRegistry Problem win98 win2k Pin
bobeth13-May-04 0:15
bobeth13-May-04 0:15 
When running on (at least) win98 or win2k, I found that you will end up with many additional Usuario keys inserted under the Servidor key, each with one additional space-character after the name, which prevents an "equal-found-so-just-update-this-one" resolution to the CReg... update operation that occurs with each check-email operation.

To prevent this, update the userData class method as follows (assumes that the argument is read-only):

int userData::setUsuario(CString unUsuario)
{
this->Usuario = unUsuario;
// add fix for string length
this->Usuario.TrimRight();
// end fix
return 0;
}

Use regedit to remove all current instances of "username" below "Server-encrypted-key" below "MailMonitor++" below "Software" below "HKEY_CURRENT_USER", and then everything should continue working as expected without additional instances of the same username added.


This is a good project.

I would like to extend it.

I have multiple email accounts, and each of them is being spammed with over 100 messages per day, so instead of having to receive the message headers and data of each of these, I want to automatically eliminate/delete-from-that-server (based upon header-info only) any email arriving from a source that is NOT on my "WhiteList" of acceptable sources for that username for that server.

This source-value should be describable as (as in trendmicro antispam notation) an individual USERNAME (USER@XXX.ZZZZZZ) or a domain (XXX.ZZZZZZ) or a keyword (portion of domain) (XXX as in anyuser@XXX.zzzzzz). These are the ones to keep. Any other incoming messages are to be deleted, unseen and without notification of delivery.

This extension is basically no more than a smart-compare of header-source information against a CStringList of perhaps 100 entries of good-guys. There should be added to the application box a button to activate a dialog box for whitelist maintenance and option-setting, and a base-screen indication as to whether this deletion-option is activated.
Whether this info is authoritative from the registry or from a text-file imported to the registry would be up to you, but you must also be able to export from registry to text to possibly transport to multiple machines with the same setup and operating at the same time.

If you would like to create this extension, that would be great, if not then please respond with an email address where I can send my own attempt at this extension, and then you can rework this code that I created into what you consider acceptable for inclusion in your project.

Respond offline to roberte@stcc.cc.x.us.




GeneralNot working Pin
BlackDice29-Apr-04 9:04
BlackDice29-Apr-04 9:04 
GeneralRe: Not working Pin
sergiols3-Nov-04 13:26
sergiols3-Nov-04 13:26 
GeneralGrande mono Pin
Gargolan28-Apr-04 17:28
Gargolan28-Apr-04 17:28 
GeneralDoesn't Work Pin
Hing5-Apr-04 15:24
Hing5-Apr-04 15:24 
GeneralRe: Doesn't Work Pin
sergiols5-Apr-04 15:47
sergiols5-Apr-04 15:47 
GeneralRe: Doesn't Work Pin
Hing5-Apr-04 17:33
Hing5-Apr-04 17:33 
GeneralRe: Doesn't Work Pin
Luis Alonso Ramos5-Apr-04 18:09
Luis Alonso Ramos5-Apr-04 18:09 
GeneralRe: Doesn't Work Pin
Hing5-Apr-04 18:13
Hing5-Apr-04 18:13 
GeneralRe: Doesn't Work Pin
David Crow22-Aug-07 7:37
David Crow22-Aug-07 7:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.