imap.select('INBOX')
status, response = imap.search(None, 'INBOX', '(UNSEEN)')
unread_msg_nums = response[0].split()
print(len(unread_msg_nums))
status, response = imap.search(None, '(UNSEEN)', '(FROM "%s")' %
    sender_of_interest)
unread_msg_nums = response[0].split()
da = []
for e_id in unread_msg_nums:
    _, response = imap.fetch(e_id, '(UID BODY[TEXT])')
da.append(response[0][1])
print(da)
for e_id in unread_msg_nums:
    imap.store(e_id, '+FLAGS', '\\Seen')
How to get unread messages and set message read flags over IMAP using Python?