Search in sources :

Example 1 with CopyResult

use of com.zimbra.cs.mailclient.imap.CopyResult in project zm-mailbox by Zimbra.

the class RemoteFolder method copyMessage.

public CopyResult copyMessage(long uid, String mbox) throws IOException {
    assert isSelected();
    String seq = String.valueOf(uid);
    ImapRequest req = connection.newUidRequest(CAtom.COPY, seq, new MailboxName(mbox));
    ResponseText rt = req.sendCheckStatus().getResponseText();
    if (rt.getCCode() == CAtom.COPYUID) {
        CopyResult cr = (CopyResult) rt.getData();
        // Bug 36373: If COPYUID result 0 then assume that message no longer exists.
        if (cr != null && cr.getToUids()[0] != 0) {
            return cr;
        }
    }
    // Message not found
    return null;
}
Also used : MailboxName(com.zimbra.cs.mailclient.imap.MailboxName) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ResponseText(com.zimbra.cs.mailclient.imap.ResponseText) CopyResult(com.zimbra.cs.mailclient.imap.CopyResult)

Example 2 with CopyResult

use of com.zimbra.cs.mailclient.imap.CopyResult in project zm-mailbox by Zimbra.

the class ImapFolderSync method moveMessage.

private boolean moveMessage(ImapMessage msgTracker) throws ServiceException, IOException {
    Message msg;
    Folder folder;
    if (!hasCopyUid())
        return false;
    try {
        msg = mailbox.getMessageById(null, msgTracker.getItemId());
        folder = mailbox.getFolderById(null, msg.getFolderId());
    } catch (MailServiceException.NoSuchItemException e) {
        return false;
    }
    if (!ds.isSyncEnabled(folder))
        return false;
    int fid = folder.getId();
    ImapFolderCollection trackedFolders = imapSync.getTrackedFolders();
    ImapFolder folderTracker = trackedFolders.getByItemId(fid);
    String remotePath;
    if (folderTracker != null) {
        remotePath = folderTracker.getRemoteId();
    } else {
        // If remote folder does not exist, then create it on demand
        RemoteFolder newFolder = createRemoteFolder(folder);
        if (newFolder == null)
            return false;
        remotePath = newFolder.getPath();
    }
    CopyResult cr;
    try {
        cr = remoteFolder.copyMessage(msgTracker.getUid(), remotePath);
    } catch (IOException e) {
        syncMessageFailed(msgTracker.getUid(), "COPY failed", e);
        return false;
    }
    if (cr == null) {
        // Message not found
        return false;
    }
    stats.msgsCopiedRemotely++;
    // If remote folder created on demand, then create folder tracker
    if (folderTracker == null) {
        long uv = cr.getUidValidity();
        if (uv == 0)
            uv = 1;
        imapSync.createFolderTracker(fid, folder.getPath(), remotePath, uv);
    } else {
        // If target folder was already sync'd, then make sure we remove
        // msg id from folder's list of new messages to be appended
        ImapFolderSync syncedFolder = imapSync.getSyncedFolder(fid);
        if (syncedFolder != null && syncedFolder.newMsgIds != null) {
            syncedFolder.newMsgIds.remove(Integer.valueOf(msg.getId()));
        }
    }
    if (!deleteMessage(msgTracker.getUid())) {
        LOG.warn("Unable to delete message with uid " + msgTracker.getUid());
        return false;
    }
    // Delete original message tracker and create new one
    msgTracker.delete();
    long uid = cr.getToUids()[0];
    msgTracker = new ImapMessage(ds, fid, msg.getId(), msgTracker.getFlags(), uid);
    msgTracker.add();
    // This bit of ugliness is to make sure we update target folder sync state
    // to reflect UID that was just added
    ImapFolderSync syncedFolder = imapSync.getSyncedFolder(fid);
    if (syncedFolder != null && syncedFolder.syncState != null) {
        syncedFolder.syncState.updateLastFetchedUid(uid);
    } else {
        FolderSyncState fss = imapSync.getFolderSyncState(fid);
        if (fss != null) {
            fss.updateLastFetchedUid(uid);
        }
    }
    return true;
}
Also used : PurgedMessage(com.zimbra.cs.db.DbDataSource.PurgedMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) IOException(java.io.IOException) Folder(com.zimbra.cs.mailbox.Folder) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) CopyResult(com.zimbra.cs.mailclient.imap.CopyResult)

Aggregations

CopyResult (com.zimbra.cs.mailclient.imap.CopyResult)2 PurgedMessage (com.zimbra.cs.db.DbDataSource.PurgedMessage)1 Folder (com.zimbra.cs.mailbox.Folder)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Message (com.zimbra.cs.mailbox.Message)1 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)1 MailboxName (com.zimbra.cs.mailclient.imap.MailboxName)1 ResponseText (com.zimbra.cs.mailclient.imap.ResponseText)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 IOException (java.io.IOException)1