private void ZeroExpandFragment(ValuePosition start, ValuePosition end, bool allowControlCharacters, System.Text.StringBuilder sb) { var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask, start, end); while (!valueIterator.Eof) { var num = (byte) valueIterator.Get(); if (!allowControlCharacters && num < 32) num = (byte) ValueDecoder.ReplaceProhibitedControlCharacter((char) num); sb.Append((char) num); } }
private Globalization.Charset DetectValueCharset(Globalization.Charset defaultCharset, bool enableJisDetection, bool enableUtf8Detection, bool enableDbcsDetection, out EncodingScheme encodingScheme) { var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask); var inboundCharsetDetector = new Globalization.FeInboundCharsetDetector(defaultCharset.CodePage, false, enableJisDetection, enableUtf8Detection, enableDbcsDetection); while (!valueIterator.Eof) { inboundCharsetDetector.AddBytes(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, false); valueIterator.Get(valueIterator.Length); } inboundCharsetDetector.AddBytes(null, 0, 0, true); var codePageChoice = inboundCharsetDetector.GetCodePageChoice(); if (codePageChoice != defaultCharset.CodePage) defaultCharset = Globalization.Charset.GetCharset(codePageChoice); encodingScheme = inboundCharsetDetector.PureAscii ? (!(defaultCharset.Name == "iso-2022-jp") || inboundCharsetDetector.Iso2022KrLikely ? EncodingScheme.None : EncodingScheme.Jis) : (inboundCharsetDetector.Iso2022JpLikely || inboundCharsetDetector.Iso2022KrLikely ? EncodingScheme.Jis : EncodingScheme.EightBit); return defaultCharset; }
private void DecodeEncodedWord( byte bOrQ, System.Text.Decoder decoder, ValuePosition encodedWordContentStart, ValuePosition encodedWordContentEnd, bool allowControlCharacters, ref byte[] byteBuffer, ref char[] charBuffer, System.Text.StringBuilder sb) { var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask, encodedWordContentStart, encodedWordContentEnd); if (charBuffer == null) charBuffer = Internal.ScratchPad.GetCharBuffer(System.Math.Min(1024, iterator.TotalLength)); if (byteBuffer == null) byteBuffer = Internal.ScratchPad.GetByteBuffer(System.Math.Max(maxCharsetNameLength + 1, System.Math.Min(1024, iterator.TotalLength))); var byteBufferLength = 0; if (bOrQ == 66) { var num1 = 0; var num2 = 0; while (!valueIterator.Eof) { var num3 = (byte) (valueIterator.Get() - 32); if (num3 < Schema.Mime.Encoders.ByteEncoder.Tables.Base64ToByte.Length) { var num4 = Schema.Mime.Encoders.ByteEncoder.Tables.Base64ToByte[num3]; if (num4 < 64) { num2 = num2 << 6 | num4; ++num1; if (num1 == 4) { var numArray1 = byteBuffer; var index1 = byteBufferLength; var num5 = 1; var num6 = index1 + num5; int num7 = (byte) (num2 >> 16); numArray1[index1] = (byte) num7; var numArray2 = byteBuffer; var index2 = num6; var num8 = 1; var num9 = index2 + num8; int num10 = (byte) (num2 >> 8); numArray2[index2] = (byte) num10; var numArray3 = byteBuffer; var index3 = num9; var num11 = 1; byteBufferLength = index3 + num11; int num12 = (byte) num2; numArray3[index3] = (byte) num12; num1 = 0; if (byteBufferLength + 3 >= byteBuffer.Length) { this.FlushDecodedBytes(byteBuffer, byteBufferLength, decoder, allowControlCharacters, charBuffer, sb); byteBufferLength = 0; } } } } } if (num1 != 0) { if (num1 == 2) { var num3 = num2 << 12; byteBuffer[byteBufferLength++] = (byte) (num3 >> 16); } else if (num1 == 3) { var num3 = num2 << 6; var numArray1 = byteBuffer; var index1 = byteBufferLength; var num4 = 1; var num5 = index1 + num4; int num6 = (byte) (num3 >> 16); numArray1[index1] = (byte) num6; var numArray2 = byteBuffer; var index2 = num5; var num7 = 1; byteBufferLength = index2 + num7; int num8 = (byte) (num3 >> 8); numArray2[index2] = (byte) num8; } } } else { while (!valueIterator.Eof) { var num1 = (byte) valueIterator.Get(); switch (num1) { case 61: var index1 = valueIterator.Get(); var index2 = valueIterator.Get(); int num2 = index1 < 0 ? byte.MaxValue : Schema.Mime.Encoders.ByteEncoder.Tables.NumFromHex[index1]; int num3 = index2 < 0 ? byte.MaxValue : Schema.Mime.Encoders.ByteEncoder.Tables.NumFromHex[index2]; num1 = num2 == (int) byte.MaxValue || num3 == (int) byte.MaxValue ? (byte) 61 : (byte) (num2 << 4 | num3); break; case 95: num1 = 32; break; } byteBuffer[byteBufferLength++] = num1; if (byteBufferLength >= byteBuffer.Length) { this.FlushDecodedBytes(byteBuffer, byteBufferLength, decoder, allowControlCharacters, charBuffer, sb); byteBufferLength = 0; } } } if (byteBufferLength == 0) return; this.FlushDecodedBytes(byteBuffer, byteBufferLength, decoder, allowControlCharacters, charBuffer, sb); }
public ValueDecoder(MimeStringList lines, uint linesMask) { iterator = new ValueIterator(lines, linesMask); maxCharsetNameLength = System.Math.Max(60, Globalization.Charset.MaxCharsetNameLength) + 10 + 1; }
private void ConvertRawFragment(ValuePosition start, ValuePosition end, System.Text.Decoder decoder, bool allowControlCharacters, ref char[] charBuffer, System.Text.StringBuilder sb) { var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask, start, end); if (valueIterator.Eof) return; if (charBuffer == null) charBuffer = Internal.ScratchPad.GetCharBuffer(System.Math.Min(1024, iterator.TotalLength)); int bytesUsed; int charsUsed; bool completed; do { decoder.Convert(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, charBuffer, 0, charBuffer.Length, false, out bytesUsed, out charsUsed, out completed); if (charsUsed != 0) { if (!allowControlCharacters) ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, charsUsed); sb.Append(charBuffer, 0, charsUsed); } valueIterator.Get(bytesUsed); } while (!completed || !valueIterator.Eof); decoder.Convert(MimeString.EmptyByteArray, 0, 0, charBuffer, 0, charBuffer.Length, true, out bytesUsed, out charsUsed, out completed); if (charsUsed == 0) return; if (!allowControlCharacters) ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, charsUsed); sb.Append(charBuffer, 0, charsUsed); }