Click here to Skip to main content
13,293,369 members (42,978 online)
Click here to Skip to main content
Add your own
alternative version

Stats

124.5K views
5.1K downloads
72 bookmarked
Posted 4 Apr 2004

Mail Monitor++

, 8 Nov 2004
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

sergiols
Web Developer
Argentina Argentina
No Biography provided

You may also be interested in...

Pro

Comments and Discussions

 
GeneralRe: Registry Problem win98 win2k Pin
sergiols3-Nov-04 14:23
membersergiols3-Nov-04 14:23 
GeneralRegistry Problem win98 win2k Pin
bobeth13-May-04 1:15
memberbobeth13-May-04 1:15 
GeneralNot working Pin
bdiamond29-Apr-04 10:04
memberbdiamond29-Apr-04 10:04 
GeneralRe: Not working Pin
sergiols3-Nov-04 14:26
membersergiols3-Nov-04 14:26 
GeneralGrande mono Pin
Gargolan28-Apr-04 18:28
memberGargolan28-Apr-04 18:28 
GeneralDoesn't Work Pin
Hing5-Apr-04 16:24
memberHing5-Apr-04 16:24 
GeneralRe: Doesn't Work Pin
sergiols5-Apr-04 16:47
membersergiols5-Apr-04 16:47 
GeneralRe: Doesn't Work Pin
Hing5-Apr-04 18:33
memberHing5-Apr-04 18:33 
Hello,

The following lines are what I got in "emails.txt":

+OK <27707.1081222190@gs17.globe-it.com>
+OK
+OK
+OK 0 0
+OK <27711.1081222191@gs17.globe-it.com>
+OK
+OK
+OK 0 0
+OK <27717.1081222192@gs17.globe-it.com>
+OK
+OK
+OK 0 0
+OK <27720.1081222192@gs17.globe-it.com>
+OK
+OK
+OK 0 0

I am looking forwards to your reply.

Best regards,
Hing
GeneralRe: Doesn't Work Pin
Luis Alonso Ramos5-Apr-04 19:09
memberLuis Alonso Ramos5-Apr-04 19:09 
GeneralRe: Doesn't Work Pin
Hing5-Apr-04 19:13
memberHing5-Apr-04 19:13 
GeneralRe: Doesn't Work Pin
DavidCrow22-Aug-07 8:37
mvpDavidCrow22-Aug-07 8: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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 9 Nov 2004
Article Copyright 2004 by sergiols
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid