public MimeHeaderBufferByteArray ReadHeader(MimeHeaderBufferByteArray header) { this._Start = this._Current; Byte *start = this._Start; Byte *lastOfLine = this._Current; if (this._Current == this._End) { return(header); } if (*this._Current == 10)// \n { this._Current++; header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return(header); } //Find LineFeed char while (true) { // \n while (*this._Current != 10) { this._Current++; } if (this._Current == this._End) { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._End - start), false); return(header); } lastOfLine = this._Current - 2; this._Current++; //Empty line is start of body if (lastOfLine - this._Start < 1) { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return(header); } if (*this._Current != 9 && *this._Current != 32)// \t or white space { header.Add(MimeParser.CreateNewBytes(new IntPtr(start), this._Current - start), true); return(header); } } }
public Byte[] ReadLine() { this._Start = this._Current; //Find LineFeed char while (*this._Current != 10) { this._Current++; } if (this._Start == this._Current) { this._Current++; return(_EmptyBytes); } this._Current++; return(MimeParser.CreateNewBytes(new IntPtr(this._Start), this._Current - this._Start)); }
public Byte[] ReadBody(Byte[] boundary, out CheckBoundaryResult result, out Boolean isEndOfBody) { result = CheckBoundaryResult.None; isEndOfBody = false; if (this._Current == this._End) { isEndOfBody = true; return(_EmptyBytes); } Int32 boundaryLength = -1; if (boundary != null) { boundaryLength = boundary.Length; } this._Start = this._Current; var line_Start = this._Current; UInt32 bbbbXor = 0; while (true) { UInt32 *bbbb = (UInt32 *)this._Current; do { bbbbXor = *bbbb++ ^ 0x0A0A0A0A; } while (((bbbbXor - 0x01010101) & ~bbbbXor & 0x80808080) == 0); this._Current = (byte *)(bbbb - 1); // 10 is \n while (*this._Current != 10) { this._Current++; } if (*line_Start == 46)// . { var lastOfLine = this._Current - 2; if (line_Start == lastOfLine) { isEndOfBody = true; //Remove last period from bodydata return(MimeParser.CreateNewBytes(new IntPtr(this._Start), lastOfLine - this._Start)); } } // Check this line is started by '-' (Boundary). //That avoid method call of CheckBoundary and improve performance. if (*line_Start == 45 && boundaryLength > -1) { //We found the end of the string by ASC 10 and assume that the end of the string is \r\n, var lastOfLine = this._Current - 1; if (*lastOfLine == 13) { lastOfLine--; } var length = lastOfLine - line_Start + 1; if (length == boundaryLength || length == boundaryLength + 2) { result = CheckBoundary(line_Start, lastOfLine + 1, boundary); if (result != CheckBoundaryResult.None) { if (result == CheckBoundaryResult.Boundary) { //Back to start of line.To read boundary line on MimeParser.ReadMimeContent method. this._Current = line_Start; } return(MimeParser.CreateNewBytes(new IntPtr(this._Start), line_Start - this._Start)); } } } if (this._Current == this._End) { //Contains only 1 line and end of buffer if (line_Start == this._Start) { this._Current = line_Start; _IsLastOfLine = true; _LastLine = MimeParser.CreateNewBytes(new IntPtr(this._Start), this._End - this._Start); return(_EmptyBytes); } return(MimeParser.CreateNewBytes(new IntPtr(this._Start), this._Current - this._Start)); } this._Current++; line_Start = this._Current; } }