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