1

I have gone through stackoverflow for this particular query and have seen several questions regarding the same. I have followed all the suggestions mentioned in each of the questions however, that does not seem to be the answer when I try to implement the code.

My Code:

conn = imaplib.IMAP4_SSL('imap.gmail.com')
conn.login('someone@gmail.com', 'mypassword')
stat  = conn.select("INBOX")
if stat[0] == "OK":
        data = conn.search(None, "UNSEEN")
        print data[1][0].split()
        for i in data[1][0].split():
                mailstat = conn.fetch(i, '(RFC822)')
                for j in mailstat[1][0]:
                        msg = email.message_from_string(j)
                        msg = re.sub(r'\n|\r|None','', str(msg['Subject']))
                        if re.findall(r'FBI\sWARNING.*', str(msg)):
                                conn.uid('STORE', i, '-FLAGS', '(\\SEEN)')
                        else:
                                print msg

======

::Update::

The suggestions in both the links mentioned in the comment will not work for me. My requirement is to read through the email initially which will mark my email as read. Once an email of a specific subject is found, I want that email to be mark as Unread.

rickydj
  • 629
  • 5
  • 17
  • 3
    Possible duplicate of [python imaplib - mark email as unread or unseen](http://stackoverflow.com/questions/17367611/python-imaplib-mark-email-as-unread-or-unseen) – tripleee Dec 13 '15 at 14:32
  • See also http://stackoverflow.com/questions/3283460/fetch-an-email-with-imaplib-but-do-not-mark-it-as-seen – tripleee Dec 13 '15 at 14:32
  • That will not work for. I wanna mark all my emails as read as I go through it. Once I find a message with a specific subject, I wanna mark it as unread/unseen. Thanks though for the attempt. – rickydj Dec 13 '15 at 15:10
  • If you disagree with the duplicate nomination, please [edit] your question to indicate how this is different. – tripleee Dec 13 '15 at 15:14

0 Answers0