Click here to Skip to main content
15,884,664 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.6K   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

 
QuestionNeed help Pin
syed rahman29-Oct-08 12:21
syed rahman29-Oct-08 12:21 
Generalthe program cann't monitor send mail Pin
人海孤鸿31-Mar-08 17:21
人海孤鸿31-Mar-08 17:21 
GeneralRe: the program cann't monitor send mail Pin
sergiols1-Apr-08 3:27
sergiols1-Apr-08 3:27 
GeneralRe: the program cann't monitor send mail Pin
人海孤鸿2-Apr-08 17:11
人海孤鸿2-Apr-08 17:11 
GeneralMS Outlook Pin
Programm3r15-Feb-07 2:50
Programm3r15-Feb-07 2:50 
General2 BUGFIXES Pin
Skippy847-Jan-06 3:14
Skippy847-Jan-06 3:14 
Generaldon't functionate! Pin
Devil for ever27-Nov-05 7:09
Devil for ever27-Nov-05 7:09 
GeneralRe: don't functionate! Pin
doggybear9-May-06 12:16
doggybear9-May-06 12:16 
GeneralGet the Attachment Pin
Gajalakshmi Krishnan11-Apr-05 5:07
Gajalakshmi Krishnan11-Apr-05 5:07 
GeneralMailMonitor++ development is moved Pin
sergiols19-Jan-05 13:23
sergiols19-Jan-05 13:23 
Generaltechnique to detect new mail Pin
saif502-Jan-05 1:58
saif502-Jan-05 1:58 
GeneralRe: technique to detect new mail Pin
sergiols3-Jan-05 13:14
sergiols3-Jan-05 13:14 
would u please explain the technique to detect the new mails.

the key is'n UIDL POP3 command:

UIDL [msg]

Arguments:
a message-number (optional), which, if present, may NOT
refer to a message marked as deleted

Restrictions:
may only be given in the TRANSACTION state.

Discussion:
If an argument was given and the POP3 server issues a positive
response with a line containing information for that message.
This line is called a "unique-id listing" for that message.

If no argument was given and the POP3 server issues a positive
response, then the response given is multi-line. After the
initial +OK, for each message in the maildrop, the POP3 server
responds with a line containing information for that message.
This line is called a "unique-id listing" for that message.

In order to simplify parsing, all POP3 servers are required to
use a certain format for unique-id listings. A unique-id
listing consists of the message-number of the message,
followed by a single space and the unique-id of the message.
No information follows the unique-id in the unique-id listing.

The unique-id of a message is an arbitrary server-determined
string, consisting of one to 70 characters in the range 0x21
to 0x7E, which uniquely identifies a message within a
maildrop and which persists across sessions. This
persistence is required even if a session ends without
entering the UPDATE state. The server should never reuse an
unique-id in a given maildrop, for as long as the entity
using the unique-id exists.

Note that messages marked as deleted are not listed.

While it is generally preferable for server implementations
to store arbitrarily assigned unique-ids in the maildrop,

this specification is intended to permit unique-ids to be
calculated as a hash of the message. Clients should be able
to handle a situation where two identical copies of a
message in a maildrop have the same unique-id.

Possible Responses:
+OK unique-id listing follows
-ERR no such message

Examples:
C: UIDL
S: +OK
S: 1 whqtswO00WBw418f9t5JxYwZ
S: 2 QhdPYR:00WBw1Ph7x7
S: .
...
C: UIDL 2
S: +OK 2 QhdPYR:00WBw1Ph7x7
...
C: UIDL 3
S: -ERR no such message, only 2 messages in maildrop
(From http://www.faqs.org/rfcs/rfc1939.html[^])

This uniqueIDs saved in registry, identifies each mail.

What will be changes to compile with VC++ 6.0

This project was made in VS C++ 6.0, if you creates a new project in vs c++6.0 it will compile Ok. Smile | :)
GeneralAnother one with open source Pin
Member 3076129-Nov-04 23:53
Member 3076129-Nov-04 23:53 
GeneralRe: Another one with open source Pin
Ravi Bhavnani11-Nov-04 15:34
professionalRavi Bhavnani11-Nov-04 15:34 
GeneralRe: Another one with open source Pin
Blake Miller22-Feb-05 12:14
Blake Miller22-Feb-05 12:14 
GeneralRe: Another one with open source Pin
Ravi Bhavnani22-Feb-05 12:24
professionalRavi Bhavnani22-Feb-05 12:24 
GeneralRe: Another one with open source Pin
Blake Miller22-Feb-05 12:35
Blake Miller22-Feb-05 12:35 
GeneralRe: Another one with open source Pin
Ravi Bhavnani22-Feb-05 12:41
professionalRavi Bhavnani22-Feb-05 12:41 
GeneralCurrent Version doesn't work Pin
bryce1-Nov-04 16:03
bryce1-Nov-04 16:03 
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 

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.