log.info("Found " + mailboxPathList.size() + " mailboxes in source mailbox manager.");
for (int i=0; i < mailboxPathList.size(); i++) {
log.info("Mailbox#" + i + " path=" + mailboxPathList.get(i));
}
MailboxPath mailboxPath = null;
for (int i=0; i < mailboxPathList.size(); i++) {
mailboxPath = mailboxPathList.get(i);
if ((mailboxPath.getName() != null) && (mailboxPath.getName().trim().length() > 0)) {
log.info("Ready to copy source mailbox path=" + mailboxPath.toString());
srcMailboxSession = srcMailboxManager.createSystemSession(mailboxPath.getUser(), log);
dstMailboxSession = dstMailboxManager.createSystemSession(mailboxPath.getUser(), log);
dstMailboxManager.startProcessingRequest(dstMailboxSession);
try {
dstMailboxManager.createMailbox(mailboxPath, dstMailboxSession);
log.info("Destination mailbox " + i + "/" + mailboxPathList.size()
+ " created with path=" + mailboxPath.toString()
+ " after " + (Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis()) + " ms.");
} catch (MailboxExistsException e) {
log.error("Mailbox " + i + " with path=" + mailboxPath.toString() + " already exists.", e);
}
dstMailboxManager.endProcessingRequest(dstMailboxSession);
srcMailboxManager.startProcessingRequest(srcMailboxSession);
MessageManager srcMessageManager = srcMailboxManager.getMailbox(mailboxPath, srcMailboxSession);
srcMailboxManager.endProcessingRequest(srcMailboxSession);
dstMailboxManager.startProcessingRequest(dstMailboxSession);
MessageManager dstMessageManager = dstMailboxManager.getMailbox(mailboxPath, dstMailboxSession);
int j=0;
Iterator<MessageResult> messageResultIterator = srcMessageManager.getMessages(MessageRange.all(), GROUP, srcMailboxSession);
while (messageResultIterator.hasNext()) {
MessageResult messageResult = messageResultIterator.next();
InputStreamContent content = (InputStreamContent) messageResult.getFullContent();
dstMailboxManager.startProcessingRequest(dstMailboxSession);
dstMessageManager.appendMessage(content.getInputStream(), messageResult.getInternalDate(), dstMailboxSession, messageResult.getFlags().contains(Flag.RECENT), messageResult.getFlags());
dstMailboxManager.endProcessingRequest(dstMailboxSession);
log.info("Message #" + j + " appended in destination mailbox with path=" + mailboxPath.toString());
j++;
}
dstMailboxManager.endProcessingRequest(dstMailboxSession);
}
else {
log.info("Destination mailbox " + i + "/" + mailboxPathList.size()
+ " with path=" + mailboxPath.toString()
+ " has a null or empty name");
}
}