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;
}
}
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();
}
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();
}
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());
}
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);
}
Aggregations