title: How to set email IMAP SEEN flag through Mailcore/Libetpan
body: <p>I'm using the <a href="http://libmailcore.com/" rel="nofollow noreferrer">Mailcore</a> library for an iOS email client. I want to mark an email as viewed (ie set the <a href="https://www.rfc-editor.org/rfc/rfc3501#section-2.3.2" rel="nofollow noreferrer">IMAP SEEN flag</a> on for the message) whenever someone views it.</p>
  <p>This is how Mailcore <a href="http://libmailcore.com/api/Classes/CTCoreMessage.html#//api/name/isUnread" rel="nofollow noreferrer">indicates</a> that a message has been <a href="https://github.com/mronge/MailCore/blob/master/Source/CTCoreMessage.m" rel="nofollow noreferrer">read</a>:</p>
  <pre><code>- (BOOL)isUnread {
      struct mail_flags *flags = myMessage-&gt;msg_flags;
      if (flags != NULL) {
          BOOL flag_seen = (flags-&gt;fl_flags &amp; MAIL_FLAG_SEEN);
          return !flag_seen;
      }        
      return NO;
  }
  </code></pre>
  <p>This is what I did to set a message as read:</p>
  <pre><code>- (void)setIsRead {
      struct mail_flags *flags = myMessage-&gt;msg_flags;
      flags-&gt;fl_flags = (flags-&gt;fl_flags | MAIL_FLAG_SEEN);
  }
  </code></pre>
  <p>(I confirmed that it works at least in the same session.. ie if I call this message on an unread message, then call <code>[self isUnread]</code> it returns <code>false</code>)</p>
  <p>My problem is that this doesn't impact the actual IMAP server. Ie if I view the same email in my gmail, it will appear unread still.</p>
  <p>Also in the CTCoreMessage <a href="http://libmailcore.com/api/Classes/CTCoreMessage.html" rel="nofollow noreferrer">documentation</a>:</p>
  <blockquote>
  <p>CTCoreMessage is how you work with messages. The easiest way to
  instantiate a CTCoreMessage is to first setup a CTCoreAccount object
  and then get a CTCoreFolder object and then use it’s convenience
  method messageWithUID: to get a message object you can work with.</p>
  </blockquote>
  <p>I did both of those things (on thing that may be worth mentioning is that I keep my IMAP connection alive all the time.. but I keep it <a href="https://www.rfc-editor.org/rfc/rfc2177" rel="nofollow noreferrer">idle</a> when I'm not actively syncing or sending emails etc.. but before I call the <code>[self setIsRead]</code> above, I send it the <a href="https://www.rfc-editor.org/rfc/rfc2177" rel="nofollow noreferrer">IMAP done command</a>).</p>
  <p>So what is missing? My thoughts is that I'm just changing the local structure of the message that I've already fetched from the IMAP server.. but I'm not updating the server with the new information. How do I do that? In Mailcore the only way to interact with the server is via <a href="http://libmailcore.com/api/Classes/CTSMTPConnection.html#//api/name/sendMessage:server:username:password:port:connectionType:useAuth:error:" rel="nofollow noreferrer">+sendMessage:server:username:password:port:connectionType:useAuth:error:</a>
  but then this would be the same as sending an email.. which is definitely not what I want.</p>
  <p>Ideas?</p>
  <p><b>update:</b>
  basically I just want to be able to issue the <a href="https://www.rfc-editor.org/rfc/rfc3501#section-6.4.6" rel="nofollow noreferrer">store IMAP command</a> like so (I've confirmed it works on the <a href="http://adityo.blog.binusian.org/?tag=telnet-imap-command" rel="nofollow noreferrer">Telnet command line</a>):</p>
  <pre><code>tag store %message_number% flags \Seen
  * %message_number% FETCH (FLAGS (\Seen))
  tag OK Success
  </code></pre>