/// <summary> /// Ranames the folder /// </summary> /// <param name="name">the name to set</param> /// <returns></returns> internal bool Rename(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Folder name cannot be empty"); } IList <string> data = new List <string>(); string encodedName = ImapUTF7.Encode(name); int i = _path.LastIndexOf(_client.Behavior.FolderDelimeter); string newPath = i < 1 ? encodedName : _path.Substring(0, i + 1) + encodedName; if (!_client.SendAndReceive(string.Format(ImapCommands.Rename, _path, newPath), ref data)) { return(false); } _name = name; _path = newPath; if (!HasChildren || _subFolders == null) { return(true); } foreach (var folder in SubFolders) { folder.UpdatePath(_path); } return(true); }
/// <summary> /// Removes a list of specified message flags /// </summary> /// <param name="flags">The flags to be removed</param> /// <returns><code>true</code> if the flags could be removed</returns> public bool RemoveRange(IEnumerable <string> flags) { if (Client == null) { foreach (string flag in flags) { RemoveInternal(flag); } return(true); } IList <string> data = new List <string>(); if (!Client.SendAndReceive( string.Format(ImapCommands.Store, _message.UId, RemoveType, string.Join(" ", flags.Where(_ => !string.IsNullOrEmpty(_)) .Select(_ => (AddQuotes ? "\"" : "") + _ + (AddQuotes ? "\"" : "")) .Select(_ => IsUTF7 ? ImapUTF7.Encode(_) : _).ToArray())), ref data)) { return(false); } foreach (string flag in flags) { List.Remove(flag); } return(true); }
/// <summary> /// Creates a new folder with the given name /// </summary> /// <param name="folderName">The folder name</param> /// <returns>The new folder if it could be created, otherwise null</returns> /// <exception cref="System.ArgumentException">If the folder name is empty</exception> public Folder Add(string folderName) { if (string.IsNullOrEmpty(folderName)) { throw new ArgumentException("The folder name cannot be empty"); } folderName = ImapUTF7.Encode(folderName); var path = _parentFolder == null ? folderName : _parentFolder.Path + Client.Behavior.FolderDelimeter + folderName; IList <string> data = new List <string>(); if (!Client.SendAndReceive(string.Format(ImapCommands.Create, path), ref data)) { return(null); } var folder = new Folder(path, new string[0], ref _parentFolder, Client); if (Client.Behavior.ExamineFolders) { folder.Examine(); } AddInternal(folder); return(folder); }
/// <summary> /// Adds the given flags to the message /// </summary> /// <param name="flags">The flags to be added</param> /// <returns><code>true</code> if the flags could be added</returns> public bool AddRange(IEnumerable <string> flags) { if (Client == null) { base.AddRangeInternal(flags); return(true); } IList <string> data = new List <string>(); if (!Client.SendAndReceive(string.Format(ImapCommands.Store, _message.UId, AddType, string.Join(" ", this.Concat(flags.Where(_ => !string.IsNullOrEmpty(_))) .Distinct() .Select(_ => (AddQuotes ? "\"" : "") + _ + (AddQuotes ? "\"" : "")) .Select(_ => (IsUTF7 ? ImapUTF7.Encode(_) : _)).ToArray())), ref data)) { return(false); } AddRangeInternal(flags.Except(List)); return(true); }