1 package com.quadcap.pop3.client; 2 3 7 8 import java.io.File ; 9 import java.io.FileOutputStream ; 10 import java.io.InputStream ; 11 import java.io.OutputStream ; 12 13 import java.util.List ; 14 import java.util.Map ; 15 import java.util.Properties ; 16 17 import com.quadcap.io.IO; 18 19 import com.quadcap.util.Debug; 20 21 25 public class MailSuck implements MessageHook { 26 boolean delete = false; 27 OutputStream os; 28 29 32 public static void main(String [] args) { 33 MailSuck suck = new MailSuck(); 34 try { 35 if (args.length == 1) { 36 suck.runMany(args[0]); 37 } else if (args.length == 4) { 38 Pop3Agent agent = new Pop3Agent(); 39 Properties props = new Properties (); 40 props.put("daysKeep", "0"); 41 props.put("host", args[0]); 42 props.put("user", args[1]); 43 props.put("passwd", args[2]); 44 props.put("suck.outfile", args[3]); 45 props.put("delete", 46 System.getProperty("suck.delete", "false")); 47 48 suck.init(props); 49 agent.run(props, suck); 50 } 51 } catch (Throwable t) { 52 Debug.print(t); 53 } finally { 54 suck.close(); 55 } 56 } 57 58 public void runMany(String accountsFile) throws Exception { 59 List agents = Pop3Service.getTuples(new File (accountsFile)); 60 for (int i = 0; i < agents.size(); i++) { 61 try { 62 Map ai = (Map )agents.get(i); 63 Pop3Agent agent = new Pop3Agent(); 64 Properties props = new Properties (); 65 props.putAll(ai); 66 props.put("daysKeep", "0"); 67 props.put("suck.outfile", ai.get("name") + ".log"); 68 props.put("delete", 69 System.getProperty("suck.delete", "false")); 70 init(props); 71 Debug.println("Running : " + ai.get("name")); 72 agent.run(props, this); 73 close(); 74 } catch (Throwable t) { 75 System.err.print(t.toString()); 76 } 77 } 78 } 79 80 83 public void init(Properties p) throws Exception { 84 os = new FileOutputStream ( 85 p.getProperty("suck.outfile", "suck.out"), 86 true); 87 delete = p.getProperty("delete", "false").equals("true"); 88 } 89 90 void close() { 91 try { 92 os.close(); 93 } catch (Throwable t) { 94 } finally { 95 os = null; 96 } 97 } 98 99 104 public boolean passAllHeaders() { 105 return true; 106 } 107 108 113 public boolean passHeaders(Map headers) { 114 return true; 115 } 116 117 124 public boolean passMessage(InputStream is) throws Exception { 125 IO.copyStream(is, os); 126 return delete; 127 } 128 } 129 | Popular Tags |