This project is read-only.

ImapX Freezing (Solved)

Topics: Issues
Dec 9, 2014 at 8:54 PM
I was having trouble with ImapX stopping while trying to access email. There were no errors or warnings, the rest of my code continued to run, but ImapX functionality was frozen. It turns out that in ImapBase.cs, the SendAndReceive function (line 326) does a reader.ReadLine() in line 358, with a StreamReader object that has an infinite timeout. It appears that the connection to the email server had been dropping out, leaving the reader waiting forever for a response it would never get. I changed the timeout value and enclosed the ReadLine function in a try-catch block as shown below. ImapX now works flawlessly for me.


SendandReceive (Line 326)

(Beginning Line 342 . . .)
StreamReader reader = encoding == null || Equals(encoding, Encoding.UTF8)
    ? _streamReader
    : new StreamReader(_ioStream, encoding);

//**********Set Timeout to some value
reader.BaseStream.ReadTimeout = 5000;

var parts = new Queue<string>(NewLineRex.Split(command));

string text = string.Format(tmpl, _counter, parts.Dequeue().Trim()) + "\r\n";
byte[] bytes = Encoding.UTF8.GetBytes(text.ToCharArray());

if (IsDebug)

_ioStream.Write(bytes, 0, bytes.Length);

while (true)
        //********New code start
        string tmp = null;

             tmp = reader.ReadLine();
        catch (IOException ex)
            //Log Exception or take other appropriate action
        //********New code end, remaining code unchanged