@@ -65,7 +65,7 @@ public static void main(String[] args)
65
65
if (argCount < 3 )
66
66
{
67
67
System .err .println (
68
- "Usage: POP3Mail [-F file] <server[:port]> <username> <password|-|*|VARNAME> [TLS [true=implicit]]" );
68
+ "Usage: POP3Mail [-F file/directory ] <server[:port]> <username> <password|-|*|VARNAME> [TLS [true=implicit]]" );
69
69
System .exit (1 );
70
70
}
71
71
@@ -137,13 +137,23 @@ public static void main(String[] args)
137
137
if (file != null ) {
138
138
System .out .println ("Getting messages: " + count );
139
139
File mbox = new File (file );
140
- System .out .println ("Writing: " + mbox );
141
- // Currently POP3Client uses iso-8859-1
142
- OutputStreamWriter fw = new OutputStreamWriter (new FileOutputStream (mbox ),Charset .forName ("iso-8859-1" ));
143
- for (int i = 1 ; i <= count ; i ++) {
144
- writeMbox (pop3 , fw , i );
140
+ if (mbox .isDirectory ()) {
141
+ System .out .println ("Writing dir: " + mbox );
142
+ // Currently POP3Client uses iso-8859-1
143
+ for (int i = 1 ; i <= count ; i ++) {
144
+ OutputStreamWriter fw = new OutputStreamWriter (new FileOutputStream (new File (mbox ,i +".eml" )),Charset .forName ("iso-8859-1" ));
145
+ writeFile (pop3 , fw , i );
146
+ fw .close ();
147
+ }
148
+ } else {
149
+ System .out .println ("Writing file: " + mbox );
150
+ // Currently POP3Client uses iso-8859-1
151
+ OutputStreamWriter fw = new OutputStreamWriter (new FileOutputStream (mbox ),Charset .forName ("iso-8859-1" ));
152
+ for (int i = 1 ; i <= count ; i ++) {
153
+ writeMbox (pop3 , fw , i );
154
+ }
155
+ fw .close ();
145
156
}
146
- fw .close ();
147
157
}
148
158
149
159
pop3 .logout ();
@@ -156,6 +166,17 @@ public static void main(String[] args)
156
166
}
157
167
}
158
168
169
+ private static void writeFile (POP3Client pop3 , OutputStreamWriter fw , int i ) throws IOException {
170
+ BufferedReader r = (BufferedReader ) pop3 .retrieveMessage (i );
171
+ String line ;
172
+ while ((line = r .readLine ()) != null )
173
+ {
174
+ fw .write (line );
175
+ fw .write ("\n " );
176
+ }
177
+ r .close ();
178
+ }
179
+
159
180
private static void writeMbox (POP3Client pop3 , OutputStreamWriter fw , int i ) throws IOException {
160
181
final SimpleDateFormat DATE_FORMAT // for mbox From_ lines
161
182
= new SimpleDateFormat ("EEE MMM dd HH:mm:ss YYYY" );
0 commit comments