Exemplo n.º 1
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));
                }
            }
        }
Exemplo n.º 2
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);
        }
        // Token: 0x06000249 RID: 585 RVA: 0x0000A614 File Offset: 0x00008814
        public AddressParserResult ParseNextMailbox(ref MimeStringList displayName, ref MimeStringList address)
        {
            AddressParserResult result = this.groupInProgress ? AddressParserResult.GroupInProgress : AddressParserResult.Mailbox;

            MimeAddressParser.ParserStage parserStage = MimeAddressParser.ParserStage.BEGIN;
            MimeStringList mimeStringList             = default(MimeStringList);
            MimeStringList mimeStringList2            = default(MimeStringList);
            MimeStringList mimeStringList3            = default(MimeStringList);
            bool           flag           = true;
            bool           flag2          = false;
            bool           ignoreNextByte = false;

            if (!this.parserInit)
            {
                throw new InvalidOperationException(Strings.AddressParserNotInitialized);
            }
            for (;;)
            {
                if (this.valueParser.ParseToDelimiter(ignoreNextByte, !flag && flag2, ref mimeStringList))
                {
                    flag2          = false;
                    ignoreNextByte = false;
                    flag           = false;
                }
                byte b  = this.valueParser.ParseGet();
                byte b2 = b;
                if (b2 <= 34)
                {
                    if (b2 != 0)
                    {
                        switch (b2)
                        {
                        case 9:
                        case 10:
                        case 13:
                            break;

                        case 11:
                        case 12:
                            goto IL_200;

                        default:
                            switch (b2)
                            {
                            case 32:
                                break;

                            case 33:
                                goto IL_200;

                            case 34:
                                this.valueParser.ParseUnget();
                                if (mimeStringList.Length != 0 && !flag)
                                {
                                    this.valueParser.ParseAppendSpace(ref mimeStringList);
                                }
                                else
                                {
                                    flag = false;
                                }
                                this.valueParser.ParseQString(true, ref mimeStringList, true);
                                flag2 = true;
                                continue;

                            default:
                                goto IL_200;
                            }
                            break;
                        }
                        this.valueParser.ParseWhitespace(false, ref mimeStringList3);
                        flag2 = true;
                        continue;
                    }
                    goto IL_213;
                }
                else if (b2 <= 46)
                {
                    if (b2 == 40)
                    {
                        if (mimeStringList2.Length != 0)
                        {
                            mimeStringList2.Reset();
                        }
                        this.valueParser.ParseUnget();
                        if (this.ignoreComments)
                        {
                            this.valueParser.ParseComment(true, false, ref mimeStringList2, true);
                            if (flag2)
                            {
                                mimeStringList.AppendFragment(new MimeString(" "));
                            }
                            mimeStringList.TakeOverAppend(ref mimeStringList2);
                        }
                        else
                        {
                            this.valueParser.ParseComment(true, true, ref mimeStringList2, true);
                        }
                        flag2 = true;
                        continue;
                    }
                    switch (b2)
                    {
                    case 44:
                        goto IL_213;

                    case 46:
                        this.valueParser.ParseAppendLastByte(ref mimeStringList);
                        flag = true;
                        continue;
                    }
                }
                else
                {
                    switch (b2)
                    {
                    case 58:
                    case 59:
                    case 60:
                    case 62:
                    case 64:
                        goto IL_213;

                    case 61:
                    case 63:
                        break;

                    default:
                        switch (b2)
                        {
                        case 91:
                        case 93:
                            goto IL_213;
                        }
                        break;
                    }
                }
IL_200:
                this.valueParser.ParseUnget();
                ignoreNextByte = true;
                continue;
IL_213:
                switch (parserStage)
                {
                case MimeAddressParser.ParserStage.BEGIN:
                {
                    byte b3 = b;
                    if (b3 > 44)
                    {
                        switch (b3)
                        {
                        case 58:
                            if (mimeStringList.GetLength(4026531839U) != 0)
                            {
                                goto Block_26;
                            }
                            continue;

                        case 59:
                            this.groupInProgress = false;
                            result = AddressParserResult.Mailbox;
                            goto IL_28D;

                        case 60:
                            break;

                        case 61:
                        case 63:
                            goto IL_33D;

                        case 62:
                            mimeStringList.Reset();
                            continue;

                        case 64:
                        {
                            int length = mimeStringList.Length;
                            this.valueParser.ParseAppendLastByte(ref mimeStringList);
                            address.TakeOver(ref mimeStringList);
                            parserStage = MimeAddressParser.ParserStage.ADDRSPEC;
                            continue;
                        }

                        default:
                            if (b3 != 91)
                            {
                                goto IL_33D;
                            }
                            if (!this.useSquareBrackets)
                            {
                                this.valueParser.ParseUnget();
                                ignoreNextByte = true;
                                continue;
                            }
                            break;
                        }
                        displayName.TakeOver(ref mimeStringList);
                        parserStage = MimeAddressParser.ParserStage.ANGLEADDR;
                        continue;
                    }
                    if (b3 == 0)
                    {
                        goto IL_330;
                    }
                    if (b3 != 44)
                    {
                        goto IL_33D;
                    }
IL_28D:
                    if (mimeStringList.GetLength(4026531839U) != 0)
                    {
                        goto Block_25;
                    }
                    mimeStringList.Reset();
                    continue;
IL_33D:
                    this.valueParser.ParseUnget();
                    ignoreNextByte = true;
                    continue;
                }

                case MimeAddressParser.ParserStage.ANGLEADDR:
                {
                    byte b4 = b;
                    if (b4 <= 44)
                    {
                        if (b4 == 0)
                        {
                            goto IL_478;
                        }
                        if (b4 == 44)
                        {
                            if (displayName.Length != 0 || mimeStringList.Length != 0)
                            {
                                goto IL_478;
                            }
                            continue;
                        }
                    }
                    else
                    {
                        switch (b4)
                        {
                        case 58:
                            mimeStringList.Reset();
                            continue;

                        case 59:
                        case 61:
                        case 63:
                            goto IL_485;

                        case 60:
                            break;

                        case 62:
                            goto IL_432;

                        case 64:
                            if (mimeStringList.Length == 0)
                            {
                                parserStage = MimeAddressParser.ParserStage.ROUTEDOMAIN;
                                continue;
                            }
                            this.valueParser.ParseAppendLastByte(ref mimeStringList);
                            address.TakeOver(ref mimeStringList);
                            parserStage = MimeAddressParser.ParserStage.ADDRSPEC;
                            continue;

                        default:
                            switch (b4)
                            {
                            case 91:
                                if (!this.useSquareBrackets)
                                {
                                    this.valueParser.ParseUnget();
                                    ignoreNextByte = true;
                                    continue;
                                }
                                break;

                            case 92:
                                goto IL_485;

                            case 93:
                                if (!this.useSquareBrackets)
                                {
                                    this.valueParser.ParseUnget();
                                    ignoreNextByte = true;
                                    continue;
                                }
                                goto IL_432;

                            default:
                                goto IL_485;
                            }
                            break;
                        }
                        if (mimeStringList.Length != 0)
                        {
                            this.valueParser.ParseUnget();
                            ignoreNextByte = true;
                            continue;
                        }
                        continue;
IL_432:
                        address.TakeOver(ref mimeStringList);
                        if (address.Length != 0 || displayName.Length != 0)
                        {
                            parserStage = MimeAddressParser.ParserStage.END;
                            continue;
                        }
                        parserStage = MimeAddressParser.ParserStage.BEGIN;
                        continue;
                    }
IL_485:
                    this.valueParser.ParseUnget();
                    ignoreNextByte = true;
                    continue;
                }

                case MimeAddressParser.ParserStage.ADDRSPEC:
                {
                    byte b5 = b;
                    if (b5 > 44)
                    {
                        switch (b5)
                        {
                        case 59:
                            this.groupInProgress = false;
                            goto IL_58B;

                        case 60:
                            if (displayName.Length == 0)
                            {
                                displayName.TakeOverAppend(ref address);
                                parserStage = MimeAddressParser.ParserStage.ANGLEADDR;
                                continue;
                            }
                            this.valueParser.ParseUnget();
                            ignoreNextByte = true;
                            continue;

                        case 61:
                            goto IL_5B5;

                        case 62:
                            break;

                        default:
                            switch (b5)
                            {
                            case 91:
                                if (mimeStringList.Length == 0)
                                {
                                    this.valueParser.ParseUnget();
                                    this.valueParser.ParseDomainLiteral(true, ref mimeStringList);
                                    address.TakeOverAppend(ref mimeStringList);
                                    parserStage = MimeAddressParser.ParserStage.END;
                                    continue;
                                }
                                this.valueParser.ParseUnget();
                                ignoreNextByte = true;
                                continue;

                            case 92:
                                goto IL_5B5;

                            case 93:
                                if (!this.useSquareBrackets)
                                {
                                    this.valueParser.ParseUnget();
                                    ignoreNextByte = true;
                                    continue;
                                }
                                break;

                            default:
                                goto IL_5B5;
                            }
                            break;
                        }
                        address.TakeOverAppend(ref mimeStringList);
                        parserStage = MimeAddressParser.ParserStage.END;
                        continue;
                    }
                    if (b5 != 0 && b5 != 44)
                    {
                        goto IL_5B5;
                    }
IL_58B:
                    address.TakeOverAppend(ref mimeStringList);
                    if (address.Length == 0 && displayName.Length == 0 && b != 0)
                    {
                        continue;
                    }
                    break;
IL_5B5:
                    this.valueParser.ParseUnget();
                    ignoreNextByte = true;
                    continue;
                }

                case MimeAddressParser.ParserStage.ROUTEDOMAIN:
                {
                    byte b6 = b;
                    if (b6 <= 44)
                    {
                        if (b6 == 0)
                        {
                            break;
                        }
                        if (b6 != 44)
                        {
                            goto IL_665;
                        }
                    }
                    else if (b6 != 58)
                    {
                        if (b6 != 62)
                        {
                            switch (b6)
                            {
                            case 91:
                                mimeStringList.Reset();
                                this.valueParser.ParseUnget();
                                this.valueParser.ParseDomainLiteral(false, ref mimeStringList3);
                                continue;

                            case 92:
                                goto IL_665;

                            case 93:
                                if (!this.useSquareBrackets)
                                {
                                    this.valueParser.ParseUnget();
                                    ignoreNextByte = true;
                                    continue;
                                }
                                break;

                            default:
                                goto IL_665;
                            }
                        }
                        mimeStringList.Reset();
                        parserStage = MimeAddressParser.ParserStage.END;
                        continue;
                    }
                    mimeStringList.Reset();
                    parserStage = MimeAddressParser.ParserStage.ANGLEADDR;
                    continue;
IL_665:
                    this.valueParser.ParseUnget();
                    ignoreNextByte = true;
                    continue;
                }

                case MimeAddressParser.ParserStage.END:
                {
                    mimeStringList.Reset();
                    byte b7 = b;
                    if (b7 != 0 && b7 != 44)
                    {
                        if (b7 != 59)
                        {
                            continue;
                        }
                        this.groupInProgress = false;
                    }
                    if (address.Length == 0 && displayName.Length == 0 && b != 0)
                    {
                        parserStage = MimeAddressParser.ParserStage.BEGIN;
                        continue;
                    }
                    break;
                }
                }
                break;
            }
            goto IL_6B9;
Block_25:
            displayName.TakeOver(ref mimeStringList);
            goto IL_6B9;
Block_26:
            displayName.TakeOver(ref mimeStringList);
            this.groupInProgress = true;
            return(AddressParserResult.GroupStart);

IL_330:
            displayName.TakeOver(ref mimeStringList);
            goto IL_6B9;
IL_478:
            address.TakeOver(ref mimeStringList);
IL_6B9:
            if (displayName.Length == 0 && mimeStringList2.Length != 0 && address.Length != 0)
            {
                displayName.TakeOver(ref mimeStringList2);
            }
            if (address.Length == 0 && displayName.Length == 0)
            {
                result = AddressParserResult.End;
            }
            return(result);
        }