Ejemplo n.º 1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolderConstructorArgs"/> class.
		/// </summary>
		/// <param name="engine">The IMAP command engine.</param>
		/// <param name="encodedName">The encoded name.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="delim">The directory separator.</param>
		internal ImapFolderConstructorArgs (ImapEngine engine, string encodedName, FolderAttributes attributes, char delim)
		{
			FullName = engine.DecodeMailboxName (encodedName);
			Name = GetBaseName (FullName, delim);
			DirectorySeparator = delim;
			EncodedName = encodedName;
			Attributes = attributes;
			Engine = engine;
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolder"/> class.
        /// </summary>
        /// <param name="engine">The IMAP engine.</param>
        /// <param name="encodedName">The encoded name.</param>
        /// <param name="attrs">The folder attributes.</param>
        /// <param name="delim">The path delimeter.</param>
        internal ImapFolder(ImapEngine engine, string encodedName, FolderAttributes attrs, char delim)
        {
            FullName = engine.DecodeMailboxName (encodedName);
            Name = GetBaseName (FullName, delim);
            DirectorySeparator = delim;
            EncodedName = encodedName;
            Attributes = attrs;
            Engine = engine;

            engine.Disconnected += (sender, e) => {
                Access = FolderAccess.None;
            };
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Parses the X-GM-LABELS list.
		/// </summary>
		/// <returns>The message labels.</returns>
		/// <param name="engine">The IMAP engine.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		public static ReadOnlyCollection<string> ParseLabelsList (ImapEngine engine, CancellationToken cancellationToken)
		{
			var token = engine.ReadToken (cancellationToken);
			var labels = new List<string> ();

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

			// Note: GMail's IMAP implementation is broken and does not quote strings with ']' like it should.
			token = engine.ReadToken (ImapStream.GMailLabelSpecials, cancellationToken);

			while (token.Type == ImapTokenType.Flag || token.Type == ImapTokenType.Atom || token.Type == ImapTokenType.QString || token.Type == ImapTokenType.Nil) {
				// Apparently it's possible to set a NIL label in GMail...
				//
				// See https://github.com/jstedfast/MailKit/issues/244 for an example.
				if (token.Type != ImapTokenType.Nil) {
					var label = engine.DecodeMailboxName ((string) token.Value);

					labels.Add (label);
				} else {
					labels.Add (null);
				}

				token = engine.ReadToken (ImapStream.GMailLabelSpecials, cancellationToken);
			}

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

			return new ReadOnlyCollection<string> (labels);
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Parses the X-GM-LABELS list.
        /// </summary>
        /// <returns>The message labels.</returns>
        /// <param name="engine">The IMAP engine.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public static ReadOnlyCollection<string> ParseLabelsList(ImapEngine engine, CancellationToken cancellationToken)
        {
            var token = engine.ReadToken (cancellationToken);
            var labels = new List<string> ();

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

            // Note: GMail's IMAP implementation is broken and does not quote strings with ']' like it should.
            token = engine.ReadToken (ImapStream.GMailLabelSpecials, cancellationToken);

            while (token.Type == ImapTokenType.Flag || token.Type == ImapTokenType.Atom || token.Type == ImapTokenType.QString) {
                var label = engine.DecodeMailboxName ((string) token.Value);

                labels.Add (label);

                token = engine.ReadToken (cancellationToken);
            }

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

            return new ReadOnlyCollection<string> (labels);
        }