Click here to Skip to main content
Licence CPOL
First Posted 4 Apr 2004
Views 104,631
Bookmarked 66 times

Mail Monitor++

By | 8 Nov 2004 | Article
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)

About the Author

sergiols

Web Developer

Argentina Argentina

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNeed help Pinmembersyed rahman12:21 29 Oct '08  
Generalthe program cann't monitor send mail Pinmemberjianpeng11474617:21 31 Mar '08  
GeneralRe: the program cann't monitor send mail Pinmembersergiols3:27 1 Apr '08  
GeneralRe: the program cann't monitor send mail Pinmemberjianpeng11474617:11 2 Apr '08  
GeneralMS Outlook PinmemberProgramm3r2:50 15 Feb '07  
General2 BUGFIXES PinmemberSkippy843:14 7 Jan '06  
Generaldon't functionate! PinmemberDevil for ever7:09 27 Nov '05  
GeneralRe: don't functionate! Pinmemberdoggybear12:16 9 May '06  
GeneralGet the Attachment PinmemberGajalakshmi Krishnan5:07 11 Apr '05  
GeneralMailMonitor++ development is moved Pinmembersergiols13:23 19 Jan '05  
Generaltechnique to detect new mail Pinmembersaif501:58 2 Jan '05  
GeneralRe: technique to detect new mail Pinmembersergiols13:14 3 Jan '05  
GeneralAnother one with open source PinmemberIgor Green23:53 9 Nov '04  
GeneralRe: Another one with open source PinmemberRavi Bhavnani15:34 11 Nov '04  
GeneralRe: Another one with open source PinmemberBlake Miller12:14 22 Feb '05  
GeneralRe: Another one with open source PinmemberRavi Bhavnani12:24 22 Feb '05  
GeneralRe: Another one with open source PinmemberBlake Miller12:35 22 Feb '05  
GeneralRe: Another one with open source PinmemberRavi Bhavnani12:41 22 Feb '05  
GeneralCurrent Version doesn't work Pinmemberbryce16:03 1 Nov '04  
GeneralRe: Current Version doesn't work Pinmemberbryce16:04 1 Nov '04  
GeneralRe: Current Version doesn't work Pinmembersergiols13:22 3 Nov '04  
GeneralUnable to open maildrop Pinmemberenjoywithme1:14 23 Jul '04  
GeneralRe: Unable to open maildrop Pinmembersergiols13:23 3 Nov '04  
QuestionHow to use it with Proxy Pinmemberritzi0:37 16 Jun '04  
GeneralRegistry Problem win98 win2k Pinmemberbobeth0:21 13 May '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 9 Nov 2004
Article Copyright 2004 by sergiols
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid