简体   繁体   English

MailKit IMailFolder.Close引发异常

[英]MailKit IMailFolder.Close throws exception

I'm having a method using MailKit that will open a folder in your mailbox. 我有一种使用MailKit的方法,它将在您的邮箱中打开一个文件夹。 If the acceslevel is lower than the provided argument, then it will close the folder, and then open the folder in the right accesslevel. 如果acceslevel低于提供的参数,则它将关闭文件夹,然后以正确的访问级别打开文件夹。

Something like this: 像这样:

public void OpenFolder(IMailFolder folder, FolderAccess level)
{
    if(folder.IsOpen() && folder.FolderAccess < level)
    {
        //Closed folder
        using(var task = folder.CloseAsync())
        {
            task.Wait();
        }
        //Open folder with correct accesslevel
        folder.Open(level);
    }
}

The task.Wait() part is throwing a AggregateException (which seems to have an inner exception by type of ImapCommandException), telling me that: task.Wait()部分引发了AggregateException(按ImapCommandException类型,它似乎具有内部异常),告诉我:

MailKit.Net.Imap.ImapCommandException: The IMAP server replied to the 'UNSELECT' command with a 'BAD' response. MailKit.Net.Imap.ImapCommandException:IMAP服务器使用“ BAD”响应回复了“ UNSELECT”命令。

What I can conclude is that the response from tying to do a CLOSE operation (which according to IMAP4 is UNSELECT), give BAD response, which should be caused by no mailbox selected. 我可以得出的结论是,绑定执行CLOSE操作(根据IMAP4,此操作为UNSELECT)的响应会给出BAD响应,这应由未选择邮箱引起。

How can I handle this close operation, so that I can close a folder with lower access level, and open it afer closing in the correct accesslevel??? 如何处理关闭操作,以便可以关闭访问级别较低的文件夹,并在以正确的访问级别关闭之后将其打开?

First, I should point out that there is no need to Close the folder before you open another folder or even the same folder with a different access level. 首先,我应该指出,在打开另一个文件夹或具有不同访问级别的同一文件夹之前,无需关闭该文件夹。 The previously opened folder will always be automatically closed for you by the server. 以前打开的文件夹将始终由服务器自动为您关闭。

I should probably update the docs to mention this as it seems a lot of people seem to think that they need to close folders. 我可能应该更新文档以提及这一点,因为似乎很多人似乎认为他们需要关闭文件夹。

Anyway, that said, I'm not sure how this could happen. 不管怎么说,我不确定这将如何发生。 What version of MailKit are you using? 您正在使用哪个版本的MailKit? There was a bug in some older MailKit versions that did not keep proper folder opened state which may be what you are hitting. 一些较旧的MailKit版本中存在一个错误,该错误未能保持正确的文件夹打开状态,这可能正是您所遇到的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM