當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。