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;
12 * This class intercepts emails so that the test cases can evaluate them
15 public class TestEmailProvider extends EmailProvider {
17 private ServerSocket servs;
19 private Socket client;
21 private DataOutputStream out;
23 private DataInputStream in;
25 protected TestEmailProvider(Properties props) {
27 servs = new ServerSocket(Integer.parseInt(props.getProperty("emailProvider.port")), 10, InetAddress.getByName("127.0.0.1"));
28 } catch (IOException e) {
34 public synchronized void sendmail(String to, String subject, String message, String from, String replyto, String toname, String fromname, String errorsto, boolean extra) throws IOException {
36 assureLocalConnection();
46 } catch (IOException e) {
52 private void assureLocalConnection() throws IOException {
56 } catch (IOException e) {
60 if (client == null || client.isClosed()) {
61 client = servs.accept();
62 out = new DataOutputStream(client.getOutputStream());
63 in = new DataInputStream(client.getInputStream());
68 public synchronized String checkEmailServer(int forUid, String address) throws IOException {
70 assureLocalConnection();
72 out.writeUTF("challengeAddrBox");
73 out.writeUTF(address);
75 } catch (IOException e) {
81 private void write(String to) throws IOException {
83 out.writeUTF("<null>");