andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

reset unseen flag #122

Open lenny76 opened 11 years ago

lenny76 commented 11 years ago

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

andyedinborough commented 11 years ago

Use ImapClient.SetFlags(...).

lenny76 commented 11 years ago

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 commented 11 years ago

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

malcom1120 commented 9 years ago

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 commented 8 years ago

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.)