Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Ensure flag changes are persisted to imap after setFlags:forMesssage: is called #50

merged 1 commit into from

4 participants

Michael Koziarski Jan Chaloupecky Dennis Kutlubaev Matt Ronge
Michael Koziarski

With libetpan mailmessage_check only updates the in memory store of the flags for a given message, it doesn't make any changes over the wire. You must ensure that imap_flags_store_process is called otherwise the data is lost.

There are a few options for ensuring this is called:

  • imapdriver_uninitialize
  • imapdriver_logout
  • imapdriver_check_folder
  • imapdriver_select_folder
  • imapdriver_expunge_folder
  • imapdriver_get_envelopes_list

Calling CHECK seemed the lowest cost alternative out there.

The current implementation of setFlags:forMessage only works if you either explicitly log out, expunge or select another folder, my particular application doesn't usually do any of those things as it only handles a single mailbox and is more likely to get suspended by a user than explicitly log out / dealloc the CTCoreFolder

Michael Koziarski NZKoz Do a folder check to ensure flags get stored immediately
Prevents loss of flags if the app terminates or otherwise doesn't call logout or expunge.
Jan Chaloupecky

FYI: I was having the same issue. See this conversation in the mailing list

Hold on, I've just had a look at the CTCoreFolder.m and the code you are submitting is already there

Michael Koziarski

@JanC Yeah, @mronge's example code works because the CTCoreFolder is dealloced which causes the imapdrive_uninitialize to be called, which sets the flags.

The code isn't there already, this is calling folder check, not message check.

Jan Chaloupecky

ah I see. I misread the code

Dennis Kutlubaev
Dennis Kutlubaev
Matt Ronge mronge merged commit 5a033e9 into from
Matt Ronge

Looks good, thanks!

Jan Chaloupecky

For me the flag is still not set when I call setFlags only. I have to refetch the folder and only then the imap command "UID STORE 148 FLAGS.SILENT (\Seen)" is actually sent to the server.

Michael Koziarski

@JanC you can see that imap_flags_store_process is called when calling mailfolder_check. Are you sure you're running the right revisions?

Jan Chaloupecky

@NZKoz I tried setting a flag with MailCoreEnableLogging(). I have a breakpoint in the method you mentioned and the only output I see after this method is:

>>>>>>> send >>>>>>

>>>>>>> end send >>>>>>

<<<<<<< read <<<<<<

3 OK CHECK completed
<<<<<<< end read <<<<<<

Michael Koziarski

If you step through that method in the debugger, does it call imap_flags_store_process? It wouldn't be reasonable for MailCore to call expunge after every flag setting as that would destroy deleted messages instantly rather than letting the programmer call expunge at a suitable point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 4, 2012
  1. Michael Koziarski

    Do a folder check to ensure flags get stored immediately

    NZKoz authored
    Prevents loss of flags if the app terminates or otherwise doesn't call logout or expunge.
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 0 deletions.
  1. +5 −0 Source/CTCoreFolder.m
5 Source/CTCoreFolder.m
@@ -587,6 +587,11 @@ - (BOOL)setFlags:(NSUInteger)flags forMessage:(CTCoreMessage *)msg {
self.lastError = MailCoreCreateErrorFromIMAPCode(err);
return NO;
+ err = mailfolder_check(myFolder);
+ if (err != MAIL_NO_ERROR) {
+ self.lastError = MailCoreCreateErrorFromIMAPCode(err);
+ return NO;
+ }
return YES;
Something went wrong with that request. Please try again.