Search in sources :

Example 56 with ZMailbox

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

the class TestPurge method testTagRetentionPolicy.

@Test
public void testTagRetentionPolicy() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZTag tag = mbox.createTag(NAME_PREFIX + "-testTagRetentionPolicy", null);
    // Set user keep policy for folder.
    TagActionSelector action = new TagActionSelector(tag.getId(), "retentionpolicy");
    RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
    action.setRetentionPolicy(rp);
    TagActionRequest req = new TagActionRequest(action);
    TagActionResponse res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
    // Make sure that the retention policy is now set.
    tag = mbox.getTagById(tag.getId());
    rp = tag.getRetentionPolicy();
    Assert.assertEquals(1, rp.getKeepPolicy().size());
    Assert.assertEquals(0, rp.getPurgePolicy().size());
    Policy p = rp.getKeepPolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("30d", p.getLifetime());
    // Turn off keep policy and set purge policy.
    action = new TagActionSelector(tag.getId(), "retentionpolicy");
    rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
    action.setRetentionPolicy(rp);
    req = new TagActionRequest(action);
    res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(tag.getId(), res.getAction().getSuccesses());
    // Make sure that the retention policy is now set.
    tag = mbox.getTagById(tag.getId());
    rp = tag.getRetentionPolicy();
    Assert.assertEquals(0, rp.getKeepPolicy().size());
    Assert.assertEquals(1, rp.getPurgePolicy().size());
    p = rp.getPurgePolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("45d", p.getLifetime());
    // Start a new session and make sure that the retention policy is still returned.
    mbox = TestUtil.getZMailbox(USER_NAME);
    tag = mbox.getTagById(tag.getId());
    Assert.assertTrue(tag.getRetentionPolicy().isSet());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) ZMailbox(com.zimbra.client.ZMailbox) TagActionResponse(com.zimbra.soap.mail.message.TagActionResponse) TagActionRequest(com.zimbra.soap.mail.message.TagActionRequest) ZTag(com.zimbra.client.ZTag) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) TagActionSelector(com.zimbra.soap.mail.type.TagActionSelector) Test(org.junit.Test)

Example 57 with ZMailbox

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

the class TestPurge method testFolderRetentionPolicy.

/**
 * Tests the SOAP API for setting retention policy on a folder.
 */
@Test
public void testFolderRetentionPolicy() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + "-testFolderRetentionPolicy");
    // Set user keep policy for folder.
    FolderActionSelector action = new FolderActionSelector(folder.getId(), "retentionpolicy");
    RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
    action.setRetentionPolicy(rp);
    FolderActionRequest req = new FolderActionRequest(action);
    FolderActionResponse res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(folder.getId(), res.getAction().getId());
    // Make sure that the retention policy is now set.
    folder = mbox.getFolderById(folder.getId());
    rp = folder.getRetentionPolicy();
    Assert.assertEquals(1, rp.getKeepPolicy().size());
    Assert.assertEquals(0, rp.getPurgePolicy().size());
    Policy p = rp.getKeepPolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("30d", p.getLifetime());
    // Turn off keep policy and set purge policy.
    action = new FolderActionSelector(folder.getId(), "retentionpolicy");
    rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
    action.setRetentionPolicy(rp);
    req = new FolderActionRequest(action);
    res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(folder.getId(), res.getAction().getId());
    // Make sure that the retention policy is now set.
    folder = mbox.getFolderById(folder.getId());
    rp = folder.getRetentionPolicy();
    Assert.assertEquals(0, rp.getKeepPolicy().size());
    Assert.assertEquals(1, rp.getPurgePolicy().size());
    p = rp.getPurgePolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("45d", p.getLifetime());
    // Start a new session and make sure that the retention policy is still returned.
    mbox = TestUtil.getZMailbox(USER_NAME);
    folder = mbox.getFolderById(folder.getId());
    Assert.assertTrue(folder.getRetentionPolicy().isSet());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) ZFolder(com.zimbra.client.ZFolder) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 58 with ZMailbox

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

the class TestPurge method testSystemRetentionPolicy.

@Test
public void testSystemRetentionPolicy() throws Exception {
    SoapProvisioning prov = TestUtil.newSoapProvisioning();
    // Test getting empty system policy.
    GetSystemRetentionPolicyRequest getReq = new GetSystemRetentionPolicyRequest();
    GetSystemRetentionPolicyResponse getRes = prov.invokeJaxb(getReq);
    RetentionPolicy rp = getRes.getRetentionPolicy();
    Assert.assertEquals(0, rp.getKeepPolicy().size());
    Assert.assertEquals(0, rp.getPurgePolicy().size());
    // Create keep policy.
    Policy keep = Policy.newSystemPolicy("keep", "60d");
    CreateSystemRetentionPolicyRequest createReq = CreateSystemRetentionPolicyRequest.newKeepRequest(keep);
    CreateSystemRetentionPolicyResponse createRes = prov.invokeJaxb(createReq);
    Policy p = createRes.getPolicy();
    Assert.assertNotNull(p.getId());
    Assert.assertEquals(keep.getName(), p.getName());
    Assert.assertEquals(keep.getLifetime(), p.getLifetime());
    keep = p;
    // Create purge policy.
    Policy purge1 = Policy.newSystemPolicy("purge1", "120d");
    createReq = CreateSystemRetentionPolicyRequest.newPurgeRequest(purge1);
    createRes = prov.invokeJaxb(createReq);
    purge1 = createRes.getPolicy();
    Policy purge2 = Policy.newSystemPolicy("purge2", "240d");
    createReq = CreateSystemRetentionPolicyRequest.newPurgeRequest(purge2);
    createRes = prov.invokeJaxb(createReq);
    purge2 = createRes.getPolicy();
    // Test getting updated system policy.
    getRes = prov.invokeJaxb(getReq);
    rp = getRes.getRetentionPolicy();
    Assert.assertEquals(1, rp.getKeepPolicy().size());
    Assert.assertEquals(keep, rp.getKeepPolicy().get(0));
    Assert.assertEquals(2, rp.getPurgePolicy().size());
    Assert.assertEquals(purge1, rp.getPolicyById(purge1.getId()));
    Assert.assertEquals(purge2, rp.getPolicyById(purge2.getId()));
    // Get system policy with the mail API.
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    com.zimbra.soap.mail.message.GetSystemRetentionPolicyResponse mailRes = mbox.invokeJaxb(new com.zimbra.soap.mail.message.GetSystemRetentionPolicyRequest());
    Assert.assertEquals(rp, mailRes.getRetentionPolicy());
    // Modify lifetime.
    Policy modLifetime = Policy.newSystemPolicy(purge1.getId(), null, "121d");
    ModifySystemRetentionPolicyRequest modifyReq = new ModifySystemRetentionPolicyRequest(modLifetime);
    ModifySystemRetentionPolicyResponse modifyRes = prov.invokeJaxb(modifyReq);
    Policy newPurge1 = modifyRes.getPolicy();
    Assert.assertEquals(Policy.newSystemPolicy(purge1.getId(), "purge1", "121d"), newPurge1);
    getRes = prov.invokeJaxb(getReq);
    Assert.assertEquals(newPurge1, getRes.getRetentionPolicy().getPolicyById(newPurge1.getId()));
    // Modify name.
    Policy modName = Policy.newSystemPolicy(purge1.getId(), "purge1-new", null);
    modifyReq = new ModifySystemRetentionPolicyRequest(modName);
    modifyRes = prov.invokeJaxb(modifyReq);
    newPurge1 = modifyRes.getPolicy();
    Assert.assertEquals(Policy.newSystemPolicy(purge1.getId(), "purge1-new", "121d"), newPurge1);
    // Delete.
    DeleteSystemRetentionPolicyRequest deleteReq = new DeleteSystemRetentionPolicyRequest(purge1);
    @SuppressWarnings("unused") DeleteSystemRetentionPolicyResponse deleteRes = prov.invokeJaxb(deleteReq);
    getRes = prov.invokeJaxb(getReq);
    rp = getRes.getRetentionPolicy();
    Assert.assertEquals(1, rp.getKeepPolicy().size());
    Assert.assertEquals(keep, rp.getKeepPolicy().get(0));
    Assert.assertEquals(1, rp.getPurgePolicy().size());
    Assert.assertEquals(purge2, rp.getPurgePolicy().get(0));
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) DeleteSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyResponse) DeleteSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.DeleteSystemRetentionPolicyRequest) CreateSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.CreateSystemRetentionPolicyResponse) GetSystemRetentionPolicyResponse(com.zimbra.soap.admin.message.GetSystemRetentionPolicyResponse) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) ModifySystemRetentionPolicyRequest(com.zimbra.soap.admin.message.ModifySystemRetentionPolicyRequest) ZMailbox(com.zimbra.client.ZMailbox) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) CreateSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.CreateSystemRetentionPolicyRequest) GetSystemRetentionPolicyRequest(com.zimbra.soap.admin.message.GetSystemRetentionPolicyRequest) ModifySystemRetentionPolicyResponse(com.zimbra.soap.admin.message.ModifySystemRetentionPolicyResponse) Test(org.junit.Test)

Example 59 with ZMailbox

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

the class TestLmtp method testMissingDiskThreshold.

/**
 * Confirms that delivery succeeds when <tt>zimbraMailDiskStreamingThreshold</tt>
 * isn't set (bug 22536).
 */
@Test
public void testMissingDiskThreshold() throws Exception {
    TestUtil.setServerAttr(Provisioning.A_zimbraMailDiskStreamingThreshold, "");
    TestUtil.setConfigAttr(Provisioning.A_zimbraMailDiskStreamingThreshold, "");
    String subject = NAME_PREFIX + " testMissingDiskThreshold";
    TestUtil.addMessageLmtp(subject, USER_NAME, USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 60 with ZMailbox

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

the class TestLmtp method testDiskStreamingEmptyFolder.

/**
 * Another test for bug 25484.  Delivers a message to user1 and user2, then confirms that
 * user1 can still read the message after user2 empties the folder that contains the message.
 */
@Test
public void testDiskStreamingEmptyFolder() throws Exception {
    TestUtil.createAccount(USER2_NAME);
    TestUtil.setServerAttr(Provisioning.A_zimbraMailDiskStreamingThreshold, "0");
    String[] recipients = { TestUtil.getAddress(USER_NAME), TestUtil.getAddress(USER2_NAME) };
    String subject = NAME_PREFIX + " testDiskStreamingMultipleRecipients";
    ZMailbox mbox1 = TestUtil.getZMailbox(USER_NAME);
    ZMailbox mbox2 = TestUtil.getZMailbox(USER2_NAME);
    TestUtil.addMessageLmtp(subject, recipients, TestUtil.getAddress(USER_NAME));
    TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
    ZMessage msg2 = TestUtil.waitForMessage(mbox2, "in:inbox subject:\"" + subject + "\"");
    // Test bug 25484.  Have user2 move the message to a folder, empty the folder,
    // and then have user1 read the message.
    ZFolder folder2 = TestUtil.createFolder(mbox2, "/" + NAME_PREFIX + " testDiskStreamingEmptyFolder");
    mbox2.moveMessage(msg2.getId(), folder2.getId());
    // Mark message as read, since unread messages result in uncache
    // getting called explicitly in Folder.propagateDeletion().
    mbox2.markItemRead(msg2.getId(), true, null);
    mbox2.emptyFolder(folder2.getId());
    mbox1 = TestUtil.getZMailbox(USER_NAME);
    TestUtil.waitForMessage(mbox1, "in:inbox subject:\"" + subject + "\"");
}
Also used : ZMessage(com.zimbra.client.ZMessage) 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