Search in sources :

Example 31 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestFilterExisting method testSimultaneous.

/**
 * Simultaneously flags and discards the same set of messages (bug 41609).
 */
@Test
public void testSimultaneous() throws Exception {
    // Add messages.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    List<String> msgIds = new ArrayList<String>();
    for (int i = 1; i <= 10; i++) {
        msgIds.add(TestUtil.addMessage(mbox, NAME_PREFIX + " discard flag " + i));
    }
    String idList = StringUtil.join(",", msgIds);
    // Start two threads that simultaneously process the same set of messages.
    RunRule runDiscard = new RunRule(DISCARD_RULE_NAME, idList);
    RunRule runFlag = new RunRule(FLAG_RULE_NAME, idList);
    Thread discardThread = new Thread(runDiscard);
    Thread flagThread = new Thread(runFlag);
    discardThread.start();
    flagThread.start();
    discardThread.join();
    flagThread.join();
    // Make sure there were no errors.
    Exception e = runDiscard.getError();
    if (e != null) {
        Assert.fail(e.toString());
    }
    e = runFlag.getError();
    if (e != null) {
        Assert.fail(e.toString());
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ArrayList(java.util.ArrayList) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 32 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestFilterExisting method testFileIntoSameFolderAndFlag.

/**
 * Confirms that a flag rule runs when a message is filed into the same
 * folder (bug 44588).
 */
@Test
public void testFileIntoSameFolderAndFlag() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder1 = TestUtil.createFolder(mbox, FOLDER1_PATH);
    String subject = NAME_PREFIX + " test folder1 and flag";
    String id = TestUtil.addMessage(mbox, subject, folder1.getId(), null);
    ZMessage msg = mbox.getMessageById(id);
    Assert.assertTrue(StringUtil.isNullOrEmpty(msg.getFlags()));
    // Run the rule, make sure the message was flagged but not moved.
    Set<String> affectedIds = runRules(new String[] { FOLDER1_AND_FLAG_RULE_NAME }, id, null);
    Assert.assertEquals(1, affectedIds.size());
    msg = TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
    Assert.assertEquals("f", msg.getFlags());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 33 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestFilterExisting method testMarkRead.

@Test
public void testMarkRead() throws Exception {
    // Add message
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    String subject = NAME_PREFIX + " test mark read";
    String id = TestUtil.addMessage(mbox, subject);
    mbox.markMessageRead(id, false);
    ZMessage msg = mbox.getMessageById(id);
    Assert.assertTrue(msg.isUnread());
    // Run mark unread rule and validate.
    Set<String> affectedIds = runRules(new String[] { MARK_READ_RULE_NAME }, id, null);
    Assert.assertEquals(1, affectedIds.size());
    mbox.noOp();
    Assert.assertFalse(msg.isUnread());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 34 with ZMailbox

use of com.zimbra.client.ZMailbox in project zm-mailbox by Zimbra.

the class TestFolderACLCache method setUp.

@Before
public void setUp() throws Exception {
    testName = testInfo.getMethodName();
    userNamePrefix = "testfolderaclcache-" + testName + "-user-";
    ownerName = userNamePrefix + "owner";
    user2Name = userNamePrefix + "haswriteaccess";
    user3Name = userNamePrefix + "hasreadwriteaccess";
    cleanUp();
    ownerAcct = createAcct(ownerName);
    USER2 = createAcct(user2Name);
    USER3 = createAcct(user3Name);
    ZMailbox ownerMbx = TestUtil.getZMailbox(ownerAcct.getName());
    ZFolder inbox = ownerMbx.getFolderByPath("inbox");
    String sub1Path = "/inbox/sub1";
    ZFolder sub1 = ownerMbx.getFolderByPath(sub1Path);
    if (sub1 == null) {
        sub1 = TestUtil.createFolder(ownerMbx, sub1Path);
        ownerMbx.modifyFolderGrant(sub1.getId(), ZGrant.GranteeType.usr, USER2.getName(), "w", null);
        ownerMbx.modifyFolderGrant(sub1.getId(), ZGrant.GranteeType.usr, USER3.getName(), "rw", null);
    }
    String sub2Path = "/inbox/sub1/sub2";
    ZFolder sub2 = ownerMbx.getFolderByPath(sub2Path);
    if (sub2 == null)
        sub2 = TestUtil.createFolder(ownerMbx, sub2Path);
    String sub3Path = "/inbox/sub3";
    ZFolder sub3 = ownerMbx.getFolderByPath(sub3Path);
    if (sub3 == null) {
        sub3 = TestUtil.createFolder(ownerMbx, sub3Path);
        ownerMbx.modifyFolderGrant(sub3.getId(), ZGrant.GranteeType.pub, null, "r", null);
    }
    OWNER_ACCT_ID = ownerAcct.getId();
    INBOX_FID = Integer.valueOf(inbox.getId());
    SUB1_FID = Integer.valueOf(sub1.getId());
    SUB2_FID = Integer.valueOf(sub2.getId());
    SUB3_FID = Integer.valueOf(sub3.getId());
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Before(org.junit.Before)

Example 35 with ZMailbox

use of com.zimbra.client.ZMailbox 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)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)383 Test (org.junit.Test)288 ZFolder (com.zimbra.client.ZFolder)90 ZMessage (com.zimbra.client.ZMessage)82 Mailbox (com.zimbra.cs.mailbox.Mailbox)61 Account (com.zimbra.cs.account.Account)60 ServiceException (com.zimbra.common.service.ServiceException)55 ArrayList (java.util.ArrayList)38 IOException (java.io.IOException)35 MessageData (com.zimbra.cs.mailclient.imap.MessageData)28 ZMountpoint (com.zimbra.client.ZMountpoint)26 Message (com.zimbra.cs.mailbox.Message)24 HashMap (java.util.HashMap)23 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)21 ZTag (com.zimbra.client.ZTag)21 SoapFaultException (com.zimbra.common.soap.SoapFaultException)21 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)21 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)20 HttpClient (org.apache.http.client.HttpClient)19 ZSearchParams (com.zimbra.client.ZSearchParams)18