andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

IDLE command does not work properly (unstable) #135

Open Umplify opened 11 years ago

Umplify commented 11 years ago

I have instantiated ImapClient class successfully. I hooked up the two events of NewMessage and MessageDeleted to be notified when a message arrives or deleted. The code sample below implies it:

        _imapClient.NewMessage += (sender, e) =>
        {
            var msg = _imapClient.GetMessage(e.MessageCount - 1);
            Trace.TraceInformation(msg.Uid);
        };

        _imapClient.MessageDeleted += (sender, e) =>
            {
                var msg = _imapClient.GetMessage(e.MessageCount - 1);
                Trace.TraceInformation(msg.Uid);
            };

There is only one incident or two that the application is notified (even that's by chance). In rest of cases, you never receive any notifications.

patwhite commented 11 years ago

So, we found a fix for this, but I'd like to run it by someone - basically, the issue is that the "Read" command was timing out before it ever could read idle updates. But, it looked like this was by design, so I'm curious if I messed anything else up by adding an optional read timeout:

internal static string ReadLine(this Stream stream, ref int maxLength, Encoding encoding, char? termChar, int readTimeout = 10000) { if (stream.CanTimeout && readTimeout > 0) stream.ReadTimeout = readTimeout;

patwhite commented 11 years ago

Correction, did this (Utilities.cs:92):

internal static string ReadLine(this Stream stream, ref int maxLength, Encoding encoding, char? termChar, int readTimeout = 10000) { if (stream.CanTimeout) stream.ReadTimeout = readTimeout;

andyedinborough commented 11 years ago

@patwhite can you send me a pull request?