use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestRemoteImapMailboxStore method testListIMAPSubscriptions.
@Test
public void testListIMAPSubscriptions() throws Exception {
String path = NAME_PREFIX + "_testPath";
MetadataList slist = new MetadataList();
slist.add(path);
// imitate subscription
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
mbox.setConfig(null, "imap", new Metadata().put("subs", slist));
// check that subscription was saved in mailbox configuration
Metadata config = mbox.getConfig(null, "imap");
Assert.assertNotNull(config);
MetadataList rlist = config.getList("subs", true);
Assert.assertNotNull(rlist);
Assert.assertNotNull(rlist.get(0));
Assert.assertTrue(rlist.get(0).equalsIgnoreCase(path));
// test listSubscriptions method
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
Set<String> subs = remoteStore.listSubscriptions(null);
Assert.assertNotNull(subs);
Assert.assertEquals(1, subs.size());
String sub = subs.iterator().next();
Assert.assertTrue(sub.equalsIgnoreCase(path));
}
use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestRemoteImapMailboxStore method testAddressMatchesAccountOrSendAs.
@Test
public void testAddressMatchesAccountOrSendAs() throws Exception {
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
Account acct = TestUtil.getAccount(USER_NAME);
RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, acct.getId());
assertTrue(remoteStore.addressMatchesAccountOrSendAs(acct.getMail()));
}
use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestRemoteImapMailboxStore method testOpenImapFolder.
@Test
public void testOpenImapFolder() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
Folder folder = mbox.createFolder(null, "TestOpenImapFolder", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
int folderId = folder.getId();
List<ImapMessage> expected = new LinkedList<ImapMessage>();
for (int i = 1; i <= 3; i++) {
Message msg = TestUtil.addMessage(mbox, folderId, String.format("imap message %s", i), System.currentTimeMillis());
expected.add(new ImapMessage(msg));
}
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
RemoteImapMailboxStore remoteStore = new RemoteImapMailboxStore(zmbox, TestUtil.getAccount(USER_NAME).getId());
List<ImapMessage> actual = remoteStore.openImapFolder(null, new ItemIdentifier(mbox.getAccountId(), folderId));
Collections.sort(expected);
Collections.sort(actual);
assertEquals("expected and actual ImapMessage lists have different lengths", expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertEquals(expected.get(i), actual.get(i));
}
}
use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestImapServerListener method testNotifyReadUnread.
@Test
public void testNotifyReadUnread() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
ZMailbox mboxStore = TestUtil.getZMailbox(REMOTE_USER_NAME);
ImapServerListener remoteListener = ImapServerListenerPool.getInstance().get(mboxStore);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
remoteListener.addListener(session);
// wait for waitset session to be created
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
session.doneSignal = new CountDownLatch(1);
String subject = "TestImapServerListener - testNotifyReadUnread";
TestUtil.addMessageLmtp(subject, TestUtil.getAddress(REMOTE_USER_NAME), "randomUserTestImapServerListener@yahoo.com");
ZMessage msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox subject:\"%s\"", subject));
assertTrue("New message should have UNREAD flag", msg.isUnread());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to be triggered after delivering the test message", session.wasTriggered());
// mark read
session.doneSignal = new CountDownLatch(1);
mboxStore.markMessageRead(msg.getId(), true);
msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox is:read subject:\"%s\"", subject));
assertFalse("New message should NOT have UNREAD flag", msg.isUnread());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to be triggered after marking test message READ", session.wasTriggered());
// mark unread
session.doneSignal = new CountDownLatch(1);
mboxStore.markMessageRead(msg.getId(), false);
msg = TestUtil.waitForMessage(mboxStore, String.format("in:inbox is:unread subject:\"%s\"", subject));
assertTrue("New message should have UNREAD flag", msg.isUnread());
try {
session.doneSignal.await((LC.zimbra_waitset_nodata_sleep_time.intValue() / 1000 + 2), TimeUnit.SECONDS);
} catch (Exception e) {
Assert.fail("Wait interrupted.");
}
assertTrue("Expected session to be triggered after marking test message UREAD", session.wasTriggered());
remoteListener.removeListener(session);
}
use of com.zimbra.cs.imap.RemoteImapMailboxStore in project zm-mailbox by Zimbra.
the class TestImapServerListener method testGetListeners.
@Test
public void testGetListeners() throws Exception {
Assume.assumeNotNull(remoteServer);
Assume.assumeNotNull(remoteAccount);
assertNotNull("ImapServerListener instance should not be null", remoteListener);
RemoteImapMailboxStore imapStore = new RemoteImapMailboxStore(mboxStore);
ImapCredentials creds = new ImapCredentials(remoteAccount);
ImapPath path = new ImapPath("INBOX", creds);
byte params = 0;
ImapHandler handler = new MockImapHandler().setCredentials(creds);
ImapFolder i4folder = new ImapFolder(path, params, handler);
MockImapListener session = new MockImapListener(imapStore, i4folder, handler);
assertNotNull("ImapListener instance should not be null", session);
Set<ImapRemoteSession> sessions = remoteListener.getListeners(remoteAccount.getId(), i4folder.getId());
assertNotNull("getListeners should not return NULL before adding a listener", sessions);
assertTrue("expecting an empty list before adding a listener", sessions.isEmpty());
remoteListener.addListener(session);
// wait for waitset session to be created
QueryWaitSetResponse resp = TestUtil.waitForSessions(1, 1, 6000, remoteListener.getWSId(), remoteServer);
sessions = remoteListener.getListeners(remoteAccount.getId(), i4folder.getId());
assertNotNull("getListeners should not return NULL after adding a listener", sessions);
assertFalse("expecting a non empty list after adding a listener", sessions.isEmpty());
remoteListener.removeListener(session);
sessions = remoteListener.getListeners(remoteAccount.getId(), i4folder.getId());
assertNotNull("getListeners should not return NULL after removing a listener", sessions);
assertTrue("expecting an empty list after removing a listener", sessions.isEmpty());
assertNull("Should not have a waitset after removing last listener", remoteListener.getWSId());
}
Aggregations