Click here to Skip to main content
Click here to Skip to main content

Mail Monitor++

By , 8 Nov 2004
Rate this:
Please Sign up or sign in to vote.

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
No Biography provided

Comments and Discussions

 
QuestionNeed help Pinmembersyed rahman29-Oct-08 12:21 
Generalthe program cann't monitor send mail Pinmemberjianpeng11474631-Mar-08 17:21 
GeneralRe: the program cann't monitor send mail Pinmembersergiols1-Apr-08 3:27 
GeneralRe: the program cann't monitor send mail Pinmemberjianpeng1147462-Apr-08 17:11 
GeneralMS Outlook PinmemberProgramm3r15-Feb-07 2:50 
General2 BUGFIXES PinmemberSkippy847-Jan-06 3:14 
I´m a beginner in C++ and MFC Development but i found 2 little Bugs.
so i would post here the fixes.
 
(and sorry for my bad english)
 

 
in the function
 
LRESULT CMailMonitorDlg::OnTrayIcon(WPARAM wParam, LPARAM lParam)
 
you can add the follow 3Lines
 
KillTimer(3);
SetTrayIcon();
Shell_NotifyIcon(NIM_MODIFY, &tnid);

 
How you make it is youre choise.
 
example i add this
 
if (uMouseMsg == WM_LBUTTONDOWN)
{
KillTimer(3);
SetTrayIcon();
Shell_NotifyIcon(NIM_MODIFY, &tnid);
}

 
and delete follow WM_LBUTTONDOWN ||
 

the next is the bug when explorer crashes the Taskicon is not recreated.
 
MailMonitorDlg.cpp
 
find
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

 
after add this
const UINT CMailMonitorDlg::m_nTaskbarCreatedMsg = ::RegisterWindowMessage(_T("TaskbarCreated"));
 

at the end add this
 
// This is called whenever the taskbar is created (eg after explorer crashes
// and restarts. Please note that the WM_TASKBARCREATED message is only passed
// to TOP LEVEL windows (like WM_QUERYNEWPALETTE)
LRESULT CMailMonitorDlg::OnTaskbarCreated(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
//ToDo
MostrarTrayIcon();
return 0L;
}

 
MailMonitorDlg.h
 
find this
void MostrarTrayIcon();
after add this
static const UINT m_nTaskbarCreatedMsg;
 

 
find this
afx_msg LRESULT OnTaskbarNotifierClicked(WPARAM wParam, LPARAM lParam);
after add this
LRESULT OnTaskbarCreated(WPARAM wParam, LPARAM lParam);
 

 
-- modified at 12:06 Saturday 7th January, 2006
Generaldon't functionate! PinmemberDevil for ever27-Nov-05 7:09 
GeneralRe: don't functionate! Pinmemberdoggybear9-May-06 12:16 
GeneralGet the Attachment PinmemberGajalakshmi Krishnan11-Apr-05 5:07 
GeneralMailMonitor++ development is moved Pinmembersergiols19-Jan-05 13:23 

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.

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