예제 #1
0
        internal override void ParseValue(ValueParser parser, bool storeValue)
        {
            MimeStringList mimeStringList = default(MimeStringList);

            parser.ParseCFWS(false, ref mimeStringList, true);
            MimeString mimeString = parser.ParseToken();

            if (storeValue)
            {
                if (mimeString.Length == 0)
                {
                    this.disp = string.Empty;
                    return;
                }
                this.disp = Header.NormalizeString(mimeString.Data, mimeString.Offset, mimeString.Length, false);
            }
        }
예제 #2
0
 public ValueParser(MimeStringList lines, ValueParser valueParser)
 {
     this.lines     = lines;
     this.allowUTF8 = valueParser.allowUTF8;
     this.nextLine  = valueParser.nextLine;
     if (this.nextLine > 0 && this.nextLine <= this.lines.Count)
     {
         int num;
         this.bytes    = this.lines[this.nextLine - 1].GetData(out this.start, out num);
         this.start    = valueParser.start;
         this.position = valueParser.position;
         this.end      = valueParser.end;
         return;
     }
     this.bytes    = null;
     this.start    = 0;
     this.end      = 0;
     this.position = 0;
 }
        // Token: 0x06000302 RID: 770 RVA: 0x00010A58 File Offset: 0x0000EC58
        internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer)
        {
            MimeStringList fragments = this.valueFragments;
            long           num       = 0L;

            if (this.valueFragments.Length == 0 && this.decodedValue != null && 0 < this.decodedValue.Length)
            {
                fragments           = this.EncodeValue(this.decodedValue, encodingOptions);
                this.valueFragments = fragments;
            }
            else if ((byte)(EncodingFlags.ForceReencode & encodingOptions.EncodingFlags) != 0 && 0 >= this.segmentNumber)
            {
                fragments = this.EncodeValue(this.Value, encodingOptions);
            }
            bool flag = false;

            if (this.IsQuotingReqired() || fragments.Length == 0)
            {
                flag = true;
            }
            else
            {
                for (int i = 0; i < fragments.Count; i++)
                {
                    MimeString str  = fragments[i];
                    int        num2 = 0;
                    int        num3 = ValueParser.ParseToken(str, out num2, encodingOptions.AllowUTF8);
                    if (268435456U != str.Mask && str.Length != num3)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            MimeNode mimeNode = null;

            if (this.segmentNumber == 0)
            {
                mimeNode = base.FirstChild;
                while (mimeNode != null && !(mimeNode is MimeParameter))
                {
                    mimeNode = mimeNode.NextSibling;
                }
            }
            MimeString mimeString = ((this.segmentNumber == 0 && mimeNode != null) || 0 < this.segmentNumber) ? new MimeString(this.segmentNumber.ToString()) : default(MimeString);

            if (1 < currentLineLength.InChars)
            {
                int    num4 = 1 + this.paramName.Length + 1;
                byte[] sz   = fragments.GetSz();
                int    num5 = ByteString.BytesToCharCount(sz, encodingOptions.AllowUTF8);
                if (mimeString.Length != 0)
                {
                    num4 += 1 + mimeString.Length;
                }
                if (this.valueEncoded)
                {
                    num4++;
                }
                int num6 = num5;
                if (flag)
                {
                    num6 += 2;
                }
                if (base.NextSibling != null)
                {
                    if (num5 == 0)
                    {
                        num4++;
                    }
                    else
                    {
                        num6++;
                    }
                }
                num6 += num4;
                if (currentLineLength.InChars + num6 > 78)
                {
                    num += Header.WriteLineEnd(stream, ref currentLineLength);
                    stream.Write(Header.LineStartWhitespace, 0, Header.LineStartWhitespace.Length);
                    num += (long)Header.LineStartWhitespace.Length;
                    currentLineLength.IncrementBy(Header.LineStartWhitespace.Length);
                }
                else
                {
                    stream.Write(MimeString.Space, 0, MimeString.Space.Length);
                    num += (long)MimeString.Space.Length;
                    currentLineLength.IncrementBy(MimeString.Space.Length);
                }
            }
            int num7 = ByteString.StringToBytesCount(this.paramName, false);

            if (scratchBuffer == null || scratchBuffer.Length < num7)
            {
                scratchBuffer = new byte[Math.Max(998, num7)];
            }
            int num8 = ByteString.StringToBytes(this.paramName, scratchBuffer, 0, false);

            stream.Write(scratchBuffer, 0, num8);
            num += (long)num8;
            currentLineLength.IncrementBy(this.paramName.Length, num8);
            if (mimeString.Length != 0)
            {
                stream.Write(MimeString.Asterisk, 0, MimeString.Asterisk.Length);
                num += (long)MimeString.Asterisk.Length;
                currentLineLength.IncrementBy(MimeString.Asterisk.Length);
                mimeString.WriteTo(stream);
                num += (long)mimeString.Length;
                currentLineLength.IncrementBy(mimeString.Length);
            }
            if (this.valueEncoded)
            {
                stream.Write(MimeString.Asterisk, 0, MimeString.Asterisk.Length);
                num += (long)MimeString.Asterisk.Length;
                currentLineLength.IncrementBy(MimeString.Asterisk.Length);
            }
            stream.Write(MimeString.EqualTo, 0, MimeString.EqualTo.Length);
            num += (long)MimeString.EqualTo.Length;
            currentLineLength.IncrementBy(MimeString.EqualTo.Length);
            int num9 = 0;

            if (base.NextSibling != null)
            {
                num9++;
            }
            num += Header.QuoteAndFold(stream, fragments, 4026531839U, flag, false, encodingOptions.AllowUTF8, num9, ref currentLineLength, ref scratchBuffer);
            int num10 = 0;

            while (mimeNode != null)
            {
                MimeParameter mimeParameter = mimeNode as MimeParameter;
                if (mimeParameter != null)
                {
                    num10++;
                    mimeParameter.segmentNumber = num10;
                    stream.Write(MimeString.Semicolon, 0, MimeString.Semicolon.Length);
                    num += (long)MimeString.Semicolon.Length;
                    currentLineLength.IncrementBy(MimeString.Semicolon.Length);
                    num += Header.WriteLineEnd(stream, ref currentLineLength);
                    stream.Write(Header.LineStartWhitespace, 0, Header.LineStartWhitespace.Length);
                    num += (long)Header.LineStartWhitespace.Length;
                    currentLineLength.IncrementBy(Header.LineStartWhitespace.Length);
                    num += mimeNode.WriteTo(stream, encodingOptions, null, ref currentLineLength, ref scratchBuffer);
                }
                mimeNode = mimeNode.NextSibling;
            }
            return(num);
        }
예제 #4
0
        private void Parse()
        {
            this.Reset();
            this.parsed = true;
            DecodingOptions headerDecodingOptions = base.GetHeaderDecodingOptions();
            ValueParser     valueParser           = new ValueParser(base.Lines, headerDecodingOptions.AllowUTF8);
            MimeStringList  mimeStringList        = default(MimeStringList);
            MimeStringList  mimeStringList2       = default(MimeStringList);
            MimeString      mimeString            = default(MimeString);
            MimeString      mimeString2           = MimeString.Empty;

            ReceivedHeader.ParseState parseState = ReceivedHeader.ParseState.None;
            for (;;)
            {
                valueParser.ParseWhitespace(true, ref mimeStringList);
                byte b = valueParser.ParseGet();
                if (b == 0)
                {
                    break;
                }
                if (59 == b)
                {
                    parseState = ReceivedHeader.ParseState.Date;
                }
                else if (40 == b && parseState == ReceivedHeader.ParseState.DomainValue)
                {
                    parseState = ReceivedHeader.ParseState.DomainAddress;
                }
                else
                {
                    valueParser.ParseUnget();
                    mimeString = valueParser.ParseToken();
                    if (mimeString.Length == 0)
                    {
                        valueParser.ParseGet();
                        mimeStringList2.TakeOverAppend(ref mimeStringList);
                        valueParser.ParseAppendLastByte(ref mimeStringList2);
                        continue;
                    }
                    ReceivedHeader.ParseState parseState2 = this.StateFromToken(mimeString);
                    if (ReceivedHeader.ParseState.None != parseState2)
                    {
                        parseState = parseState2;
                    }
                }
                switch (parseState)
                {
                case ReceivedHeader.ParseState.Domain:
                case ReceivedHeader.ParseState.OptInfo:
                    if (mimeString2.Length != 0)
                    {
                        this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
                    }
                    else
                    {
                        mimeStringList2.Reset();
                    }
                    mimeString2 = mimeString;
                    valueParser.ParseWhitespace(false, ref mimeStringList);
                    mimeStringList.Reset();
                    parseState++;
                    break;

                case ReceivedHeader.ParseState.DomainValue:
                    mimeStringList2.TakeOverAppend(ref mimeStringList);
                    mimeStringList2.AppendFragment(mimeString);
                    break;

                case ReceivedHeader.ParseState.DomainAddress:
                {
                    bool flag = mimeString2.CompareEqI(ReceivedHeader.ParamFrom);
                    this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
                    mimeStringList.Reset();
                    valueParser.ParseUnget();
                    valueParser.ParseComment(true, false, ref mimeStringList2, true);
                    byte[] sz   = mimeStringList2.GetSz();
                    string text = (sz == null) ? null : ByteString.BytesToString(sz, headerDecodingOptions.AllowUTF8);
                    if (flag)
                    {
                        this.fromTcpInfoValue = text;
                    }
                    else
                    {
                        this.byTcpInfoValue = text;
                    }
                    mimeStringList2.Reset();
                    parseState = ReceivedHeader.ParseState.None;
                    break;
                }

                case ReceivedHeader.ParseState.OptInfoValue:
                    mimeStringList2.TakeOverAppend(ref mimeStringList);
                    mimeStringList2.AppendFragment(mimeString);
                    break;

                case ReceivedHeader.ParseState.Date:
                {
                    this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
                    mimeStringList.Reset();
                    valueParser.ParseWhitespace(false, ref mimeStringList);
                    valueParser.ParseToEnd(ref mimeStringList2);
                    byte[] sz2 = mimeStringList2.GetSz();
                    this.dateValue = ((sz2 == null) ? null : ByteString.BytesToString(sz2, false));
                    break;
                }

                case ReceivedHeader.ParseState.None:
                    mimeStringList2.Reset();
                    break;
                }
            }
            this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
        }
예제 #5
0
        private static void ParseValue(MimeStringList list, out DateTime utcDateTime, out TimeSpan timeZoneOffset)
        {
            MimeStringList mimeStringList = default(MimeStringList);
            ValueParser    valueParser    = new ValueParser(list, false);

            DateHeader.ParseStage parseStage = DateHeader.ParseStage.DayOfWeek;
            int[] array = new int[8];
            byte  b     = 32;

            while (parseStage != DateHeader.ParseStage.Count)
            {
                valueParser.ParseCFWS(false, ref mimeStringList, true);
                byte b2 = valueParser.ParseGet();
                if (b2 == 0)
                {
                    break;
                }
                if (!MimeScan.IsToken(b2) || b2 == 45 || b2 == 43)
                {
                    b = b2;
                    valueParser.ParseCFWS(false, ref mimeStringList, true);
                }
                else
                {
                    if (MimeScan.IsDigit(b2))
                    {
                        if (parseStage == DateHeader.ParseStage.DayOfWeek)
                        {
                            parseStage = DateHeader.ParseStage.DayOfMonth;
                        }
                        if (parseStage == DateHeader.ParseStage.Second && b != 58)
                        {
                            parseStage = DateHeader.ParseStage.Zone;
                        }
                        int num = 0;
                        do
                        {
                            num++;
                            array[(int)parseStage] *= 10;
                            array[(int)parseStage] += (int)(b2 - 48);
                            b2 = valueParser.ParseGet();
                        }while (b2 != 0 && MimeScan.IsDigit(b2));
                        if (b2 != 0)
                        {
                            valueParser.ParseUnget();
                        }
                        if (parseStage == DateHeader.ParseStage.Year && num <= 2)
                        {
                            array[(int)parseStage] += ((array[(int)parseStage] < 30) ? 2000 : 1900);
                        }
                        if (parseStage == DateHeader.ParseStage.Zone && num <= 2)
                        {
                            array[(int)parseStage] *= 100;
                        }
                        if (parseStage == DateHeader.ParseStage.Zone && b == 45)
                        {
                            array[(int)parseStage] = -array[(int)parseStage];
                        }
                        parseStage++;
                    }
                    else if (MimeScan.IsAlpha(b2))
                    {
                        valueParser.ParseUnget();
                        MimeString mimeString = valueParser.ParseToken(MimeScan.Token.Alpha);
                        if (parseStage == DateHeader.ParseStage.DayOfWeek)
                        {
                            parseStage = DateHeader.ParseStage.DayOfMonth;
                        }
                        else if (parseStage == DateHeader.ParseStage.Month)
                        {
                            array[(int)parseStage] = DateHeader.MapMonthToInt(mimeString.Data, mimeString.Offset, mimeString.Length);
                            parseStage             = DateHeader.ParseStage.Year;
                        }
                        else if (parseStage >= DateHeader.ParseStage.Second)
                        {
                            if (mimeString.Length == 2 && 65 == DateHeader.MakeUpper(mimeString[0]) && 77 == DateHeader.MakeUpper(mimeString[1]))
                            {
                                if (array[4] == 12)
                                {
                                    array[4] = 0;
                                }
                                parseStage = DateHeader.ParseStage.Zone;
                            }
                            else if (mimeString.Length == 2 && 80 == DateHeader.MakeUpper(mimeString[0]) && 77 == DateHeader.MakeUpper(mimeString[1]))
                            {
                                if (array[4] < 12)
                                {
                                    array[4] += 12;
                                }
                                parseStage = DateHeader.ParseStage.Zone;
                            }
                            else
                            {
                                array[7]   = (int)DateHeader.MapZoneToInt(mimeString.Data, mimeString.Offset, mimeString.Length);
                                parseStage = DateHeader.ParseStage.Count;
                            }
                        }
                    }
                    b = 32;
                }
            }
            if (parseStage > DateHeader.ParseStage.Year)
            {
                int num2 = array[3];
                int num3 = array[2];
                int num4 = array[1];
                int num5 = array[4];
                int num6 = array[5];
                int num7 = array[6];
                if (num5 == 23 && num6 == 59 && num7 == 60)
                {
                    num7 = 59;
                }
                if (num2 >= 1900 && num2 <= 9999 && num3 >= 1 && num3 <= 12 && num4 >= 1 && num4 <= DateTime.DaysInMonth(num2, num3) && num5 >= 0 && num5 < 24 && num6 >= 0 && num6 < 60 && num7 >= 0 && num7 < 60)
                {
                    try
                    {
                        utcDateTime = new DateTime(num2, num3, num4, num5, num6, num7, 0, DateTimeKind.Utc);
                        goto IL_319;
                    }
                    catch (ArgumentException)
                    {
                        utcDateTime = DateHeader.minDateTime;
                        goto IL_319;
                    }
                }
                utcDateTime = DateHeader.minDateTime;
            }
            else
            {
                utcDateTime = DateHeader.minDateTime;
            }
IL_319:
            if (parseStage != DateHeader.ParseStage.Count || !(utcDateTime > DateHeader.minDateTime))
            {
                timeZoneOffset = TimeSpan.Zero;
                return;
            }
            int num8 = array[7] / 100;
            int num9 = array[7] % 100;

            if (num8 > 99 || num8 < -99)
            {
                num8 = 0;
                num9 = 0;
            }
            if (num9 > 59 || num9 < -59)
            {
                num9 = 0;
            }
            timeZoneOffset = new TimeSpan(num8, num9, 0);
            if (utcDateTime.Ticks >= timeZoneOffset.Ticks && DateTime.MaxValue.Ticks >= utcDateTime.Ticks - timeZoneOffset.Ticks)
            {
                utcDateTime -= timeZoneOffset;
                return;
            }
            utcDateTime    = DateHeader.minDateTime;
            timeZoneOffset = TimeSpan.Zero;
        }
예제 #6
0
 public sealed override bool IsValueValid(string value)
 {
     return(value != null && ValueParser.ParseToken(value, 0, false) == value.Length);
 }
예제 #7
0
        internal void ParseParameters(ref ValueParser parser, DecodingOptions decodingOptions, int countLimit, int bytesLimit)
        {
            MimeStringList mimeStringList  = default(MimeStringList);
            MimeStringList mimeStringList2 = default(MimeStringList);
            bool           flag            = false;
            int            num             = 0;
            bool           flag2           = DecodingFlags.None != (DecodingFlags.Rfc2231 & decodingOptions.DecodingFlags);

            for (;;)
            {
                parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                byte b = parser.ParseGet();
                if (b != 59)
                {
                    if (b == 0)
                    {
                        break;
                    }
                    parser.ParseUnget();
                    parser.ParseSkipToNextDelimiterByte(59);
                }
                else
                {
                    parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                    MimeString mimeString = parser.ParseToken();
                    if (mimeString.Length != 0 && mimeString.Length < 128)
                    {
                        parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                        b = parser.ParseGet();
                        if (b != 61)
                        {
                            if (b == 0)
                            {
                                return;
                            }
                            parser.ParseUnget();
                        }
                        else
                        {
                            parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                            parser.ParseParameterValue(ref mimeStringList2, ref flag, this.handleISO2022);
                            if (2147483647 != countLimit || 2147483647 != bytesLimit)
                            {
                                if (++num > countLimit)
                                {
                                    goto Block_8;
                                }
                                if (mimeStringList2.Length > bytesLimit)
                                {
                                    goto Block_9;
                                }
                            }
                            else
                            {
                                bool valueEncoded = false;
                                int  num2         = -1;
                                if (flag2)
                                {
                                    int num3 = ByteString.IndexOf(mimeString.Data, 42, mimeString.Offset, mimeString.Length);
                                    if (num3 > 0)
                                    {
                                        int num4 = mimeString.Offset + mimeString.Length;
                                        int num5 = num3 + 1;
                                        num2 = 0;
                                        while (num5 != num4 && mimeString.Data[num5] >= 48 && mimeString.Data[num5] <= 57)
                                        {
                                            num2 = num2 * 10 + (int)(mimeString.Data[num5] - 48);
                                            if (10000 < num2)
                                            {
                                                num2 = -1;
                                                break;
                                            }
                                            num5++;
                                        }
                                        if (-1 != num2)
                                        {
                                            bool flag3 = 42 == mimeString.Data[num4 - 1];
                                            if (num5 < num4 - 1 || (num5 < num4 && !flag3))
                                            {
                                                num2 = -1;
                                            }
                                            else
                                            {
                                                valueEncoded = flag3;
                                                mimeString.TrimRight(num4 - num3);
                                            }
                                        }
                                    }
                                }
                                string        text          = Header.NormalizeString(mimeString.Data, mimeString.Offset, mimeString.Length, false);
                                MimeParameter mimeParameter = new MimeParameter(text);
                                mimeParameter.AppendValue(ref mimeStringList2);
                                mimeParameter.SegmentNumber = num2;
                                mimeParameter.ValueEncoded  = valueEncoded;
                                MimeNode mimeNode;
                                MimeNode nextSibling;
                                for (mimeNode = base.FirstChild; mimeNode != null; mimeNode = nextSibling)
                                {
                                    nextSibling = mimeNode.NextSibling;
                                    MimeParameter mimeParameter2 = mimeNode as MimeParameter;
                                    if (mimeParameter2 != null && mimeParameter2.Name == text)
                                    {
                                        break;
                                    }
                                }
                                if (0 >= num2)
                                {
                                    if (mimeNode != null)
                                    {
                                        mimeParameter.AllowAppend = true;
                                        for (MimeNode mimeNode2 = mimeNode.FirstChild; mimeNode2 != null; mimeNode2 = nextSibling)
                                        {
                                            nextSibling = mimeNode2.NextSibling;
                                            if (mimeNode2 is MimeParameter)
                                            {
                                                mimeNode.RemoveChild(mimeNode2);
                                                mimeParameter.InternalAppendChild(mimeNode2);
                                            }
                                        }
                                        mimeParameter.AllowAppend = false;
                                        base.InternalRemoveChild(mimeNode);
                                    }
                                    base.InternalAppendChild(mimeParameter);
                                }
                                else
                                {
                                    if (mimeNode == null)
                                    {
                                        MimeParameter mimeParameter3 = new MimeParameter(text);
                                        mimeParameter3.SegmentNumber = 0;
                                        base.InternalAppendChild(mimeParameter3);
                                        mimeNode = mimeParameter3;
                                    }
                                    MimeNode mimeNode3;
                                    MimeNode previousSibling;
                                    for (mimeNode3 = mimeNode.LastChild; mimeNode3 != null; mimeNode3 = previousSibling)
                                    {
                                        previousSibling = mimeNode3.PreviousSibling;
                                        MimeParameter mimeParameter4 = mimeNode3 as MimeParameter;
                                        if (mimeParameter4 != null && mimeParameter4.SegmentNumber <= num2)
                                        {
                                            break;
                                        }
                                    }
                                    MimeParameter mimeParameter5 = (MimeParameter)mimeNode;
                                    mimeParameter5.AllowAppend = true;
                                    mimeParameter5.InternalInsertAfter(mimeParameter, mimeNode3);
                                    mimeParameter5.AllowAppend = false;
                                }
                            }
                        }
                    }
                }
                if (b == 0)
                {
                    return;
                }
            }
            return;

Block_8:
            throw new MimeException(Strings.TooManyParameters(num, countLimit));
Block_9:
            throw new MimeException(Strings.TooManyTextValueBytes(mimeStringList2.Length, bytesLimit));
        }
예제 #8
0
 internal abstract void ParseValue(ValueParser parser, bool storeValue);