1 package com.quadcap.pop3.client; 2 3 40 41 import java.util.Date ; 42 import java.util.Hashtable ; 43 import java.util.Vector ; 44 45 import java.io.IOException ; 46 import java.io.InputStream ; 47 48 import com.quadcap.util.Debug; 49 50 import com.quadcap.util.threads.Command; 51 52 61 public class Agent implements Runnable { 62 String host; 63 String user; 64 String password; 65 Session pop3 = null; 66 67 72 public Agent(String host, String user, String password) { 73 this.host = host; 74 this.user = user; 75 this.password = password; 76 } 77 78 81 public void run() { 82 Debug.println("[" + user + "] begin"); 83 try { 84 if (pop3 == null) pop3 = new Session(host, 110); 85 pop3.connect(); 86 87 if (pop3.user(user) != Session.OK) { 88 throw new IOException ("user failed: " + user); 89 } 90 if (pop3.pass(password) != Session.OK) { 91 throw new IOException ("password failed: " + user); 92 } 93 getAndDeleteMail(); 94 } catch (IOException e) { 95 Debug.print(e); 96 97 } finally { 98 try { 99 pop3.quit(); 100 } catch (IOException e) { 101 Debug.print(e); 102 } 103 pop3 = null; 106 } 107 Debug.println("[" + user + "] done"); 108 } 109 110 114 void getAndDeleteMail() throws IOException { 115 Vector r = pop3.stat(); 116 int cnt = Integer.parseInt(r.elementAt(1).toString()); 117 byte[] buf = new byte[16384]; 118 for (int i = 1; i <= cnt; i++) { 119 Debug.println("[" + user + "] getting message " + i); 120 InputStream is = pop3.retr(i); 121 if (is != null) { 122 int xcnt = 0; 123 while ((xcnt = is.read(buf)) > 0) continue; 124 is.close(); 125 } 126 pop3.dele(i); 127 } 128 Debug.println("[" + user + "] deleted " + cnt + " messages"); 129 } 130 131 public static void main(String [] args) { 132 while (true) { 133 for (int i = 0; i < 100; i++) { 134 Agent agent = new Agent("nt1", "stan"+i, "stan"+i); 135 agent.run(); 136 } 137 } 138 } 139 } 140 141 | Popular Tags |