Search in sources :

Example 36 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 37 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)

Example 38 with ZFolder

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

the class ZMailboxUtil method dumpMessage.

private void dumpMessage(ZMessage msg) throws ServiceException {
    stdout.format("Id: %s%n", msg.getId());
    stdout.format("Conversation-Id: %s%n", msg.getConversationId());
    ZFolder f = mMbox.getFolderById(msg.getFolderId());
    stdout.format("Folder: %s%n", f == null ? msg.getFolderId() : f.getPath());
    stdout.format("Subject: %s%n", msg.getSubject());
    doHeader(msg.getEmailAddresses(), "From", ZEmailAddress.EMAIL_TYPE_FROM);
    doHeader(msg.getEmailAddresses(), "To", ZEmailAddress.EMAIL_TYPE_TO);
    doHeader(msg.getEmailAddresses(), "Cc", ZEmailAddress.EMAIL_TYPE_CC);
    stdout.format("Date: %s\n", DateUtil.toRFC822Date(new Date(msg.getReceivedDate())));
    if (msg.hasTags())
        stdout.format("Tags: %s%n", lookupTagNames(msg.getTagIds()));
    if (msg.hasFlags())
        stdout.format("Flags: %s%n", ZMessage.Flag.toNameList(msg.getFlags()));
    stdout.format("Size: %s%n", formatSize(msg.getSize()));
    stdout.println();
    if (dumpBody(msg.getMimeStructure()))
        stdout.println();
}
Also used : ZFolder(com.zimbra.client.ZFolder) Date(java.util.Date)

Example 39 with ZFolder

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

the class TestFolderFilterRules method verifyFolderSize.

/**
     * Verifies message count for the given folder.
     */
private void verifyFolderSize(String folderId, int size) throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder f = mbox.getFolderById(folderId);
    List<ZMessage> messages = TestUtil.search(mbox, "in:" + f.getPath());
    assertEquals("Incorrect message count for folder " + f.getPath(), size, messages.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder)

Example 40 with ZFolder

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

the class TestFolderFilterRules method renameFolder.

/**
     * Renames the given folder and confirms that filter rules were updated
     * with the new path.
     */
private void renameFolder(String folderId, String newName, String newParentId) throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder = mbox.getFolderById(folderId);
    // Confirm that the old path is in the script.
    String oldPath = folder.getPath();
    if (oldPath.charAt(0) == '/') {
        // Path in scripts may not have a leading slash.  
        oldPath = oldPath.substring(1, oldPath.length());
    }
    String script = account.getAttr(Provisioning.A_zimbraMailSieveScript);
    assertTrue("Could not find path " + oldPath + " in script: " + script, script.contains(oldPath));
    // Rename the folder and check the new path.
    mbox.renameFolder(folderId, newName, newParentId);
    folder = mbox.getFolderById(folder.getId());
    String newPath = folder.getPath();
    if (newPath.charAt(0) == '/') {
        newPath = newPath.substring(1, newPath.length());
    }
    assertEquals(newName, folder.getName());
    assertTrue("Folder path '" + newPath + "' does not end with " + newName, folder.getPath().endsWith(newName));
    // Confirm that filter rules are updated.
    // refresh
    account = TestUtil.getAccount(USER_NAME);
    script = account.getAttr(Provisioning.A_zimbraMailSieveScript);
    assertFalse("Found old path '" + oldPath + " in script: " + script, script.indexOf(oldPath) >= 0);
    assertTrue("Could not find new path '" + newPath + " in script: " + script, script.indexOf(newPath) >= 0);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder)

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