/// <summary> /// Parses MIME entiry from the specified stream. /// </summary> /// <param name="stream">Source stream.</param> /// <param name="headerEncoding">Header reading encoding. If not sure UTF-8 is recommended.</param> /// <param name="defaultContentType">Default content type.</param> /// <exception cref="ArgumentNullException">Is raised when <b>stream</b>,<b>headerEncoding</b> or <b>defaultContentType</b> is null reference.</exception> internal protected void Parse(SmartStream stream, Encoding headerEncoding, MIME_h_ContentType defaultContentType) { if (stream == null) { throw new ArgumentNullException("stream"); } if (headerEncoding == null) { throw new ArgumentNullException("headerEncoding"); } if (defaultContentType == null) { throw new ArgumentNullException("defaultContentType"); } m_pHeader.Parse(stream, headerEncoding); m_pBody = m_pBodyProvider.Parse(this, stream, defaultContentType); m_pBody.SetParent(this, false); }
/// <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>defaultContentType</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"); } // We need to buffer all body data, otherwise we don't know if we have readed all data // from stream. MemoryStream msBuffer = new MemoryStream(); Net_Utils.StreamCopy(stream, msBuffer, 32000); msBuffer.Position = 0; SmartStream parseStream = new SmartStream(msBuffer, true); MIME_b_MessageDeliveryStatus retVal = new MIME_b_MessageDeliveryStatus(); //Pare per-message fields. retVal.m_pMessageFields.Parse(parseStream); // Parse per-recipient fields. while (parseStream.Position - parseStream.BytesInReadBuffer < parseStream.Length) { MIME_h_Collection recipientFields = new MIME_h_Collection(new MIME_h_Provider()); recipientFields.Parse(parseStream); retVal.m_pRecipientBlocks.Add(recipientFields); } return(retVal); }