コード例 #1
0
ファイル: Reader.cs プロジェクト: YSRE/SuperRocket
        /// <summary>
        /// Reads a disposition from the underlying string. A disposition in
        /// this context is a list of attribute/value literals (enclosed in
        /// double-quotes) preceded by a word enclosed in parenthesis.
        /// </summary>
        /// <returns>An initialized ContentDisposition instance representing
        /// the parsed disposition.</returns>
        /// <exception cref="EndOfStringException">Thrown when reading is
        /// attempted past the end of the underlying string.</exception>
        public ContentDisposition ReadDisposition()
        {
            ContentDisposition Disp = new ContentDisposition();
            char c;

            char[] last = new char[3];
            while ((c = (char)Read()) != '(')
            {
                last[0] = last[1];
                last[1] = last[2];
                last[2] = c;
                if ((new string(last)) == "NIL")
                {
                    return(Disp);
                }
            }

            string type = ReadWord();

            Disp.Type       = ContentDispositionTypeMap.fromString(type);
            Disp.Attributes = ReadList();
            ReadUntil(')');

            if (Disp.Attributes.ContainsKey("Filename"))
            {
                Disp.Filename = Disp.Attributes["Filename"];
            }
            return(Disp);
        }
コード例 #2
0
        /// <summary>
        /// Glue method to create a bodypart from a MIMEPart instance.
        /// </summary>
        /// <param name="mimePart">The MIMEPart instance to create the bodypart instance from.</param>
        /// <returns>An initialized instance of the Bodypart class.</returns>
        static Bodypart BodypartFromMIME(MIMEPart mimePart)
        {
            NameValueCollection contentType = ParseMIMEField(
                mimePart.header["Content-Type"]);
            Bodypart p = new Bodypart(null);
            Match    m = Regex.Match(contentType["value"], "(.+)/(.+)");

            if (m.Success)
            {
                p.Type    = ContentTypeMap.fromString(m.Groups[1].Value);
                p.Subtype = m.Groups[2].Value;
            }
            p.Encoding = ContentTransferEncodingMap.fromString(
                mimePart.header["Content-Transfer-Encoding"]);
            p.Id = mimePart.header["Content-Id"];
            foreach (string k in contentType.AllKeys)
            {
                p.Parameters.Add(k, contentType[k]);
            }
            p.Size = mimePart.body.Length;
            if (mimePart.header["Content-Disposition"] != null)
            {
                NameValueCollection disposition = ParseMIMEField(
                    mimePart.header["Content-Disposition"]);
                p.Disposition.Type = ContentDispositionTypeMap.fromString(
                    disposition["value"]);
                p.Disposition.Filename = disposition["Filename"];
                foreach (string k in disposition.AllKeys)
                {
                    p.Disposition.Attributes.Add(k, disposition[k]);
                }
            }
            return(p);
        }