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