Article View: borland.public.cppbuilder.internet.socket
Article #5316Re: Get list of new messages in POP3
From: Jim Dodd
Date: Thu, 23 Sep 2004 13:07
Date: Thu, 23 Sep 2004 13:07
63 lines
3557 bytes
3557 bytes
Remy Lebeau (TeamB) wrote:
> "Jim Dodd" <bcbuilderboy@yahoo.com> wrote in message
> news:4151d06a$1@newsgroups.borland.com...
>
> If you are not going to download and delete the messages, then the best way
> to check for new messages is probably to keep a running list of all of the
> known message's IDs. Then each time you run the loop, you can check to see
> if any new IDs have appeared on the server.
>
> Gambit
>
>
Thank you, Gambit. You saved me from wasting more of my time. I've
decided to use the Date value (which is correct in the IdMessage object)
and keep track of when I last requested the information. I cycle through
the messages and check if any of them have a date and time since my last
check. If they do, I count that as a new message and report it at the
end. I found I needed to convert the local time in Date to UTC and
compare it with the UTC time of my last check so I could get around
Daylight Savings Time madness.
Here's a sample of my working version:
int NewMsgCount = 0;
Edit1->Text = String("Wait...");
Application->ProcessMessages();
IdPOP31->Connect();
int iMsg = IdPOP31->CheckMessages(); // get total messages
if( iMsg > 0 )
{
// loop through all messages to check Date
for( int iMsgNum = 1; iMsgNum <= iMsg; iMsgNum++ )
{
TIdMessage *idm = new TIdMessage(IdPOP31);
idm->Clear(); // may not be necessary
if( IdPOP31->RetrieveHeader(iMsgNum, idm) )
{
// GetFloatTimeZoneBias() is my function to
// get time zone and Daylight Savings Time bias
// to convert local time to UTC
TDateTime dt = idm->Date - GetFloatTimeZoneBias();
if( dt > LastUse )
NewMsgCount++;
}
delete idm;
}
}
IdPOP31->Disconnect();
Edit1->Text = String(NewMsgCount);
LastUse = GetUTC(); // my function to get PC time in UTC
I save LastUse in a configuration file so I can restore it the next time
the program runs. I run this program in the background doing this check
every five minutes or so. It checks all my e-mail accounts and warns me
when new mail arrives in any of them since the last check. This seems to
work (this is for my own use so I'm not going to spend much more time on
it). Thank you for steering me away from the wrong turn.
Regards,
Jim Dodd
Onset Computer Corp.
Technical Details
Message-ID:
<4152ca85$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4151d06a$1@newsgroups.borland.com> <4151dd11$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,6a75ae9b12954a47 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 23 Sep 2004 09:07:18 -0400 From: Jim Dodd <bcbuilderboy@yahoo.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.1) Gecko/20040707 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Get list of new messages in POP3 References: <4151d06a$1@newsgroups.borland.com> <4151dd11$1@newsgroups.borland.com> In-Reply-To: <4151dd11$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.75.243.226 Message-ID: <4152ca85$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1095944837 24.75.243.226 (23 Sep 2004 06:07:17 -0700) Lines: 63 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail