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.