public static void Write(INntpConnection connection, NntpArticle article) { WriteHeaders(connection, article); connection.WriteLine(string.Empty); WriteBody(connection, article); connection.WriteLine("."); }
private static void WriteBody(INntpConnection connection, NntpArticle article) { foreach (string line in article.Body) { if (line.Length > 0 && line[0] == '.') { connection.WriteLine("." + line); continue; } connection.WriteLine(line); } }
private static void WriteHeader(INntpConnection connection, string key, string val) { if (key == NntpHeaders.MessageId) { val = new NntpMessageId(val); } string line = $"{key}: {val}"; if (line.Length <= maxHeaderLength) { connection.WriteLine(line); return; } // header line is too long, fold it connection.WriteLine(line.Substring(0, maxHeaderLength)); line = line.Substring(maxHeaderLength); while (line.Length > maxHeaderLength) { connection.WriteLine("\t" + line.Substring(0, maxHeaderLength - 1)); line = line.Substring(maxHeaderLength - 1); } connection.WriteLine("\t" + line); }