I received some email flaged seen with mail_status="UNSEEN".Below is my code.I would be very grateful if you could help me.
def get_email(self, mail_index=None, mail_status="UNSEEN", mailbox="INBOX"):
self.imap_client.select(mailbox,readonly=False)
_, dat = self.imap_client.search(None, mail_status)
if not dat\[0\]:
raise RuntimeError("not email")
if mail_index is None:
mail_index = dat[0].decode("utf-8").split(" ")[-1]
mail_index = str(mail_index)
#@patch:some seen email appear
self.is_may_seen_before=False
if self.is_email_seen(mail_index):
self.is_may_seen_before=True
_, dat = self.imap_client.fetch(mail_index, '(RFC822)')
dat_obj = ParseEmail(dat[0][1])
return dat_obj
def is_email_seen(self, mail_index):
try:
_, status = self.imap_client.fetch(mail_index, '(FLAGS)')
return "\\Seen" in status\[0\].decode()
except Exception as e:
del_err(e)
return False