• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1529
  • Last Modified:

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
0
clyde99
Asked:
clyde99
  • 7
  • 3
  • 3
  • +2
3 Solutions
 
MerijnBSr. Software EngineerCommented:
since 254 is nearly one byte, it almost sounds logical :)
0
 
clyde99Author Commented:
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.
0
 
ziolkoCommented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ziolkoCommented:
... 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.
0
 
clyde99Author Commented:
>... 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.
0
 
developmentguruCommented:
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.
0
 
ziolkoCommented:
try connect to your pop3 server with telnet
and see what list and stat returns then you'll be sure wheter it's pop server or indy

ziolko.
0
 
clyde99Author Commented:
>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.

0
 
clyde99Author Commented:
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.
0
 
TheRealLokiSenior DeveloperCommented:
This is GMail trying to be clever.
Changing settings in Gmail such as Archive when read may help your problem.

I've seen a few threads on other forums about this.
eg.
"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
lot of mail over the years, there's no way of downloading them locally
for backup.
I still like gmail, but very frustrated I can't download all of my email "

I'm also aware of an issue where GMail attempts to detect duplicates, so you may connect and see 1 mail waiting, but if you log on to the site, you may see 3
0
 
clyde99Author Commented:
>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
0
 
developmentguruCommented:
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.
0
 
clyde99Author Commented:
I would give it a go, but I can't see how I can issue this command using the indy pop3 client.
0
 
MerijnBSr. Software EngineerCommented:
I think what you want is not possible (at the moment), sorry. You're the victim of a gmail quirk.

I'd try to contact gmail support for this one, though I'm afraid there won't be an easy solution.
0
 
clyde99Author Commented:
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.
0
 
MerijnBSr. Software EngineerCommented:
that's entirely up to you.
Divide them over the people you think helped you to get to this conclusion :)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 7
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now