1 package org.ibex.mail.protocol;
5 // Next step: implement both sides using the POP interface
6 public interface POP3 {
8 public abstract void userpass(String user, String pass) throws POPException;
9 public abstract void apop(String user, String digest) throws POPException;
10 public abstract BufferedReader top(int m, int maxlines);
11 public abstract BufferedReader retr(int m);
12 public abstract long stat(); // top 32 bits is number of messages, bottom 32 is total size
13 public abstract long[] list(); // top 32 bits is message number, bottom 32 is size
14 public abstract long list(int m);
15 public abstract void dele(int m);
16 public abstract void noop(int m);
17 public abstract void rset(int m);
18 public abstract String uidl(int m);
19 public abstract String[] uidl(); // FIXME, also needs message number
20 public static class POPException extends IOException { }
22 public static class Server {
24 public static void main(String[] args) throws Exception {
25 ServerSocket ss = new ServerSocket(110);
27 System.out.println("listening");
28 final Socket s = ss.accept();
29 System.out.println("connected");
34 } catch (Exception e) {
42 public static void service(Socket s) throws IOException {
43 BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
44 PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
45 pw.print("+OK POP3 server ready\r\n");
50 String command = br.readLine().trim();
51 System.out.println("command: " + command);
52 if (command.toUpperCase().startsWith("QUIT ")) {
55 } else if (command.toUpperCase().startsWith("USER ")) {
56 user = command.substring(5).trim();
57 pw.print("+OK now give me your password\r\n");
59 } else if (command.toUpperCase().startsWith("PASS ")) {
61 pw.print("-ERR I need your password first\r\n");
64 pass = command.substring(5).trim();
69 System.out.println("login from " + user + " / " + pass);
70 String server = user.substring(user.indexOf('@') + 1);
71 user = user.substring(0, user.indexOf('@'));
72 Socket pop = new Socket(InetAddress.getByName(server), 117);
74 BufferedReader br2 = new BufferedReader(new InputStreamReader(pop.getInputStream()));
75 PrintWriter pw2 = new PrintWriter(new OutputStreamWriter(pop.getOutputStream()));
77 System.out.println("pop said " + br2.readLine());
78 pw2.print("USER " + user + "\r\n");
80 System.out.println("pop said " + br2.readLine());
81 pw2.print("PASS " + pass + "\r\n");
83 System.out.println("pop said " + br2.readLine());