From 16b2eb3e004b5c88a07ebd07064dacb0743f201f Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 19 Jun 2004 04:24:38 +0000 Subject: [PATCH] cleaned up POP3 interface darcs-hash:20040619042438-5007d-7386a64230cb369fa01bf121899fa7b0938b6fa3.gz --- src/org/ibex/mail/protocol/POP3.java | 116 +++++++++++++++++----------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/src/org/ibex/mail/protocol/POP3.java b/src/org/ibex/mail/protocol/POP3.java index e34311c..a8988a4 100644 --- a/src/org/ibex/mail/protocol/POP3.java +++ b/src/org/ibex/mail/protocol/POP3.java @@ -3,11 +3,8 @@ import java.net.*; import java.io.*; // Next step: implement both sides using the POP interface +public interface POP3 { -class POPException extends IOException { -} - -interface POP { public abstract void userpass(String user, String pass) throws POPException; public abstract void apop(String user, String digest) throws POPException; public abstract BufferedReader top(int m, int maxlines); @@ -20,71 +17,72 @@ interface POP { public abstract void rset(int m); public abstract String uidl(int m); public abstract String[] uidl(); // FIXME, also needs message number -} + public static class POPException extends IOException { } -public class POP3 extends MessageProtocol { + public static class Server { - public static void main(String[] args) throws Exception { - ServerSocket ss = new ServerSocket(110); - while(true) { - System.out.println("listening"); - final Socket s = ss.accept(); - System.out.println("connected"); - new Thread() { - public void run() { - try { - service(s); - } catch (Exception e) { - e.printStackTrace(); + public static void main(String[] args) throws Exception { + ServerSocket ss = new ServerSocket(110); + while(true) { + System.out.println("listening"); + final Socket s = ss.accept(); + System.out.println("connected"); + new Thread() { + public void run() { + try { + service(s); + } catch (Exception e) { + e.printStackTrace(); + } } - } - }.start(); + }.start(); + } } - } - public static void service(Socket s) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); - PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); - pw.print("+OK POP3 server ready\r\n"); - pw.flush(); - String user = null; - String pass = null; - while(true) { - String command = br.readLine().trim(); - System.out.println("command: " + command); - if (command.toUpperCase().startsWith("QUIT ")) { - s.close(); - return; - } else if (command.toUpperCase().startsWith("USER ")) { - user = command.substring(5).trim(); - pw.print("+OK now give me your password\r\n"); - pw.flush(); - } else if (command.toUpperCase().startsWith("PASS ")) { - if (user == null) { - pw.print("-ERR I need your password first\r\n"); + public static void service(Socket s) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); + PrintWriter pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream())); + pw.print("+OK POP3 server ready\r\n"); + pw.flush(); + String user = null; + String pass = null; + while(true) { + String command = br.readLine().trim(); + System.out.println("command: " + command); + if (command.toUpperCase().startsWith("QUIT ")) { + s.close(); + return; + } else if (command.toUpperCase().startsWith("USER ")) { + user = command.substring(5).trim(); + pw.print("+OK now give me your password\r\n"); pw.flush(); - } else { - pass = command.substring(5).trim(); - break; + } else if (command.toUpperCase().startsWith("PASS ")) { + if (user == null) { + pw.print("-ERR I need your password first\r\n"); + pw.flush(); + } else { + pass = command.substring(5).trim(); + break; + } } } - } - System.out.println("login from " + user + " / " + pass); - String server = user.substring(user.indexOf('@') + 1); - user = user.substring(0, user.indexOf('@')); - Socket pop = new Socket(InetAddress.getByName(server), 117); + System.out.println("login from " + user + " / " + pass); + String server = user.substring(user.indexOf('@') + 1); + user = user.substring(0, user.indexOf('@')); + Socket pop = new Socket(InetAddress.getByName(server), 117); - BufferedReader br2 = new BufferedReader(new InputStreamReader(pop.getInputStream())); - PrintWriter pw2 = new PrintWriter(new OutputStreamWriter(pop.getOutputStream())); + BufferedReader br2 = new BufferedReader(new InputStreamReader(pop.getInputStream())); + PrintWriter pw2 = new PrintWriter(new OutputStreamWriter(pop.getOutputStream())); - System.out.println("pop said " + br2.readLine()); - pw2.print("USER " + user + "\r\n"); - pw2.flush(); - System.out.println("pop said " + br2.readLine()); - pw2.print("PASS " + pass + "\r\n"); - pw2.flush(); - System.out.println("pop said " + br2.readLine()); + System.out.println("pop said " + br2.readLine()); + pw2.print("USER " + user + "\r\n"); + pw2.flush(); + System.out.println("pop said " + br2.readLine()); + pw2.print("PASS " + pass + "\r\n"); + pw2.flush(); + System.out.println("pop said " + br2.readLine()); - s.close(); + s.close(); + } } } -- 1.7.10.4