Ejemplo n.º 1
0
        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.GetString(SR.MailHeaderFieldMalformedHeader));
                }

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

                while (MailBnfHelper.SkipCFWS(disposition, ref offset))
                {
                    // ensure that the separator charactor is present
                    if (disposition[offset++] != ';')
                        throw new FormatException(SR.GetString(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.GetString(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.GetString(SR.ContentDispositionInvalid));
                    }

                    if (disposition[offset] == '"')
                    {
                        paramValue = MailBnfHelper.ReadQuotedString(disposition, ref offset, null);
                    }
                    else
                    {
                        paramValue = 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.GetString(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.GetString(SR.ContentDispositionInvalid), exception);
            }
            parameters.IsChanged = false;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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(Strings.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(string.Format(Strings.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(Strings.MailHeaderFieldMalformedHeader);
                    }

                    if (!MailBnfHelper.SkipCFWS(_disposition, ref offset))
                    {
                        // parameter was at end of string and has no value
                        // this is not valid
                        throw new FormatException(Strings.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(Strings.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(Strings.ContentDispositionInvalid, exception);
            }

            _parameters.IsChanged = false;
        }