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());
}
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));
}
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()));
}
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()));
}
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);
}
Aggregations