5
votes

I am trying to issue simple POP3 commands to Gmail like so:

openssl s_client -connect pop.gmail.com:995
+OK Gpop ready for requests from XX.XX.XX.XX
USER [email protected]
+OK send PASS
PASS mypassword
+OK Welcome.

Connection and authentication all works fine. However when I issue a STAT or LIST command I receive the following:

STAT
+OK 345 20351669

This states I have 345 messages in my Inbox. In actuality I have 180, only a few unread. This number couldn't be refering to ALL of my emails... I've had this account for 5 years and definitely have WAY more than 345. So, I started RETR'ing some messages. The newest one (#345) is from Jan 2007 and the oldest one (#1) is from late 2006. Over the course of writing this I've received a few new emails, but even after reconnecting and issuing new LIST commands the 345 number does not change.

I'm no e-mail/pop expert but I'm really stumped here... POP3 is enabled for "all messages" in gmail settings. I even tried doing this same thing with another Gmail account and I get the exact same results; a really low message count and really old messages.

Any ideas?

7

7 Answers

2
votes

try

USER recent:my-email

instead of

USER my-email

Seems like the "recent:" prefix on the username re-fetches the most recent messages:

How to re-download recent Gmail messages

1
votes

GMail itself will only give 300-400 messages when requested. In order to get the others, you need to supply the optional message number argument as specified in RFC1939 "Post Office Protocol - Version 3", section 5 "The TRANSACTION state", LIST command.

1
votes

This List is The list of emails in Inbox + Sent Emails folder! i just discovered that! perhaps other folders are being included.

0
votes

You might try changing your Gmail settings to turn off POP, then turn it back on for "only new messages". I remember that worked for me once, long ago.

0
votes

I have encounted the same probleam and what should you do is to change you gmail account POP Download settings in "setting"->"Forwarding and POP/IMAP"->"pop download". The default option is that "POP is enabled for all mail that has arrived since M/dd/yyyy" and you should change it to "Enable POP for all mail (even mail that's already been downloaded)". Everything is ok now.

0
votes

Gmail uses a "most recent 30 days" algorithm so that if you log in from multiple devices, each device sees all the messages even if another has already downloaded them.

0
votes

This is a common problem, unfortunately it does not always have the easiest solution. Hopefully, this information will help you and others arrive at the best implementation that suits your needs.

Gmail has its own Pop3 implementation, and with that said, not all of this is relevant to other pop3 providers Here is the lifecycle of the issue and some information that can help you manage it:

You connect to the pop3 server either in NORMAL mode or RECENT mode. This puts the "session" on the pop server into a "transaction state". Recent mode is used by prefixing the username on connection with "recent:" + Username. Recent mode will return the last 30 days of email on the server. Note* this will supersede the UIDL command which I will touch on below. I.e. recent mode will return all 30 days worth of email if they have not been removed. Since it always returns the last 30 days, if you have multiple clients, they will all receive the same information in recent mode.

Normal mode is the default. Normal mode will respect the limitations of the commands you choose to use. UIDL will return a chunk of roughly 250 of the oldest emails on the server. If you have 500 emails on the server, and you do not remove any, UIDL will return the id and Unique Identifier for those first 250 emails regardless, so you may not be aware of the new 250. The caveat here is as follows, GMAIL has an option on the web console where you configure pop, to "Enable pop from now on". By selecting that and saving, the timestamp at that moment will be used by the pop server to "refresh" the oldest time. Therefore UIDL will start returning messages back you from that point on up until you reach the 250 mark again (assuming you have not removed them).

It is important to note that the transaction state exists until you issue the QUIT command. Upon issuing that command the server enters the "Update" state, where it will begin issuing the updates you requested, like DELETE commands, or popping them after they have been downloaded. Until QUIT is issued successfully, nothing will be deleted and the server state does not change.

STAT command will show you the number of emails in the pop3 stack, that are on your server.

RETR command will retrieve, or download the email, but it is not marked as downloaded until you successfully end the session

UIDL which many developers use to retrieve the message numbers and unique identifiers, is very useful if you maintain the state of the server and pop the email. UIDL will only ever return the oldest 250-ish (I have seen 251-255) emails. If you are constantly polling for new email, this is dangerous if email hasn't been removed. ALSO! if you need to delete email, make sure the GMAIL setting to, Keep a copy in my inbox, is configured in the web console, so that you have access those emails as a backup.

LIST command would solve your problem in normal mode for getting more than 250 emails back, (note: you still need to maintain an id file locally to cross check incoming mail in order to know that it is new or old)... HOWEVER: this command also returns mail from the SENT box, which for many, is not a viable solution.

Hints:

If you are managing the inbox quickly and effectively and do not believe 250 to be a limiting factor in your process, UIDL and RETR will work.

If you will not be able to keep your inbox below 250 but also need access to new email, AND you do not expect the inbox to grow to outrageous size and the performance is not concerning, RECENT mode should work.

Helpful Docs