I am processing emails using imapclient.IMAPClient in Python and want to flag the successfully processed emails as "Seen" at the end. I have tried different ways but they either do not flag all the successful email or do not show as "read" in my Gmail inbox. I am looking for a way to update Gmail inbox flags of successfully processed emails using IMAP.
Here is the summary of code that I've tried:
imapObj = imapclient.IMAPClient(self.server_host, ssl=True)
imapObj.login(self.user_name, self.password)
imapObj.select_folder(email_folder, readonly=False)
#searches unseen emails with subject containing document
self.emails = imapObj.search(
[search_criterion1, search_value1,
search_criterion2, search_value2,
search_criterion3, search_value3,
search_flag])
#using PEEK to not mark all the emails as [Seen]
self.raw_messages = imapObj.fetch(self.emails, 'BODY.PEEK[]')
self.successful_emails = []
for i, self.email_id in enumerate(self.emails):
...do some process and for each successful process, append the email_id to list...
self.successful_emails.append(self.email_id)
#flag the successfully processed email as [SEEN]
imapObj.set_flags(self.successful_emails, '+FLAGS', '\SEEN')