Hello,
here is a sample code which determines whether the folder is Subscribed or not using the Imap.GetFolderList method together with the ImapFolderListMode.Subscribed mode:
private bool IsSubscribed(Imap client, string folder)
{
if (!client.IsConnected || !client.IsAuthenticated)
return false;
// get the subfolders which are subscribed
var subscribedFolders = client.GetFolderList("", ImapFolderListMode.Subscribed);
// you might want to use GetFolderList("", ImapFolderListMode.Subscribed, true)
// to also return subfolders of subfolders
foreach (var subscribed in subscribedFolders)
{
// the folder was found
if (subscribed.Name == folder)
return true;
}
return false;
}
Imap client = new Imap();
client.Connect("exchange");
client.Login("user", "password");
client.SelectFolder("INBOX");
client.Subscribe("subfolder");
Console.WriteLine(IsSubscribed(client, "subfolder"));
client.Unsubscribe("subfolder");
Console.WriteLine(IsSubscribed(client, "subfolder"));
client.Disconnect();