Search in sources :

Example 6 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class TestImapOneWayImport method compare.

private void compare() throws Exception {
    // Recursively compare the folder trees
    ZFolder folder1 = mRemoteMbox.getUserRoot();
    ZFolder folder2 = mLocalMbox.getFolderByPath(DS_FOLDER_ROOT);
    compare(mRemoteMbox, folder1, mLocalMbox, folder2);
}
Also used : ZFolder(com.zimbra.client.ZFolder)

Example 7 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class TestImapOneWayImport method setUp.

@Override
public void setUp() throws Exception {
    cleanUp();
    mDisplayMailFoldersOnly = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
    Provisioning.getInstance().getLocalServer().setImapDisplayMailFoldersOnly(false);
    // Get mailbox references
    if (!TestUtil.accountExists(LOCAL_USER_NAME)) {
        TestUtil.createAccount(LOCAL_USER_NAME);
    }
    if (!TestUtil.accountExists(REMOTE_USER_NAME)) {
        TestUtil.createAccount(REMOTE_USER_NAME);
    }
    mRemoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    mLocalMbox = TestUtil.getZMailbox(LOCAL_USER_NAME);
    // Get or create folder
    ZFolder folder = mLocalMbox.getFolderByPath(DS_FOLDER_ROOT);
    if (folder == null) {
        folder = TestUtil.createFolder(mLocalMbox, NAME_PREFIX);
    }
    // Create data source
    int port = Integer.parseInt(TestUtil.getServerAttr(Provisioning.A_zimbraImapBindPort));
    mDataSource = new ZImapDataSource(NAME_PREFIX, true, "localhost", port, REMOTE_USER_NAME, TestUtil.DEFAULT_PASSWORD, folder.getId(), ConnectionType.cleartext, true);
    String id = mLocalMbox.createDataSource(mDataSource);
    mDataSource = null;
    for (ZDataSource ds : mLocalMbox.getAllDataSources()) {
        if (ds.getId().equals(id)) {
            mDataSource = ds;
        }
    }
    assertNotNull(mDataSource);
    // Turn on cleartext login
    mOriginalCleartextValue = TestUtil.getServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled);
    TestUtil.setServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled, ProvisioningConstants.TRUE);
    // Turn off STARTTLS support so that unit tests don't bomb on Linux
    // (see bug 33683).
    mOriginalEnableStarttls = LC.javamail_imap_enable_starttls.booleanValue();
    LC.javamail_imap_enable_starttls.setDefault(Boolean.toString(false));
}
Also used : ZImapDataSource(com.zimbra.client.ZImapDataSource) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource)

Example 8 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class RuleRewriter method createFolderIfNecessary.

private void createFolderIfNecessary(String path, String ruleName) throws ServiceException {
    Pair<Folder, String> folderAndRemotePath = mMailbox.getFolderByPathLongestMatch(null, Mailbox.ID_FOLDER_USER_ROOT, path);
    Folder folder = folderAndRemotePath.getFirst();
    String remotePath = folderAndRemotePath.getSecond();
    if (StringUtil.isNullOrEmpty(remotePath)) {
        remotePath = null;
    }
    if (folder instanceof Mountpoint && remotePath != null) {
        // Create remote folder path
        Mountpoint mountpoint = (Mountpoint) folder;
        ZimbraLog.filter.info("Creating folder %s in remote folder %s for rule %s.", remotePath, folder.getPath(), ruleName);
        ZMailbox remoteMbox = FilterUtil.getRemoteZMailbox(mMailbox, (Mountpoint) folder);
        ItemId id = mountpoint.getTarget();
        ZFolder parent = remoteMbox.getFolderById(id.toString());
        if (parent == null) {
            String msg = String.format("Could not find folder with id %d in remote mailbox %s.", mountpoint.getRemoteId(), mountpoint.getOwnerId());
            throw ServiceException.FAILURE(msg, null);
        }
        String[] pathElements = remotePath.split(ZMailbox.PATH_SEPARATOR);
        for (String folderName : pathElements) {
            if (!StringUtil.isNullOrEmpty(folderName)) {
                ZFolder currentFolder = parent.getSubFolderByPath(folderName);
                if (currentFolder != null) {
                    parent = currentFolder;
                } else {
                    parent = remoteMbox.createFolder(parent.getId(), folderName, ZFolder.View.message, null, null, null);
                }
            }
        }
    } else if (remotePath != null) {
        // Create local folder path
        ZimbraLog.filter.info("Creating folder %s for rule %s.", path, ruleName);
        mMailbox.createFolder(null, path, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ItemId(com.zimbra.cs.service.util.ItemId)

Example 9 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class Mailbox method refreshMountpoint.

/**
     * Updates the remote owner and item id stored in the mountpoint to match the current location of the
     * target folder.  The target folder is identified by the remote UUID stored in the mountpoint's metadata.
     * @param octxt
     * @param mountpointId item id of the Mountpoint
     * @return
     * @throws ServiceException
     */
public Mountpoint refreshMountpoint(OperationContext octxt, int mountpointId) throws ServiceException {
    Mountpoint mp = getMountpointById(octxt, mountpointId);
    Provisioning prov = Provisioning.getInstance();
    ShareLocator shloc = prov.getShareLocatorById(mp.getRemoteUuid());
    if (shloc == null || mp.getOwnerId().equalsIgnoreCase(shloc.getShareOwnerAccountId())) {
        // Share apparently did not move.
        return mp;
    }
    // Look up remote folder by UUID to discover the new numeric id.
    Account shareOwner = Provisioning.getInstance().get(Key.AccountBy.id, shloc.getShareOwnerAccountId());
    AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
    String pxyAuthToken = Provisioning.onLocalServer(shareOwner) ? null : at.getProxyAuthToken();
    ZAuthToken zat = null;
    if (pxyAuthToken == null) {
        zat = at.toZAuthToken();
        zat.resetProxyAuthToken();
    } else {
        zat = new ZAuthToken(pxyAuthToken);
    }
    ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(shareOwner));
    zoptions.setNoSession(true);
    zoptions.setTargetAccount(shareOwner.getId());
    zoptions.setTargetAccountBy(Key.AccountBy.id);
    ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
    ZFolder zfolder = zmbx.getFolderByUuid(shloc.getUuid());
    if (zfolder != null) {
        ItemId fid = new ItemId(zfolder.getId(), shareOwner.getId());
        return refreshMountpoint(octxt, mountpointId, shareOwner.getId(), fid.getId());
    } else {
        return null;
    }
}
Also used : Account(com.zimbra.cs.account.Account) ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) Options(com.zimbra.client.ZMailbox.Options) ZMailbox(com.zimbra.client.ZMailbox) Options(com.zimbra.client.ZMailbox.Options) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ItemId(com.zimbra.cs.service.util.ItemId) Provisioning(com.zimbra.cs.account.Provisioning) ShareLocator(com.zimbra.cs.account.ShareLocator)

Example 10 with ZFolder

use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.

the class ZMailboxUtil method dumpContact.

private void dumpContact(ZContact contact) throws ServiceException {
    stdout.format("Id: %s%n", contact.getId());
    ZFolder f = mMbox.getFolderById(contact.getFolderId());
    stdout.format("Folder: %s%n", f == null ? contact.getFolderId() : f.getPath());
    stdout.format("Date: %tD %<tR%n", contact.getMetaDataChangedDate());
    if (contact.hasTags())
        stdout.format("Tags: %s%n", lookupTagNames(contact.getTagIds()));
    if (contact.hasFlags())
        stdout.format("Flags: %s%n", ZContact.Flag.toNameList(contact.getFlags()));
    stdout.format("Revision: %s%n", contact.getRevision());
    stdout.format("Attrs:%n");
    Map<String, String> attrs = contact.getAttrs();
    for (Map.Entry<String, String> entry : attrs.entrySet()) {
        stdout.format("  %s: %s%n", entry.getKey(), entry.getValue());
    }
    if (contact.isGroup()) {
        stdout.format("GroupMembers: %s%n", contact.getMembers().keySet());
    }
    stdout.println();
}
Also used : ZFolder(com.zimbra.client.ZFolder) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ZFolder (com.zimbra.client.ZFolder)84 ZMailbox (com.zimbra.client.ZMailbox)54 Folder (com.zimbra.cs.mailbox.Folder)21 Test (org.junit.Test)21 ServiceException (com.zimbra.common.service.ServiceException)19 Account (com.zimbra.cs.account.Account)19 Mailbox (com.zimbra.cs.mailbox.Mailbox)17 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)17 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)13 ItemId (com.zimbra.cs.service.util.ItemId)13 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)12 ZMessage (com.zimbra.client.ZMessage)10 ZMountpoint (com.zimbra.client.ZMountpoint)9 AccountServiceException (com.zimbra.cs.account.AccountServiceException)9 ZAuthToken (com.zimbra.common.auth.ZAuthToken)7 ArrayList (java.util.ArrayList)7 ZDataSource (com.zimbra.client.ZDataSource)6 ZSearchFolder (com.zimbra.client.ZSearchFolder)6 Provisioning (com.zimbra.cs.account.Provisioning)6 AuthToken (com.zimbra.cs.account.AuthToken)5