Example #1
0
        public State ParseBuffer(
            byte[] buffer,
            int bytesReady,
            ref int bytesConsumed,
            out ArraySegment <byte> remainingBodyPart,
            out ArraySegment <byte> bodyPart,
            out bool isFinalBodyPart)
        {
            if (buffer == null)
            {
                throw Error.ArgumentNull("buffer");
            }

            State parseStatus = State.NeedMoreData;

            remainingBodyPart = MimeMultipartParser._emptyBodyPart;
            bodyPart          = MimeMultipartParser._emptyBodyPart;
            isFinalBodyPart   = false;

            try
            {
                parseStatus = MimeMultipartParser.ParseBodyPart(
                    buffer,
                    bytesReady,
                    ref bytesConsumed,
                    ref this._bodyPartState,
                    this._maxMessageSize,
                    ref this._totalBytesConsumed,
                    this._currentBoundary);
            }
            catch (Exception)
            {
                parseStatus = State.Invalid;
            }

            remainingBodyPart = this._currentBoundary.GetDiscardedBoundary();
            bodyPart          = this._currentBoundary.BodyPart;
            if (parseStatus == State.BodyPartCompleted)
            {
                isFinalBodyPart = this._currentBoundary.IsFinal;
                this._currentBoundary.ClearAll();
            }
            else
            {
                this._currentBoundary.ClearBodyPart();
            }

            return(parseStatus);
        }