Exemple #1
0
        private void ParseBody(byte[] data)
        {
            this.UnprocessedData = new byte[] { };
            if (StartBoundary == "--") //isEmpty = > singlepart
            {
                this._bodyBytes = data;
            }
            else //multipart
            {
                var    crlf  = DefaultEncoding.GetBytes(CRLF);
                int    index = 0;
                byte[] stringBytes;
                //чтение собственного текста
                {
                    int nextIndex = index;
                    while (readLine(data, ref nextIndex, out stringBytes))
                    {
                        if (stringBytes.ValueEquals(this.StartBoundaryBytes1) || stringBytes.ValueEquals(this.EndBoundaryBytes))
                        {
                            this._bodyBytes = data.GetSubArray(0, index);
                            break;
                        }

                        index = nextIndex;
                    }
                    index = nextIndex;
                }

                //достигнут конец данных
                if (stringBytes == null || stringBytes.ValueEquals(this.EndBoundaryBytes))
                {
                    return;
                }

                int endIndex = BytesExtensions.IndexOf(data, this.EndBoundaryBytes, index);
                if (endIndex == -1)
                {
                    endIndex = data.Length;
                }

                while (index < endIndex)
                {
                    int nextIndex = BytesExtensions.IndexOf(data, this.StartBoundaryBytes1, index);
                    if (nextIndex == -1)
                    {
                        nextIndex = data.Length + crlf.Length;
                    }
                    var childData = data.GetSubArray(index, nextIndex - index - crlf.Length);
                    var child     = createMimeReader(this, childData);
                    this.Children.Add(child);
                    index = nextIndex + this.StartBoundaryBytes1.Length + crlf.Length;
                }
            }
        }
Exemple #2
0
 private bool readLine(byte[] data, ref int index, out byte[] stringBytes)
 {
     if (index >= data.Length)
     {
         stringBytes = null;
         return(false);
     }
     else
     {
         var crlf      = DefaultEncoding.GetBytes(CRLF);
         var crlfIndex = BytesExtensions.IndexOf(data, crlf, index);
         if (crlfIndex == -1)
         {
             stringBytes = data.GetSubArrayStartingAt(index);
             index       = data.Length;
         }
         else
         {
             stringBytes = data.GetSubArray(index, crlfIndex - index);
             index       = crlfIndex + crlf.Length;
         }
         return(true);
     }
 }
Exemple #3
0
        private byte[] ParseHeaders(byte[] data)
        {
            var crlf = DefaultEncoding.GetBytes(CRLF);

            var endOfHeader   = false;
            var currentHeader = "";
            int index         = 0;

            while (index < data.Length && !endOfHeader)
            {
                int lineBreakIndex = BytesExtensions.IndexOf(data, crlf, index);
                var breakFound     = (lineBreakIndex != -1);
                if (!breakFound)
                {
                    lineBreakIndex = data.Length;
                }

                int subStringLength = lineBreakIndex - index;

                var headerLineBytes = new byte[subStringLength];
                Array.Copy(data, index, headerLineBytes, 0, subStringLength);

                var line = DefaultEncoding.GetString(headerLineBytes);
                processHeaderLine(ref currentHeader, line, ref endOfHeader);
                index = lineBreakIndex;
                if (breakFound)
                {
                    index += crlf.Length;
                }
            }

            this._headerBytes = new byte[index];
            Array.Copy(data, this._headerBytes, index);
            processCommonHeaderAttribs();
            return(getUnprocessedData(data, index));
        }