]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/email/TestEmailProvider.java
Add assurance functions.
[gigi.git] / src / org / cacert / gigi / email / TestEmailProvider.java
index 9f37be97f3966bcb7091c1fa328eae5446de830f..07343502303073313a9c7002d96c8bcac39f8b23 100644 (file)
@@ -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 {