*/
protected void doProcess(CopyRequest request, final ImapSession session, String tag, ImapCommand command, final Responder responder) {
final MailboxPath targetMailbox = buildFullPath(session, request.getMailboxName());
final IdRange[] idSet = request.getIdSet();
final boolean useUids = request.isUseUids();
final SelectedMailbox currentMailbox = session.getSelected();
try {
final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
final MailboxManager mailboxManager = getMailboxManager();
final boolean mailboxExists = mailboxManager.mailboxExists(targetMailbox, mailboxSession);
if (!mailboxExists) {
no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, ResponseCode.tryCreate());
} else {
final MessageManager mailbox = mailboxManager.getMailbox(targetMailbox, mailboxSession);
List<IdRange> resultRanges = new ArrayList<IdRange>();
for (int i = 0; i < idSet.length; i++) {
MessageRange messageSet = messageRange(currentMailbox, idSet[i], useUids);
if (messageSet != null) {
List<MessageRange> processedUids = process(
targetMailbox, currentMailbox, mailboxSession,
mailboxManager, messageSet);
for (MessageRange mr : processedUids) {
// Set recent flag on copied message as this SHOULD be
// done.
// See RFC 3501 6.4.7. COPY Command
// See IMAP-287
//
// Disable this as this is now done directly in the scope of the copy operation.
// See MAILBOX-85
//mailbox.setFlags(new Flags(Flags.Flag.RECENT), true, false, mr, mailboxSession);
resultRanges.add(new IdRange(mr.getUidFrom(), mr.getUidTo()));
}
}
}
IdRange[] resultUids = IdRange.mergeRanges(resultRanges).toArray(new IdRange[0]);
// get folder UIDVALIDITY
Long uidValidity = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_UNSEEN).getUidValidity();
unsolicitedResponses(session, responder, useUids);
okComplete(command, tag, ResponseCode.copyUid(uidValidity, idSet, resultUids), responder);
}
} catch (MessageRangeException e) {
if (session.getLog().isDebugEnabled()) {
session.getLog().debug("Copy failed from mailbox " + currentMailbox.getPath() + " to " + targetMailbox + " for invalid sequence-set " + idSet.toString(), e);
}
taggedBad(command, tag, responder, HumanReadableText.INVALID_MESSAGESET);
} catch (MailboxException e) {
if (session.getLog().isInfoEnabled()) {
session.getLog().info("Copy failed from mailbox " + currentMailbox.getPath() + " to " + targetMailbox + " for sequence-set " + idSet.toString(), e);
}
no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
}
}