use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestFolders method testCreateManyFolders.
@Ignore
@Test
public void testCreateManyFolders() throws Exception {
//normally skip this test since it takes a long time to complete. just keep it around for quick perf checks
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String parentPath = "/parent";
ZFolder parent = TestUtil.createFolder(mbox, parentPath);
int max = 10000;
int pad = ((int) Math.log10(max)) + 1;
long totalTime = 0;
double avgTime;
long maxTime = 0;
for (int i = 0; i < max; i++) {
long start = System.currentTimeMillis();
TestUtil.createFolder(mbox, parent.getId(), "child" + Strings.padStart(i + "", pad, '0'));
long end = System.currentTimeMillis();
long elapsed = (end - start);
totalTime += elapsed;
if (elapsed > maxTime) {
maxTime = elapsed;
ZimbraLog.mailbox.info("FOLDER TIME new max time %dms at index %d", maxTime, i);
}
if (i > 0 && (i % 100 == 0 || i == max - 1)) {
avgTime = (totalTime * 1.0) / (i * 1.0);
ZimbraLog.mailbox.info("FOLDER TIME average after %d = %dms", i, Math.round(avgTime));
}
}
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestFolders method testEmptyLargeFolder.
@Test
public void testEmptyLargeFolder() throws Exception {
TestUtil.setServerAttr(Provisioning.A_zimbraMailEmptyFolderBatchSize, Integer.toString(3));
// Create folders.
String parentPath = "/parent";
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFolder parent = TestUtil.createFolder(mbox, parentPath);
ZFolder child = TestUtil.createFolder(mbox, parent.getId(), "child");
// Add messages.
for (int i = 1; i <= 5; i++) {
TestUtil.addMessage(mbox, "parent " + i, parent.getId());
TestUtil.addMessage(mbox, "child " + i, child.getId());
}
mbox.noOp();
assertEquals(5, parent.getMessageCount());
assertEquals(5, child.getMessageCount());
// Empty parent folder without deleting subfolders.
mbox.emptyFolder(parent.getId(), false);
mbox.noOp();
assertEquals(0, parent.getMessageCount());
assertEquals(5, child.getMessageCount());
// Add more messages to the parent folder.
for (int i = 6; i <= 10; i++) {
TestUtil.addMessage(mbox, "parent " + i, parent.getId());
}
mbox.noOp();
assertEquals(5, parent.getMessageCount());
assertEquals(5, child.getMessageCount());
// Empty parent folder and delete subfolders.
String childPath = child.getPath();
assertNotNull(mbox.getFolderByPath(childPath));
mbox.emptyFolder(parent.getId(), true);
mbox.noOp();
assertEquals(0, parent.getMessageCount());
assertNull(mbox.getFolderByPath(childPath));
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestSpam method testSpamHandler.
@Test
public void testSpamHandler() throws Exception {
TestUtil.createAccount(REMOTE_USER_NAME);
TestUtil.createAccount(SPAM_NAME);
TestUtil.createAccount(HAM_NAME);
//check if AS is installed
List<String> zimbraServiceInstalled = Arrays.asList(prov.getLocalServer().getServiceInstalled());
if (zimbraServiceInstalled == null || zimbraServiceInstalled.isEmpty() || !zimbraServiceInstalled.contains("antispam")) {
return;
}
Config config = prov.getConfig();
config.setSpamIsSpamAccount(TestUtil.getAddress(SPAM_NAME));
config.setSpamIsNotSpamAccount(TestUtil.getAddress(HAM_NAME));
// Set filter rule.
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZFilterCondition cond = new ZHeaderCondition("Subject", ZFilterCondition.HeaderOp.CONTAINS, NAME_PREFIX);
ZFolder spamFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_SPAM));
ZFolder inboxFolder = mbox.getFolderById(Integer.toString(Mailbox.ID_FOLDER_INBOX));
ZFilterAction action = new ZFileIntoAction(spamFolder.getPath());
ZFilterRule rule = new ZFilterRule(NAME_PREFIX + " testSpamHandler", true, true, Arrays.asList(cond), Arrays.asList(action));
ZFilterRules rules = new ZFilterRules(Arrays.asList(rule));
mbox.saveIncomingFilterRules(rules);
// Confirm that the message was delivered to the Spam folder and that the report was sent.
String subject = NAME_PREFIX + " testSpamHandler";
TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
ZMessage msg = TestUtil.getMessage(mbox, "in:" + spamFolder.getPath() + " subject:\"" + subject + "\"");
ZMailbox spamMbox = TestUtil.getZMailbox(SPAM_NAME);
ZMessage reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "filter", null, spamFolder.getPath(), null);
spamMbox.deleteMessage(reportMsg.getId());
// Move out of spam folder.
mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_INBOX));
ZMailbox hamMbox = TestUtil.getZMailbox(HAM_NAME);
reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "move", spamFolder.getPath(), inboxFolder.getPath(), null);
hamMbox.deleteMessage(reportMsg.getId());
// Move back to spam folder.
mbox.moveMessage(msg.getId(), Integer.toString(Mailbox.ID_FOLDER_SPAM));
reportMsg = TestUtil.waitForMessage(spamMbox, "zimbra-spam-report spam");
validateSpamReport(TestUtil.getContent(spamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "spam", "move", inboxFolder.getPath(), spamFolder.getPath(), null);
spamMbox.deleteMessage(reportMsg.getId());
// Move to remote folder.
ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
String mountpointPath = NAME_PREFIX + " remote";
TestUtil.createMountpoint(remoteMbox, "/Inbox", mbox, mountpointPath);
ZFolder mountpoint = mbox.getFolderByPath(mountpointPath);
mbox.moveMessage(msg.getId(), mountpoint.getId());
reportMsg = TestUtil.waitForMessage(hamMbox, "zimbra-spam-report ham");
validateSpamReport(TestUtil.getContent(hamMbox, reportMsg.getId()), TestUtil.getAddress(USER_NAME), "ham", "remote move", spamFolder.getPath(), inboxFolder.getPath(), TestUtil.getAddress(REMOTE_USER_NAME));
hamMbox.deleteMessage(reportMsg.getId());
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestUtil method createMountpoint.
/**
* Creates a mountpoint between two mailboxes. The mountpoint gives the "to" user full rights on the folder.
*
* @param remoteMbox
* remote mailbox
* @param remotePath
* remote folder path. Folder is created if it doesn't exist.
* @param localMbox
* local mailbox
* @param mountpointName
* the name of the mountpoint folder. The folder is created directly under the user root.
*/
public static ZMountpoint createMountpoint(ZMailbox remoteMbox, String remotePath, ZMailbox localMbox, String mountpointName) throws ServiceException {
ZFolder remoteFolder = remoteMbox.getFolderByPath(remotePath);
if (remoteFolder == null) {
remoteFolder = createFolder(remoteMbox, remotePath);
}
ZGetInfoResult remoteInfo = remoteMbox.getAccountInfo(true);
remoteMbox.modifyFolderGrant(remoteFolder.getId(), GranteeType.all, null, "rwidx", null);
return localMbox.createMountpoint(Integer.toString(Mailbox.ID_FOLDER_USER_ROOT), mountpointName, null, null, null, OwnerBy.BY_ID, remoteInfo.getId(), SharedItemBy.BY_ID, remoteFolder.getId(), false);
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestUtil method createFolder.
public static ZFolder createFolder(ZMailbox mbox, String path, ZFolder.View view) throws ServiceException {
String parentId = Integer.toString(Mailbox.ID_FOLDER_USER_ROOT);
String name = null;
int idxLastSlash = path.lastIndexOf('/');
if (idxLastSlash < 0) {
name = path;
} else if (idxLastSlash == 0) {
name = path.substring(1);
} else {
String parentPath = path.substring(0, idxLastSlash);
name = path.substring(idxLastSlash + 1);
ZFolder parent = mbox.getFolderByPath(parentPath);
if (parent == null) {
String msg = String.format("Creating folder %s: parent %s does not exist", name, parentPath);
throw ServiceException.FAILURE(msg, null);
}
parentId = parent.getId();
}
return mbox.createFolder(parentId, name, view, null, null, null);
}
Aggregations