Пример #1
0
        private void WatchIdleQueue()
        {
            try
            {
                string last = null, resp;

                while (true)
                {
                    if (!TryGetResponse(out resp, idleTimeout))
                    {   //send NOOP every 20 minutes
                        NoopAsync(false);        //call noop without aborting this Idle thread
                        continue;
                    }

                    if (resp.Contains("OK IDLE"))
                        return;

                    var data = resp.Split(' ');
                    if (data[0] == "*" && data.Length >= 3)
                    {
                        var e = new MessageEventArgs { Client = this, MessageCount = int.Parse(data[1]) };
                        if (data[2].Is("EXISTS") && !last.Is("EXPUNGE") && e.MessageCount > 0)
                        {
                            ThreadPool.QueueUserWorkItem(callback => _NewMessage.Fire(this, e));    //Fire the event on a separate thread
                        }
                        else if (data[2].Is("EXPUNGE"))
                        {
                            _MessageDeleted.Fire(this, e);
                        }
                        last = data[2];
                    }
                }
            }
            catch (Exception) { }
        }
Пример #2
0
 async Task imap_NewMessage(object sender, MessageEventArgs e)
 {
     var imap = (sender as ImapClient);
     var msg = await imap.GetMessageAsync(e.MessageCount - 1);
     Console.WriteLine(msg.Subject);
 }