|
|
Hi all,
in my case there is a service that schould open a connection to a imap server and schould fetch a message as soon as the were received. For that i
run startIdle within a background worker and try to stop when the newmessagereceive event is published and fetch the new message after that.
But a exception is thrown afterBeginHeaderObject is called (message -> Command "DONE" failed : * 20 EXISTS), so what´s the wright ay to use IDLE?
Thanks in advance
Ralf
private void startImap()
{
idleWorker = new BackgroundWorker();
idleWorker.DoWork += new DoWorkEventHandler(StartIdleProcess);
idleWorker.RunWorkerAsync();
Console.ReadLine();
idleWorker.CancelAsync();
}
private static void StartIdleProcess(object sender, DoWorkEventArgs e)
{
// Get the BackgroundWorker that raised this event.
//BackgroundWorker worker = sender as BackgroundWorker;
if (imapClient != null && imapClient.IsConnected)
{
imapClient.StopIdle();
imapClient.Disconnect();
}
imapClient = new Imap4Client();
HeaderRetrievingEventHandler(imapClient_HeaderRetrieving);
imapClient.HeaderRetrieved += new HeaderRetrievedEventHandler(imapClient_HeaderRetrieved);
imapClient.Nooped += new NoopedEventHandler(imapClient_Nooped);
imapClient.NewMessageReceived += new NewMessageReceivedEventHandler(imapClient_NewMessageReceived);
imapClient.Connect("my.server.com");
imapClient.LoginFast("user", "password");
box = imapClient.SelectMailbox(@"Folder");
imapClient.StartIdle();
}
static void imapClient_NewMessageReceived(object sender, NewMessageReceivedEventArgs e)
{
imapClient.StopIdle();
Console.WriteLine(string.Format("{0} new message(s) were received!", e.MessageCount));
box.Fetch.BeginHeaderObject(box.FirstUnseen, null); }
|
|