poplib mark as seen

1.7k Views Asked by At

I am using poplib in Python 3.3 to fetch emails from a gmail account and everything is working well, except that the mails are not marked as read after retrieving them with the retr() method, despite the fact that the documentation says "Retrieve whole message number which, and set its seen flag."

Here is the code:

pop = poplib.POP3_SSL("pop.gmail.com", "995")
pop.user("recent:[email protected]")
pop.pass_("mypassword")
numMessages = len(pop.list()[1])
for i in range(numMessages):
    for j in pop.retr(i+1)[1]:
        print(j)
pop.quit()

Am I doing something wrong or does the documentation lie? (or, did I just misinterpret it?)

1

There are 1 best solutions below

1
On BEST ANSWER

The POP protocol has no concept of "read" or "unread" messages; the LIST command simply shows all existing messages. You may want to use another protocol, like IMAP, if the server supports it.

You could delete messages after successful retrieval, using the DELE command. Only after a successful QUIT command will the server actually delete them.