How can I make my email show only one time per email?

Viewed 99

I've been making a Python script which checks for emails since logging in. Here is my code so far:

#!/usr/bin/python
import imaplib, getpass

mail = imaplib.IMAP4_SSL('imap.gmail.com')
u = raw_input('Your Gmail Address: ')
p = getpass.getpass()
mail.login(u, p)
mail.select("inbox")

while 1:
        r, data = mail.search(None, "ALL")
        ids = data[0]
        id_list = ids.split()
        latest_email_id = id_list[-1]
        r, data = mail.fetch(latest_email_id, "(RFC822)")
        raw_email = data[0][1]
        print raw_email

The problem is that it keeps showing the same email over and over again (until a new one is received) because of the while loop.

How can I make it:

  1. Only show a received email once until a new one is received
  2. Only show the new one once
  3. Repeat forever
2 Answers
Related