I'm having a method using MailKit that will open a folder in your mailbox. If the acceslevel is lower than the provided argument, then it will close the folder, and then open the folder in the right accesslevel.
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:
MailKit.Net.Imap.ImapCommandException: The IMAP server replied to the 'UNSELECT' command with a 'BAD' response.
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.
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???