public string GetMessageContext() { NetStream stream = BodyStream; if (stream == null) { return(null); } return(stream.PeekString(1, 4)); }
/// <summary> /// Parses TcpMessage reply-line from /// </summary> /// <param name="line">TcpMessage server reply-line.</param> /// <returns>Returns parsed TcpMessage server reply-line.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>line</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when reply-line parsing fails.</exception> public static TcpReply Parse(NetStream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } /* RFC 5321 4.2. * Reply-line = *( Reply-code "-" [ textstring ] CRLF ) * Reply-code [ SP textstring ] CRLF * * Since, in violation of this specification, the text is sometimes not sent, clients that do not * receive it SHOULD be prepared to process the code alone (with or without a trailing space character). */ if (stream.Length < 3) { throw new ParseException("Invalid TcpMessage server reply."); } int replyCode = stream.PeekInt32(0); if (replyCode <= 0) { throw new ParseException("Invalid TcpMessage server reply '" + replyCode + "' reply-code."); } string msgtype = stream.PeekString(4, 6); var bytes = stream.PeekBytes(7, stream.iLength - 9); bool isLastLine = true; if (line.Length > 3) { isLastLine = (line[3] == ' '); } string text = ""; if (line.Length > 5) { text = line.Substring(4); } return(new TcpReply(replyCode, text, isLastLine)); }