public FieldParser() { m_UnfoldPattern = PatternFactory.GetInstance().Get(typeof (UnfoldPattern)); m_FieldPattern = PatternFactory.GetInstance().Get(typeof (FieldPattern)); m_HeaderNamePattern = PatternFactory.GetInstance().Get(typeof (FieldNamePattern)); m_HeaderBodyPattern = PatternFactory.GetInstance().Get(typeof (FieldBodyPattern)); m_DataReader = new DataReader(); }
public Result ParseFields(ref Stream dataStream, DataReader reader) { var result = reader.ReadData(ref dataStream); var headers = new string(result.Data); headers = m_UnfoldPattern.RegularExpression.Replace(headers, " "); IList<RFC822.Field> fields = new List<RFC822.Field>(); Parse(ref fields, ref headers); return new Result() { Data = fields, FulfilledCritera = result.FulfilledCritera }; }
private string ReadDiscreteBody(ref Stream dataStream, ref IEntity entity, ref string body) { StringBuilder sBuilder; char[] cLine; string currentLine, boundary; bool bContinue = true; int fulFilledCriteria; var dataReader = new DataReader(m_EndOfMessageCriteria, new EndOfLineStrategy()); sBuilder = new StringBuilder(); do { var result = dataReader.ReadData(ref dataStream); cLine = result.Data; currentLine = new string(cLine); boundary = m_delimiterFinder.FindDelimiter(ref entity, ref currentLine); if (!string.IsNullOrEmpty(boundary)) { break; } // Have we found the end of this message? if (result.FulfilledCritera < 0) { boundary = string.Empty; break; } sBuilder.Append(result.Data); } while (bContinue); body = sBuilder.ToString(); sBuilder.Append(cLine); m_Source.Append(sBuilder); return boundary; }
private string FindStartDelimiter(ref Stream dataStream, ref IEntity entity) { int fulFilledCriteria; string line, delimiter; var dataReader = new DataReader(m_EndOfMessageCriteria, new EndOfLineStrategy()); do { var result = dataReader.ReadData(ref dataStream); fulFilledCriteria = result.FulfilledCritera; line = new string(result.Data); m_Source.Append(line); if (result.FulfilledCritera == 0) { delimiter = string.Empty; break; } delimiter = m_delimiterFinder.FindDelimiter(ref entity, ref line); if (!string.IsNullOrEmpty(delimiter)) { break; } } while (fulFilledCriteria >= 0); return delimiter; }