Search in sources :

Example 1 with ItemIdentifier

use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.

the class ZBaseItem method getIdInMailbox.

public int getIdInMailbox(String id) throws ServiceException {
    String acctId = null;
    try {
        acctId = mMailbox.getAccountId();
    } catch (ServiceException e) {
    }
    ItemIdentifier itemId = new ItemIdentifier(id, acctId);
    return itemId.id;
}
Also used : ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) ServiceException(com.zimbra.common.service.ServiceException)

Example 2 with ItemIdentifier

use of com.zimbra.common.mailbox.ItemIdentifier 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 3 with ItemIdentifier

use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.

the class ImapServerListener method removeListener.

public void removeListener(ImapRemoteSession listener) throws ServiceException {
    ItemIdentifier folderIdent = listener.getFolderItemIdentifier();
    String accountId = (folderIdent.accountId != null) ? folderIdent.accountId : listener.getTargetAccountId();
    ConcurrentHashMap<Integer, Set<ImapRemoteSession>> foldersToSessions = sessionMap.get(accountId);
    if (foldersToSessions != null) {
        Integer folderId = folderIdent.id;
        Set<ImapRemoteSession> sessions = foldersToSessions.get(folderId);
        if (sessions != null) {
            ZimbraLog.imap.debug("removeListener acct=%s folderId=%s %s", listener.getTargetAccountId(), folderIdent, listener);
            sessions.remove(listener);
            // cleanup to save memory at cost of reducing speed of adding/removing sessions
            if (sessions.isEmpty()) {
                // if no more sessions are registered for this folder remove the empty List from the map
                foldersToSessions.remove(folderId);
                if (foldersToSessions.isEmpty()) {
                    // if no more sessions registered for this account remove the empty map
                    sessionMap.remove(accountId);
                    if (sessionMap.isEmpty()) {
                        deleteWaitSet();
                    }
                }
            }
            if (wsID != null) {
                initWaitSet(accountId, true);
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) HashSet(java.util.HashSet) Set(java.util.Set)

Example 4 with ItemIdentifier

use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.

the class GetIMAPRecentCutoff method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    GetIMAPRecentCutoffRequest req = zsc.elementToJaxb(request);
    ItemIdentifier itemIdent = ItemIdentifier.fromOwnerAndRemoteId(mbox.getAccountId(), req.getId());
    if (!mbox.getAccountId().equals(itemIdent.accountId)) {
        throw MailServiceException.NO_SUCH_FOLDER(req.getId());
    }
    return zsc.jaxbToElement(new GetIMAPRecentCutoffResponse(mbox.getImapRecentCutoff(octxt, itemIdent.id)));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) GetIMAPRecentCutoffRequest(com.zimbra.soap.mail.message.GetIMAPRecentCutoffRequest) ItemIdentifier(com.zimbra.common.mailbox.ItemIdentifier) GetIMAPRecentCutoffResponse(com.zimbra.soap.mail.message.GetIMAPRecentCutoffResponse) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Example 5 with ItemIdentifier

use of com.zimbra.common.mailbox.ItemIdentifier in project zm-mailbox by Zimbra.

the class TestZClient method testSetTags.

@Test
public void testSetTags() throws Exception {
    ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
    Mailbox mbox = TestUtil.getMailbox(USER_NAME);
    Message msg = TestUtil.addMessage(mbox, Mailbox.ID_FOLDER_INBOX, "testAlterTag message", System.currentTimeMillis());
    String tag1Name = "testSetTags tag1";
    String tag2Name = "testSetTags tag2";
    String tag3Name = "testSetTags tag3";
    int msgId = msg.getId();
    zmbox.createTag(tag1Name, ZTag.Color.blue);
    Collection<ItemIdentifier> ids = new ArrayList<ItemIdentifier>(1);
    ids.add(new ItemIdentifier(mbox.getAccountId(), msgId));
    // add tag via zmailbox
    zmbox.alterTag(null, ids, tag1Name, true);
    assertTrue("Message should be tagged with " + tag1Name, waitForTag(msgId, mbox, tag1Name, true, 3000));
    assertTrue(msg.isTagged(tag1Name));
    // override via setTags
    Collection<String> newTags = new ArrayList<String>();
    newTags.add(tag2Name);
    newTags.add(tag3Name);
    zmbox.setTags(null, ids, 0, newTags);
    assertTrue("Message should NOT be tagged with " + tag1Name, waitForTag(msgId, mbox, tag1Name, false, 3000));
    assertTrue("Message should be tagged with " + tag2Name, waitForTag(msgId, mbox, tag2Name, true, 3000));
    assertTrue("Message should be tagged with " + tag3Name, waitForTag(msgId, mbox, tag3Name, true, 3000));
    msg = mbox.getMessageById(null, msgId);
    assertFalse(msg.isTagged("testSetTags tag1"));
    assertTrue(msg.isTagged("testSetTags tag2"));
    assertTrue(msg.isTagged("testSetTags tag3"));
}
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) ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Message(com.zimbra.cs.mailbox.Message) ArrayList(java.util.ArrayList) ZMountpoint(com.zimbra.client.ZMountpoint) Test(org.junit.Test)

Aggregations

ItemIdentifier (com.zimbra.common.mailbox.ItemIdentifier)26 ZMailbox (com.zimbra.client.ZMailbox)12 Mailbox (com.zimbra.cs.mailbox.Mailbox)12 Test (org.junit.Test)11 ZMessage (com.zimbra.client.ZMessage)6 ServiceException (com.zimbra.common.service.ServiceException)6 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)6 ArrayList (java.util.ArrayList)6 ZMountpoint (com.zimbra.client.ZMountpoint)5 MailboxStore (com.zimbra.common.mailbox.MailboxStore)5 ImapMessage (com.zimbra.cs.imap.ImapMessage)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 Message (com.zimbra.cs.mailbox.Message)5 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)4 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)4 Folder (com.zimbra.cs.mailbox.Folder)4 ZContact (com.zimbra.client.ZContact)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Contact (com.zimbra.cs.mailbox.Contact)3 OperationContext (com.zimbra.cs.mailbox.OperationContext)3