protected ImapMessageInfoBase(ImapOpenedMailboxInfo mailbox)
        {
            if (mailbox == null)
            throw new ArgumentNullException("mailbox");

              this.Mailbox = mailbox;
              this.UidValidity = mailbox.UidValidity; // save current UIDVALIDITY
        }
        public ImapMailboxSizeChangedEventArgs(ImapOpenedMailboxInfo mailbox,
                                           long currentCount,
                                           long prevCount)
        {
            if (mailbox == null)
            throw new ArgumentNullException("mailbox");
              if (currentCount < 0L)
            throw new ArgumentOutOfRangeException("currentCount", currentCount, "must be zero or positive number");
              if (prevCount < 0L)
            throw new ArgumentOutOfRangeException("prevCount", prevCount, "must be zero or positive number");

              this.Mailbox = mailbox;
              this.CurrentCount = currentCount;
              this.PrevCount = prevCount;
        }
 public MessageSet(ImapOpenedMailboxInfo mailbox, ImapSequenceSet sequenceOrUidSet)
     : base(mailbox)
 {
     this.sequenceOrUidSet = sequenceOrUidSet;
 }
            public ImapSequenceSet GetSequenceOrUidSet(ImapOpenedMailboxInfo mailbox)
            {
                ImapMatchedSequenceSet matchedSequenceNumbers;

                mailbox.ProcessResult(mailbox.Client.Session.Sort(sortOrder,
                                                          searchCriteria,
                                                          encoding,
                                                          out matchedSequenceNumbers));

                return matchedSequenceNumbers;
            }
            public ImapSequenceSet GetSequenceOrUidSet(ImapOpenedMailboxInfo mailbox)
            {
                ImapMatchedSequenceSet matchedSequenceNumbers;

                if (mailbox.Client.IsCapable(ImapCapability.Searchres))
                  mailbox.ProcessResult(mailbox.Client.Session.ESearch(searchCriteria,
                                                               encoding,
                                                               ImapSearchResultOptions.Save,
                                                               out matchedSequenceNumbers));
                else
                  mailbox.ProcessResult(mailbox.Client.Session.Search(searchCriteria,
                                                              encoding,
                                                              out matchedSequenceNumbers));

                return matchedSequenceNumbers;
            }
 public ImapSequenceSet GetSequenceOrUidSet(ImapOpenedMailboxInfo mailbox)
 {
     return sequenceSet;
 }
            public ImapSequenceSet GetSequenceOrUidSet(ImapOpenedMailboxInfo mailbox)
            {
                mailbox.Refresh();

                if (mailbox.ExistMessageCount <= 0L)
                  return ImapSequenceSet.CreateSet(new long[0]);
                else
                  return ImapSequenceSet.CreateRangeSet(1L, mailbox.ExistMessageCount);
            }
        /*
         * CLOSE
         */
        public void CloseMailbox()
        {
            /*
               *       The CLOSE command permanently removes all messages that have the
               *       \Deleted flag set from the currently selected mailbox, and returns
               *       to the authenticated state from the selected state.  No untagged
               *       EXPUNGE responses are sent.
               *
               *       No messages are removed, and no error is given, if the mailbox is
               *       selected by an EXAMINE command or is otherwise selected read-only.
               */
              if (Session.SelectedMailbox != null)
            ThrowIfError(Session.Close());

              openedMailbox = null;
        }
        internal void RaiseRecentMessageCountChanged(ImapOpenedMailboxInfo mailbox, long prevCount)
        {
            var ev = RecentMessageCountChanged;

              if (ev != null)
            ev(this, new ImapMailboxSizeChangedEventArgs(mailbox, mailbox.RecentMessageCount, prevCount));
        }
        public ImapOpenedMailboxInfo OpenMailbox(ImapMailboxInfo mailbox, bool readOnly)
        {
            if (mailbox == null)
            throw new ArgumentNullException("mailbox");
              if (!mailbox.Exists)
            throw new ImapProtocolViolationException("mailbox is not existent");
              else if (mailbox.IsUnselectable)
            throw new ImapProtocolViolationException("mailbox is not existent");

              if (ServerCapabilities.Has(ImapCapability.CondStore))
            ThrowIfError(readOnly
                     ? Session.ExamineCondStore(mailbox.FullName)
                     : Session.SelectCondStore(mailbox.FullName));
              else
            ThrowIfError(readOnly
                     ? Session.Examine(mailbox.FullName)
                     : Session.Select(mailbox.FullName));

              openedMailbox = new ImapOpenedMailboxInfo(this, Session.SelectedMailbox);

              return openedMailbox;
        }