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