Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class.
        /// </summary>
        /// <param name="entity">Information used by the constructor.</param>
        /// <remarks>
        /// Custom <see cref="MimeEntity"/> subclasses MUST implement this constructor
        /// in order to register it using <see cref="MimeEntity.Register"/>.
        /// </remarks>
        protected MimeEntity(MimeEntityConstructorInfo entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            Headers     = new HeaderList(entity.ParserOptions);
            ContentType = entity.ContentType;

            ContentType.Changed += ContentTypeChanged;
            Headers.Changed     += HeadersChanged;

            IsInitializing = true;
            foreach (var header in entity.Headers)
            {
                if (entity.IsTopLevel && !header.Field.StartsWith("Content-", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                Headers.Add(header);
            }
            IsInitializing = false;
        }
Example #2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class
		/// based on the <see cref="MimeEntityConstructorInfo"/>.
		/// </summary>
		/// <remarks>
		/// Custom <see cref="MimeEntity"/> subclasses MUST implement this constructor
		/// in order to register it using <see cref="ParserOptions.RegisterMimeType"/>.
		/// </remarks>
		/// <param name="entity">Information used by the constructor.</param>
		protected MimeEntity (MimeEntityConstructorInfo entity)
		{
			if (entity == null)
				throw new ArgumentNullException ("entity");

			Headers = new HeaderList (entity.ParserOptions);
			ContentType = entity.ContentType;

			ContentType.Changed += ContentTypeChanged;
			Headers.Changed += HeadersChanged;

			foreach (var header in entity.Headers) {
				if (entity.IsTopLevel && !header.Field.StartsWith ("Content-", StringComparison.OrdinalIgnoreCase))
					continue;

				Headers.Add (header);
			}
		}
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.Multipart"/> class.
 /// </summary>
 /// <param name="entity">Information used by the constructor.</param>
 public Multipart(MimeEntityConstructorInfo entity) : base(entity)
 {
     children = new List <MimeEntity> ();
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.MessagePartial"/> class.
 /// </summary>
 /// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
 /// <param name="entity">Information used by the constructor.</param>
 public MessagePartial(MimeEntityConstructorInfo entity)
     : base(entity)
 {
 }
Example #5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.TextPart"/> class.
		/// </summary>
		/// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
		/// <param name="entity">Information used by the constructor.</param>
		public TextPart (MimeEntityConstructorInfo entity) : base (entity)
		{
		}
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.MimePart"/> class.
 /// </summary>
 /// <param name="entity">Information used by the constructor.</param>
 public MimePart(MimeEntityConstructorInfo entity) : base(entity)
 {
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.MessagePartial"/> class.
 /// </summary>
 /// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
 /// <param name="entity">Information used by the constructor.</param>
 public MessagePartial(MimeEntityConstructorInfo entity) : base(entity)
 {
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.MultipartRelated"/> class.
 /// </summary>
 /// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
 /// <param name="entity">Information used by the constructor.</param>
 public MultipartRelated(MimeEntityConstructorInfo entity) : base(entity)
 {
 }
Example #9
0
        internal MimeEntity CreateEntity(ContentType contentType, IEnumerable <Header> headers, bool toplevel)
        {
            var entity  = new MimeEntityConstructorInfo(this, contentType, headers, toplevel);
            var subtype = contentType.MediaSubtype.ToLowerInvariant();
            var type    = contentType.MediaType.ToLowerInvariant();

            if (mimeTypes.Count > 0)
            {
                var             mimeType = string.Format("{0}/{1}", type, subtype);
                ConstructorInfo ctor;

                if (mimeTypes.TryGetValue(mimeType, out ctor))
                {
                    return((MimeEntity)ctor.Invoke(new object[] { entity }));
                }
            }

            if (type == "message")
            {
                if (subtype == "partial")
                {
                    return(new MessagePartial(entity));
                }

                return(new MessagePart(entity));
            }

            if (type == "multipart")
            {
                                #if !__MIMEKIT_LITE__
                if (subtype == "encrypted")
                {
                    return(new MultipartEncrypted(entity));
                }

                if (subtype == "signed")
                {
                    return(new MultipartSigned(entity));
                }
                                #endif

                return(new Multipart(entity));
            }

                        #if !__MIMEKIT_LITE__
            if (type == "application")
            {
                switch (subtype)
                {
                case "x-pkcs7-signature":
                case "pkcs7-signature":
                    return(new ApplicationPkcs7Signature(entity));

                case "x-pgp-encrypted":
                case "pgp-encrypted":
                    return(new ApplicationPgpEncrypted(entity));

                case "x-pgp-signature":
                case "pgp-signature":
                    return(new ApplicationPgpSignature(entity));

                case "x-pkcs7-mime":
                case "pkcs7-mime":
                    return(new ApplicationPkcs7Mime(entity));
                }
            }
                        #endif

            if (type == "text")
            {
                return(new TextPart(entity));
            }

            return(new MimePart(entity));
        }
Example #10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.MultipartRelated"/> class.
		/// </summary>
		/// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
		/// <param name="entity">Information used by the constructor.</param>
		public MultipartRelated (MimeEntityConstructorInfo entity) : base (entity)
		{
		}
Example #11
0
        internal static MimeEntity Create(ParserOptions options, ContentType ctype, IEnumerable<Header> headers, bool toplevel)
        {
            var entity = new MimeEntityConstructorInfo (options, ctype, headers, toplevel);
            var subtype = ctype.MediaSubtype.ToLowerInvariant ();
            var type = ctype.MediaType.ToLowerInvariant ();

            if (CustomMimeTypes.Count > 0) {
                var mimeType = string.Format ("{0}/{1}", type, subtype);
                lock (CustomMimeTypes) {
                    ConstructorInfo ctor;

                    if (CustomMimeTypes.TryGetValue (mimeType, out ctor))
                        return (MimeEntity) ctor.Invoke (new object[] { entity });
                }
            }

            if (type == "message") {
                if (subtype == "partial")
                    return new MessagePartial (entity);

                return new MessagePart (entity);
            }

            if (type == "multipart") {
                if (subtype == "encrypted")
                    return new MultipartEncrypted (entity);

                if (subtype == "signed")
                    return new MultipartSigned (entity);

                return new Multipart (entity);
            }

            if (type == "application") {
                switch (subtype) {
                case "x-pkcs7-signature":
                case "pkcs7-signature":
                    return new ApplicationPkcs7Signature (entity);
                case "x-pgp-encrypted":
                case "pgp-encrypted":
                    return new ApplicationPgpEncrypted (entity);
                case "x-pgp-signature":
                case "pgp-signature":
                    return new ApplicationPgpSignature (entity);
                case "x-pkcs7-mime":
                case "pkcs7-mime":
                    return new ApplicationPkcs7Mime (entity);
                }
            }

            if (type == "text")
                return new TextPart (entity);

            return new MimePart (entity);
        }
		internal MimeEntity CreateEntity (ContentType contentType, IList<Header> headers, bool toplevel)
		{
			var entity = new MimeEntityConstructorInfo (this, contentType, headers, toplevel);
			var subtype = contentType.MediaSubtype.ToLowerInvariant ();
			var type = contentType.MediaType.ToLowerInvariant ();

			if (mimeTypes.Count > 0) {
				var mimeType = string.Format ("{0}/{1}", type, subtype);
				ConstructorInfo ctor;

				if (mimeTypes.TryGetValue (mimeType, out ctor))
					return (MimeEntity) ctor.Invoke (new object[] { entity });
			}

			// Note: message/rfc822 and message/partial are not allowed to be encoded according to rfc2046
			// (sections 5.2.1 and 5.2.2, respectively). Since some broken clients will encode them anyway,
			// it is necessary for us to treat those as opaque blobs instead, and thus the parser should
			// parse them as normal MimeParts instead of MessageParts.
			//
			// Technically message/disposition-notification is only allowed to have use the 7bit encoding
			// as well, but since MessageDispositionNotification is a MImePart subclass rather than a
			// MessagePart subclass, it means that the content won't be parsed until later and so we can
			// actually handle that w/o any problems.
			if (type == "message") {
				switch (subtype) {
				case "disposition-notification":
					return new MessageDispositionNotification (entity);
				case "partial":
					if (!IsEncoded (headers))
						return new MessagePartial (entity);
					break;
				case "external-body":
				case "rfc2822":
				case "rfc822":
				case "news":
					if (!IsEncoded (headers))
						return new MessagePart (entity);
					break;
				}
			}

			if (type == "multipart") {
				if (subtype == "related")
					return new MultipartRelated (entity);

#if ENABLE_CRYPTO
				if (subtype == "encrypted")
					return new MultipartEncrypted (entity);

				if (subtype == "signed")
					return new MultipartSigned (entity);
#endif

				return new Multipart (entity);
			}

#if ENABLE_CRYPTO
			if (type == "application") {
				switch (subtype) {
				case "x-pkcs7-signature":
				case "pkcs7-signature":
					return new ApplicationPkcs7Signature (entity);
				case "x-pgp-encrypted":
				case "pgp-encrypted":
					return new ApplicationPgpEncrypted (entity);
				case "x-pgp-signature":
				case "pgp-signature":
					return new ApplicationPgpSignature (entity);
				case "x-pkcs7-mime":
				case "pkcs7-mime":
					return new ApplicationPkcs7Mime (entity);
				case "vnd.ms-tnef":
				case "ms-tnef":
					return new TnefPart (entity);
				}
			}
#endif

			if (type == "text")
				return new TextPart (entity);

			return new MimePart (entity);
		}
		internal MimeEntity CreateEntity (ContentType contentType, IEnumerable<Header> headers, bool toplevel)
		{
			var entity = new MimeEntityConstructorInfo (this, contentType, headers, toplevel);
			var subtype = contentType.MediaSubtype.ToLowerInvariant ();
			var type = contentType.MediaType.ToLowerInvariant ();

			if (mimeTypes.Count > 0) {
				var mimeType = string.Format ("{0}/{1}", type, subtype);
				ConstructorInfo ctor;

				if (mimeTypes.TryGetValue (mimeType, out ctor))
					return (MimeEntity) ctor.Invoke (new object[] { entity });
			}

			if (type == "message") {
				if (subtype == "partial")
					return new MessagePartial (entity);

				return new MessagePart (entity);
			}

			if (type == "multipart") {
#if ENABLE_CRYPTO
				if (subtype == "encrypted")
					return new MultipartEncrypted (entity);

				if (subtype == "signed")
					return new MultipartSigned (entity);
#endif

				return new Multipart (entity);
			}

#if ENABLE_CRYPTO
			if (type == "application") {
				switch (subtype) {
				case "x-pkcs7-signature":
				case "pkcs7-signature":
					return new ApplicationPkcs7Signature (entity);
				case "x-pgp-encrypted":
				case "pgp-encrypted":
					return new ApplicationPgpEncrypted (entity);
				case "x-pgp-signature":
				case "pgp-signature":
					return new ApplicationPgpSignature (entity);
				case "x-pkcs7-mime":
				case "pkcs7-mime":
					return new ApplicationPkcs7Mime (entity);
				case "vnd.ms-tnef":
				case "ms-tnef":
					return new TnefPart (entity);
				}
			}
#endif

			if (type == "text")
				return new TextPart (entity);

			return new MimePart (entity);
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.MessageDispositionNotification"/> class.
		/// </summary>
		/// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
		/// <param name="entity">Information used by the constructor.</param>
		public MessageDispositionNotification (MimeEntityConstructorInfo entity) : base (entity)
		{
		}
Example #15
0
        internal MimeEntity CreateEntity(ContentType contentType, IList <Header> headers, bool toplevel)
        {
            var entity  = new MimeEntityConstructorInfo(this, contentType, headers, toplevel);
            var subtype = contentType.MediaSubtype.ToLowerInvariant();
            var type    = contentType.MediaType.ToLowerInvariant();

            if (mimeTypes.Count > 0)
            {
                var             mimeType = string.Format("{0}/{1}", type, subtype);
                ConstructorInfo ctor;

                if (mimeTypes.TryGetValue(mimeType, out ctor))
                {
                    return((MimeEntity)ctor.Invoke(new object[] { entity }));
                }
            }

            // Note: message/rfc822 and message/partial are not allowed to be encoded according to rfc2046
            // (sections 5.2.1 and 5.2.2, respectively). Since some broken clients will encode them anyway,
            // it is necessary for us to treat those as opaque blobs instead, and thus the parser should
            // parse them as normal MimeParts instead of MessageParts.
            //
            // Technically message/disposition-notification is only allowed to have use the 7bit encoding
            // as well, but since MessageDispositionNotification is a MImePart subclass rather than a
            // MessagePart subclass, it means that the content won't be parsed until later and so we can
            // actually handle that w/o any problems.
            if (type == "message")
            {
                switch (subtype)
                {
                case "disposition-notification":
                    return(new MessageDispositionNotification(entity));

                case "partial":
                    if (!IsEncoded(headers))
                    {
                        return(new MessagePartial(entity));
                    }
                    break;

                case "external-body":
                case "rfc2822":
                case "rfc822":
                case "news":
                    if (!IsEncoded(headers))
                    {
                        return(new MessagePart(entity));
                    }
                    break;
                }
            }

            if (type == "multipart")
            {
                if (subtype == "related")
                {
                    return(new MultipartRelated(entity));
                }

#if ENABLE_CRYPTO
                if (subtype == "encrypted")
                {
                    return(new MultipartEncrypted(entity));
                }

                if (subtype == "signed")
                {
                    return(new MultipartSigned(entity));
                }
#endif

                return(new Multipart(entity));
            }

#if ENABLE_CRYPTO
            if (type == "application")
            {
                switch (subtype)
                {
                case "x-pkcs7-signature":
                case "pkcs7-signature":
                    return(new ApplicationPkcs7Signature(entity));

                case "x-pgp-encrypted":
                case "pgp-encrypted":
                    return(new ApplicationPgpEncrypted(entity));

                case "x-pgp-signature":
                case "pgp-signature":
                    return(new ApplicationPgpSignature(entity));

                case "x-pkcs7-mime":
                case "pkcs7-mime":
                    return(new ApplicationPkcs7Mime(entity));

                case "vnd.ms-tnef":
                case "ms-tnef":
                    return(new TnefPart(entity));
                }
            }
#endif

            if (type == "text")
            {
                return(new TextPart(entity));
            }

            return(new MimePart(entity));
        }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeKit.MessageDispositionNotification"/> class.
 /// </summary>
 /// <remarks>This constructor is used by <see cref="MimeKit.MimeParser"/>.</remarks>
 /// <param name="entity">Information used by the constructor.</param>
 public MessageDispositionNotification(MimeEntityConstructorInfo entity) : base(entity)
 {
 }