X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Femail%2FTestEmailProvider.java;h=07343502303073313a9c7002d96c8bcac39f8b23;hb=1cfb44d81a7d919db6670a06b0832c7b398005be;hp=9f37be97f3966bcb7091c1fa328eae5446de830f;hpb=093f4797bc1e84c4963a67093f2b21393656edab;p=gigi.git diff --git a/src/org/cacert/gigi/email/TestEmailProvider.java b/src/org/cacert/gigi/email/TestEmailProvider.java index 9f37be97..07343502 100644 --- a/src/org/cacert/gigi/email/TestEmailProvider.java +++ b/src/org/cacert/gigi/email/TestEmailProvider.java @@ -26,13 +26,8 @@ class TestEmailProvider extends EmailProvider { public synchronized void sendmail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException { - boolean sent = false; - while (!sent) { - if (client == null || client.isClosed()) { - client = servs.accept(); - out = new DataOutputStream(client.getOutputStream()); - in = new DataInputStream(client.getInputStream()); - } + while (true) { + assureLocalConnection(); try { out.writeUTF("mail"); write(to); @@ -41,18 +36,39 @@ class TestEmailProvider extends EmailProvider { write(from); write(replyto); out.flush(); - sent = true; + return; } catch (IOException e) { client = null; } } } + private void assureLocalConnection() throws IOException { + if (out != null) { + try { + out.writeUTF("ping"); + } catch (IOException e) { + client = null; + } + } + if (client == null || client.isClosed()) { + client = servs.accept(); + out = new DataOutputStream(client.getOutputStream()); + in = new DataInputStream(client.getInputStream()); + } + } @Override - public String checkEmailServer(int forUid, String address) + public synchronized String checkEmailServer(int forUid, String address) throws IOException { - out.writeUTF("challengeAddrBox"); - out.writeUTF(address); - return in.readUTF(); + while (true) { + assureLocalConnection(); + try { + out.writeUTF("challengeAddrBox"); + out.writeUTF(address); + return in.readUTF(); + } catch (IOException e) { + client = null; + } + } } private void write(String to) throws IOException {