Search in sources :

Example 71 with ZFolder

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

the class TestImapSync method testSync.

@Test
public void testSync() throws Exception {
    LOG.info("Testing adding message to local mailbox");
    ZFolder folder = TestUtil.createFolder(localMailbox, TEST_FOLDER_1);
    TestUtil.addMessage(localMailbox, "msg1", folder.getId(), "u");
    Assert.assertFalse(imapFolder1.exists());
    syncFolders();
    Assert.assertTrue(imapFolder1.exists());
    MailboxInfo mb = imapFolder1.select();
    Assert.assertEquals(1, mb.getExists());
    Assert.assertEquals(1, mb.getUnseen());
}
Also used : ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo)

Example 72 with ZFolder

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

the class TestImap method testStoreTags.

@Test
public void testStoreTags() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue(tags == null || tags.size() == 0);
    String tagName = "T1";
    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);
    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo2"), true);
    MailboxInfo info = connection.select("INBOX");
    assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(2, 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));
    seq = it.next();
    assertFalse("flag unexpectedly set on second message", data.get(seq).getFlags().isSet(tagName));
    connection.store(seq + "", "+FLAGS", tagName);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flag not set after STORE in INBOX", data.get(seq).getFlags().isSet(tagName));
    mbox.addMessage(folder.getId(), "u", "", System.currentTimeMillis(), simpleMessage("bar"), true);
    info = connection.select(folderName);
    assertFalse(folderName + " contains unexpected flag " + tagName, info.getFlags().isSet(tagName));
    data = connection.fetch("*", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertFalse("flag unexpectedly set on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    connection.store(seq + "", "+FLAGS", tagName);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    info = connection.select(folderName);
    assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
    String tagName2 = "T2";
    connection.store(seq + "", "+FLAGS", tagName2);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
    info = connection.select(folderName);
    assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
    assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName2));
    //should not have created T2 as a visible tag
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    String tagName3 = "T3";
    connection.store(seq + "", "FLAGS", tagName3);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
    assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
    assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName3));
    info = connection.select(folderName);
    assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName3));
    assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName));
    assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
    //should not have created T2 or T3 as a visible tag
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    connection.store(seq + "", "-FLAGS", tagName3);
    data = connection.fetch(seq + "", "FLAGS");
    assertEquals(1, data.size());
    seq = data.keySet().iterator().next();
    assertTrue("flags unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isEmpty());
    info = connection.select("INBOX");
    assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
    assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ZTag(com.zimbra.client.ZTag) ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 73 with ZFolder

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

the class TestShareNotifications method testContactShareNotification.

public void testContactShareNotification() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    // create and share the first calendar
    ZFolder newContactsFolder = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.contact);
    String contactsFolderId = newContactsFolder.getId();
    FolderActionSelector action = new FolderActionSelector(contactsFolderId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(contactsFolderId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 1, 1000);
    assertEquals("should have exactly one share notification", 1, shares.size());
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Example 74 with ZFolder

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

the class TestShareNotifications method testContactAndCalendarShareNotifications.

public void testContactAndCalendarShareNotifications() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    // create and share the first calendar
    ZFolder newCal = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.appointment);
    String calendarId = newCal.getId();
    FolderActionSelector action = new FolderActionSelector(calendarId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    // create and share the second calendar
    ZFolder newContactsFolder = TestUtil.createFolder(mbox, CONTACTS_NAME1, ZFolder.View.contact);
    String contactsFolderId = newContactsFolder.getId();
    action = new FolderActionSelector(contactsFolderId, "grant");
    grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    folderActionReq = new FolderActionRequest(action);
    folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(contactsFolderId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 2, 1000);
    assertEquals("should have exactly two share notification", 2, shares.size());
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Example 75 with ZFolder

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

the class TestDataSourceServer method testScheduling.

public void testScheduling() throws Exception {
    // Create data source.
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder = TestUtil.createFolder(zmbox, "/" + NAME_PREFIX + "-testScheduling");
    Provisioning prov = Provisioning.getInstance();
    Server server = prov.getLocalServer();
    int port = server.getImapBindPort();
    ZImapDataSource zds = new ZImapDataSource(NAME_PREFIX + " testScheduling", true, "localhost", port, "user2", "test123", folder.getId(), ConnectionType.cleartext);
    String dsId = zmbox.createDataSource(zds);
    // Test scheduling based on polling interval. 
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    String attrName = Provisioning.A_zimbraDataSourcePollingInterval;
    String imapAttrName = Provisioning.A_zimbraDataSourceImapPollingInterval;
    TestUtil.setDataSourceAttr(USER_NAME, zds.getName(), attrName, "0");
    checkSchedule(mbox, dsId, null);
    TestUtil.setDataSourceAttr(USER_NAME, zds.getName(), attrName, "10m");
    checkSchedule(mbox, dsId, 600000);
    TestUtil.setAccountAttr(USER_NAME, imapAttrName, "");
    TestUtil.setDataSourceAttr(USER_NAME, zds.getName(), attrName, "");
    checkSchedule(mbox, dsId, null);
    TestUtil.setAccountAttr(USER_NAME, imapAttrName, "5m");
    checkSchedule(mbox, dsId, 300000);
    TestUtil.setDataSourceAttr(USER_NAME, zds.getName(), attrName, "0");
    checkSchedule(mbox, dsId, null);
    // Bug 44502: test changing polling interval from 0 to unset when
    // interval is set on the account.
    TestUtil.setDataSourceAttr(USER_NAME, zds.getName(), attrName, "");
    checkSchedule(mbox, dsId, 300000);
    TestUtil.setDataSourceAttr(USER_NAME, zds.getName(), Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_FALSE);
    checkSchedule(mbox, dsId, null);
}
Also used : ZImapDataSource(com.zimbra.client.ZImapDataSource) ZMailbox(com.zimbra.client.ZMailbox) Server(com.zimbra.cs.account.Server) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Provisioning(com.zimbra.cs.account.Provisioning)

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