/// <summary> /// /// </summary> /// <param name="http_content_type"></param> /// <param name="binary_content"></param> /// <returns></returns> public MimeContent DeserializeMimeContent(string http_content_type, byte[] binary_content) { // // First of all parse the http content type // string _mimeType = null, _mimeBoundary = null, _mimeStart = null; ParseHttpContentTypeHeader(http_content_type, ref _mimeType, ref _mimeBoundary, ref _mimeStart); // // Create the mime-content // MimeContent _content = new MimeContent() { Boundary = _mimeBoundary }; // // Start finding the parts in the mime message // Note: in MIME RFC a "--" represents the end of something // var _endBoundaryHelperNdx = 0; byte[] _mimeBoundaryBytes = ParserEncoding.GetBytes("--" + _mimeBoundary); for (int i = 0; i < binary_content.Length; i++) { if (AreArrayPartsForTextEqual(_mimeBoundaryBytes, 0, binary_content, i, _mimeBoundaryBytes.Length)) { _endBoundaryHelperNdx = i + _mimeBoundaryBytes.Length; if ((_endBoundaryHelperNdx + 1) < binary_content.Length) { // The end of the MIME-message is the boundary followed by "--" if (binary_content[_endBoundaryHelperNdx] == '-' && binary_content[_endBoundaryHelperNdx + 1] == '-') { break; } } else { throw new ProxyException("Invalid MIME content parsed, premature End-Of-File detected!"); } // Start reading the mime part after the boundary MimePart _part = ReadMimePart(binary_content, ref i, _mimeBoundaryBytes); if (_part != null) { _content.Parts.Add(_part); } } } // // Finally return the ready-to-use object model // _content.SetAsStartPart(_mimeStart); return(_content); }