Ejemplo n.º 1
0
        /// <summary>
        /// Create a new e-mail content type by parsing the given string.
        /// </summary>
        /// <param name="ContentTypeString"></param>
        public MailContentType(AbstractEMail EMailHeader,
                               String ContentTypeString)
        {
            this._EMailHeader = EMailHeader;
            this._Text        = ContentTypeString;

            var Splitted = ContentTypeString.
                           Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries).
                           Select(v => v.Trim()).
                           ToArray();

            if (Splitted.Length == 0)
            {
                this._ContentType = MailContentTypes.text_plain;
            }

            else if (!Enum.TryParse <MailContentTypes>(Splitted[0].Replace("/", "_").Replace("+", "__"), out this._ContentType))
            {
                this._ContentType = MailContentTypes.text_plain;
            }


            else
            {
                foreach (var SubInformation in Splitted.Skip(1))
                {
                    if (SubInformation.ToLower().StartsWith("charset="))
                    {
                        _CharSet = SubInformation.Substring("charset=".Length).Trim().ToLower();

                        if (_CharSet.StartsWith(@""""))
                        {
                            _CharSet = _CharSet.Remove(0, 1);
                        }

                        if (_CharSet.EndsWith(@""""))
                        {
                            _CharSet = _CharSet.Substring(0, _CharSet.Length - 1);
                        }

                        continue;
                    }

                    if (SubInformation.ToLower().StartsWith("boundary="))
                    {
                        _MIMEBoundary = SubInformation.Substring("boundary=".Length).Trim();

                        if (_MIMEBoundary.StartsWith(@""""))
                        {
                            _MIMEBoundary = _MIMEBoundary.Remove(0, 1);
                        }

                        if (_MIMEBoundary.EndsWith(@""""))
                        {
                            _MIMEBoundary = _MIMEBoundary.Substring(0, MIMEBoundary.Length - 1);
                        }

                        continue;
                    }
                }
            }

            // Update text-version within the e-mail header
            if (_EMailHeader != null)
            {
                _EMailHeader.SetEMailHeader("Content-Type", this.ToString());
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a new e-mail content type.
 /// </summary>
 /// <param name="ContentType">The content type.</param>
 public MailContentType(AbstractEMail EMailHeader,
                        MailContentTypes ContentType = MailContentTypes.unknown)
 {
     this._EMailHeader = EMailHeader;
     this._ContentType = ContentType;
 }