Can't mark email read with InterIMAP, folder is read-only

耗尽温柔 提交于 2019-12-11 05:56:41

问题


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?


回答1:


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.




回答2:


Segue código ajustado que funcionou para remover a mensagem da caixa IMAP GMAIL!

    public void DeleteMail(IMAPMessage msg)
    {
        msg.Folder.Select();
        string cmd = "UID STORE {0} +FLAGS (\\Deleted \\Seen)\r\n";
        ArrayList result = new ArrayList();
        SendAndReceive(String.Format(cmd, msg.Uid), ref result);

        int countResult = result.Count - 1;

        while (countResult >= 0)
        {
            if (result[countResult].ToString().ToLower().Contains("ok"))
            {
                msg.Flags.New = false;
                msg.Flags.Deleted = true;

                string cmd2 = "EXPUNGE\r\n";
                ArrayList result2 = new ArrayList();
                SendAndReceive(String.Format(cmd2, msg.Uid), ref result2);

                if (result2[0].ToString().ToLower().Contains("ok"))
                {
                    //Deu certo!!
                    msg.Folder.Examine();
                }

            }

            countResult--;
        }
    }


来源:https://stackoverflow.com/questions/2491939/cant-mark-email-read-with-interimap-folder-is-read-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!