@@ -135,7 +135,7 @@ public static void main(String[] args) throws IOException
135
135
loaded ++;
136
136
}
137
137
} catch (IOException e ) {
138
- System .out .println (imap .getReplyString ());
138
+ System .out .println ("Error processing msg: " + total + " " + imap .getReplyString ());
139
139
e .printStackTrace ();
140
140
System .exit (10 );
141
141
return ;
@@ -151,15 +151,27 @@ private static boolean startsWith(String input, Pattern pat) {
151
151
return m .lookingAt ();
152
152
}
153
153
154
+ private static String getDate (String msg ) {
155
+ final Pattern FROM_RE = Pattern .compile ("From \\ S+ +\\ S+ (\\ S+) ?(\\ S+) (\\ S+) (\\ S+)" ); // From SENDER Fri Sep 13 17:04:01 2019
156
+ // [Fri] Sep 13 HMS 2019
157
+ // output date: 13-Sep-2019 17:04:01 +0000
158
+ String date = null ;
159
+ Matcher m = FROM_RE .matcher (msg );
160
+ if (m .lookingAt ()) {
161
+ date = m .group (2 )+"-" +m .group (1 )+"-" +m .group (4 )+" " +m .group (3 )+" +0000" ;
162
+ }
163
+ return date ;
164
+ }
165
+
154
166
private static boolean process (final StringBuilder sb , final IMAPClient imap , final String folder
155
167
,final int msgNum ) throws IOException {
156
168
final int length = sb .length ();
157
169
boolean haveMessage = length > 2 ;
158
170
if (haveMessage ) {
159
171
System .out .println ("MsgNum: " + msgNum +" Length " + length );
160
- sb .setLength (length -2 ); // drop trailing CRLF
172
+ sb .setLength (length -2 ); // drop trailing CRLF (mbox format has trailing blank line)
161
173
String msg = sb .toString ();
162
- if (!imap .append (folder , null , null , msg )) {
174
+ if (!imap .append (folder , null , getDate ( msg ) , msg )) {
163
175
throw new IOException ("Failed to import message: " + msgNum + " " + imap .getReplyString ());
164
176
}
165
177
}
0 commit comments