/// <summary> /// The get header. /// </summary> /// <param name="messageId"> /// The message id. /// </param> /// <param name="part"> /// The part. /// </param> /// <returns> /// </returns> private ArticleHeader GetHeader(string messageId, out MIMEPart part) { string response = null; var header = new ArticleHeader(); string name = null; string value = null; header.ReferenceIds = new string[0]; string[] values = null; string[] values2 = null; Match m = null; part = null; int i = -1; while ((response = this.sr.ReadLine()) != null && response != string.Empty) { m = Regex.Match(response, @"^\s+(\S+)$"); if (m.Success) { value = m.Groups[1].ToString(); } else { i = response.IndexOf(':'); if (i == -1) { continue; } name = response.Substring(0, i).ToUpper(); value = response.Substring(i + 1); } switch (name) { case "REFERENCES": values = value.Trim().Split(' '); values2 = header.ReferenceIds; header.ReferenceIds = new string[values.Length + values2.Length]; values.CopyTo(header.ReferenceIds, 0); values2.CopyTo(header.ReferenceIds, values.Length); break; case "SUBJECT": header.Subject += NntpUtil.Base64HeaderDecode(value); break; case "DATE": // vzrus: 31.03.10 dateTime and tz conversion int offTz; header.Date = NntpUtil.DecodeUTC(value, out offTz); header.TimeZoneOffset = offTz; break; case "FROM": header.From += NntpUtil.Base64HeaderDecode(value); break; case "NNTP-POSTING-HOST": header.PostingHost += value; break; case "LINES": header.LineCount = int.Parse(value); break; case "MIME-VERSION": part = new MIMEPart(); part.ContentType = "TEXT/PLAIN"; part.Charset = "US-ASCII"; part.ContentTransferEncoding = "7BIT"; part.Filename = null; part.Boundary = null; break; case "CONTENT-TYPE": if (part != null) { m = Regex.Match(response, @"CONTENT-TYPE: ""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.ContentType = m.Groups[1].ToString(); } m = Regex.Match(response, @"BOUNDARY=""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.Boundary = m.Groups[1].ToString(); part.EmbeddedPartList = new ArrayList(); } m = Regex.Match(response, @"CHARSET=""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.Charset = m.Groups[1].ToString(); } m = Regex.Match(response, @"NAME=""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.Filename = m.Groups[1].ToString(); } } break; case "CONTENT-TRANSFER-ENCODING": if (part != null) { m = Regex.Match(response, @"CONTENT-TRANSFER-ENCODING: ""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.ContentTransferEncoding = m.Groups[1].ToString(); } } break; } } return header; }
/// <summary> /// The get header. /// </summary> /// <param name="messageId"> /// The message id. /// </param> /// <param name="part"> /// The part. /// </param> /// <returns> /// </returns> private ArticleHeader GetHeader(string messageId, out MIMEPart part) { string response = null; var header = new ArticleHeader(); string name = null; string value = null; header.ReferenceIds = new string[0]; string[] values = null; string[] values2 = null; Match m = null; part = null; int i = -1; while ((response = this.sr.ReadLine()) != null && response != string.Empty) { m = Regex.Match(response, @"^\s+(\S+)$"); if (m.Success) { value = m.Groups[1].ToString(); } else { i = response.IndexOf(':'); if (i == -1) { continue; } name = response.Substring(0, i).ToUpper(); value = response.Substring(i + 1); } switch (name) { case "REFERENCES": values = value.Trim().Split(' '); values2 = header.ReferenceIds; header.ReferenceIds = new string[values.Length + values2.Length]; values.CopyTo(header.ReferenceIds, 0); values2.CopyTo(header.ReferenceIds, values.Length); break; case "SUBJECT": header.Subject += NntpUtil.Base64HeaderDecode(value); break; case "DATE": // vzrus: 31.03.10 dateTime and tz conversion int offTz; header.Date = NntpUtil.DecodeUTC(value, out offTz); header.TimeZoneOffset = offTz; break; case "FROM": header.From += NntpUtil.Base64HeaderDecode(value); break; case "NNTP-POSTING-HOST": header.PostingHost += value; break; case "LINES": header.LineCount = int.Parse(value); break; case "MIME-VERSION": part = new MIMEPart(); part.ContentType = "TEXT/PLAIN"; part.Charset = "US-ASCII"; part.ContentTransferEncoding = "7BIT"; part.Filename = null; part.Boundary = null; break; case "CONTENT-TYPE": if (part != null) { m = Regex.Match(response, @"CONTENT-TYPE: ""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.ContentType = m.Groups[1].ToString(); } m = Regex.Match(response, @"BOUNDARY=""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.Boundary = m.Groups[1].ToString(); part.EmbeddedPartList = new ArrayList(); } m = Regex.Match(response, @"CHARSET=""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.Charset = m.Groups[1].ToString(); } m = Regex.Match(response, @"NAME=""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.Filename = m.Groups[1].ToString(); } } break; case "CONTENT-TRANSFER-ENCODING": if (part != null) { m = Regex.Match(response, @"CONTENT-TRANSFER-ENCODING: ""?([^""\s;]+)", RegexOptions.IgnoreCase); if (m.Success) { part.ContentTransferEncoding = m.Groups[1].ToString(); } } break; } } return(header); }