1

Closed

CreateFolder - _client not instantiated

description

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);
client.CreateFolder("FolderX");
//this fails because IMAPFolder._client is not instantiated:
client.Folders["FolderX"].CreateFolder("Processed", false);
client.Folders["FolderX"].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.");
            return;
        }

        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;
 
            //MODIFIED:
            oNewFolder.SetClient(this);
            //END MODIFICATION
 
            _folders.Add(oNewFolder);
            UpdateCache(true);
            Log(IMAPBase.LogTypeEnum.INFO, String.Format("Folder {0} created successfully.", name));
        }
        else
        {
            _imap.Log(IMAPBase.LogTypeEnum.ERROR, "Folder could not be created (" + result[0].ToString()+")");
        }
 
    }
 
 
and in the IMAPFolder.CreateFolder version:
 
if (this._client != null)
 oNewFolder.SetClient(this._client);
 
 
Is this a real bug or did I use the library in a way I shouldn't use it?
Closed Apr 5, 2010 at 6:11 PM by JasonMiesionczek
This issue relates to the Synchronous client which is no longer supported. If you are still actively developing a project that uses this library, please consider switching to the Async client.

comments