X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fcacert%2Fgigi%2Femail%2FTestEmailProvider.java;h=7beaa9a98001bf190cbe79546cc8ea3601473a69;hb=fb38a9c8b9d86289213a36bd3d2afddc58ec7d3f;hp=35c4b3fe81351af1aaf6df7a44a983899a92ee30;hpb=2824d1c165c501e2f3a8809044788b33b81f478a;p=gigi.git diff --git a/src/org/cacert/gigi/email/TestEmailProvider.java b/src/org/cacert/gigi/email/TestEmailProvider.java index 35c4b3fe..7beaa9a9 100644 --- a/src/org/cacert/gigi/email/TestEmailProvider.java +++ b/src/org/cacert/gigi/email/TestEmailProvider.java @@ -9,75 +9,77 @@ import java.net.Socket; import java.util.Properties; class TestEmailProvider extends EmailProvider { - ServerSocket servs; - Socket client; - DataOutputStream out; - DataInputStream in; - protected TestEmailProvider(Properties props) { - try { - servs = new ServerSocket(Integer.parseInt(props.getProperty("emailProvider.port")), 10, - InetAddress.getByName("127.0.0.1")); - } catch (IOException e) { - e.printStackTrace(); - } - } + private ServerSocket servs; - @Override - public synchronized void sendmail(String to, String subject, String message, String from, String replyto, - String toname, String fromname, String errorsto, boolean extra) throws IOException { - while (true) { - assureLocalConnection(); - try { - out.writeUTF("mail"); - write(to); - write(subject); - write(message); - write(from); - write(replyto); - out.flush(); - return; - } catch (IOException e) { - client = null; - } - } - } + private Socket client; - 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()); - } - } + private DataOutputStream out; - @Override - public synchronized String checkEmailServer(int forUid, String address) throws IOException { - while (true) { - assureLocalConnection(); - try { - out.writeUTF("challengeAddrBox"); - out.writeUTF(address); - return in.readUTF(); - } catch (IOException e) { - client = null; - } - } - } + private DataInputStream in; - private void write(String to) throws IOException { - if (to == null) { - out.writeUTF(""); - } else { - out.writeUTF(to); - } - } + protected TestEmailProvider(Properties props) { + try { + servs = new ServerSocket(Integer.parseInt(props.getProperty("emailProvider.port")), 10, InetAddress.getByName("127.0.0.1")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public synchronized void sendmail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException { + while (true) { + assureLocalConnection(); + try { + out.writeUTF("mail"); + write(to); + write(subject); + write(message); + write(from); + write(replyto); + out.flush(); + 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 synchronized String checkEmailServer(int forUid, String address) throws IOException { + 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 { + if (to == null) { + out.writeUTF(""); + } else { + out.writeUTF(to); + } + } }