// ------------------------- 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); }
/// <summary> /// Crack the component parts of the encoded-word string starting at InBx /// in the string. Return an object pair. pair.a is a bool set to false if the /// encoded-word string is not correctly formed. pair.b is a MimeEncodedWord object /// containing the component parts of the cracked word. /// </summary> /// <param name="InString"></param> /// <param name="InBx"></param> /// <returns></returns> public static BoolObjectPair CrackEncodedWord(string InString, int InBx) { int Fx, Ix, Lx, RemLx; string ws = null; MimeEncodedWord ew = new MimeEncodedWord( ); bool isEncodedWord = true; try { // isolate the next 80 chars from the string as a workspace ( encoded words are // limited to 75 chars or less ) ew.Bx = InBx; ws = AcCommon.PullString(InString, InBx, 80, null).ToLower( ); Ix = 0; // isolate the charset name Ix = 2; if (isEncodedWord == true) { RemLx = ws.Length - Ix; if (RemLx <= 3) { isEncodedWord = false; } else { Fx = ws.IndexOf("?q?", Ix); if (Fx == -1) { isEncodedWord = false; } else { Lx = Fx - Ix; ew.CharSet = InString.Substring(InBx + Ix, Lx); Ix = Fx + 3; } } } // quoted-printable encoded text runs until "?=" if (isEncodedWord == true) { RemLx = ws.Length - Ix; if (RemLx <= 2) { isEncodedWord = false; } else { Fx = ws.IndexOf("?=", Ix); if (Fx == -1) { isEncodedWord = false; } else { Lx = Fx - Ix; string qpEncoded = InString.Substring(InBx + Ix, Lx); ew.DecodedValue = QuotedPrintable.DecodeString(qpEncoded); ew.Lx = Fx + 2; } } } } catch (Exception) { isEncodedWord = false; } return(new BoolObjectPair(isEncodedWord, ew)); }