I'm trying to mark email as unseen on Gmail server.
I'm using this command:
res, data = mailbox.uid('STORE', uid, '-FLAGS', '(\Seen)')
b'46 (FLAGS (-FLAGS \\Seen))'
mailbox.append(db_email.folder, "-FLAGS \Seen", time.mktime(db_email.date.timetuple()), mail.as_bytes())
It appears you've misunderstood flags on APPEND a bit.
APPEND folder (-FLAGS \Seen) ... you've actually created a message with two flags: The standard
\Seen flag, and a nonstandard
To create a message without the \Seen flag, just use
() as your flag list for
-FLAGS is a subcommand to STORE, saying to remove these flags from the current list. Conversely,
+FLAGS is add these flags to the current list. The plain
FLAGS overwrites the current list.
Also, if you do remove the
\Seen flag over an IMAP connection, it can take sometime to show up in the GMail WebUI. You may need to refresh or switch folders to get the changes to render.
NB: You are not protecting your backslashes.
\S is not a legal escape sequence, so will be passed through, but you should either use a double backslash (
'\\Seen') or a raw string (