// ------------------------- FoldNewLine --------------------------- // add a fold ( crlf-space ) to the current line. This will public ChunkPair FoldNewLine(Chunk InSpaceChunk) { // must be a space chunk if (InSpaceChunk.ChunkType != ChunkType.Spaces) { throw(new ApplicationException("FoldNewLine method must be passed spaces")); } // end the current line. Chunk eolChunk = new Chunk(ChunkType.EndOfLine); CurrentLine.AddChunk(eolChunk); // split the space chunk. one char for the fold chunk. the remainder to be // placed as processing continues. ChunkPair pair = InSpaceChunk.Split(ParentLineBuilder.Traits, 1); // the fold chunk is a single space. ( this is a single space from the // unicode string so it has a Bx. ) Chunk foldChunk = pair.a; CurrentLine.AddChunk(foldChunk); return(pair); }
// ------------------------- SpaceChunk_ToEndOfEncodedLine -------------------- // spaces being placed at the last chunk on the line. That means the last char // of the spaces must be QP encoded as =20 in order to prevent the spaces from // being trimmed by mail transfer agents. private Chunk SpaceChunk_ToEndOfEncodedLine( Chunk InChunk, EncodedLines InLines) { ChunkPair pair = null; // isolate the chunk we are working with. Chunk chunk = InChunk; // space remaining on the line. int RemLx = InLines.CurrentLine.CalcDesiredMaxRemLx(Traits); // how much room is used by single space in encoded-word form. int SingleEncodedSpaceUsedLx = new Chunk(ChunkType.Spaces, " ") .SetEncodeAlways(true) .Encode(Traits) .Length; int maxSeg1SpaceCx = RemLx - SingleEncodedSpaceUsedLx - 1; // not enough room to encode a single space. fold right here. if (SingleEncodedSpaceUsedLx > RemLx) { pair = InLines.FoldNewLine(chunk); chunk = pair.a; } // only one space in the chunk. that space is needed for the fold. fold // right away. else if (chunk.Value.Length == 1) { pair = InLines.FoldNewLine(chunk); chunk = pair.a; } // place spaces on the line, then a space in encoded-word form, then fold the // line. else { // place as many spaces before the encoded-word space. int seg1SpaceCx = chunk.Value.Length - 2; if (seg1SpaceCx > maxSeg1SpaceCx) { seg1SpaceCx = maxSeg1SpaceCx; } if (seg1SpaceCx > 0) { pair = chunk.Split(Traits, seg1SpaceCx); InLines.CurrentLine.AddChunk(pair.a); chunk = pair.b; } // there should be at least 2 spaces remaining. if (chunk.Value.Length < 2) { throw(new ApplicationException("Space chunk is too small")); } // split a space from the chunk and add it to the line in forced encoded form. // this is the last chunk on the line. pair = chunk.Split(Traits, 1); pair.a.SetEncodeAlways(true); InLines.CurrentLine.AddChunk(pair.a); chunk = pair.b; // fold the line, using another space as the fold char on the new line. pair = InLines.FoldNewLine(chunk); chunk = pair.a; } // return with the last chunk placed on the line. return(chunk); }