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


C# ImapEngine.PeekToken方法代码示例

本文整理汇总了C#中MailKit.Net.Imap.ImapEngine.PeekToken方法的典型用法代码示例。如果您正苦于以下问题:C# ImapEngine.PeekToken方法的具体用法?C# ImapEngine.PeekToken怎么用?C# ImapEngine.PeekToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MailKit.Net.Imap.ImapEngine的用法示例。


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

示例1: ParseImplementation

		/// <summary>
		/// Parses an untagged ID response.
		/// </summary>
		/// <param name="engine">The IMAP engine.</param>
		/// <param name="ic">The IMAP command.</param>
		/// <param name="index">The index.</param>
		public static void ParseImplementation (ImapEngine engine, ImapCommand ic, int index)
		{
			string format = string.Format (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "ID", "{0}");
			var token = engine.ReadToken (ic.CancellationToken);
			ImapImplementation implementation;

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

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

			token = engine.PeekToken (ic.CancellationToken);

			implementation = new ImapImplementation ();

			while (token.Type != ImapTokenType.CloseParen) {
				var property = ReadStringToken (engine, format, ic.CancellationToken);
				var value = ReadNStringToken (engine, format, false, ic.CancellationToken);

				implementation.Properties[property] = value;

				token = engine.PeekToken (ic.CancellationToken);
			}

			ic.UserData = implementation;

			// read the ')' token
			engine.ReadToken (ic.CancellationToken);
		}
开发者ID:jstedfast,项目名称:MailKit,代码行数:36,代码来源:ImapUtils.cs

示例2: UntaggedQuota

		static void UntaggedQuota (ImapEngine engine, ImapCommand ic, int index)
		{
			string format = string.Format (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "QUOTA", "{0}");
			var encodedName = ReadStringToken (engine, format, ic.CancellationToken);
			ImapFolder quotaRoot;
			FolderQuota quota;

			if (!engine.GetCachedFolder (encodedName, out quotaRoot)) {
				// Note: this shouldn't happen because the quota root should
				// be one of the parent folders which will all have been added
				// to the folder cache by this point.
			}

			ic.UserData = quota = new FolderQuota (quotaRoot);

			var token = engine.ReadToken (ic.CancellationToken);

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

			while (token.Type != ImapTokenType.CloseParen) {
				uint used, limit;
				string resource;

				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type != ImapTokenType.Atom)
					throw ImapEngine.UnexpectedToken (format, token);

				resource = (string) token.Value;

				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out used))
					throw ImapEngine.UnexpectedToken (format, token);

				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out limit))
					throw ImapEngine.UnexpectedToken (format, token);

				switch (resource.ToUpperInvariant ()) {
				case "MESSAGE":
					quota.CurrentMessageCount = used;
					quota.MessageLimit = limit;
					break;
				case "STORAGE":
					quota.CurrentStorageSize = used;
					quota.StorageLimit = limit;
					break;
				}

				token = engine.PeekToken (ic.CancellationToken);
			}

			// read the closing paren
			engine.ReadToken (ic.CancellationToken);
		}
开发者ID:dcga,项目名称:MailKit,代码行数:58,代码来源:ImapFolder.cs

示例3: FetchSummaryItems

		void FetchSummaryItems (ImapEngine engine, ImapCommand ic, int index)
		{
			var token = engine.ReadToken (ic.CancellationToken);

			if (token.Type != ImapTokenType.OpenParen)
				throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token);

			var ctx = (FetchSummaryContext) ic.UserData;
			IMessageSummary isummary;
			MessageSummary summary;

			if (!ctx.Results.TryGetValue (index, out isummary)) {
				summary = new MessageSummary (index);
				ctx.Results.Add (index, summary);
			} else {
				summary = (MessageSummary) isummary;
			}

			do {
				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln)
					break;

				if (token.Type != ImapTokenType.Atom)
					throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token);

				var atom = (string) token.Value;
				string format;
				ulong value64;
				uint value;
				int idx;

				switch (atom) {
				case "INTERNALDATE":
					token = engine.ReadToken (ic.CancellationToken);

					switch (token.Type) {
					case ImapTokenType.QString:
					case ImapTokenType.Atom:
						summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value);
						break;
					case ImapTokenType.Nil:
						summary.InternalDate = null;
						break;
					default:
						throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
					}

					summary.Fields |= MessageSummaryItems.InternalDate;
					break;
				case "RFC822.SIZE":
					token = engine.ReadToken (ic.CancellationToken);

					if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value))
						throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);

					summary.Fields |= MessageSummaryItems.MessageSize;
					summary.Size = value;
					break;
				case "BODYSTRUCTURE":
					format = string.Format (ImapEngine.GenericItemSyntaxErrorFormat, "BODYSTRUCTURE", "{0}");
					summary.Body = ImapUtils.ParseBody (engine, format, string.Empty, ic.CancellationToken);
					summary.Fields |= MessageSummaryItems.BodyStructure;
					break;
				case "BODY":
					token = engine.PeekToken (ic.CancellationToken);

					if (token.Type == ImapTokenType.OpenBracket) {
						// consume the '['
						token = engine.ReadToken (ic.CancellationToken);

						if (token.Type != ImapTokenType.OpenBracket)
							throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);

						// References and/or other headers were requested...

						do {
							token = engine.ReadToken (ic.CancellationToken);

							if (token.Type == ImapTokenType.CloseBracket)
								break;

							if (token.Type == ImapTokenType.OpenParen) {
								do {
									token = engine.ReadToken (ic.CancellationToken);

									if (token.Type == ImapTokenType.CloseParen)
										break;

									// the header field names will generally be atoms or qstrings but may also be literals
									switch (token.Type) {
									case ImapTokenType.Literal:
										engine.ReadLiteral (ic.CancellationToken);
										break;
									case ImapTokenType.QString:
									case ImapTokenType.Atom:
										break;
									default:
										throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
//.........这里部分代码省略.........
开发者ID:dcga,项目名称:MailKit,代码行数:101,代码来源:ImapFolder.cs

示例4: UntaggedQuotaRoot

		static void UntaggedQuotaRoot (ImapEngine engine, ImapCommand ic, int index)
		{
			// The first token should be the mailbox name
			ReadStringToken (engine, ic.CancellationToken);

			// ...followed by 0 or more quota roots
			var token = engine.PeekToken (ic.CancellationToken);

			while (token.Type != ImapTokenType.Eoln) {
				ReadStringToken (engine, ic.CancellationToken);

				token = engine.PeekToken (ic.CancellationToken);
			}
		}
开发者ID:sstraus,项目名称:MailKit,代码行数:14,代码来源:ImapFolder.cs

示例5: UntaggedListRights

		static void UntaggedListRights (ImapEngine engine, ImapCommand ic, int index)
		{
			string format = string.Format (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "LISTRIGHTS", "{0}");
			var access = (AccessRights) ic.UserData;
			ImapToken token;

			// read the mailbox name
			ReadStringToken (engine, format, ic.CancellationToken);

			// read the identity name
			ReadStringToken (engine, format, ic.CancellationToken);

			do {
				var rights = ReadStringToken (engine, format, ic.CancellationToken);

				access.AddRange (rights);

				token = engine.PeekToken (ic.CancellationToken);
			} while (token.Type != ImapTokenType.Eoln);
		}
开发者ID:dcga,项目名称:MailKit,代码行数:20,代码来源:ImapFolder.cs

示例6: ParseMultipart

		static BodyPart ParseMultipart (ImapEngine engine, string path, string subtype, CancellationToken cancellationToken)
		{
			var prefix = path.Length > 0 ? path + "." : string.Empty;
			var body = new BodyPartMultipart ();
			ImapToken token;
			int index = 1;

			// Note: if subtype is not null, then we are working around a GMail bug...
			if (subtype == null) {
				do {
					body.BodyParts.Add (ParseBody (engine, prefix + index, cancellationToken));
					token = engine.PeekToken (cancellationToken);
					index++;
				} while (token.Type == ImapTokenType.OpenParen);

				subtype = ReadStringToken (engine, cancellationToken);
			}

			body.ContentType = new ContentType ("multipart", subtype);
			body.PartSpecifier = path;

			token = engine.PeekToken (cancellationToken);

			if (token.Type != ImapTokenType.CloseParen) {
				token = engine.ReadToken (cancellationToken);

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

				var builder = new StringBuilder ();
				ContentType contentType;

				builder.AppendFormat ("{0}/{1}", body.ContentType.MediaType, body.ContentType.MediaSubtype);
				ParseParameterList (builder, engine, cancellationToken);

				if (ContentType.TryParse (builder.ToString (), out contentType))
					body.ContentType = contentType;

				token = engine.PeekToken (cancellationToken);
			}

			if (token.Type != ImapTokenType.CloseParen) {
				body.ContentDisposition = ParseContentDisposition (engine, cancellationToken);
				token = engine.PeekToken (cancellationToken);
			}

			if (token.Type != ImapTokenType.CloseParen) {
				body.ContentLanguage = ParseContentLanguage (engine, cancellationToken);
				token = engine.PeekToken (cancellationToken);
			}

			if (token.Type != ImapTokenType.CloseParen) {
				body.ContentLocation = ParseContentLocation (engine, cancellationToken);
				token = engine.PeekToken (cancellationToken);
			}

			if (token.Type != ImapTokenType.CloseParen)
				SkipBodyExtensions (engine, cancellationToken);

			// read the ')'
			token = engine.ReadToken (cancellationToken);

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

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

示例7: UntaggedAcl

		static void UntaggedAcl (ImapEngine engine, ImapCommand ic, int index)
		{
			var acl = (AccessControlList) ic.UserData;
			string name, rights;
			ImapToken token;

			// read the mailbox name
			ReadStringToken (engine, ic.CancellationToken);

			do {
				name = ReadStringToken (engine, ic.CancellationToken);
				rights = ReadStringToken (engine, ic.CancellationToken);

				acl.Add (new AccessControl (name, rights));

				token = engine.PeekToken (ic.CancellationToken);
			} while (token.Type != ImapTokenType.Eoln);
		}
开发者ID:sstraus,项目名称:MailKit,代码行数:18,代码来源:ImapFolder.cs

示例8: FetchSummaryItems

        static void FetchSummaryItems(ImapEngine engine, ImapCommand ic, int index)
        {
            var token = engine.ReadToken (ic.CancellationToken);

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

            var results = (SortedDictionary<int, IMessageSummary>) ic.UserData;
            IMessageSummary isummary;
            MessageSummary summary;

            if (!results.TryGetValue (index, out isummary)) {
                summary = new MessageSummary (index);
                results.Add (index, summary);
            } else {
                summary = (MessageSummary) isummary;
            }

            do {
                token = engine.ReadToken (ic.CancellationToken);

                if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln)
                    break;

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

                var atom = (string) token.Value;
                ulong value64;
                uint value;

                switch (atom) {
                case "INTERNALDATE":
                    token = engine.ReadToken (ic.CancellationToken);

                    switch (token.Type) {
                    case ImapTokenType.QString:
                    case ImapTokenType.Atom:
                        summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value);
                        break;
                    case ImapTokenType.Nil:
                        summary.InternalDate = null;
                        break;
                    default:
                        throw ImapEngine.UnexpectedToken (token, false);
                    }
                    break;
                case "RFC822.SIZE":
                    token = engine.ReadToken (ic.CancellationToken);

                    if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value))
                        throw ImapEngine.UnexpectedToken (token, false);

                    summary.MessageSize = value;
                    break;
                case "BODYSTRUCTURE":
                    summary.Body = ImapUtils.ParseBody (engine, string.Empty, ic.CancellationToken);
                    break;
                case "BODY":
                    token = engine.PeekToken (ic.CancellationToken);

                    if (token.Type == ImapTokenType.OpenBracket) {
                        // consume the '['
                        token = engine.ReadToken (ic.CancellationToken);

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

                        // References were requested...

                        do {
                            token = engine.ReadToken (ic.CancellationToken);

                            if (token.Type == ImapTokenType.CloseBracket)
                                break;

                            if (token.Type == ImapTokenType.OpenParen) {
                                do {
                                    token = engine.ReadToken (ic.CancellationToken);

                                    if (token.Type == ImapTokenType.CloseParen)
                                        break;

                                    if (token.Type != ImapTokenType.Atom)
                                        throw ImapEngine.UnexpectedToken (token, false);
                                } while (true);
                            } else if (token.Type != ImapTokenType.Atom) {
                                throw ImapEngine.UnexpectedToken (token, false);
                            }
                        } while (true);

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

                        token = engine.ReadToken (ic.CancellationToken);

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

                        try {
//.........这里部分代码省略.........
开发者ID:rajeshwarn,项目名称:MailKit,代码行数:101,代码来源:ImapFolder.cs

示例9: ParseBody

        public static BodyPart ParseBody(ImapEngine engine, string path, CancellationToken cancellationToken)
        {
            var token = engine.ReadToken (cancellationToken);

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

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

            token = engine.PeekToken (cancellationToken);

            if (token.Type == ImapTokenType.OpenParen)
                return ParseMultipart (engine, path, cancellationToken);

            var type = ParseContentType (engine, cancellationToken);
            var id = ReadNStringToken (engine, false, cancellationToken);
            var desc = ReadNStringToken (engine, true, cancellationToken);
            var enc = ReadStringToken (engine, cancellationToken);
            var octets = ReadNumber (engine, cancellationToken);
            BodyPartBasic body;

            if (type.Matches ("message", "rfc822")) {
                var mesg = new BodyPartMessage ();
                mesg.Envelope = ParseEnvelope (engine, cancellationToken);
                mesg.Body = ParseBody (engine, path, cancellationToken);
                mesg.Lines = ReadNumber (engine, cancellationToken);
                body = mesg;
            } else if (type.Matches ("text", "*")) {
                var text = new BodyPartText ();
                text.Lines = ReadNumber (engine, cancellationToken);
                body = text;
            } else {
                body = new BodyPartBasic ();
            }

            body.ContentTransferEncoding = enc;
            body.ContentDescription = desc;
            body.PartSpecifier = path;
            body.ContentType = type;
            body.ContentId = id;
            body.Octets = octets;

            // if we are parsing a BODYSTRUCTURE, we may get some more tokens before the ')'
            token = engine.PeekToken (cancellationToken);

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentMd5 = ReadNStringToken (engine, false, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentDisposition = ParseContentDisposition (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentLanguage = ParseContentLocation (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentLocation = ReadNStringToken (engine, false, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen)
                SkipBodyExtensions (engine, cancellationToken);

            // read the ')'
            token = engine.ReadToken (cancellationToken);

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

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

示例10: ParseMultipart

        static BodyPart ParseMultipart(ImapEngine engine, string path, CancellationToken cancellationToken)
        {
            var prefix = path.Length > 0 ? path + "." : string.Empty;
            var body = new BodyPartMultipart ();
            ImapToken token;
            int index = 1;

            do {
                body.BodyParts.Add (ParseBody (engine, prefix + index, cancellationToken));
                token = engine.PeekToken (cancellationToken);
                index++;
            } while (token.Type == ImapTokenType.OpenParen);

            var subtype = ReadStringToken (engine, cancellationToken);

            body.ContentType = new ContentType ("multipart", subtype);
            body.PartSpecifier = path;

            token = engine.PeekToken (cancellationToken);

            if (token.Type != ImapTokenType.CloseParen) {
                token = engine.ReadToken (cancellationToken);

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

                ParseParameterList (body.ContentType.Parameters, engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentDisposition = ParseContentDisposition (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentLanguage = ParseContentLocation (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentLocation = ReadNStringToken (engine, false, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen)
                SkipBodyExtensions (engine, cancellationToken);

            // read the ')'
            token = engine.ReadToken (cancellationToken);

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

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

示例11: ParseParameterList

        static void ParseParameterList(ParameterList paramList, ImapEngine engine, CancellationToken cancellationToken)
        {
            ImapToken token;

            do {
                token = engine.PeekToken (cancellationToken);

                if (token.Type == ImapTokenType.CloseParen)
                    break;

                var name = ReadStringToken (engine, cancellationToken);
                var value = ReadStringToken (engine, cancellationToken);

                // FIXME: may need to decode params
                paramList[name] = value;
            } while (true);

            // read the ')'
            engine.ReadToken (cancellationToken);
        }
开发者ID:rashoodkhan,项目名称:MailKit,代码行数:20,代码来源:ImapUtils.cs

示例12: ParseBody

        public static BodyPart ParseBody(ImapEngine engine, string path, CancellationToken cancellationToken)
        {
            var token = engine.ReadToken (cancellationToken);

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

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

            token = engine.PeekToken (cancellationToken);

            if (token.Type == ImapTokenType.OpenParen)
                return ParseMultipart (engine, path, cancellationToken);

            var type = ParseContentType (engine, cancellationToken);
            var id = ReadNStringToken (engine, false, cancellationToken);
            var desc = ReadNStringToken (engine, true, cancellationToken);
            // Note: technically, body-fld-enc, is not allowed to be NIL, but we need to deal with broken servers...
            var enc = ReadNStringToken (engine, false, cancellationToken);
            var octets = ReadNumber (engine, cancellationToken);
            BodyPartBasic body;

            if (type.Matches ("message", "rfc822")) {
                var mesg = new BodyPartMessage ();

                // Note: GMail's support for message/rfc822 body parts is broken. Essentially,
                // GMail treats message/rfc822 parts as if they were basic body parts.
                //
                // For examples, see issue #32 and issue #59.
                //
                // The workaround is to check for the expected '(' signifying an envelope token.
                // If we do not get an '(', then we are likely looking at the Content-MD5 token
                // which gets handled below.
                token = engine.PeekToken (cancellationToken);

                if (!engine.IsGMail || token.Type == ImapTokenType.OpenParen) {
                    mesg.Envelope = ParseEnvelope (engine, cancellationToken);
                    mesg.Body = ParseBody (engine, path, cancellationToken);
                    mesg.Lines = ReadNumber (engine, cancellationToken);
                }

                body = mesg;
            } else if (type.Matches ("text", "*")) {
                var text = new BodyPartText ();
                text.Lines = ReadNumber (engine, cancellationToken);
                body = text;
            } else {
                body = new BodyPartBasic ();
            }

            body.ContentTransferEncoding = enc;
            body.ContentDescription = desc;
            body.PartSpecifier = path;
            body.ContentType = type;
            body.ContentId = id;
            body.Octets = octets;

            // if we are parsing a BODYSTRUCTURE, we may get some more tokens before the ')'
            token = engine.PeekToken (cancellationToken);

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentMd5 = ReadNStringToken (engine, false, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentDisposition = ParseContentDisposition (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentLanguage = ParseContentLanguage (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen) {
                body.ContentLocation = ParseContentLocation (engine, cancellationToken);
                token = engine.PeekToken (cancellationToken);
            }

            if (token.Type != ImapTokenType.CloseParen)
                SkipBodyExtensions (engine, cancellationToken);

            // read the ')'
            token = engine.ReadToken (cancellationToken);

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

            return body;
        }
开发者ID:rajeshwarn,项目名称:MailKit,代码行数:92,代码来源:ImapUtils.cs

示例13: UntaggedQuota

		static void UntaggedQuota (ImapEngine engine, ImapCommand ic, int index)
		{
			var format = string.Format (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "QUOTA", "{0}");
			var quotaRoot = ReadStringToken (engine, format, ic.CancellationToken);
			var ctx = (QuotaContext) ic.UserData;
			var quota = new Quota ();

			var token = engine.ReadToken (ic.CancellationToken);

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

			while (token.Type != ImapTokenType.CloseParen) {
				uint used, limit;
				string resource;

				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type != ImapTokenType.Atom)
					throw ImapEngine.UnexpectedToken (format, token);

				resource = (string) token.Value;

				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out used))
					throw ImapEngine.UnexpectedToken (format, token);

				token = engine.ReadToken (ic.CancellationToken);

				if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out limit))
					throw ImapEngine.UnexpectedToken (format, token);

				switch (resource.ToUpperInvariant ()) {
				case "MESSAGE":
					quota.CurrentMessageCount = used;
					quota.MessageLimit = limit;
					break;
				case "STORAGE":
					quota.CurrentStorageSize = used;
					quota.StorageLimit = limit;
					break;
				}

				token = engine.PeekToken (ic.CancellationToken);
			}

			// read the closing paren
			engine.ReadToken (ic.CancellationToken);

			ctx.Quotas[quotaRoot] = quota;
		}
开发者ID:jstedfast,项目名称:MailKit,代码行数:52,代码来源:ImapFolder.cs

示例14: ParseContentType

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

			value = null;

			// Note: work around broken IMAP server implementations...
			if (token.Type == ImapTokenType.OpenParen) {
				if (engine.IsGMail) {
					// 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;
				}

				// Note: In other IMAP server implementations, such as the one found in
				// https://github.com/jstedfast/MailKit/issues/371, if the server comes
				// across something like "Content-Type: X-ZIP", it will only send a
				// media-subtype token and completely fail to send a media-type token.
				subtype = type;
				type = "application";
			} else {
				subtype = ReadNStringToken (engine, format, 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 (format, token);

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

			ParseParameterList (builder, engine, format, cancellationToken);

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

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

示例15: ParseContentLanguage

		static string[] ParseContentLanguage (ImapEngine engine, CancellationToken cancellationToken)
		{
			var token = engine.ReadToken (cancellationToken);
			var languages = new List<string> ();
			string language;

			switch (token.Type) {
			case ImapTokenType.Literal:
				language = engine.ReadLiteral (cancellationToken);
				languages.Add (language);
				break;
			case ImapTokenType.QString:
			case ImapTokenType.Atom:
				language = (string) token.Value;
				languages.Add (language);
				break;
			case ImapTokenType.Nil:
				return null;
			case ImapTokenType.OpenParen:
				do {
					token = engine.PeekToken (cancellationToken);

					if (token.Type == ImapTokenType.CloseParen)
						break;

					language = ReadStringToken (engine, cancellationToken);
					languages.Add (language);
				} while (true);

				// read the ')'
				engine.ReadToken (cancellationToken);
				break;
			default:
				throw ImapEngine.UnexpectedToken (token, false);
			}

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


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