/// <summary> /// Parses header field from the specified value. /// </summary> /// <param name="value">Header field value. Header field name must be included. For example: 'Content-Type: text/plain'.</param> /// <returns>Returns parsed header field.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when header field parsing errors.</exception> public static MIME_h_ContentType Parse(string value) { if (value == null) { throw new ArgumentNullException("value"); } // We should not have encoded words here, but some email clients do this, so encoded them if any. string valueDecoded = MIME_Encoding_EncodedWord.DecodeS(value); MIME_h_ContentType retVal = new MIME_h_ContentType(); string[] name_value = valueDecoded.Split(new char[] { ':' }, 2); if (name_value.Length != 2) { throw new ParseException("Invalid Content-Type: header field value '" + value + "'."); } MIME_Reader r = new MIME_Reader(name_value[1]); string type = r.Token(); if (type == null) { throw new ParseException("Invalid Content-Type: header field value '" + value + "'."); } retVal.m_Type = type; if (r.Char(false) != '/') { throw new ParseException("Invalid Content-Type: header field value '" + value + "'."); } string subtype = r.Token(); if (subtype == null) { throw new ParseException("Invalid Content-Type: header field value '" + value + "'."); } retVal.m_SubType = subtype; if (r.Available > 0) { retVal.m_pParameters.Parse(r); } retVal.m_ParseValue = value; retVal.m_IsModified = false; return(retVal); }
/// <summary> /// Parses header field from the specified value. /// </summary> /// <param name="value">Header field value. Header field name must be included. For example: 'Content-Type: text/plain'.</param> /// <returns>Returns parsed header field.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>value</b> is null reference.</exception> /// <exception cref="ParseException">Is raised when header field parsing errors.</exception> public static MIME_h_ContentDisposition Parse(string value) { if (value == null) { throw new ArgumentNullException("value"); } // We should not have encoded words here, but some email clients do this, so encoded them if any. string valueDecoded = MIME_Encoding_EncodedWord.DecodeS(value); MIME_h_ContentDisposition retVal = new MIME_h_ContentDisposition(); string[] name_value = valueDecoded.Split(new char[] { ':' }, 2); if (name_value.Length != 2) { throw new ParseException("Invalid Content-Type: header field value '" + value + "'."); } MIME_Reader r = new MIME_Reader(name_value[1]); string type = r.Token(); if (type == null) { throw new ParseException("Invalid Content-Disposition: header field value '" + value + "'."); } retVal.m_DispositionType = type.Trim(); retVal.m_pParameters.Parse(r); retVal.m_ParseValue = value; return(retVal); }