/// <summary> /// Creates a new sub-folder under this folder /// </summary> /// <param name="name">Name of folder to create</param> /// <param name="autoSelect">Automatically select this folder upon successful creation</param> public void CreateFolder(string name, bool autoSelect) { if (_client.OfflineMode) { _client.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}/{1}", this.FolderPath, name); _client._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 = this; oNewFolder.ParentFolderName = this.FolderName; _subFolders.Add(oNewFolder); if (autoSelect) { oNewFolder.Select(); } _client.UpdateCache(true); } else { _client.Log(IMAPBase.LogTypeEnum.ERROR, "Folder could not be created." + result[0].ToString()); } }
/// <summary> /// This method will delete all the messages in the specified folder. Use with caution. /// </summary> /// <param name="folderName">The name of the folder to empty</param> public void EmptyFolder(string folderName) { if (OfflineMode) { Log(IMAPBase.LogTypeEnum.WARN, "Cannot delete messages in offline mode."); return; } IMAPFolder foundFolder = null; foreach (IMAPFolder f in _folders) { if (f.FolderName.Equals(folderName)) { foundFolder = f; } } if (foundFolder == null) { Log(IMAPBase.LogTypeEnum.ERROR, String.Format("Folder \"{0}\" not found.", folderName)); return; } string cmd = "STORE {0}:{1} +FLAGS (\\Deleted)\r\n"; ArrayList result = new ArrayList(); if (foundFolder._messages.Count == 0) { return; } int firstUID = foundFolder._messages[0].Uid; int lastUID = foundFolder._messages[foundFolder._messages.Count - 1].Uid; foundFolder.Select(); _imap.SendAndReceive(String.Format(cmd, firstUID, lastUID), ref result); cmd = "EXPUNGE\r\n"; _imap.SendAndReceive(cmd, ref result); foundFolder.Examine(); foundFolder._messages.Clear(); Log(IMAPBase.LogTypeEnum.INFO, String.Format("Folder {0} emptied successfully.", folderName)); }