/// <summary> /// Request the folder structure for a specific path /// </summary> /// <param name="path">The path to search</param> /// <param name="commonFolders">The list of common folders to update</param> /// <param name="parent">The parent folder</param> /// <param name="isFirstLevel">if <code>true</code>, will request the subfolders of all folders found. Thsi settign depends on the current FolderTreeBrowseMode</param> /// <returns>A list of folders</returns> internal FolderCollection GetFolders(string path, CommonFolderCollection commonFolders, Folder parent = null, bool isFirstLevel = false) { var result = new FolderCollection(this, parent); var cmd = string.Format(Capabilities.XList && !Capabilities.XGMExt1 ? ImapCommands.XList : ImapCommands.List, path, Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full ? "*" : "%"); IList <string> data = new List <string>(); if (!SendAndReceive(cmd, ref data)) { return(result); } for (var i = 0; i < data.Count - 1; i++) { var folder = Folder.Parse(data[i], ref parent, this); commonFolders.TryBind(ref folder); if (Behavior.ExamineFolders) { folder.Examine(); } if (folder.HasChildren && (isFirstLevel || Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full)) { folder.SubFolders = GetFolders(folder.Path + Behavior.FolderDelimeter, commonFolders, folder); } result.AddInternal(folder); } return(result); }
/// <summary> /// Request the folder structure for a specific path /// </summary> /// <param name="path">The path to search</param> /// <param name="commonFolders">The list of common folders to update</param> /// <param name="parent">The parent folder</param> /// <param name="isFirstLevel">if <code>true</code>, will request the subfolders of all folders found. Thsi settign depends on the current FolderTreeBrowseMode</param> /// <returns>A list of folders</returns> internal FolderCollection GetFolders(string path, CommonFolderCollection commonFolders, Folder parent = null, bool isFirstLevel = false) { var result = new FolderCollection(this, parent); string rewritePath = path.Replace(Behavior.FolderDelimeter.ToString(), Behavior.FolderDelimeterString); var cmd = string.Format(Capabilities.XList && !Capabilities.XGMExt1 ? ImapCommands.XList : ImapCommands.List, rewritePath, Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full ? "*" : "%"); IList <string> data = new List <string>(); if (!SendAndReceive(cmd, ref data)) { return(result); } for (var i = 0; i < data.Count - 1; i++) { string checkLiteralString = data[i]; // RZ 10/23/2015 detect literal var literalMatch = Expressions.LiteralRex.Match(checkLiteralString); if (literalMatch.Success && literalMatch.Groups.Count == 2) { // read more lines until the number of characters are received. // get the number of characters first int iLength, iCumulate = 0; if (!int.TryParse(literalMatch.Groups[Expressions.LITERAL_LENGTH_GROUP].Value, out iLength)) { throw new OperationFailedException(string.Format("Invalid literal length detected from server:{0}", literalMatch.Groups[Expressions.LITERAL_LENGTH_GROUP].Value)); } int iStartIndex = literalMatch.Groups[Expressions.LITERAL_LENGTH_GROUP].Index; // truncate input to the start of literal checkLiteralString = checkLiteralString.Substring(0, iStartIndex - 1); if (iLength > 0) { var sb = new StringBuilder(); while (iCumulate < iLength) { // read more i++; // NOTE: increase i to the next line string moreLine = data[i]; iCumulate += moreLine.Length; sb.Append(moreLine); } if (IsDebug) { Debug.WriteLine("ImapX string Literal:{0}", sb.ToString()); } checkLiteralString += sb.ToString(); } else { checkLiteralString += " \"\""; // add empty string } if (IsDebug) { Debug.WriteLine("ImapX Rewrite return into:{0}", checkLiteralString); } } var folder = Folder.Parse(checkLiteralString, ref parent, this); commonFolders.TryBind(ref folder); if (Behavior.ExamineFolders) { folder.Examine(); } if (folder.HasChildren && (isFirstLevel || Behavior.FolderTreeBrowseMode == FolderTreeBrowseMode.Full)) { folder.SubFolders = GetFolders(folder.Path + Behavior.FolderDelimeter, commonFolders, folder); } result.AddInternal(folder); } return(result); }