Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset unseen flag #122

Open
lenny76 opened this issue Feb 16, 2013 · 6 comments
Open

reset unseen flag #122

lenny76 opened this issue Feb 16, 2013 · 6 comments

Comments

@lenny76
Copy link

lenny76 commented Feb 16, 2013

Hi,
how can I reset the message flag to unseen state?
thanks
Lenny

@andyedinborough
Copy link
Owner

Use ImapClient.SetFlags(...).

@lenny76
Copy link
Author

lenny76 commented Feb 17, 2013

I cannot make it works.
setflag add flags to messages, but how to remove them?
i cannot set message to unseen but I need to remove the "seen" flag
the same for flagged flag etc...

thanks

@andyedinborough
Copy link
Owner

:/ It seems there is an issue here. I'll get back to you.

@malcom1120
Copy link

Has this been resolved? I'm trying to do the same. It seems like there needs to be a removeFlag method that uses -FLAGS.SILENT(\Seen). All I see in the code is Replace() and Add (+) for flags, but not remove.

@Atrejoe
Copy link

Atrejoe commented Aug 15, 2016

I'm fighting with this too, but it looks like you have to do a bitwise comparison ensuring removing the specific flag. Currently I've made a convenience method for me for easily setting/removing the 'flagged' (a.k.a 'Starred') flag:

private static void SetFlag(ImapClient client, MailMessage msg, bool flagged)
{
    var currentflags = msg.Flags;
    Flags newflag;

    if (flagged)
        newflag = currentflags | Flags.Flagged;  //Ensure flagged
    else
        newflag = currentflags & ~Flags.Flagged; //Ensure not flagged

    if (msg.Flags != newflag)
        client.SetFlags(newflag, msg); //Only set flag if flag is not yet applied
}

However, from time to time a get a somewhat cryptic error message, like: 1 FETCH (UID 9 FLAGS (\Flagged)) (being a System.Exception directly translating the servers' response, so not very straightforward to handle.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@andyedinborough @Atrejoe @lenny76 @malcom1120 and others