diff --git a/app/src/main/java/com/sun/mail/iap/ResponseInputStream.java b/app/src/main/java/com/sun/mail/iap/ResponseInputStream.java index 9e05b18f1f..dc6f65078b 100644 --- a/app/src/main/java/com/sun/mail/iap/ResponseInputStream.java +++ b/app/src/main/java/com/sun/mail/iap/ResponseInputStream.java @@ -75,8 +75,23 @@ public class ResponseInputStream { boolean gotCRLF=false; // Read a CRLF terminated line from the InputStream - while (!gotCRLF && - ((b = bin.read()) != -1)) { + int wait = 1; + while (!gotCRLF) { + b = bin.read(); + if (b == -1) { + wait *= 10; + if (wait > 1000) + throw new IOException("Connection dropped by server?" , + new Throwable(new String(buffer, 0, idx))); + else + try { + Thread.sleep(wait); + continue; + } catch (InterruptedException ex) { + eu.faircode.email.Log.w(ex); + } + } else + wait = 1; if (b == '\n') { if ((idx > 0) && buffer[idx-1] == '\r') gotCRLF = true; @@ -91,9 +106,6 @@ public class ResponseInputStream { buffer[idx++] = (byte)b; } - if (b == -1) - throw new IOException("Connection dropped by server?"); - // Now lets check for literals : {}CRLF // Note: index needs to >= 5 for the above sequence to occur if (idx < 5 || buffer[idx-3] != '}') @@ -131,10 +143,23 @@ public class ResponseInputStream { * so call repeatedly till we are done */ int actual; + wait = 1; while (count > 0) { actual = bin.read(buffer, idx, count); - if (actual == -1) - throw new IOException("Connection dropped by server?"); + if (actual == -1) { + wait *= 10; + if (wait > 1000) + throw new IOException("Connection dropped by server?" , + new Throwable(new String(buffer, 0, idx))); + else + try { + Thread.sleep(wait); + continue; + } catch (InterruptedException ex) { + eu.faircode.email.Log.w(ex); + } + } else + wait = 1; count -= actual; idx += actual; }