public static ExamineResult ParseExamineResponse(string examineResponse) { ExamineResult status = new ExamineResult(); Regex regex; Match m; string existsPattern = "^\\* (\\d+) EXISTS\r\n"; regex = new Regex(existsPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.Exists = Convert.ToInt32(m.Groups[1].ToString()); string recentPattern = "^\\* (\\d+) RECENT\r\n"; regex = new Regex(recentPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.Recent = Convert.ToInt32(m.Groups[1].ToString()); string uidNextPattern = "^\\* (?<ok>\\w+) \\[UIDNEXT (?<value>\\d+)\\]"; regex = new Regex(uidNextPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.UidNext = Convert.ToInt32(m.Groups["value"].ToString()); string uidValidityPattern = "^\\* (?<ok>\\w+) \\[UIDVALIDITY (?<value>\\d+)\\]"; regex = new Regex(uidValidityPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.UidValidity = Convert.ToInt32(m.Groups["value"].ToString()); string flagsPattern = "^\\* FLAGS \\((.*)\\)\r\n"; regex = new Regex(flagsPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); if (m.Success) { string flagsString = m.Groups[1].ToString(); if (!string.IsNullOrWhiteSpace(flagsString)) { string[] flags = flagsString.Split(' '); status.Flags = new List <string>(flags); } } string permanentFlagsPattern = "^\\* (?<ok>\\w+) \\[PERMANENTFLAGS \\((?<value>.*)\\)\\]"; regex = new Regex(permanentFlagsPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); if (m.Success) { string flagsString = m.Groups["value"].ToString(); if (!string.IsNullOrWhiteSpace(flagsString)) { string[] permFlags = flagsString.Split(' '); status.PermanemtFlags = new List <string>(permFlags); } } return(status); }
// Sends 'EXAMINE' command to the server with the specified mailbox. public bool SelectMailbox(string mailboxPath, bool readOnly, out ExamineResult status) { status = new ExamineResult(); string tag = NextTag(); if (readOnly) { SendString(tag + " EXAMINE " + mailboxPath); } else { SendString(tag + " SELECT " + mailboxPath); } string response = string.Empty; if (!ReadResponse(tag, out response)) { Error = response; return(false); } status = ImapParser.ParseExamine(response); return(true); }
public static ExamineResult ParseExamineResponse(string examineResponse) { ExamineResult status = new ExamineResult(); Regex regex; Match m; string existsPattern = "^\\* (\\d+) EXISTS\r\n"; regex = new Regex(existsPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.Exists = Convert.ToInt32(m.Groups[1].ToString()); string recentPattern = "^\\* (\\d+) RECENT\r\n"; regex = new Regex(recentPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.Recent = Convert.ToInt32(m.Groups[1].ToString()); string uidNextPattern = "^\\* (?<ok>\\w+) \\[UIDNEXT (?<value>\\d+)\\]"; regex = new Regex(uidNextPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.UidNext = Convert.ToInt32(m.Groups["value"].ToString()); string uidValidityPattern = "^\\* (?<ok>\\w+) \\[UIDVALIDITY (?<value>\\d+)\\]"; regex = new Regex(uidValidityPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); status.UidValidity = Convert.ToInt32(m.Groups["value"].ToString()); string flagsPattern = "^\\* FLAGS \\((.*)\\)\r\n"; regex = new Regex(flagsPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); if (m.Success) { string flagsString = m.Groups[1].ToString(); if (!string.IsNullOrWhiteSpace(flagsString)) { string[] flags = flagsString.Split(' '); status.Flags = new List<string>(flags); } } string permanentFlagsPattern = "^\\* (?<ok>\\w+) \\[PERMANENTFLAGS \\((?<value>.*)\\)\\]"; regex = new Regex(permanentFlagsPattern, RegexOptions.Multiline); m = regex.Match(examineResponse); if (m.Success) { string flagsString = m.Groups["value"].ToString(); if (!string.IsNullOrWhiteSpace(flagsString)) { string[] permFlags = flagsString.Split(' '); status.PermanemtFlags = new List<string>(permFlags); } } return status; }
// Selects specified mailbox as working directory. public bool SelectMailbox(string mailboxPath, bool readOnly, out ExamineResult status) { status = new ExamineResult(); string tag = NextTag(); string command = readOnly ? "EXAMINE" : "SELECT"; string queryString = tag + " " + command + " " + mailboxPath; if (!SendString(queryString)) { return(false); } string response; if (!ReadResponse(tag, out response)) { return(false); } SelectedMailboxName = mailboxPath; status = ImapParser.ParseExamineResponse(response); return(true); }
// Selects specified mailbox as working directory. public bool SelectMailbox(string mailboxPath, bool readOnly, out ExamineResult status) { status = new ExamineResult(); string tag = NextTag(); string command = readOnly ? "EXAMINE" : "SELECT"; string queryString = tag + " " + command + " " + mailboxPath; if (!SendString(queryString)) { return false; } string response; if (!ReadResponse(tag, out response)) { return false; } SelectedMailboxName = mailboxPath; status = ImapParser.ParseExamineResponse(response); return true; }
public bool SelectMailbox(string mailboxPath, bool readOnly) { ExamineResult result = new ExamineResult(); return(SelectMailbox(mailboxPath, readOnly, out result)); }