Esempio n. 1
0
        /// <summary>
        /// Parses a bodypart entry from the body structure and advances the
        /// read pointer.
        /// </summary>
        /// <param name="partNumber">The designated part specifier by which the body
        /// part is refered to by the server.</param>
        /// <param name="parenthesis">Set to true if the bodypart is enclosed
        /// in parenthesis.</param>
        /// <returns></returns>
        private Bodypart ParseBodypart(string partNumber, bool parenthesis = true)
        {
            Bodypart part = new Bodypart(partNumber);

            // Mandatory fields:
            //  "Type"² "Subtype"² ("Attribute" "Value")² "Id"² "Description"² "Encoding"² Size³
            //  ² String value, but can be NIL, ³ Integer value
            part.Type        = ContentTypeMap.fromString(reader.ReadWord());
            part.Subtype     = reader.ReadWord();
            part.Parameters  = reader.ReadList();
            part.Id          = reader.ReadWord();
            part.Description = reader.ReadWord();
            part.Encoding    = ContentTransferEncodingMap.fromString(reader.ReadWord());
            part.Size        = reader.ReadInteger();
            if (part.Type == ContentType.Text)
            {
                part.Lines = reader.ReadInteger();
            }
            if (part.Type == ContentType.Message && part.Subtype.ToUpper() == "RFC822")
            {
                ParseMessage822Fields(part);
            }
            try {
                ParseOptionalFields(part, parenthesis);
            } catch (EndOfStringException) {}
            return(part);
        }
Esempio n. 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>
        private 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);
        }