Example #1
0
        private void ParseValue()
        {
            int offset = 0;

            try
            {
                this.dispositionType = MailBnfHelper.ReadToken(this.disposition, ref offset, null);
                if (string.IsNullOrEmpty(this.dispositionType))
                {
                    throw new FormatException(SR.GetString("MailHeaderFieldMalformedHeader"));
                }
                if (this.parameters == null)
                {
                    this.parameters = new TrackingValidationObjectDictionary(validators);
                }
                else
                {
                    this.parameters.Clear();
                }
                while (MailBnfHelper.SkipCFWS(this.disposition, ref offset))
                {
                    string str2;
                    if (this.disposition[offset++] != ';')
                    {
                        throw new FormatException(SR.GetString("MailHeaderFieldInvalidCharacter", new object[] { this.disposition[offset - 1] }));
                    }
                    if (!MailBnfHelper.SkipCFWS(this.disposition, ref offset))
                    {
                        goto Label_018C;
                    }
                    string str = MailBnfHelper.ReadParameterAttribute(this.disposition, ref offset, null);
                    if (this.disposition[offset++] != '=')
                    {
                        throw new FormatException(SR.GetString("MailHeaderFieldMalformedHeader"));
                    }
                    if (!MailBnfHelper.SkipCFWS(this.disposition, ref offset))
                    {
                        throw new FormatException(SR.GetString("ContentDispositionInvalid"));
                    }
                    if (this.disposition[offset] == '"')
                    {
                        str2 = MailBnfHelper.ReadQuotedString(this.disposition, ref offset, null);
                    }
                    else
                    {
                        str2 = MailBnfHelper.ReadToken(this.disposition, ref offset, null);
                    }
                    if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(str2))
                    {
                        throw new FormatException(SR.GetString("ContentDispositionInvalid"));
                    }
                    this.Parameters.Add(str, str2);
                }
            }
            catch (FormatException exception)
            {
                throw new FormatException(SR.GetString("ContentDispositionInvalid"), exception);
            }
Label_018C:
            this.parameters.IsChanged = false;
        }
Example #2
0
        private void ParseValue()
        {
            try
            {
                int offset = 0;

                _mediaType = MailBnfHelper.ReadToken(_type, ref offset, null);
                if (_mediaType == null || _mediaType.Length == 0 || offset >= _type.Length || _type[offset++] != '/')
                {
                    throw new FormatException(SR.ContentTypeInvalid);
                }

                _subType = MailBnfHelper.ReadToken(_type, ref offset, null);
                if (_subType == null || _subType.Length == 0)
                {
                    throw new FormatException(SR.ContentTypeInvalid);
                }

                while (MailBnfHelper.SkipCFWS(_type, ref offset))
                {
                    if (_type[offset++] != ';')
                    {
                        throw new FormatException(SR.ContentTypeInvalid);
                    }

                    if (!MailBnfHelper.SkipCFWS(_type, ref offset))
                    {
                        break;
                    }

                    string?paramAttribute = MailBnfHelper.ReadParameterAttribute(_type, ref offset, null);

                    if (paramAttribute == null || paramAttribute.Length == 0)
                    {
                        throw new FormatException(SR.ContentTypeInvalid);
                    }

                    string?paramValue;
                    if (offset >= _type.Length || _type[offset++] != '=')
                    {
                        throw new FormatException(SR.ContentTypeInvalid);
                    }

                    if (!MailBnfHelper.SkipCFWS(_type, ref offset))
                    {
                        throw new FormatException(SR.ContentTypeInvalid);
                    }

                    paramValue = _type[offset] == '"' ?
                                 MailBnfHelper.ReadQuotedString(_type, ref offset, null) :
                                 MailBnfHelper.ReadToken(_type, ref offset, null);

                    if (paramValue == null)
                    {
                        throw new FormatException(SR.ContentTypeInvalid);
                    }

                    _parameters.Add(paramAttribute, paramValue);
                }

                _parameters.IsChanged = false;
            }
            catch (FormatException fe) when(fe.Message != SR.ContentTypeInvalid)
            {
                throw new FormatException(SR.ContentTypeInvalid);
            }
        }
        private void ParseValue()
        {
            int       num = 0;
            Exception ex  = null;

            _parameters = new Dictionary <string, string>();
            try
            {
                _mediaType = MailBnfHelper.ReadToken(_type, ref num, null);
                if (string.IsNullOrEmpty(_mediaType) || num >= _type.Length || _type[num++] != '/')
                {
                    ex = new FormatException();
                }
                if (ex == null)
                {
                    _subType = MailBnfHelper.ReadToken(_type, ref num, null);
                    if (string.IsNullOrEmpty(_subType))
                    {
                        ex = new FormatException();
                    }
                }
                if (ex == null)
                {
                    while (MailBnfHelper.SkipCfWs(_type, ref num))
                    {
                        if (_type[num++] != ';')
                        {
                            ex = new FormatException();
                            break;
                        }
                        if (!MailBnfHelper.SkipCfWs(_type, ref num))
                        {
                            break;
                        }
                        string text = MailBnfHelper.ReadParameterAttribute(_type, ref num, null);
                        if (string.IsNullOrEmpty(text))
                        {
                            ex = new FormatException();
                            break;
                        }
                        if (num >= _type.Length || _type[num++] != '=')
                        {
                            ex = new FormatException();
                            break;
                        }
                        if (!MailBnfHelper.SkipCfWs(_type, ref num))
                        {
                            ex = new FormatException();
                            break;
                        }
                        string text2 = _type[num] == '"' ? MailBnfHelper.ReadQuotedString(_type, ref num, null) : MailBnfHelper.ReadToken(_type, ref num, null);
                        if (text2 == null)
                        {
                            ex = new FormatException();
                            break;
                        }
                        _parameters.Add(text, text2);
                    }
                }
            }
            catch (FormatException)
            {
                throw new FormatException();
            }
            if (ex != null)
            {
                throw new FormatException();
            }
        }
Example #4
0
        private void ParseValue()
        {
            int offset = 0;

            try
            {
                // the disposition MUST be the first parameter in the string
                _dispositionType = MailBnfHelper.ReadToken(_disposition, ref offset, null);

                // disposition MUST not be empty
                if (string.IsNullOrEmpty(_dispositionType))
                {
                    throw new FormatException(SR.MailHeaderFieldMalformedHeader);
                }

                // now we know that there are parameters so we must initialize or clear
                // and parse
                if (_parameters == null)
                {
                    _parameters = new TrackingValidationObjectDictionary(s_validators);
                }
                else
                {
                    _parameters.Clear();
                }

                while (MailBnfHelper.SkipCFWS(_disposition, ref offset))
                {
                    // ensure that the separator charactor is present
                    if (_disposition[offset++] != ';')
                    {
                        throw new FormatException(SR.Format(SR.MailHeaderFieldInvalidCharacter, _disposition[offset - 1]));
                    }

                    // skip whitespace and see if there's anything left to parse or if we're done
                    if (!MailBnfHelper.SkipCFWS(_disposition, ref offset))
                    {
                        break;
                    }

                    string paramAttribute = MailBnfHelper.ReadParameterAttribute(_disposition, ref offset, null);
                    string paramValue;

                    // verify the next character after the parameter is correct
                    if (_disposition[offset++] != '=')
                    {
                        throw new FormatException(SR.MailHeaderFieldMalformedHeader);
                    }

                    if (!MailBnfHelper.SkipCFWS(_disposition, ref offset))
                    {
                        // parameter was at end of string and has no value
                        // this is not valid
                        throw new FormatException(SR.ContentDispositionInvalid);
                    }

                    paramValue = _disposition[offset] == '"' ?
                                 MailBnfHelper.ReadQuotedString(_disposition, ref offset, null) :
                                 MailBnfHelper.ReadToken(_disposition, ref offset, null);

                    // paramValue could potentially still be empty if it was a valid quoted string that
                    // contained no inner value.  this is invalid
                    if (string.IsNullOrEmpty(paramAttribute) || string.IsNullOrEmpty(paramValue))
                    {
                        throw new FormatException(SR.ContentDispositionInvalid);
                    }

                    // if validation is needed, the parameters dictionary will have a validator registered
                    // for the parameter that is being set so no additional formatting checks are needed here
                    Parameters.Add(paramAttribute, paramValue);
                }
            }
            catch (FormatException exception)
            {
                // it's possible that something in MailBNFHelper could throw so ensure that we catch it and wrap it
                // so that the exception has the correct text
                throw new FormatException(SR.ContentDispositionInvalid, exception);
            }

            _parameters.IsChanged = false;
        }
Example #5
0
        // Helper methods.

        void ParseValue()
        {
            int       offset    = 0;
            Exception exception = null;

            parameters = new TrackingStringDictionary();

            try{
                mediaType = MailBnfHelper.ReadToken(type, ref offset, null);
                if (mediaType == null || mediaType.Length == 0 || offset >= type.Length || type[offset++] != '/')
                {
                    exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                }

                if (exception == null)
                {
                    subType = MailBnfHelper.ReadToken(type, ref offset, null);
                    if (subType == null || subType.Length == 0)
                    {
                        exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                    }
                }

                if (exception == null)
                {
                    while (MailBnfHelper.SkipCFWS(type, ref offset))
                    {
                        if (type[offset++] != ';')
                        {
                            exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                            break;
                        }

                        if (!MailBnfHelper.SkipCFWS(type, ref offset))
                        {
                            break;
                        }

                        string paramAttribute = MailBnfHelper.ReadParameterAttribute(type, ref offset, null);

                        if (paramAttribute == null || paramAttribute.Length == 0)
                        {
                            exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                            break;
                        }

                        string paramValue;
                        if (offset >= type.Length || type[offset++] != '=')
                        {
                            exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                            break;
                        }

                        if (!MailBnfHelper.SkipCFWS(type, ref offset))
                        {
                            exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                            break;
                        }

                        if (type[offset] == '"')
                        {
                            paramValue = MailBnfHelper.ReadQuotedString(type, ref offset, null);
                        }
                        else
                        {
                            paramValue = MailBnfHelper.ReadToken(type, ref offset, null);
                        }

                        if (paramValue == null)
                        {
                            exception = new FormatException(SR.GetString(SR.ContentTypeInvalid));
                            break;
                        }

                        parameters.Add(paramAttribute, paramValue);
                    }
                }
                parameters.IsChanged = false;
            }
            catch (FormatException) {
                throw new FormatException(SR.GetString(SR.ContentTypeInvalid));
            }

            if (exception != null)
            {
                throw new FormatException(SR.GetString(SR.ContentTypeInvalid));
            }
        }
        private void ParseValue()
        {
            int       offset    = 0;
            Exception exception = null;

            this.parameters = new TrackingStringDictionary();
            try
            {
                this.mediaType = MailBnfHelper.ReadToken(this.type, ref offset, null);
                if (((this.mediaType == null) || (this.mediaType.Length == 0)) || ((offset >= this.type.Length) || (this.type[offset++] != '/')))
                {
                    exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                }
                if (exception == null)
                {
                    this.subType = MailBnfHelper.ReadToken(this.type, ref offset, null);
                    if ((this.subType == null) || (this.subType.Length == 0))
                    {
                        exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                    }
                }
                if (exception == null)
                {
                    while (MailBnfHelper.SkipCFWS(this.type, ref offset))
                    {
                        string str2;
                        if (this.type[offset++] != ';')
                        {
                            exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                            break;
                        }
                        if (!MailBnfHelper.SkipCFWS(this.type, ref offset))
                        {
                            break;
                        }
                        string key = MailBnfHelper.ReadParameterAttribute(this.type, ref offset, null);
                        if ((key == null) || (key.Length == 0))
                        {
                            exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                            break;
                        }
                        if ((offset >= this.type.Length) || (this.type[offset++] != '='))
                        {
                            exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                            break;
                        }
                        if (!MailBnfHelper.SkipCFWS(this.type, ref offset))
                        {
                            exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                            break;
                        }
                        if (this.type[offset] == '"')
                        {
                            str2 = MailBnfHelper.ReadQuotedString(this.type, ref offset, null);
                        }
                        else
                        {
                            str2 = MailBnfHelper.ReadToken(this.type, ref offset, null);
                        }
                        if (str2 == null)
                        {
                            exception = new FormatException(SR.GetString("ContentTypeInvalid"));
                            break;
                        }
                        this.parameters.Add(key, str2);
                    }
                }
                this.parameters.IsChanged = false;
            }
            catch (FormatException)
            {
                throw new FormatException(SR.GetString("ContentTypeInvalid"));
            }
            if (exception != null)
            {
                throw new FormatException(SR.GetString("ContentTypeInvalid"));
            }
        }