Bug in IMAPClient.CreateFolder ?

Aug 25, 2008 at 2:55 PM

Trying to do some more advanced InterIMAP stuff, I ran into the following issue:

I create a new folder (folderX) using client.CreateFolder.

Then I want to add 2 subfolders to that but I get an error:

IMAPClient client = new IMAPClient(config, null, 5);
//this fails:
client.Folders[cFolders.Text].CreateFolder("Processed", false);
client.Folders[cFolders.Text].CreateFolder("Unknown", false);

it fails because the _client property of the new folder FolderX is null while it should point to client (as fas as I could figure out)

I updated the code in IMAPClient to this and now it works for me:

public void CreateFolder(string name)
            if (OfflineMode)
                Log(IMAPBase.LogTypeEnum.WARN, "Cannot create folders in offline mode.");
            string cmd = "CREATE \"{0}\"\r\n";
            ArrayList result = new ArrayList();
            string newFolder = String.Format("{0}", name);
            _imap.SendAndReceive(String.Format(cmd, newFolder), ref result);
            if (result[0].ToString().Contains("OK"))
                IMAPFolder oNewFolder = new IMAPFolder();
                oNewFolder.FolderName = name;
                oNewFolder.FolderPath = newFolder;
                oNewFolder.ParentFolder = null;
                oNewFolder.ParentFolderName = String.Empty;

                oNewFolder._client = this;
                //END MODIFICATION

                Log(IMAPBase.LogTypeEnum.INFO, String.Format("Folder {0} created successfully.", name));
                _imap.Log(IMAPBase.LogTypeEnum.ERROR, "Folder could not be created (" + result[0].ToString()+")");


Is this a real bug or did I use the library in a way I shouldn't use it?
Aug 25, 2008 at 3:03 PM
Edited Aug 25, 2008 at 3:13 PM
this is probably a little better:


and in the IMAPFolder.CreateFolder version:

if (this._client != null)