MimeKit.ParserOptions.CreateEntity C# (CSharp) Method

CreateEntity() private method

private CreateEntity ( MimeKit.ContentType contentType, IList
headers, bool toplevel ) : MimeKit.MimeEntity
contentType MimeKit.ContentType
headers IList
toplevel bool
return MimeKit.MimeEntity
		internal MimeEntity CreateEntity (ContentType contentType, IList<Header> headers, bool toplevel)
		{
			var args = new MimeEntityConstructorArgs (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[] { args });
			}

			// 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 (args);
				case "delivery-status":
					return new MessageDeliveryStatus (args);
				case "partial":
					if (!IsEncoded (headers))
						return new MessagePartial (args);
					break;
				case "external-body":
				case "rfc2822":
				case "rfc822":
				case "news":
					if (!IsEncoded (headers))
						return new MessagePart (args);
					break;
				}
			}

			if (type == "multipart") {
				switch (subtype) {
				case "alternative":
					return new MultipartAlternative (args);
				case "related":
					return new MultipartRelated (args);
				case "report":
					return new MultipartReport (args);
#if ENABLE_CRYPTO
				case "encrypted":
					return new MultipartEncrypted (args);
				case "signed":
					return new MultipartSigned (args);
#endif
				default:
					return new Multipart (args);
				}
			}

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

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

			return new MimePart (args);
		}
	}