Search in sources :

Example 31 with ZFolder

use of com.zimbra.client.ZFolder 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 32 with ZFolder

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

the class TestImapImport method compare.

private void compare(ZMailbox mbox1, ZFolder folder1, ZMailbox mbox2, ZFolder folder2) throws Exception {
    assertNotNull(mbox1);
    assertNotNull(folder1);
    assertNotNull(mbox2);
    assertNotNull(folder2);
    // Recursively compare children
    for (ZFolder child1 : folder1.getSubFolders()) {
        if (isMailFolder(child1)) {
            ZFolder child2 = folder2.getSubFolderByPath(child1.getName());
            String msg = String.format("Could not find folder %s/%s for %s", folder2.getPath(), child1.getName(), mbox2.getName());
            assertNotNull(msg, child2);
            compare(mbox1, child1, mbox2, child2);
        }
    }
    assertEquals("Message count doesn't match (folder1 = " + folder1 + ", folder2 = " + folder2 + ")", folder1.getMessageCount(), folder2.getMessageCount());
    // Compare folders as long as neither one is the user root
    if (!(folder1.getPath().equals("/") || folder2.getPath().equals("/"))) {
        List<ZMessage> msgs1 = TestUtil.search(mbox1, "in:" + folder1.getPath());
        List<ZMessage> msgs2 = TestUtil.search(mbox2, "in:" + folder2.getPath());
        compareMessages(msgs1, msgs2);
    }
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZFolder(com.zimbra.client.ZFolder)

Example 33 with ZFolder

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

the class TestImapOneWayImport method compare.

private void compare() throws Exception {
    // Recursively compare the folder trees
    ZFolder folder1 = mRemoteMbox.getUserRoot();
    ZFolder folder2 = mLocalMbox.getFolderByPath(DS_FOLDER_ROOT);
    compare(mRemoteMbox, folder1, mLocalMbox, folder2);
}
Also used : ZFolder(com.zimbra.client.ZFolder)

Example 34 with ZFolder

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

the class TestImapOneWayImport method setUp.

@Override
public void setUp() throws Exception {
    cleanUp();
    mDisplayMailFoldersOnly = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
    Provisioning.getInstance().getLocalServer().setImapDisplayMailFoldersOnly(false);
    // Get mailbox references
    if (!TestUtil.accountExists(LOCAL_USER_NAME)) {
        TestUtil.createAccount(LOCAL_USER_NAME);
    }
    if (!TestUtil.accountExists(REMOTE_USER_NAME)) {
        TestUtil.createAccount(REMOTE_USER_NAME);
    }
    mRemoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
    mLocalMbox = TestUtil.getZMailbox(LOCAL_USER_NAME);
    // Get or create folder
    ZFolder folder = mLocalMbox.getFolderByPath(DS_FOLDER_ROOT);
    if (folder == null) {
        folder = TestUtil.createFolder(mLocalMbox, NAME_PREFIX);
    }
    // Create data source
    int port = Integer.parseInt(TestUtil.getServerAttr(Provisioning.A_zimbraImapBindPort));
    mDataSource = new ZImapDataSource(NAME_PREFIX, true, "localhost", port, REMOTE_USER_NAME, TestUtil.DEFAULT_PASSWORD, folder.getId(), ConnectionType.cleartext, true);
    String id = mLocalMbox.createDataSource(mDataSource);
    mDataSource = null;
    for (ZDataSource ds : mLocalMbox.getAllDataSources()) {
        if (ds.getId().equals(id)) {
            mDataSource = ds;
        }
    }
    assertNotNull(mDataSource);
    // Turn on cleartext login
    mOriginalCleartextValue = TestUtil.getServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled);
    TestUtil.setServerAttr(Provisioning.A_zimbraImapCleartextLoginEnabled, ProvisioningConstants.TRUE);
    // Turn off STARTTLS support so that unit tests don't bomb on Linux
    // (see bug 33683).
    mOriginalEnableStarttls = LC.javamail_imap_enable_starttls.booleanValue();
    LC.javamail_imap_enable_starttls.setDefault(Boolean.toString(false));
}
Also used : ZImapDataSource(com.zimbra.client.ZImapDataSource) ZFolder(com.zimbra.client.ZFolder) ZDataSource(com.zimbra.client.ZDataSource)

Example 35 with ZFolder

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

the class RuleRewriter method createFolderIfNecessary.

private void createFolderIfNecessary(String path, String ruleName) throws ServiceException {
    Pair<Folder, String> folderAndRemotePath = mMailbox.getFolderByPathLongestMatch(null, Mailbox.ID_FOLDER_USER_ROOT, path);
    Folder folder = folderAndRemotePath.getFirst();
    String remotePath = folderAndRemotePath.getSecond();
    if (StringUtil.isNullOrEmpty(remotePath)) {
        remotePath = null;
    }
    if (folder instanceof Mountpoint && remotePath != null) {
        // Create remote folder path
        Mountpoint mountpoint = (Mountpoint) folder;
        ZimbraLog.filter.info("Creating folder %s in remote folder %s for rule %s.", remotePath, folder.getPath(), ruleName);
        ZMailbox remoteMbox = FilterUtil.getRemoteZMailbox(mMailbox, (Mountpoint) folder);
        ItemId id = mountpoint.getTarget();
        ZFolder parent = remoteMbox.getFolderById(id.toString());
        if (parent == null) {
            String msg = String.format("Could not find folder with id %d in remote mailbox %s.", mountpoint.getRemoteId(), mountpoint.getOwnerId());
            throw ServiceException.FAILURE(msg, null);
        }
        String[] pathElements = remotePath.split(ZMailbox.PATH_SEPARATOR);
        for (String folderName : pathElements) {
            if (!StringUtil.isNullOrEmpty(folderName)) {
                ZFolder currentFolder = parent.getSubFolderByPath(folderName);
                if (currentFolder != null) {
                    parent = currentFolder;
                } else {
                    parent = remoteMbox.createFolder(parent.getId(), folderName, ZFolder.View.message, null, null, null);
                }
            }
        }
    } else if (remotePath != null) {
        // Create local folder path
        ZimbraLog.filter.info("Creating folder %s for rule %s.", path, ruleName);
        mMailbox.createFolder(null, path, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    }
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ItemId(com.zimbra.cs.service.util.ItemId)

Aggregations

ZFolder (com.zimbra.client.ZFolder)84 ZMailbox (com.zimbra.client.ZMailbox)54 Folder (com.zimbra.cs.mailbox.Folder)21 Test (org.junit.Test)21 ServiceException (com.zimbra.common.service.ServiceException)19 Account (com.zimbra.cs.account.Account)19 Mailbox (com.zimbra.cs.mailbox.Mailbox)17 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)17 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)13 ItemId (com.zimbra.cs.service.util.ItemId)13 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)12 ZMessage (com.zimbra.client.ZMessage)10 ZMountpoint (com.zimbra.client.ZMountpoint)9 AccountServiceException (com.zimbra.cs.account.AccountServiceException)9 ZAuthToken (com.zimbra.common.auth.ZAuthToken)7 ArrayList (java.util.ArrayList)7 ZDataSource (com.zimbra.client.ZDataSource)6 ZSearchFolder (com.zimbra.client.ZSearchFolder)6 Provisioning (com.zimbra.cs.account.Provisioning)6 AuthToken (com.zimbra.cs.account.AuthToken)5