ParseHeaderFiledSubField() public static method

Parses header field sub field value. For example: CONTENT-TYPE: application\octet-stream; name="yourFileName.xxx", fieldName="CONTENT-TYPE:" and subFieldName="name".
public static ParseHeaderFiledSubField ( string fieldName, string subFieldName, string headers ) : string
fieldName string Main header field name.
subFieldName string Header field's sub filed name.
headers string Full headrs string.
return string
Exemplo n.º 1
0
        /// <summary>
        /// Parse charset.
        /// </summary>
        /// <param name="headers"></param>
        /// <returns></returns>
        private string ParseCharSet(string headers)
        {
            string charset = MimeParser.ParseHeaderFiledSubField("Content-Type:", "charset", headers);

            if (charset.Length > 0)
            {
                try{
                    Encoding.GetEncoding(charset);

                    return(charset);
                }
                catch {
                    return("ascii");
                }
            }
            // If no charset, consider it as ascii
            else
            {
                return("ascii");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="mimeEntry"></param>
        /// <param name="mime"></param>
        public MimeEntry(byte[] mimeEntry, MimeParser mime)
        {
            MemoryStream entryStrm = new MemoryStream(mimeEntry);

            m_Headers     = MimeParser.ParseHeaders(entryStrm);
            m_ContentType = mime.ParseContentType(m_Headers);

            // != multipart content
            if (m_ContentType.ToLower().IndexOf("multipart") == -1)
            {
                m_CharSet         = ParseCharSet(m_Headers);
                m_ContentEncoding = ParseEncoding(m_Headers);

                m_Data = new byte[entryStrm.Length - entryStrm.Position];
                entryStrm.Read(m_Data, 0, m_Data.Length);
            }
            else              // multipart content, get nested entries
            {
                string boundaryID = MimeParser.ParseHeaderFiledSubField("Content-Type:", "boundary", m_Headers);
                m_Entries = mime.ParseEntries(entryStrm, (int)entryStrm.Position, boundaryID);
            }
        }