00001
package com.quadcap.pop3.client;
00002
00003
00004
00005
00006
00007
00008
import java.io.File;
00009
import java.io.FileOutputStream;
00010
import java.io.InputStream;
00011
import java.io.OutputStream;
00012
00013
import java.util.List;
00014
import java.util.Map;
00015
import java.util.Properties;
00016
00017
import com.quadcap.io.IO;
00018
00019
import com.quadcap.util.Debug;
00020
00021
00022
00023
00024
00025 public class MailSuck implements MessageHook {
00026 boolean delete =
false;
00027 OutputStream
os;
00028
00029
00030
00031
00032 public static void main(String[] args) {
00033
MailSuck suck =
new MailSuck();
00034
try {
00035
if (args.length == 1) {
00036 suck.
runMany(args[0]);
00037 }
else if (args.length == 4) {
00038
Pop3Agent agent =
new Pop3Agent();
00039 Properties props =
new Properties();
00040 props.put(
"daysKeep",
"0");
00041 props.put(
"host", args[0]);
00042 props.put(
"user", args[1]);
00043 props.put(
"passwd", args[2]);
00044 props.put(
"suck.outfile", args[3]);
00045 props.put(
"delete",
00046 System.getProperty(
"suck.delete",
"false"));
00047
00048 suck.
init(props);
00049 agent.
run(props, suck);
00050 }
00051 }
catch (Throwable t) {
00052
Debug.print(t);
00053 } finally {
00054 suck.
close();
00055 }
00056 }
00057
00058 public void runMany(String accountsFile)
throws Exception {
00059 List agents =
Pop3Service.getTuples(
new File(accountsFile));
00060
for (
int i = 0; i < agents.size(); i++) {
00061
try {
00062 Map ai = (Map)agents.get(i);
00063
Pop3Agent agent =
new Pop3Agent();
00064 Properties props =
new Properties();
00065 props.putAll(ai);
00066 props.put(
"daysKeep",
"0");
00067 props.put(
"suck.outfile", ai.get(
"name") +
".log");
00068 props.put(
"delete",
00069 System.getProperty(
"suck.delete",
"false"));
00070
init(props);
00071
Debug.println(
"Running : " + ai.get(
"name"));
00072 agent.
run(props,
this);
00073
close();
00074 }
catch (Throwable t) {
00075 System.err.print(t.toString());
00076 }
00077 }
00078 }
00079
00080
00081
00082
00083 public void init(Properties p)
throws Exception {
00084
os =
new FileOutputStream(
00085 p.getProperty(
"suck.outfile",
"suck.out"),
00086
true);
00087
delete = p.getProperty(
"delete",
"false").equals(
"true");
00088 }
00089
00090 void close() {
00091
try {
00092
os.close();
00093 }
catch (Throwable t) {
00094 } finally {
00095
os = null;
00096 }
00097 }
00098
00099
00100
00101
00102
00103
00104 public boolean passAllHeaders() {
00105
return true;
00106 }
00107
00108
00109
00110
00111
00112
00113 public boolean passHeaders(Map headers) {
00114
return true;
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124 public boolean passMessage(InputStream is)
throws Exception {
00125
IO.copyStream(is,
os);
00126
return delete;
00127 }
00128 }