public static MessageSummary Parse(byte[] content) { try { if (content == null || content.Length == 0) { return(null); } MessageSummary ret = null; String body = Encoding.UTF8.GetString(content, 0, content.Length); Match messageMatch = MESSAGE_SUMMARY_EXPR.Match(body); if (messageMatch != null && messageMatch.Success) { String status = messageMatch.Groups["msg_status"].Success ? messageMatch.Groups["msg_status"].Value : String.Empty; String account = messageMatch.Groups["account_uri"].Success ? messageMatch.Groups["account_uri"].Value : String.Empty; if (!String.IsNullOrEmpty(status) && !String.IsNullOrEmpty(account)) { bool waitingMessages = (String.Equals(status, "yes", StringComparison.InvariantCultureIgnoreCase)); ret = new MessageSummary(account, waitingMessages); if (waitingMessages) { System.Text.RegularExpressions.Group lines = messageMatch.Groups["msg_summary_line"]; foreach (Capture capture in lines.Captures) { String line = capture.Value; Match lineMatch = SUMMARY_LINE_EXPR.Match(line); if (lineMatch != null && lineMatch.Success) { String messageClass = lineMatch.Groups["message_context_class"].Value; int newMessages = Convert.ToInt32(lineMatch.Groups["newmsgs"].Success ? lineMatch.Groups["newmsgs"].Value : "0"); int oldMessages = Convert.ToInt32(lineMatch.Groups["oldmsgs"].Success ? lineMatch.Groups["oldmsgs"].Value : "0"); int newUrgentMessages = Convert.ToInt32(lineMatch.Groups["new_urgentmsgs"].Success ? lineMatch.Groups["new_urgentmsgs"].Value : "0"); int oldUrgentMessages = Convert.ToInt32(lineMatch.Groups["old_urgentmsgs"].Success ? lineMatch.Groups["old_urgentmsgs"].Value : "0"); ret.SetMessageCount(messageClass, newMessages, oldMessages, newUrgentMessages, oldUrgentMessages); } } } } } return(ret); } catch (Exception e) { LOG.Error(e); return(null); } }
public static MessageSummary Parse(byte[] content) { try { if (content == null || content.Length == 0) { return null; } MessageSummary ret = null; String body = Encoding.UTF8.GetString(content, 0, content.Length); Match messageMatch = MESSAGE_SUMMARY_EXPR.Match(body); if (messageMatch != null && messageMatch.Success) { String status = messageMatch.Groups["msg_status"].Success ? messageMatch.Groups["msg_status"].Value : String.Empty; String account = messageMatch.Groups["account_uri"].Success ? messageMatch.Groups["account_uri"].Value : String.Empty; if (!String.IsNullOrEmpty(status) && !String.IsNullOrEmpty(account)) { bool waitingMessages = (String.Equals(status, "yes", StringComparison.InvariantCultureIgnoreCase)); ret = new MessageSummary(account, waitingMessages); if (waitingMessages) { System.Text.RegularExpressions.Group lines = messageMatch.Groups["msg_summary_line"]; foreach (Capture capture in lines.Captures) { String line = capture.Value; Match lineMatch = SUMMARY_LINE_EXPR.Match(line); if (lineMatch != null && lineMatch.Success) { String messageClass = lineMatch.Groups["message_context_class"].Value; int newMessages = Convert.ToInt32(lineMatch.Groups["newmsgs"].Success ? lineMatch.Groups["newmsgs"].Value : "0"); int oldMessages = Convert.ToInt32(lineMatch.Groups["oldmsgs"].Success ? lineMatch.Groups["oldmsgs"].Value : "0"); int newUrgentMessages = Convert.ToInt32(lineMatch.Groups["new_urgentmsgs"].Success ? lineMatch.Groups["new_urgentmsgs"].Value : "0"); int oldUrgentMessages = Convert.ToInt32(lineMatch.Groups["old_urgentmsgs"].Success ? lineMatch.Groups["old_urgentmsgs"].Value : "0"); ret.SetMessageCount(messageClass, newMessages, oldMessages, newUrgentMessages, oldUrgentMessages); } } } } } return ret; } catch (Exception e) { LOG.Error(e); return null; } }