Пример #1
0
        /// <summary>
        /// Parses specified header field.
        /// </summary>
        /// <param name="field">Header field string (Name: value).</param>
        /// <returns>Returns parsed header field.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>field</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when header field parsing errors.</exception>
        public MIME_h Parse(string field)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            MIME_h headerField = null;

            string[] name_value = field.Split(new char[] { ':' }, 2);
            string   name       = name_value[0].Trim();

            if (name == string.Empty)
            {
                throw new ParseException("Invalid header field value '" + field + "'.");
            }
            else
            {
                try{
                    if (m_pHeadrFields.ContainsKey(name))
                    {
                        headerField = (MIME_h)m_pHeadrFields[name].GetMethod("Parse").Invoke(null, new object[] { field });
                    }
                    else
                    {
                        headerField = (MIME_h)m_pDefaultHeaderField.GetMethod("Parse").Invoke(null, new object[] { field });
                    }
                }
                catch (Exception x) {
                    headerField = new MIME_h_Unparsed(field, x.InnerException);
                }
            }

            return(headerField);
        }
Пример #2
0
        /// <summary>
        /// Parses specified header field.
        /// </summary>
        /// <param name="field">Header field string (Name: value).</param>
        /// <returns>Returns parsed header field.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>field</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when header field parsing errors.</exception>
        public MIME_h Parse(string field)
        {
            if(field == null){
                throw new ArgumentNullException("field");
            }

            // <CRLF> is misssing from end, add it.
            if(!field.EndsWith("\r\n")){
                field += "\r\n";
            }

            MIME_h   headerField = null;
            string[] name_value  = field.Split(new char[]{':'},2);
            string   name        = name_value[0].Trim();
            if(name == string.Empty){
                throw new ParseException("Invalid header field value '" + field + "'.");
            }
            else{
                try{
                    if(m_pHeadrFields.ContainsKey(name)){ 
                        headerField = (MIME_h)m_pHeadrFields[name].GetMethod("Parse").Invoke(null,new object[]{field});
                    }
                    else{
                        headerField = (MIME_h)m_pDefaultHeaderField.GetMethod("Parse").Invoke(null,new object[]{field});
                    }
                }
                catch(Exception x){
                    headerField = new MIME_h_Unparsed(field,x.InnerException);
                }
            }

            return headerField;
        }
Пример #3
0
        /// <summary>
        /// Parses specified header field.
        /// </summary>
        /// <param name="field">Header field string (Name: value).</param>
        /// <returns>Returns parsed header field.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>field</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when header field parsing errors.</exception>
        public MIME_h Parse(string field)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }

            // <CRLF> is misssing from end, add it.
            if (!field.EndsWith("\r\n"))
            {
                field += "\r\n";
            }

            MIME_h headerField = null;

            string[] name_value = field.Split(new char[] { ':' }, 2);
            string   name       = name_value[0].Trim();

            if (name == string.Empty)
            {
                throw new ParseException("Invalid header field value '" + field + "'.");
            }
            else
            {
                try
                {
                    if (m_pHeadrFields.ContainsKey(name))
                    {
                        headerField = (MIME_h)System.Reflection.IntrospectionExtensions.GetTypeInfo(m_pHeadrFields[name])
                                      .GetMethod("Parse").Invoke(null, new object[] { field });
                    }
                    else
                    {
                        headerField = (MIME_h)System.Reflection.IntrospectionExtensions.GetTypeInfo(m_pDefaultHeaderField)
                                      .GetMethod("Parse").Invoke(null, new object[] { field });
                    }
                }
                catch (Exception x)
                {
                    headerField = new MIME_h_Unparsed(field, x.InnerException);
                }
            }

            return(headerField);
        }