9 static ServerSocket ssock;
11 private static PrintWriter os=null;
12 private static InputStreamReader ir=null;
13 private static Socket s=null;
14 private static BufferedReader br=null;
16 private static void give_capabilities() throws IOException
18 String []list = Sasl.getMechanismNames();
20 String cap="* CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ NAMESPACE UIDPLUS X-NON-HIERARCHICAL-RENAME NO_ATOMIC_RENAME";
22 for (int lup=0;lup<list.length;lup++)
23 cap+= (" AUTH="+list[lup]);
30 private static void do_auth(String mech, Socket remoteclient, int minssf, int maxssf) throws IOException
33 Hashtable props = new Hashtable();
34 props.put("javax.security.sasl.encryption.minimum",String.valueOf(minssf));
35 props.put("javax.security.sasl.encryption.maximum",String.valueOf(maxssf));
36 props.put("javax.security.sasl.ip.local",s.getLocalAddress().getHostName());
37 props.put("javax.security.sasl.ip.remote",
38 remoteclient.getInetAddress().getHostAddress());
40 ServerHandler cbh = new ServerHandler();
44 SaslServer saslconn = Sasl.CreateSaslServer(mech,
46 s.getLocalAddress().getHostName(),
54 byte[] out = saslconn.evaluateResponse(in);
56 if (saslconn.isComplete()==true) {
59 String outline = "+ ";
61 System.out.println("outlen = "+ (out.length));
62 outline = "+ "+SaslUtils.encode64(out);
67 String line = br.readLine();
69 System.out.println("in = "+line);
72 in = SaslUtils.decode64(line);
77 send(". OK Authenticated");
79 System.out.println("Authenticated!!!\n");
81 } catch (SaslException e) {
82 send(". NO Authentication failed");
86 private static void pretend_to_be_imapd() throws IOException
90 send("* OK pretend imapd. Use the '.' tag");
97 System.out.println("I think the client quit on us");
101 if (line.startsWith(". ")==false) {
102 send("* BAD Must use '.' tag");
106 line=line.substring(2);
108 if (line.equalsIgnoreCase("CAPABILITY")==true) {
115 if (line.toUpperCase().startsWith("AUTHENTICATE ")==true) {
116 line = line.substring(13);
118 System.out.println("mechanism = "+line);
125 if (line.equalsIgnoreCase("NOOP")==true) {
130 if (line.equalsIgnoreCase("LOGOUT")==true) {
132 send(". OK yeah i'll exit. seya");
137 send("* BAD don't support whatever you tried");
144 static void send(String str)
146 os.print(str+"\r\n");
150 public static void main (String args[])
156 ssock = new ServerSocket(port);
158 System.out.println("Listening on port "+port);
161 os=new PrintWriter(s.getOutputStream());
162 ir=new InputStreamReader(s.getInputStream());
163 br=new BufferedReader(ir);
166 pretend_to_be_imapd();
168 } catch (IOException e) {
169 System.out.println("IO exception");