use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestImap method testStoreTagsDirty.
@Test
public void testStoreTagsDirty() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue(tags == null || tags.size() == 0);
String tagName = "T1";
final String tagName2 = "T2";
ZTag tag = mbox.getTag(tagName);
if (tag == null) {
tag = mbox.createTag(tagName, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(1, data.size());
Iterator<Long> it = data.keySet().iterator();
Long seq = it.next();
assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
req.setResponseHandler(new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) throws Exception {
if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
Flags flags = (Flags) res.getData();
assertTrue(flags.isSet(tagName2));
}
}
});
req.sendCheckStatus();
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestImapImport method compare.
private void compare(ZMailbox mbox1, ZFolder folder1, ZMailbox mbox2, ZFolder folder2) throws Exception {
assertNotNull(mbox1);
assertNotNull(folder1);
assertNotNull(mbox2);
assertNotNull(folder2);
// Recursively compare children
for (ZFolder child1 : folder1.getSubFolders()) {
if (isMailFolder(child1)) {
ZFolder child2 = folder2.getSubFolderByPath(child1.getName());
String msg = String.format("Could not find folder %s/%s for %s", folder2.getPath(), child1.getName(), mbox2.getName());
assertNotNull(msg, child2);
compare(mbox1, child1, mbox2, child2);
}
}
assertEquals("Message count doesn't match (folder1 = " + folder1 + ", folder2 = " + folder2 + ")", folder1.getMessageCount(), folder2.getMessageCount());
// Compare folders as long as neither one is the user root
if (!(folder1.getPath().equals("/") || folder2.getPath().equals("/"))) {
List<ZMessage> msgs1 = TestUtil.search(mbox1, "in:" + folder1.getPath());
List<ZMessage> msgs2 = TestUtil.search(mbox2, "in:" + folder2.getPath());
compareMessages(msgs1, msgs2);
}
}
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));
}
}
Aggregations