private ImapMessageInfo GetMessage(ImapSequenceSet sequenceOrUidSet, ImapMessageFetchAttributeOptions options)
        {
            var message = (new ImapMessageInfoList(this, options, sequenceOrUidSet)).FirstOrDefault();

              if (message == null)
            throw new ImapMessageNotFoundException(sequenceOrUidSet);

              return message;
        }
 public ImapMessageInfoList WaitForMessageArrival(TimeSpan pollingInterval,
                                              TimeSpan timeout,
                                              ImapMessageFetchAttributeOptions options)
 {
     return WaitForMessageArrival((int)pollingInterval.TotalMilliseconds,
                            (int)timeout.TotalMilliseconds,
                            options);
 }
        public ImapMessageInfoList WaitForMessageArrival(int millisecondsPollingInterval,
                                                     int millisecondsTimeout,
                                                     ImapMessageFetchAttributeOptions options)
        {
            if (millisecondsTimeout < -1)
            throw new ArgumentOutOfRangeException("millisecondsTimeout", millisecondsTimeout, "must be greater than or equals to -1");

              var asyncResult = BeginWaitForMessageArrival(millisecondsPollingInterval, options, null, null);

              asyncResult.AsyncWaitHandle.WaitOne(millisecondsTimeout, false);

              return EndWaitForMessageArrival(asyncResult);
        }
        public ImapMessageInfoList GetSortedMessages(ImapSortCriteria sortOrder,
                                                 ImapSearchCriteria searchCriteria,
                                                 Encoding encoding,
                                                 ImapMessageFetchAttributeOptions options)
        {
            if (sortOrder == null)
            throw new ArgumentNullException("sortOrder");
              if (searchCriteria == null)
            throw new ArgumentNullException("searchCriteria");

              Client.ThrowIfIncapable(ImapCapability.Sort);

              return new ImapMessageInfoList(this, options, new SortMessageQuery(sortOrder, searchCriteria, encoding));
        }
 public ImapMessageInfoList WaitForMessageArrival(int millisecondsTimeout,
                                              ImapMessageFetchAttributeOptions options)
 {
     return WaitForMessageArrival(defaultPollingInterval,
                            millisecondsTimeout,
                            options);
 }
        private void TestMessages(string fetchResponse, ImapMessageFetchAttributeOptions options, Action<ImapPseudoServer, ImapMessageInfo[]> action)
        {
            var selectResp = "$tag OK [READ-WRITE] done\r\n";

              TestUtils.TestOpenedMailbox(new[] {ImapCapability.ESearch, ImapCapability.Searchres},
                                  "INBOX",
                                  selectResp,
                                  delegate(ImapPseudoServer server, ImapOpenedMailboxInfo mailbox) {
            // SEARCH
            server.EnqueueTaggedResponse("$tag OK done\r\n");
            // FETCH
            server.EnqueueTaggedResponse(fetchResponse);

            var messages = new List<ImapMessageInfo>(mailbox.GetMessages(ImapSearchCriteria.All, options));

            server.DequeueRequest(); // SEARCH
            server.DequeueRequest(); // FETCH

            action(server, messages.ToArray());
              });
        }
 public ImapMessageInfoList GetSortedMessages(ImapSortCriteria sortOrder,
                                          ImapSearchCriteria searchCriteria,
                                          ImapMessageFetchAttributeOptions options)
 {
     return GetSortedMessages(sortOrder, searchCriteria, null, options);
 }
 public ImapMessageInfoList GetMessages(ImapMessageFetchAttributeOptions options, long uid, params long[] uids)
 {
     return new ImapMessageInfoList(this, options, ImapSequenceSet.CreateUidSet(uid, uids));
 }
 public ImapMessageInfoList GetMessages(ImapSearchCriteria searchCriteria,
                                    ImapMessageFetchAttributeOptions options)
 {
     return GetMessages(searchCriteria, null, options);
 }
        public ImapMessageInfo GetMessageByUid(long uid, ImapMessageFetchAttributeOptions options)
        {
            if (uid <= 0L)
            throw new ArgumentOutOfRangeException("uid", uid, "uid must be non-zero positive number");

              /*
               * 6.4.8. UID Command
               *       A non-existent unique identifier is ignored without any error
               *       message generated.  Thus, it is possible for a UID FETCH command
               *       to return an OK without any data or a UID COPY or UID STORE to
               *       return an OK without performing any operations.
               */
              return GetMessage(ImapSequenceSet.CreateUidSet(uid), options);
        }
 public ImapMessageInfoList GetMessages(ImapMessageFetchAttributeOptions options)
 {
     return new ImapMessageInfoList(this, options, new AllMessageQuery());
 }
        public ImapMessageInfo GetMessageBySequence(long sequence, ImapMessageFetchAttributeOptions options)
        {
            if (sequence <= 0L)
            throw new ArgumentOutOfRangeException("sequence", sequence, "sequence must be non-zero positive number");

              // Refresh();

              if (ExistMessageCount < sequence)
            throw new ArgumentOutOfRangeException("sequence",
                                              sequence,
                                              string.Format("specified sequence number is greater than exist message count. (exist message count = {0})",
                                                             ExistMessageCount));

              return GetMessage(ImapSequenceSet.CreateSet(sequence), options);
        }
        public IAsyncResult BeginWaitForMessageArrival(int millisecondsPollingInterval,
                                                   ImapMessageFetchAttributeOptions options,
                                                   object asyncState,
                                                   AsyncCallback asyncCallback)
        {
            if (millisecondsPollingInterval <= 0)
            throw new ArgumentOutOfRangeException("millisecondsPollingInterval", millisecondsPollingInterval, "must be non-zero positive number");
              if (waitForMessageArrivalAsyncResult != null)
            throw new InvalidOperationException("another operation proceeding");

              var isIdleCapable = Client.ServerCapabilities.Has(ImapCapability.Idle);

              if (!isIdleCapable && maximumPollingInterval <= millisecondsPollingInterval)
            throw new ArgumentOutOfRangeException("millisecondsPollingInterval",
                                              millisecondsPollingInterval,
                                              string.Format("maximum interval is {0} but requested was {1}", maximumPollingInterval, millisecondsPollingInterval));

              var proc = isIdleCapable
            ? new WaitForMessageArrivalProc(WaitForMessageArrivalIdle)
            : new WaitForMessageArrivalProc(WaitForMessageArrivalNoOp);

              waitForMessageArrivalAsyncResult = new WaitForMessageArrivalAsyncResult(millisecondsPollingInterval,
                                                                              Mailbox,
                                                                              options,
                                                                              proc,
                                                                              asyncState,
                                                                              asyncCallback);

              waitForMessageArrivalAsyncResult.BeginProc();

              return waitForMessageArrivalAsyncResult;
        }
 public IAsyncResult BeginWaitForMessageArrival(TimeSpan pollingInterval,
                                            ImapMessageFetchAttributeOptions options,
                                            object asyncState,
                                            AsyncCallback asyncCallback)
 {
     return BeginWaitForMessageArrival((int)pollingInterval.TotalMilliseconds,
                                 options,
                                 asyncState,
                                 asyncCallback);
 }
 public WaitForMessageArrivalAsyncResult(int pollingInterval,
                                   ImapMailbox mailbox,
                                   ImapMessageFetchAttributeOptions fetchOptions,
                                   WaitForMessageArrivalProc proc,
                                   object asyncState,
                                   AsyncCallback asyncCallback)
     : base(pollingInterval, mailbox, fetchOptions)
 {
     this.proc = proc;
     this.AsyncState = asyncState;
     this.asyncCallback = asyncCallback;
 }
        public ImapMessageInfoList GetMessages(ImapSearchCriteria searchCriteria,
                                           Encoding encoding,
                                           ImapMessageFetchAttributeOptions options)
        {
            if (searchCriteria == null)
            throw new ArgumentNullException("searchCriteria");

              return new ImapMessageInfoList(this, options, new SearchMessageQuery(searchCriteria, encoding));
        }
 public WaitForMessageArrivalContext(int pollingInterval,
                               ImapMailbox mailbox,
                               ImapMessageFetchAttributeOptions fetchOptions)
 {
     this.PollingInterval = pollingInterval;
     this.Mailbox = mailbox;
     this.CurrentMessageCount = mailbox.ExistsMessage;
     this.FetchOptions = fetchOptions;
 }
Exemple #18
0
 private void TestMessage(string fetchResponse, ImapMessageFetchAttributeOptions options, Action<ImapPseudoServer, ImapMessageInfo> action)
 {
     TestMessages(fetchResponse, options, delegate(ImapPseudoServer server, ImapMessageInfo[] messages) {
     action(server, messages.First());
       });
 }