Search in sources :

Example 1 with MoveItem

use of com.zimbra.cs.redolog.op.MoveItem in project zm-mailbox by Zimbra.

the class Mailbox method moveInternal.

private void moveInternal(OperationContext octxt, int[] itemIds, MailItem.Type type, int targetId, TargetConstraint tcon) throws ServiceException {
    MoveItem redoRecorder = new MoveItem(mId, itemIds, type, targetId, tcon);
    boolean success = false;
    try {
        beginTransaction("move", octxt, redoRecorder);
        setOperationTargetConstraint(tcon);
        Folder target = getFolderById(targetId);
        MailItem[] items = getItemById(itemIds, type);
        for (MailItem item : items) {
            checkItemChangeID(item);
        }
        int oldUIDNEXT = target.getImapUIDNEXT();
        boolean resetUIDNEXT = false;
        for (MailItem item : items) {
            // train the spam filter if necessary...
            trainSpamFilter(octxt, item, target, "move");
            // ...do the move...
            boolean moved = item.move(target);
            // ...and determine whether the move needs to cause an UIDNEXT change
            if (moved && !resetUIDNEXT && isTrackingImap() && (item instanceof Conversation || item instanceof Message || item instanceof Contact)) {
                resetUIDNEXT = true;
            }
        }
        // if this operation should cause the target folder's UIDNEXT value to change but it hasn't yet, do it here
        if (resetUIDNEXT && oldUIDNEXT == target.getImapUIDNEXT()) {
            MoveItem redoPlayer = (MoveItem) currentChange().getRedoPlayer();
            redoRecorder.setUIDNEXT(getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getUIDNEXT()));
            target.updateUIDNEXT();
        }
        success = true;
    } finally {
        endTransaction(success);
    }
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) ImapMessage(com.zimbra.cs.imap.ImapMessage) Pop3Message(com.zimbra.cs.pop3.Pop3Message) MimeMessage(javax.mail.internet.MimeMessage) CreateMessage(com.zimbra.cs.redolog.op.CreateMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MoveItem(com.zimbra.cs.redolog.op.MoveItem) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint) ModifyContact(com.zimbra.cs.redolog.op.ModifyContact) ParsedContact(com.zimbra.cs.mime.ParsedContact) CreateContact(com.zimbra.cs.redolog.op.CreateContact)

Aggregations

ZFolder (com.zimbra.client.ZFolder)1 DbMailItem (com.zimbra.cs.db.DbMailItem)1 ImapMessage (com.zimbra.cs.imap.ImapMessage)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 ParsedContact (com.zimbra.cs.mime.ParsedContact)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 Pop3Message (com.zimbra.cs.pop3.Pop3Message)1 CreateContact (com.zimbra.cs.redolog.op.CreateContact)1 CreateFolder (com.zimbra.cs.redolog.op.CreateFolder)1 CreateMessage (com.zimbra.cs.redolog.op.CreateMessage)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 ModifyContact (com.zimbra.cs.redolog.op.ModifyContact)1 MoveItem (com.zimbra.cs.redolog.op.MoveItem)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1 MimeMessage (javax.mail.internet.MimeMessage)1