// ----------------------- Split ----------------------------------- public ChunkPair Split(MimeHeaderLineTraits InTraits, int InFirstPartLx) { string part1Value = null; string part2Value = null; Chunk part1 = null; Chunk part2 = null; int part1Lx = InFirstPartLx; int part2Lx = Value.Length - part1Lx; int part1Bx = Bx; int part2Bx = Bx + part1Lx; if (part1Lx > 0) { part1Value = Value.Substring(0, part1Lx); part1 = new Chunk( ); part1.Bx = part1Bx; part1.Value = part1Value; part1.EvalChunkType(InTraits); } if (part2Lx > 0) { part2Value = Value.Substring(part1Lx, part2Lx); part2 = new Chunk( ); part2.Bx = part2Bx; part2.Value = part2Value; part2.EvalChunkType(InTraits); } return(new ChunkPair(part1, part2)); }
// --------------------- CalcQuotedPrintableTraits ------------------------ // Setup an object containing the traits for the Quoted-Printable encoding of // contents of the MimeHeaderLine. public static QuotedPrintableTraits CalcQuotedPrintableTraits( MimeHeaderLineTraits InMimeLineTraits) { QuotedPrintableTraits qpTraits = new QuotedPrintableTraits( ); qpTraits.SetCharSet(InMimeLineTraits.EncoderCharSet); return(qpTraits); }
public static string Encode(string InValue, MimeHeaderLineTraits InHdrTraits) { QuotedPrintableTraits qpTraits = CalcQuotedPrintableTraits(InHdrTraits); string ec = QuotedPrintable.Encode(InValue, qpTraits); string results = "=?" + InHdrTraits.EncoderCharSet + "?Q?" + ec + "?="; return(results); }
// --------------------- CalcQuotedPrintableTraits ------------------------ // Setup an object containing the traits for the Quoted-Printable encoding of // contents of the MimeHeaderLine. private static QuotedPrintableTraits CalcQuotedPrintableTraits( MimeHeaderLineTraits InTraits) { string otherEncodeChars = " \t\n\r?"; QuotedPrintableTraits qpTraits = new QuotedPrintableTraits( ); qpTraits.SetEncoder(InTraits.Encoder); if (InTraits.OtherEncodeChars != null) { otherEncodeChars = otherEncodeChars + InTraits.OtherEncodeChars; } qpTraits.SetOtherEncodeChars(otherEncodeChars); return(qpTraits); }
// ---------------------- EvalChunkType ---------------------- // eval the ChunkType based on examination of the chunk value public Chunk EvalChunkType(MimeHeaderLineTraits InTraits) { // isolate the chunk value. string chunkValue = Value; int Lx = chunkValue.Length; // classify the chunk. is it a literal chunk or an encoded-word required one. bool mustEncode = false; bool allSpaces = true; for (int Ix = 0; Ix < Lx; ++Ix) { char ch1 = chunkValue[Ix]; if ((ch1 < 33) || (ch1 > 126)) { mustEncode = true; break; } else if ((InTraits.OtherEncodeChars != null) && (InTraits.OtherEncodeChars.IndexOf(ch1) != -1)) { mustEncode = true; break; } if ((allSpaces == true) && (ch1 != ' ')) { allSpaces = false; } } // assign the chunk type. if (mustEncode == true) { ChunkType = ChunkType.EncodedChars; } else if (allSpaces == true) { ChunkType = ChunkType.Spaces; } else { ChunkType = ChunkType.LiteralChars; } return(this); }
// ------------------------- Chunk.Encode ------------------------------- // encode the chunk as it will be placed in the mime header. public string Encode(MimeHeaderLineTraits InTraits) { EncodedValue = null; if ((ChunkType == ChunkType.EncodedChars) || (EncodeAlways == true)) { EncodedValue = MimeEncodedWord.Encode(Value, InTraits); } else if (ChunkType == ChunkType.EndOfLine) { EncodedValue = "\r\n"; } else { EncodedValue = Value; } return(EncodedValue); }
// --------------------- CalcDesiredMaxRemLx ------------------------------- // how much open space remains on the encoded output line. public int CalcDesiredMaxRemLx(MimeHeaderLineTraits InTraits) { int remLx = InTraits.LineDesiredMaxLength - EncodedEx; return(remLx); }