コード例 #1
0
ファイル: ImapClient.cs プロジェクト: Metric/S22.Imap
		/// <summary>
		/// Selects a mailbox so that messages in the mailbox can be accessed.
		/// </summary>
		/// <param name="mailbox">The mailbox to select. If this parameter is null, the
		/// default mailbox is selected.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mailbox could
		/// not be selected. The message property of the exception contains the error message
		/// returned by the server.</exception>
		public Mailbox Select(string mailbox) {
			if (!Authed)
				throw new NotAuthenticatedException();
			if (mailbox == null)
				mailbox = defaultMailbox;
			/* requested mailbox is already selected */
            if (selectedMailbox != null)
            {
                if (selectedMailbox.ToUpper() == mailbox.ToUpper())
                    return this.currentMailbox;
            }

			lock (sequenceLock) {
				
                /* Variables Needed */
                int messages = 0;
                List<string> flags = new List<string>();
                long uidvalidity = 0, uidnext = 0;

				string tag = GetTag();
				string response = SendCommandGetResponse(tag + "SELECT " +
					mailbox.QuoteString());
				/* evaluate untagged data */
				while (response.StartsWith("*")) {
                    Match m = ImapParsing.SelectExists.Match(response);
                    if (m.Success)
                        messages = Convert.ToInt32(m.Groups[1].Value);

                    m = ImapParsing.SelectUIDValidity.Match(response);
                    if (m.Success)
                        uidvalidity = Convert.ToInt64(m.Groups[1].Value);

                    m = ImapParsing.SelectUIDNext.Match(response);
                    if (m.Success)
                        uidnext = Convert.ToInt64(m.Groups[1].Value);

                    m = ImapParsing.SelectFlags.Match(response);
                    if (m.Success)
                    {
                        flags = m.Groups[1].Value.Split(' ').ToList();
                    }

					response = GetResponse();
				}
				if (!IsResponseOK(response, tag))
					throw new BadServerResponseException(response);
				selectedMailbox = mailbox;

                /* Collect quota information if server supports it */
                UInt64 usedStorage = 0, freeStorage = 0;

                List<long> ids = this.Search(SearchCondition.Unseen());
                MailboxStatus status = new MailboxStatus(messages, ids.Count, usedStorage, freeStorage, uidvalidity, uidnext);
                Mailbox cMailbox = new Mailbox(selectedMailbox, status, flags);
                this.currentMailbox = cMailbox;
     
                return cMailbox;
            }
		}
コード例 #2
0
ファイル: Mailbox.cs プロジェクト: Metric/S22.Imap
        /// <summary>
		/// Initializes a new Mailbox instance with the specified name, mailboxstatus and messageflags
		/// </summary>
		/// <param name="name">The name of the mailbox.</param>
		/// <param name="status">The mailbox status.</param>
		/// <param name="flags">The flags associated with the mailbox.</param>
		internal Mailbox(string name, MailboxStatus status, List<string> flags) {
            this.Name = name;
            this.Status = status;
            this.Flags = flags;
		}