当前位置: 首页>>代码示例>>C#>>正文


C# MimeKit.ContentType类代码示例

本文整理汇总了C#中MimeKit.ContentType的典型用法代码示例。如果您正苦于以下问题:C# ContentType类的具体用法?C# ContentType怎么用?C# ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentType类属于MimeKit命名空间,在下文中一共展示了ContentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MimeEntityConstructorArgs

		internal MimeEntityConstructorArgs (ParserOptions options, ContentType ctype, IEnumerable<Header> headers, bool toplevel)
		{
			ParserOptions = options;
			IsTopLevel = toplevel;
			ContentType = ctype;
			Headers = headers;
		}
开发者ID:ruffin--,项目名称:MimeKit,代码行数:7,代码来源:MimeEntityConstructorArgs.cs

示例2: TestBreakingOfLongParamValues

        public void TestBreakingOfLongParamValues()
        {
            string encoded, expected;
            ContentType type;

            expected = "Content-Type: text/plain; charset=iso-8859-1;\n\tname*0=\"this is a really really long filename that should force MimeKi\";\n\tname*1=\"t to break it apart - yay!.html\"";
            type = new ContentType ("text", "plain");
            type.Parameters.Add ("charset", "iso-8859-1");
            type.Parameters.Add ("name", "this is a really really long filename that should force MimeKit to break it apart - yay!.html");
            encoded = type.ToString (Encoding.UTF8, true);
            Assert.AreEqual (expected, encoded, "Encoded Content-Type does not match: {0}", expected);
        }
开发者ID:vdaron,项目名称:MimeKit,代码行数:12,代码来源:ContentTypeTests.cs

示例3: CreateEntity

		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);
		}
开发者ID:yijunwu,项目名称:scheduledmailsender,代码行数:60,代码来源:ParserOptions.cs

示例4: TryParse

        /// <summary>
        /// Tries to parse the given text into a new <see cref="MimeKit.ContentType"/> instance.
        /// </summary>
        /// <returns><c>true</c>, if the content type was successfully parsed, <c>false</c> otherwise.</returns>
        /// <param name="text">The text to parse.</param>
        /// <param name="type">The parsed content type.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="text"/> is <c>null</c>.
        /// </exception>
        public static bool TryParse(string text, out ContentType type)
        {
            if (text == null)
                throw new ArgumentNullException ("text");

            var buffer = Encoding.UTF8.GetBytes (text);
            int index = 0;

            return TryParse (ParserOptions.Default, buffer, ref index, buffer.Length, false, out type);
        }
开发者ID:princeoffoods,项目名称:MimeKit,代码行数:19,代码来源:ContentType.cs

示例5: CreateEntity

		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);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:91,代码来源:ParserOptions.cs

示例6: TryParse

		/// <summary>
		/// Tries to parse the given text into a new <see cref="MimeKit.ContentType"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a Content-Type value from the specified text.
		/// </remarks>
		/// <returns><c>true</c>, if the content type was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="text">The text to parse.</param>
		/// <param name="type">The parsed content type.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="text"/> is <c>null</c>.
		/// </exception>
		public static bool TryParse (string text, out ContentType type)
		{
			return TryParse (ParserOptions.Default, text, out type);
		}
开发者ID:dcga,项目名称:MimeKit,代码行数:16,代码来源:ContentType.cs

示例7: ParseContentType

        static ContentType ParseContentType(ImapEngine engine, CancellationToken cancellationToken)
        {
            var type = ReadStringToken (engine, cancellationToken);
            var subtype = ReadStringToken (engine, cancellationToken);
            var contentType = new ContentType (type, subtype);
            var token = engine.ReadToken (cancellationToken);

            if (token.Type == ImapTokenType.Nil)
                return contentType;

            if (token.Type != ImapTokenType.OpenParen)
                throw ImapEngine.UnexpectedToken (token, false);

            ParseParameterList (contentType.Parameters, engine, cancellationToken);

            return contentType;
        }
开发者ID:rashoodkhan,项目名称:MailKit,代码行数:17,代码来源:ImapUtils.cs

示例8: TryParse

		static bool TryParse (string text, ref int index, bool multipart, out ContentType contentType)
		{
			IList<Parameter> parameters;
			string type, subtype;

			contentType = null;

			while (index < text.Length && text[index] == ' ')
				index++;

			if (index >= text.Length)
				return false;

			if (!multipart) {
				if (!TryParse (text, ref index, out type))
					return false;
			} else {
				type = "multipart";
			}

			if (!TryParse (text, ref index, out subtype))
				return false;

			if (!TryParse (text, ref index, out parameters))
				return false;

			contentType = new ContentType (type, subtype);

			foreach (var param in parameters)
				contentType.Parameters.Add (param);

			return true;
		}
开发者ID:BehnamEmamian,项目名称:MailKit,代码行数:33,代码来源:BodyPart.cs

示例9: Encode

		internal static void Encode (StringBuilder builder, ContentType contentType)
		{
			Encode (builder, contentType.MediaType);
			builder.Append (' ');
			Encode (builder, contentType.MediaSubtype);
			builder.Append (' ');
			Encode (builder, contentType.Parameters);
		}
开发者ID:BehnamEmamian,项目名称:MailKit,代码行数:8,代码来源:BodyPart.cs

示例10: ParseContentType

		static bool ParseContentType (ImapEngine engine, CancellationToken cancellationToken, out ContentType contentType, out string value)
		{
			var type = ReadNStringToken (engine, false, cancellationToken) ?? string.Empty;
			var token = engine.PeekToken (cancellationToken);

			value = null;

			if (engine.IsGMail && token.Type == ImapTokenType.OpenParen) {
				// Note: GMail's IMAP server implementation breaks when it encounters
				// nested multiparts with the same boundary and returns a BODYSTRUCTURE
				// like the example in https://github.com/jstedfast/MailKit/issues/205
				contentType = null;
				value = type;
				return false;
			}

			var subtype = ReadNStringToken (engine, false, cancellationToken) ?? string.Empty;

			token = engine.ReadToken (cancellationToken);

			if (token.Type == ImapTokenType.Nil) {
				contentType = new ContentType (type, subtype);
				return true;
			}

			if (token.Type != ImapTokenType.OpenParen)
				throw ImapEngine.UnexpectedToken (token, false);

			var builder = new StringBuilder ();
			builder.AppendFormat ("{0}/{1}", type, subtype);

			ParseParameterList (builder, engine, cancellationToken);

			if (!ContentType.TryParse (builder.ToString (), out contentType))
				contentType = new ContentType (type, subtype);

			return true;
		}
开发者ID:BehnamEmamian,项目名称:MailKit,代码行数:38,代码来源:ImapUtils.cs

示例11: Create

        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);
        }
开发者ID:princeoffoods,项目名称:MimeKit,代码行数:55,代码来源:MimeEntity.cs

示例12: MimePart

		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.MimePart"/> class
		/// with the specified content type.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="MimePart"/> with the specified Content-Type value.
		/// </remarks>
		/// <param name="contentType">The content type.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="contentType"/> is <c>null</c>.
		/// </exception>
		public MimePart (ContentType contentType) : base (contentType)
		{
		}
开发者ID:andyhebear,项目名称:MimeKit,代码行数:14,代码来源:MimePart.cs

示例13: MimeEntity

        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.MimeEntity"/> class.
        /// </summary>
        /// <param name="mediaType">The media type.</param>
        /// <param name="mediaSubtype">The media subtype.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="mediaType"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="mediaSubtype"/> is <c>null</c>.</para>
        /// </exception>
        protected MimeEntity(string mediaType, string mediaSubtype)
        {
            ContentType = new ContentType (mediaType, mediaSubtype);
            Headers = new HeaderList ();

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

            SerializeContentType ();
        }
开发者ID:princeoffoods,项目名称:MimeKit,代码行数:20,代码来源:MimeEntity.cs

示例14: TextPart

		internal TextPart (ContentType contentType) : base (contentType)
		{
		}
开发者ID:surekqomi,项目名称:MimeKit,代码行数:3,代码来源:TextPart.cs

示例15: ParseContentType

        static ContentType ParseContentType(ImapEngine engine, CancellationToken cancellationToken)
        {
            var type = ReadStringToken (engine, cancellationToken);
            var subtype = ReadStringToken (engine, cancellationToken);
            var token = engine.ReadToken (cancellationToken);
            ContentType contentType;

            if (token.Type == ImapTokenType.Nil)
                return new ContentType (type, subtype);

            if (token.Type != ImapTokenType.OpenParen)
                throw ImapEngine.UnexpectedToken (token, false);

            var builder = new StringBuilder ();
            builder.AppendFormat ("{0}/{1}", type, subtype);

            ParseParameterList (builder, engine, cancellationToken);

            if (!ContentType.TryParse (builder.ToString (), out contentType))
                contentType = new ContentType (type, subtype);

            return contentType;
        }
开发者ID:EGrun,项目名称:MailKit,代码行数:23,代码来源:ImapUtils.cs


注:本文中的MimeKit.ContentType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。