Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit b9e9c33

Browse files
committed
add -W option to warn instead of fail when a message can't be copied
1 parent 3cc5d4d commit b9e9c33

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

demo/src/main/java/populate.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997-2016 Oracle and/or its affiliates. All rights reserved.
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -47,6 +47,7 @@ public class populate {
4747
static boolean skipSpecial = false;
4848
static boolean clear = false;
4949
static boolean dontPreserveFlags = false;
50+
static boolean warn = false;
5051

5152
public static void main(String argv[]) {
5253
String srcURL = null;
@@ -70,6 +71,8 @@ public static void main(String argv[]) {
7071
clear = true;
7172
} else if (argv[optind].equals("-P")) {
7273
dontPreserveFlags = true;
74+
} else if (argv[optind].equals("-W")) {
75+
warn = true;
7376
} else if (argv[optind].equals("--")) {
7477
optind++;
7578
break;
@@ -222,7 +225,20 @@ private static void copyMessages(Folder src, Folder dst)
222225
msgs[i] = m;
223226
}
224227
}
225-
src.copyMessages(msgs, dst);
228+
if (warn) {
229+
// have to copy messages one at a time
230+
for (int i = 0; i < msgs.length; i++) {
231+
try {
232+
src.copyMessages(new Message[] { msgs[i] }, dst);
233+
} catch (MessagingException mex) {
234+
System.out.println("WARNING: Copy of message " + (i + 1) +
235+
" from " + src.getFullName() +
236+
" to " + dst.getFullName() +
237+
" failed: " + mex.toString());
238+
}
239+
}
240+
} else
241+
src.copyMessages(msgs, dst);
226242
}
227243

228244
private static void printUsage() {

0 commit comments

Comments
 (0)