poplib and email module will not reloop through a message if it has alread read it

Posted by user1440925 on Stack Overflow See other posts from Stack Overflow or by user1440925
Published on 2012-06-06T22:37:00Z Indexed on 2012/06/06 22:40 UTC
Read the original article Hit count: 135

Filed under:
|
|

I'm currently trying to write a script that gets messages from my gmail account but I'm noticing a problem. If poplib loops through a message in my inbox it will never loop through it again. Here is my code

import poplib, string, email

user = "[email protected]"
password = "p0ckystyx"

message = ""
mail = poplib.POP3_SSL('pop.gmail.com')
mail.user(user)
mail.pass_(password)

iMessageCount = len(mail.list()[1])
message = ""
msg = mail.retr(iMessageCount)
str = string.join(msg[1], "\n")
frmMail = email.message_from_string(str)

for part in frmMail.walk():
    if part.get_content_type() == "text/plain":
        print part.get_payload()

mail.quit()

Every time I run this script it goes to the next newest email and just skips over the email that was shown last time it was run.

© Stack Overflow or respective owner

Related posts about python

Related posts about email