Search in sources :

Example 6 with ZMailbox

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

the class TestImap method testStoreTagsDirty.

@Test
public void testStoreTagsDirty() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue(tags == null || tags.size() == 0);
    String tagName = "T1";
    final String tagName2 = "T2";
    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);
    MailboxInfo info = connection.select("INBOX");
    assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
    assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(1, 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));
    ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
    req.setResponseHandler(new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) throws Exception {
            if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
                Flags flags = (Flags) res.getData();
                assertTrue(flags.isSet(tagName2));
            }
        }
    });
    req.sendCheckStatus();
}
Also used : ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ZTag(com.zimbra.client.ZTag) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) ServiceException(com.zimbra.common.service.ServiceException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 7 with ZMailbox

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

the class ImapServerListenerPoolTest method testInstanceManagement.

@Test
public void testInstanceManagement() throws ServiceException {
    String serverName1 = "example1.zimbra.com";
    String serverName2 = "example2.zimbra.com";
    HashMap<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraServiceHostname, "example1.zimbra.com");
    attrs.put(Provisioning.A_zimbraAdminPort, 7071);
    prov.createServer(serverName1, attrs);
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraServiceHostname, "example2.zimbra.com");
    attrs.put(Provisioning.A_zimbraAdminPort, 7071);
    prov.createServer(serverName2, new HashMap<String, Object>());
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
    attrs.put(Provisioning.A_zimbraMailHost, serverName1);
    Account user1 = prov.createAccount("user1@example1.zimbra.com", "test123", attrs);
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
    attrs.put(Provisioning.A_zimbraMailHost, serverName1);
    Account user1_2 = prov.createAccount("user1_2@example1.zimbra.com", "test123", attrs);
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
    attrs.put(Provisioning.A_zimbraMailHost, serverName2);
    Account user2 = prov.createAccount("user2@example2.zimbra.com", "test123", attrs);
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
    attrs.put(Provisioning.A_zimbraMailHost, serverName2);
    Account user2_2 = prov.createAccount("user2_2@example2.zimbra.com", "test123", attrs);
    ZMailbox.Options options = new ZMailbox.Options();
    options.setAccount(user1.getId());
    options.setAccountBy(Key.AccountBy.id);
    options.setPassword("test123");
    options.setAuthAuthToken(false);
    options.setAuthToken("sometoken");
    options.setUri("https://" + serverName1);
    ZMailbox testMbox1 = new MockZMailbox(options);
    options = new ZMailbox.Options();
    options.setAccount(user1_2.getId());
    options.setAccountBy(Key.AccountBy.id);
    options.setPassword("test123");
    options.setAuthAuthToken(false);
    options.setAuthToken("sometoken");
    options.setUri("https://" + serverName1);
    ZMailbox testMbox1_2 = new MockZMailbox(options);
    options = new ZMailbox.Options();
    options.setAccount(user2.getId());
    options.setAccountBy(Key.AccountBy.id);
    options.setPassword("test123");
    options.setAuthAuthToken(false);
    options.setAuthToken("sometoken");
    options.setUri("https://" + serverName2);
    ZMailbox testMbox2 = new MockZMailbox(options);
    options = new ZMailbox.Options();
    options.setAccount(user2_2.getId());
    options.setAccountBy(Key.AccountBy.id);
    options.setPassword("test123");
    options.setAuthAuthToken(false);
    options.setAuthToken("sometoken");
    options.setUri("https://" + serverName2);
    ZMailbox testMbox2_2 = new MockZMailbox(options);
    ImapServerListenerPool pool = ImapServerListenerPool.getInstance();
    ImapServerListener listener1 = pool.get(testMbox1);
    ImapServerListener listener2 = pool.get(testMbox2);
    ImapServerListener listener1_2 = pool.get(testMbox1_2);
    ImapServerListener listener2_2 = pool.get(testMbox2_2);
    assertNotSame("listener 1 should be different from listener 2", listener1, listener2);
    assertNotSame("listener 1_2 should be different from listener 2_2", listener1_2, listener2_2);
    assertSame("listener 1 should be the same as listener 1_2", listener1, listener1_2);
    assertSame("listener 2 should be the same as listener 2_2", listener2, listener2_2);
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with ZMailbox

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

the class ImapPath method setupMailboxStoreForTarget.

private ImapMailboxStore setupMailboxStoreForTarget(Account target, ItemId iidRemote) throws ServiceException {
    ImapMailboxStore imapMailboxStore = null;
    // if both target and owner are on local server and using local imap
    if (Provisioning.onLocalServer(target) && onLocalServer()) {
        try {
            MailboxStore mbox = MailboxManager.getInstance().getMailboxByAccount(target);
            imapMailboxStore = ImapMailboxStore.get(mbox, target.getId());
        } catch (ServiceException se) {
            ZimbraLog.imap.debug("Unexpected exception", se);
        }
    } else {
        Account acct = mCredentials == null ? null : Provisioning.getInstance().get(AccountBy.id, mCredentials.getAccountId());
        if (acct == null) {
            return null;
        }
        try {
            ZMailbox zmbx = getZMailboxForAccount(target);
            ZFolder zfolder = zmbx.getFolderById(iidRemote.toString(mCredentials.getAccountId()));
            if (zfolder == null) {
                return null;
            }
            imapMailboxStore = ImapMailboxStore.get(zmbx);
        } catch (ServiceException e) {
            ZimbraLog.imap.debug("Unexpected exception", e);
        }
    }
    return imapMailboxStore;
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) MailboxStore(com.zimbra.common.mailbox.MailboxStore) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZFolder(com.zimbra.client.ZFolder)

Example 9 with ZMailbox

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

the class ImapServerListener method addListener.

public void addListener(ImapRemoteSession listener) throws ServiceException {
    ItemIdentifier folderIdent = listener.getFolderItemIdentifier();
    String accountId = (folderIdent.accountId != null) ? folderIdent.accountId : listener.getTargetAccountId();
    boolean alreadyListening = sessionMap.containsKey(accountId);
    sessionMap.putIfAbsent(accountId, new ConcurrentHashMap<Integer, Set<ImapRemoteSession>>());
    Integer folderId = folderIdent.id;
    ConcurrentHashMap<Integer, Set<ImapRemoteSession>> foldersToSessions = sessionMap.get(accountId);
    foldersToSessions.putIfAbsent(folderId, Collections.newSetFromMap(new ConcurrentHashMap<ImapRemoteSession, Boolean>()));
    Set<ImapRemoteSession> sessions = foldersToSessions.get(folderId);
    if (!sessions.contains(listener)) {
        ZimbraLog.imap.debug("addListener acct=%s folderId=%s %s", listener.getTargetAccountId(), folderIdent, listener);
        sessions.add(listener);
    }
    if (wsID != null) {
        ZMailbox zmbox = (ZMailbox) listener.getMailbox();
        zmbox.setCurWaitSetID(wsID);
    }
    initWaitSet(accountId, alreadyListening);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) HashSet(java.util.HashSet) Set(java.util.Set) ZMailbox(com.zimbra.client.ZMailbox) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 10 with ZMailbox

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

the class ImapServerListener method unsetWaitSetIdOnMailboxes.

private void unsetWaitSetIdOnMailboxes() {
    for (Map<Integer, Set<ImapRemoteSession>> foldersToSessions : sessionMap.values()) {
        for (Set<ImapRemoteSession> sessions : foldersToSessions.values()) {
            for (ImapRemoteSession session : sessions) {
                ZMailbox zmbox = (ZMailbox) session.getMailbox();
                zmbox.unsetCurWaitSetID();
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashSet(java.util.HashSet) Set(java.util.Set) ZMailbox(com.zimbra.client.ZMailbox)

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