/// <summary> /// Parses body from the specified stream /// </summary> /// <param name="owner">Owner MIME entity.</param> /// <param name="defaultContentType">Default content-type for this body.</param> /// <param name="stream">Stream from where to read body.</param> /// <returns>Returns parsed body.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>stream</b>, <b>mediaType</b> or <b>stream</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when any parsing errors.</exception> protected static new MIME_b Parse(MIME_Entity owner, MIME_h_ContentType defaultContentType, SmartStream stream) { if (owner == null) { throw new ArgumentNullException("owner"); } if (defaultContentType == null) { throw new ArgumentNullException("defaultContentType"); } if (stream == null) { throw new ArgumentNullException("stream"); } MIME_b_Text retVal = null; if (owner.ContentType != null) { retVal = new MIME_b_Text(owner.ContentType.TypeWithSubtype); } else { retVal = new MIME_b_Text(defaultContentType.TypeWithSubtype); } Net_Utils.StreamCopy(stream, retVal.EncodedStream, stream.LineBufferSize); retVal.SetModified(false); return(retVal); }
/// <summary> /// Creates text/plain MIME entity. /// </summary> /// <param name="transferEncoding">Content transfer encoding.</param> /// <param name="charset">Charset to use to encode text. If not sure, utf-8 is recommended.</param> /// <param name="text">Text.</param> /// <returns>Returns created entity.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>transferEncoding</b>, <b>charset</b> or <b>text</b> is null reference.</exception> /// <exception cref="NotSupportedException">Is raised when body contains not supported Content-Transfer-Encoding.</exception> public static MIME_Entity CreateEntity_Text_Plain(string transferEncoding, Encoding charset, string text) { if (transferEncoding == null) { throw new ArgumentNullException("transferEncoding"); } if (charset == null) { throw new ArgumentNullException("charset"); } if (text == null) { throw new ArgumentNullException("text"); } MIME_Entity retVal = new MIME_Entity(); MIME_b_Text body = new MIME_b_Text(MIME_MediaTypes.Text.plain); retVal.Body = body; body.SetText(transferEncoding, charset, text); return(retVal); }