Пример #1
0
 private static void RemoveProhibitedControlCharacters(char[] charBuffer, int offset, int length)
 {
     while (length != 0)
     {
         char c = charBuffer[offset];
         if (c < ' ')
         {
             charBuffer[offset] = ValueDecoder.ReplaceProhibitedControlCharacter(c);
         }
         offset++;
         length--;
     }
 }
Пример #2
0
        private void ZeroExpandFragment(ValuePosition start, ValuePosition end, bool allowControlCharacters, StringBuilder sb)
        {
            ValueIterator valueIterator = new ValueIterator(this.iterator.Lines, this.iterator.LinesMask, start, end);

            while (!valueIterator.Eof)
            {
                byte b = (byte)valueIterator.Get();
                if (!allowControlCharacters && b < 32)
                {
                    b = (byte)ValueDecoder.ReplaceProhibitedControlCharacter((char)b);
                }
                sb.Append((char)b);
            }
        }
Пример #3
0
        private void FlushDecoder(Decoder decoder, bool allowControlCharacters, ref byte[] byteBuffer, ref char[] charBuffer, StringBuilder sb)
        {
            int  num;
            int  num2;
            bool flag;

            decoder.Convert(byteBuffer, 0, 0, charBuffer, 0, charBuffer.Length, true, out num, out num2, out flag);
            if (num2 != 0)
            {
                if (!allowControlCharacters)
                {
                    ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, num2);
                }
                sb.Append(charBuffer, 0, num2);
            }
        }
Пример #4
0
        // Token: 0x0600024C RID: 588 RVA: 0x0000AD74 File Offset: 0x00008F74
        internal static bool TryDecodeValue(MimeStringList lines, uint linesMask, DecodingOptions decodingOptions, out DecodingResults decodingResults, out string value)
        {
            decodingResults = default(DecodingResults);
            if (lines.GetLength(linesMask) == 0)
            {
                value = string.Empty;
                return(true);
            }
            DecodingFlags decodingFlags          = decodingOptions.DecodingFlags;
            bool          flag                   = DecodingFlags.None != (DecodingFlags.FallbackToRaw & decodingFlags);
            bool          allowControlCharacters = DecodingFlags.None != (DecodingFlags.AllowControlCharacters & decodingFlags);
            bool          enable                 = false;
            bool          enableJisDetection     = false;
            bool          enableUtf8Detection    = false;
            bool          enableDbcsDetection    = false;
            Charset       defaultCharset         = null;
            ValueDecoder  valueDecoder           = new ValueDecoder(lines, linesMask);

            if ((decodingFlags & DecodingFlags.AllEncodings) == DecodingFlags.None)
            {
                if (!flag)
                {
                    defaultCharset = Charset.ASCII;
                }
            }
            else
            {
                enable              = (DecodingFlags.None != (DecodingFlags.Rfc2047 & decodingFlags));
                enableJisDetection  = (DecodingFlags.None != (DecodingFlags.Jis & decodingFlags));
                enableUtf8Detection = (DecodingFlags.None != (DecodingFlags.Utf8 & decodingFlags));
                enableDbcsDetection = (DecodingFlags.None != (DecodingFlags.Dbcs & decodingFlags));
                defaultCharset      = decodingOptions.Charset;
            }
            string         charsetName;
            string         cultureName;
            EncodingScheme encodingScheme;
            bool           flag2 = valueDecoder.TryDecodeValue(defaultCharset, flag, allowControlCharacters, enable, enableJisDetection, enableUtf8Detection, enableDbcsDetection, out charsetName, out cultureName, out encodingScheme, out value);

            decodingResults.EncodingScheme = encodingScheme;
            decodingResults.CharsetName    = charsetName;
            decodingResults.CultureName    = cultureName;
            decodingResults.DecodingFailed = !flag2;
            return(flag2);
        }
Пример #5
0
        private void FlushDecodedBytes(byte[] byteBuffer, int byteBufferLength, Decoder decoder, bool allowControlCharacters, char[] charBuffer, StringBuilder sb)
        {
            int  num = 0;
            bool flag;

            do
            {
                int num2;
                int num3;
                decoder.Convert(byteBuffer, num, byteBufferLength, charBuffer, 0, charBuffer.Length, false, out num2, out num3, out flag);
                if (num3 != 0)
                {
                    if (!allowControlCharacters)
                    {
                        ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, num3);
                    }
                    sb.Append(charBuffer, 0, num3);
                }
                num += num2;
                byteBufferLength -= num2;
            }while (!flag);
        }
Пример #6
0
        private void ConvertRawFragment(ValuePosition start, ValuePosition end, Decoder decoder, bool allowControlCharacters, ref char[] charBuffer, StringBuilder sb)
        {
            ValueIterator valueIterator = new ValueIterator(this.iterator.Lines, this.iterator.LinesMask, start, end);

            if (!valueIterator.Eof)
            {
                if (charBuffer == null)
                {
                    charBuffer = ScratchPad.GetCharBuffer(Math.Min(1024, this.iterator.TotalLength));
                }
                int  length;
                int  num;
                bool flag;
                do
                {
                    decoder.Convert(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, charBuffer, 0, charBuffer.Length, false, out length, out num, out flag);
                    if (num != 0)
                    {
                        if (!allowControlCharacters)
                        {
                            ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, num);
                        }
                        sb.Append(charBuffer, 0, num);
                    }
                    valueIterator.Get(length);
                }while (!flag || !valueIterator.Eof);
                decoder.Convert(MimeString.EmptyByteArray, 0, 0, charBuffer, 0, charBuffer.Length, true, out length, out num, out flag);
                if (num != 0)
                {
                    if (!allowControlCharacters)
                    {
                        ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, num);
                    }
                    sb.Append(charBuffer, 0, num);
                }
            }
        }
Пример #7
0
        private bool ParseEncodedWord(string lastEncodedWordCharsetName, string lastEncodedWordLanguage, ref byte[] byteBuffer, out string encodedWordCharsetName, out string encodedWordLanguage, out byte bOrQ, out ValuePosition encodedWordContentStart, out ValuePosition encodedWordContentEnd)
        {
            encodedWordCharsetName = null;
            encodedWordLanguage    = null;
            bOrQ = 0;
            ValuePosition valuePosition = default(ValuePosition);

            encodedWordContentEnd   = valuePosition;
            encodedWordContentStart = (encodedWordContentEnd = valuePosition);
            int num = this.iterator.Get();

            if (this.iterator.Get() != 63)
            {
                return(false);
            }
            if (byteBuffer == null)
            {
                byteBuffer = ScratchPad.GetByteBuffer(Math.Max(this.maxCharsetNameLength + 1, Math.Min(1024, this.iterator.TotalLength)));
            }
            int num2 = -1;
            int i;

            for (i = 0; i < this.maxCharsetNameLength + 1; i++)
            {
                num = this.iterator.Get();
                if (!ValueDecoder.Is2047Token((byte)num))
                {
                    break;
                }
                byteBuffer[i] = (byte)num;
                if (num2 == -1 && num == 42)
                {
                    num2 = i;
                }
            }
            if (i == this.maxCharsetNameLength + 1 || num != 63 || i == 0 || num2 == 0)
            {
                return(false);
            }
            num  = this.iterator.Get();
            bOrQ = ((num == 66 || num == 98) ? 66 : ((num == 81 || num == 113) ? 81 : 0));
            if (bOrQ == 0 || this.iterator.Get() != 63)
            {
                return(false);
            }
            if (num2 != -1)
            {
                int num3 = num2 + 1;
                int num4 = i - (num2 + 1);
                i = num2;
                if (num4 != 0)
                {
                    if (lastEncodedWordLanguage != null && num4 == lastEncodedWordLanguage.Length)
                    {
                        int num5 = 0;
                        while (num5 < num4 && lastEncodedWordLanguage[num5] == (char)byteBuffer[num3 + num5])
                        {
                            num5++;
                        }
                        if (num5 != num4)
                        {
                            encodedWordLanguage = ByteString.BytesToString(byteBuffer, num3, num4, false);
                        }
                        else
                        {
                            encodedWordLanguage = lastEncodedWordLanguage;
                        }
                    }
                    else
                    {
                        encodedWordLanguage = ByteString.BytesToString(byteBuffer, num3, num4, false);
                    }
                }
            }
            if (lastEncodedWordCharsetName != null && i == lastEncodedWordCharsetName.Length)
            {
                int num6 = 0;
                while (num6 < i && lastEncodedWordCharsetName[num6] == (char)byteBuffer[num6])
                {
                    num6++;
                }
                if (num6 != i)
                {
                    encodedWordCharsetName = ByteString.BytesToString(byteBuffer, 0, i, false);
                }
                else
                {
                    encodedWordCharsetName = lastEncodedWordCharsetName;
                }
            }
            else
            {
                encodedWordCharsetName = ByteString.BytesToString(byteBuffer, 0, i, false);
            }
            encodedWordContentStart = this.iterator.CurrentPosition;
            bool flag = false;

            for (;;)
            {
                encodedWordContentEnd = this.iterator.CurrentPosition;
                num = this.iterator.Get();
                if (num == -1)
                {
                    break;
                }
                if (MimeScan.IsLWSP((byte)num))
                {
                    flag = true;
                }
                else
                {
                    if (num == 63)
                    {
                        num = this.iterator.Get();
                        if (num == -1)
                        {
                            return(false);
                        }
                        if (num == 61)
                        {
                            return(true);
                        }
                        this.iterator.Unget();
                        if (bOrQ != 81)
                        {
                            return(false);
                        }
                    }
                    else if (num == 61 && flag)
                    {
                        num = this.iterator.Get();
                        if (num == -1)
                        {
                            return(false);
                        }
                        if (num == 63)
                        {
                            goto Block_33;
                        }
                        this.iterator.Unget();
                    }
                    flag = false;
                }
            }
            return(false);

Block_33:
            this.iterator.Unget();
            this.iterator.Unget();
            return(false);
        }