Exemple #1
0
 internal void RaiseNewMessagesArrived(IdleEventArgs args)
 {
     if (OnNewMessagesArrived == null)
     {
         return;
     }
     OnNewMessagesArrived(this, args);
 }
Exemple #2
0
        private void ProcessIdleServerEvents()
        {
            while (true)
            {
                string tmp;
                if (!_idleEvents.TryDequeue(out tmp))
                {
                    if (_idleState == IdleState.On)
                    {
                        // instead of an instant retry: wait for a signal that will be emitted after a new value was put into the queue
                        _idleEventsResetEvent.WaitOne();
                        continue;
                    }
                    return;
                }


                Match match = Expressions.IdleResponseRex.Match(tmp);

                if (!match.Success)
                {
                    continue;
                }

                if (match.Groups[2].Value == "EXISTS")
                {
                    SelectedFolder.Status(new[] { FolderStatusFields.UIdNext });

                    if (_lastIdleUId != SelectedFolder.UidNext)
                    {
                        var msgs =
                            SelectedFolder.Search(string.Format("UID {0}:{1}", _lastIdleUId, SelectedFolder.UidNext));
                        var args = new IdleEventArgs
                        {
                            Folder   = SelectedFolder,
                            Messages = msgs
                        };
                        if (OnNewMessagesArrived != null)
                        {
                            OnNewMessagesArrived(SelectedFolder, args);
                        }
                        SelectedFolder.RaiseNewMessagesArrived(args);
                        _lastIdleUId = SelectedFolder.UidNext;
                    }
                }
            }
        }