Link to home
Start Free TrialLog in
Avatar of clyde99
clyde99

asked on

Delphi5, Indy 9, pop3, gmail

Hi,

I am having problems with google mail and pop3 access, using Indy 9.

I can access the pop3 account without any problems. However, my problem is the number of messages that the pop3 client can "see"

For testing purposes, this is what I did:

1. Created a new google mail account
2. Enabled pop3 for this account
3. Sent 500 messages to this account

Now, using Delphi 5 and Indy 9 I am using the pop3 client to connect.

I conned to the mail box OK and then use:

pop3.CheckMessages;

This is where it gets weird. The number returned by this command is 254, and I can't get access to the other 246 messages.

If I retrieve these messages, these are the first 254 messages sent.

If I log into my gmail account via the web and delete some of the messages, run the test program again, I can see some of the newer messages, but pop3.CheckMessages still only returns 254

Is this some magic number or is there a limit to the number of messages a gmail account will let you "pop" in one session?

Thanks for any help
Avatar of MerijnB
MerijnB
Flag of Netherlands image

since 254 is nearly one byte, it almost sounds logical :)
Avatar of clyde99
clyde99

ASKER

I have searched the Internet, but can't find any such limitation.

Others are using this combination of software but don't seem to have this problem. Perhaps they have never tried to read that many messages or there is a setting somewhere I am missing.

I was hoping that one of the experts would have a definitive answer on this.
I've looked into indy source code and found this:

function TIdPOP3.CheckMessages: longint;
var
  s: string;
begin
  Result := 0;
  SendCmd('STAT', wsOk);    {Do not Localize}
  // Only gets here if exception is not raised
  s := LastCmdResult.Text[0];
  if Length(s) > 0 then begin
    Result := StrToInt(Copy(s, 1, IndyPos(' ', s) - 1));    {Do not Localize}
  end;
end;


so i think that's value returned by gmail.

ziolko.
... take a look at this:
function TIdPOP3.RetrieveMailBoxSize: integer;
var
  CurrentLine: string;
begin
  // Returns the size of the mailbox. Issues a LIST command and then
  // sums up each message size. The message sizes are returned in the format
  // 1 1400 2 405 3 100 etc....
  // With this routine, we prevent the user having to call REtrieveSize for
  // each message to get the mailbox size
  Result := 0;
  try
    SendCmd('LIST', wsOk);    {Do not Localize}
    CurrentLine := ReadLn;
    while (CurrentLine <> '.') and (CurrentLine <> '') do    {Do not Localize}
    begin
      CurrentLine := Copy(CurrentLine, IndyPos(' ', CurrentLine) + 1,    {Do not Localize}
        Length(CurrentLine) - IndyPos(' ', CurrentLine) + 1);    {Do not Localize}
      Result := Result + StrToIntDef(CurrentLine, 0);
      CurrentLine := ReadLn;
    end;
  except
    Result := -1;
  end;
end;

maybe this will help to write your own method to retrive message count:)

ziolko.
Avatar of clyde99

ASKER

>... take a look at this:
>function TIdPOP3.RetrieveMailBoxSize: integer;

Unfortunately, same problem with this function.

When I debug this function it only processes 252 messages as well

I am at a loss to understand why no one else has run into this problem.
On a hunch I would try the same thing with Indy 10 components.  Perhaps the problem has already been addressed.  If you find that does not work either I will see if I can spend more time on it.
SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clyde99

ASKER

>On a hunch I would try the same thing with Indy 10 components.

You can't have Indy 9 and 10 loaded at the same time.

Converting to Indy 10 is currently not an option for me because I have many projects that use Indy 9 and changes in Indy 10 have broken the way pop3 works with existing code. There are other compatibility issues as well.

>try connect to your pop3 server with telnet

Google pop3 uses SSL on port 995 - I am not that familiar with telent clients but I don't think the standard Windows telnet client supports SSL

What I would really like is for someone to open up a gmail account and send it 500 messages (or I can do this) and do the same testing I am doing, with the view of debugging the exact problem.

If we can resolve the exact problem in this way I would be willing to double the point value or even higher.

Avatar of clyde99

ASKER

I would also add that this is a gmail specific issue (as indicated in my question title).

If have done the same test with other pop3 accounts and do not have any problems getting all the messages.

I know gmail does have some quirks, but I can't seem to find this exact issue when searching google.

This is why it puzzles me and I was hoping it was just something obvious and there was an easy fix.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clyde99

ASKER

>Pop access works, but gmail has a really *really* annoying feature.
>You're limited to downloading only 200? 300? emails. So if you have a

OK, that is making sense and has helped push me in the right direction in the sense I now think I understand what the real problem  is.

I set up Outlook express to get the emails from this gmail account - and sure enough it only downloaded 252 emails. When I got it to check again, in the next pass it downloaded the other 248, giving me the expected total of 500 emails.

So it would appear that once you "read" a gmail email it flags the email as read. Flagging the email as "read" then makes room for other emails to be read in the next pass. So if you want access to all your emails in your gmail account you need to do multiple passes/checks.

Now here is my *real* problem. I only want to download certain messages (by interrogating the subject line) so I am currently using pop3.RetrieveHeader to get the header information, Then only "read" the email if there is a match. Multiple passes won't work in this scenario because the pop3.RetrieveHeader command does not read the "whole" message and therefor does not flag the google mail message as read.

I can live with the fact that I now need to do multiple passes when using gmail, but I don't want to download every message just to "flag" it as read to make room for more reads.This would be too time consuming (not to mention a bandwidth waste)

So now my question heads down a different path. If I could just issue a command that indicates to the google pop3 server that the email has been "read" without actaully reading the whole email I think my whole problem would be solved. After checking the message header I could then issue this command to indicate the email had been "read", making room for more emails to be read on the next pass.

I am no pop3 guru, so I am hoping there is a simple command I can issue to tell the gmail pop3 server the email has been read without actually reading it.

Does anyone know of such a command. If so how do you issue such a command when using the Indy pop3 client.

Thanks
You can try this.  From what I read some implementations of POP3 may not support the command...

http://www.freesoft.org/CIE/RFC/1725/7.htm

This allows you to request part of the message be read (first line).  If this marks your message as read then you will effectively have the ability you were looking for.  Let me know.
Avatar of clyde99

ASKER

I would give it a go, but I can't see how I can issue this command using the indy pop3 client.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clyde99

ASKER

Yes, I have come to the conclusion this is a gmail "quirk" that I (or the users that use my program) will have to live with.

That is, they will have to suffer the overhead of using pop3.Retrieve in order to be able to access messages beyond the "magic number"

So how do I close this question off now. I am happy to award points for help offered but who should I give them to?

Sorry, I don't fully understand how this process works.
that's entirely up to you.
Divide them over the people you think helped you to get to this conclusion :)