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"));
            }
        }
示例#2
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));
            }
        }
示例#3
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));
            }
        }