In the IMAP world, every message has flags. You can set separate flags for each message. When you select a message, you can actually read the message without using the \ Seen flag.
Most email clients will use the \ Seen flag when reading a message. So, if the message has already been read outside your application, you will need to remove the \ Seen flag.
Just like fyi ... here is the relevant part about flags from the RFC:
A system flag is the name of a flag that is predefined in this specification. All system flags begin with "\". A specific flags system (\ Deleted and \ Seen) describes special semantics elsewhere. Currently, system flags are:
\Seen Message has been read \Answered Message has been answered \Flagged Message is "flagged" for urgent/special attention \Deleted Message is "deleted" for removal by later EXPUNGE \Draft Message has not completed composition (marked as a draft). \Recent Message is "recently" arrived in this mailbox. This session is the first session to have been notified about this message; if the session is read-write, subsequent sessions will not see \Recent set for this message. This flag can not be altered by the client. If it is not possible to determine whether or not this session is the first session to be notified about a message, then that message SHOULD be considered recent. If multiple connections have the same mailbox selected simultaneously, it is undefined which of these connections will see newly-arrived messages with \Recent set and which will see it without \Recent set.
source share