boolean debug = false;// change to get more errors
if (argv.length != 5) {
System.out.println( "usage: copier <urlname> <src folder>" +
"<dest folder> <start msg #> <end msg #>");
return;
}
try {
URLName url = new URLName(argv[0]);
String src = argv[1]; // source folder
String dest = argv[2]; // dest folder
int start = Integer.parseInt(argv[3]); // copy from message #
int end = Integer.parseInt(argv[4]); // to message #
// Get the default Session object
Session session = Session.getInstance(System.getProperties(), null);
// session.setDebug(debug);
// Get a Store object that implements
// the protocol.
Store store = session.getStore(url);
store.connect();
System.out.println("Connected...");
// Open Source Folder
Folder folder = store.getFolder(src);
folder.open(Folder.READ_WRITE);
System.out.println("Opened source...");
if (folder.getMessageCount() == 0) {
System.out.println("Source folder has no messages ..");
folder.close(false);
store.close();
}
// Open destination folder, create if needed
Folder dfolder = store.getFolder(dest);
if (!dfolder.exists()) // create
dfolder.create(Folder.HOLDS_MESSAGES);
Message[] msgs = folder.getMessages(start, end);
System.out.println("Got messages...");
// Copy messages into destination,
folder.copyMessages(msgs, dfolder);
System.out.println("Copied messages...");
// Close the folder and store
folder.close(false);
store.close();
System.out.println("Closed folder and store...");
} catch (Exception e) {
e.printStackTrace();
}
System.exit(0);