Search in sources :

Example 26 with ZFolder

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));
        }
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with ZFolder

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));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 28 with ZFolder

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());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Config(com.zimbra.cs.account.Config) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZFilterAction(com.zimbra.client.ZFilterAction) ZFilterRule(com.zimbra.client.ZFilterRule) ZFolder(com.zimbra.client.ZFolder) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 29 with ZFolder

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);
}
Also used : ZGetInfoResult(com.zimbra.client.ZGetInfoResult) ZFolder(com.zimbra.client.ZFolder)

Example 30 with ZFolder

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);
}
Also used : ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint)

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