views:

119

answers:

1

I'm trying to mark emails read (/SEEN) with InterIMAP, but this doesn't work. I stepped through the code with debugger, and found out that the response from mail server is "IMAP0078 OK Store ignored with read-only mailbox.", which pretty much tells me why it doesn't work. But it looks like there's no way to tell InterIMAP to open the connection as read-write. If I use something like Thunderbird, I can set the messages as read.

Does anyone know how I should use InterIMAP to achieve what I'm trying, or how to change the source code so that I'd be able to mark messages as read?

A: 

I was able to fix the situation with the following change to Imap.cs

public void MarkMessageAsRead(IMAPMessage msg)
{
    string cmd = "UID STORE {0} +FLAGS (\\Seen)\r\n";
    ArrayList result = new ArrayList();
    SendAndReceive(String.Format(cmd, msg.Uid), ref result);
    if (result[0].ToString().ToLower().Contains("ok"))
        msg.Flags.New = false;
}

Changed to

 public void MarkMessageAsRead(IMAPMessage msg)
    {
        msg.Folder.Select();
        string cmd = "UID STORE {0} +FLAGS (\\Seen)\r\n";
        ArrayList result = new ArrayList();
        SendAndReceive(String.Format(cmd, msg.Uid), ref result);
        if (result[0].ToString().ToLower().Contains("ok"))
            msg.Flags.New = false;
        msg.Folder.Examine();
    }

Not sure if this is the cleanest way to fix my problem, but it's better than nothing.

Morri
It looks like the cause of the problem was that the mailbox (=folder) was opened using the "EXAMINE" command instead of "SELECT" command. These IMAP commands are very similar - the main difference is that "EXAMINE" opens the folder in read-only mode. I'm not familiar with InterIMAP, but if you are able to make it use "SELECT" instead of "EXAMINE" prior to calling the MarkMessagesAsRead method, you won't need this fix any more.
Lukas Pokorny