示例#1
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));
            }
        }
示例#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);
            }
        }
示例#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));
            }
        }