1 package org.cacert.gigi.email;
3 import java.io.DataInputStream;
4 import java.io.DataOutputStream;
5 import java.io.IOException;
6 import java.net.InetAddress;
7 import java.net.ServerSocket;
8 import java.net.Socket;
9 import java.util.Properties;
11 class TestEmailProvider extends EmailProvider {
13 private ServerSocket servs;
15 private Socket client;
17 private DataOutputStream out;
19 private DataInputStream in;
21 protected TestEmailProvider(Properties props) {
23 servs = new ServerSocket(Integer.parseInt(props.getProperty("emailProvider.port")), 10, InetAddress.getByName("127.0.0.1"));
24 } catch (IOException e) {
30 public synchronized void sendmail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
32 assureLocalConnection();
42 } catch (IOException e) {
48 private void assureLocalConnection() throws IOException {
52 } catch (IOException e) {
56 if (client == null || client.isClosed()) {
57 client = servs.accept();
58 out = new DataOutputStream(client.getOutputStream());
59 in = new DataInputStream(client.getInputStream());
64 public synchronized String checkEmailServer(int forUid, String address) throws IOException {
66 assureLocalConnection();
68 out.writeUTF("challengeAddrBox");
69 out.writeUTF(address);
71 } catch (IOException e) {
77 private void write(String to) throws IOException {
79 out.writeUTF("<null>");