Esempio n. 1
0
        internal bool IsHeaderLineTooLong(long nameLength, out bool merge)
        {
            int  num    = 0;
            bool result = false;

            merge = false;
            for (int i = 0; i < this.lines.Count; i++)
            {
                int    num2;
                int    num3;
                byte[] data = this.lines[i].GetData(out num2, out num3);
                bool   flag = MimeScan.IsLWSP(data[num2]);
                if (num != 0 && !flag)
                {
                    result = true;
                    merge  = true;
                }
                num += num3;
                if (i == 0 && (long)num3 + nameLength + 1L > 998L)
                {
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 2
0
        internal static long WriteLines(MimeStringList lines, Stream stream)
        {
            if (lines.Count == 0)
            {
                MimeStringLength mimeStringLength = new MimeStringLength(0);
                return(Header.WriteLineEnd(stream, ref mimeStringLength));
            }
            long num = 0L;

            for (int i = 0; i < lines.Count; i++)
            {
                int    num2;
                int    num3;
                byte[] data = lines[i].GetData(out num2, out num3);
                if (num3 != 0)
                {
                    if (!MimeScan.IsLWSP(data[num2]))
                    {
                        stream.Write(MimeString.Space, 0, MimeString.Space.Length);
                        num += (long)MimeString.Space.Length;
                    }
                    stream.Write(data, num2, num3);
                    num += (long)num3;
                }
                MimeStringLength mimeStringLength2 = new MimeStringLength(0);
                num += Header.WriteLineEnd(stream, ref mimeStringLength2);
            }
            return(num);
        }
        // Token: 0x0600032A RID: 810 RVA: 0x000120A0 File Offset: 0x000102A0
        private bool FindBoundary(byte[] data, int line, int nextNL, out int nextBoundaryLevel, out bool nextBoundaryEnd)
        {
            while (nextNL > line && MimeScan.IsLWSP(data[nextNL - 1]))
            {
                nextNL--;
            }
            uint num = ByteString.ComputeCrc(data, line, nextNL - line);
            bool flag;

            if (this.currentLevel.IsBoundary(data, line, nextNL - line, (long)((ulong)num), out flag))
            {
                nextBoundaryLevel = this.parseStackTop;
                nextBoundaryEnd   = flag;
                return(true);
            }
            for (int i = this.parseStackTop - 1; i >= 0; i--)
            {
                if (this.parseStack[i].IsBoundary(data, line, nextNL - line, (long)((ulong)num), out flag))
                {
                    nextBoundaryLevel = i;
                    nextBoundaryEnd   = flag;
                    return(true);
                }
            }
            nextBoundaryLevel = -1;
            nextBoundaryEnd   = false;
            return(false);
        }
Esempio n. 4
0
        public void ParseParameterValue(ref MimeStringList value, ref bool goodValue, bool handleISO2022)
        {
            MimeStringList mimeStringList = default(MimeStringList);

            goodValue = true;
            while (this.position != this.end || this.ParseNextLine())
            {
                byte b = this.bytes[this.position];
                if (b == 34)
                {
                    value.Reset();
                    mimeStringList.Reset();
                    this.ParseQString(true, ref value, handleISO2022);
                    return;
                }
                if (b == 40 || MimeScan.IsLWSP(b))
                {
                    this.ParseCFWS(true, ref mimeStringList, handleISO2022);
                }
                else
                {
                    if (b == 59)
                    {
                        return;
                    }
                    int num = this.position;
                    do
                    {
                        int num2 = 1;
                        if (!MimeScan.IsToken(b))
                        {
                            if (this.allowUTF8 && b >= 128)
                            {
                                if (!MimeScan.IsUTF8NonASCII(this.bytes, this.position, this.end, out num2))
                                {
                                    num2      = 1;
                                    goodValue = false;
                                }
                            }
                            else
                            {
                                goodValue = false;
                            }
                        }
                        this.position += num2;
                        if (this.position == this.end)
                        {
                            break;
                        }
                        b = this.bytes[this.position];
                    }while (b != 59 && b != 40 && !MimeScan.IsLWSP(b));
                    value.TakeOverAppend(ref mimeStringList);
                    value.AppendFragment(new MimeString(this.bytes, num, this.position - num));
                }
            }
        }
        // Token: 0x06000251 RID: 593 RVA: 0x0000AEB8 File Offset: 0x000090B8
        internal static bool IsEncodingRequired(string value, bool allowUTF8)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }
            char[] array = new char[1];
            int    num   = 0;

            foreach (char c in value)
            {
                if (c < '\u0080')
                {
                    if (MimeScan.IsEncodingRequired((byte)c))
                    {
                        return(true);
                    }
                    if (MimeScan.IsLWSP((byte)c))
                    {
                        num = 0;
                    }
                    else
                    {
                        num++;
                    }
                }
                else
                {
                    if (!allowUTF8)
                    {
                        return(true);
                    }
                    array[0] = c;
                    num     += ByteString.StringToBytesCount(new string(array), allowUTF8);
                }
                if (998 < num + 1)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 6
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);
        }