Search in sources :

Example 16 with RemoteImapMailboxStore

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));
}
Also used : MetadataList(com.zimbra.cs.mailbox.MetadataList) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) Metadata(com.zimbra.cs.mailbox.Metadata) Test(org.junit.Test)

Example 17 with RemoteImapMailboxStore

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()));
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) Test(org.junit.Test)

Example 18 with RemoteImapMailboxStore

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));
    }
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ImapMessage(com.zimbra.cs.imap.ImapMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ImapMessage(com.zimbra.cs.imap.ImapMessage) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) Folder(com.zimbra.cs.mailbox.Folder) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 19 with RemoteImapMailboxStore

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);
}
Also used : ZMessage(com.zimbra.client.ZMessage) ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) CountDownLatch(java.util.concurrent.CountDownLatch) HttpException(org.apache.http.HttpException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ImapServerListener(com.zimbra.cs.imap.ImapServerListener) ZMailbox(com.zimbra.client.ZMailbox) Test(org.junit.Test)

Example 20 with RemoteImapMailboxStore

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());
}
Also used : ImapRemoteSession(com.zimbra.cs.imap.ImapRemoteSession) ImapFolder(com.zimbra.cs.imap.ImapFolder) QueryWaitSetResponse(com.zimbra.soap.admin.message.QueryWaitSetResponse) RemoteImapMailboxStore(com.zimbra.cs.imap.RemoteImapMailboxStore) ImapHandler(com.zimbra.cs.imap.ImapHandler) ImapCredentials(com.zimbra.cs.imap.ImapCredentials) ImapPath(com.zimbra.cs.imap.ImapPath) Test(org.junit.Test)

Aggregations

RemoteImapMailboxStore (com.zimbra.cs.imap.RemoteImapMailboxStore)20 Test (org.junit.Test)19 ZMailbox (com.zimbra.client.ZMailbox)16 ImapCredentials (com.zimbra.cs.imap.ImapCredentials)14 ImapFolder (com.zimbra.cs.imap.ImapFolder)14 ImapHandler (com.zimbra.cs.imap.ImapHandler)14 ImapPath (com.zimbra.cs.imap.ImapPath)14 QueryWaitSetResponse (com.zimbra.soap.admin.message.QueryWaitSetResponse)12 ServiceException (com.zimbra.common.service.ServiceException)10 ImapServerListener (com.zimbra.cs.imap.ImapServerListener)10 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 HttpException (org.apache.http.HttpException)10 ZMessage (com.zimbra.client.ZMessage)5 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 ZFolder (com.zimbra.client.ZFolder)2 ZTag (com.zimbra.client.ZTag)2 ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)2 SoapTransport (com.zimbra.common.soap.SoapTransport)2 Account (com.zimbra.cs.account.Account)2