Search in sources :

Example 41 with ZFolder

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

the class TestFilterExisting method testFileIntoSameFolder.

/**
     * Confirms that filing into the same folder doesn't result in a duplicate copy
     * of the message (bug 42051).
     */
@Test
public void testFileIntoSameFolder() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder3 = TestUtil.createFolder(mbox, FOLDER3_PATH);
    String subject = NAME_PREFIX + " test folder3";
    String id = TestUtil.addMessage(mbox, subject, folder3.getId(), null);
    // Run the folder3 rule, and make sure one message matches instead of two.
    Set<String> affectedIds = runRules(new String[] { FOLDER3_RULE_NAME }, id, null);
    Assert.assertEquals(0, affectedIds.size());
    TestUtil.getMessage(mbox, "subject:\"" + subject + "\"");
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) Test(org.junit.Test)

Example 42 with ZFolder

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

the class TestPop3Import method testFiltering.

/**
     * Confirms that messages pulled from a POP3 account are affected by
     * mail filtering (bug 13821).
     */
@Test
public void testFiltering() throws Exception {
    String folderPath = "/" + NAME_PREFIX + "-testFiltering";
    String filteredPath = "/" + NAME_PREFIX + "-testFiltering-filtered";
    // Create remote account
    prov.createAccount(TestUtil.getAddress(TEMP_USER_NAME), "test123", null);
    // Add message to remote mailbox
    ZMailbox remoteMbox = TestUtil.getZMailbox(TEMP_USER_NAME);
    TestUtil.addMessage(remoteMbox, NAME_PREFIX + " testFiltering");
    // Create local folders
    ZMailbox localMbox = TestUtil.getZMailbox(USER_NAME);
    localMbox.getFolderByPath("/Inbox");
    ZFolder dsFolder = TestUtil.createFolder(localMbox, folderPath);
    TestUtil.createFolder(localMbox, filteredPath);
    // Create filter rule that files to the local folder
    List<ZFilterRule> rules = new ArrayList<ZFilterRule>();
    List<ZFilterCondition> conditions = new ArrayList<ZFilterCondition>();
    List<ZFilterAction> actions = new ArrayList<ZFilterAction>();
    conditions.add(new ZHeaderCondition("subject", HeaderOp.CONTAINS, "testFiltering"));
    actions.add(new ZFileIntoAction(filteredPath));
    rules.add(new ZFilterRule("testFiltering", true, false, conditions, actions));
    localMbox.saveIncomingFilterRules(new ZFilterRules(rules));
    // Set up data source and run import
    ZPop3DataSource ds = getZDataSource();
    ds.setUsername(TEMP_USER_NAME);
    ds.setFolderId(dsFolder.getId());
    ds.setEnabled(true);
    localMbox.modifyDataSource(ds);
    // Import data and make sure the message was filed to the folder
    TestUtil.importDataSource(ds, localMbox, remoteMbox);
    List<ZMessage> messages = TestUtil.search(localMbox, "in:" + folderPath);
    Assert.assertEquals("Found unexpected messages in " + folderPath, 0, messages.size());
    messages = TestUtil.search(localMbox, "in:" + filteredPath);
    Assert.assertEquals("Message not found in " + filteredPath, 1, messages.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZHeaderCondition(com.zimbra.client.ZFilterCondition.ZHeaderCondition) ZFilterCondition(com.zimbra.client.ZFilterCondition) ArrayList(java.util.ArrayList) ZFilterRule(com.zimbra.client.ZFilterRule) ZFilterAction(com.zimbra.client.ZFilterAction) ZMailbox(com.zimbra.client.ZMailbox) ZPop3DataSource(com.zimbra.client.ZPop3DataSource) ZFileIntoAction(com.zimbra.client.ZFilterAction.ZFileIntoAction) ZFolder(com.zimbra.client.ZFolder) ZFilterRules(com.zimbra.client.ZFilterRules) Test(org.junit.Test)

Example 43 with ZFolder

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

the class AbstractProxyProperty method getMountpoints.

protected ArrayList<Pair<Mountpoint, ZFolder>> getMountpoints(DavContext ctxt) {
    ArrayList<Pair<Mountpoint, ZFolder>> mps = new ArrayList<Pair<Mountpoint, ZFolder>>();
    try {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        for (MailItem item : mbox.getItemList(ctxt.getOperationContext(), MailItem.Type.MOUNTPOINT)) {
            Mountpoint mp = (Mountpoint) item;
            // skip non-calendar mountpoints
            if (mp.getDefaultView() != MailItem.Type.APPOINTMENT && mp.getDefaultView() != MailItem.Type.TASK) {
                continue;
            }
            ZAuthToken zat = AuthProvider.getAuthToken(ctxt.getAuthAccount()).toZAuthToken();
            ZMailbox zmbx = RemoteCollection.getRemoteMailbox(zat, mp.getOwnerId());
            // skip dangling mountpoints
            if (zmbx == null) {
                continue;
            }
            try {
                ZFolder folder = zmbx.getFolderById(mp.getTarget().toString(account));
                // skip dangling mountpoints
                if (folder == null) {
                    continue;
                }
                mps.add(new Pair<Mountpoint, ZFolder>(mp, folder));
            } catch (ServiceException se) {
                ZimbraLog.dav.warn("can't get remote folder", se);
            }
        }
    } catch (ServiceException se) {
        ZimbraLog.dav.warn("can't get mailbox", se);
    }
    return mps;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ArrayList(java.util.ArrayList) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZAuthToken(com.zimbra.common.auth.ZAuthToken) Pair(com.zimbra.common.util.Pair)

Example 44 with ZFolder

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

the class CalendarProxyReadFor method toElement.

@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
    Element proxy = super.toElement(ctxt, parent, true);
    if (nameOnly) {
        return proxy;
    }
    ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
    HashSet<Account> writeProxies = new HashSet<Account>();
    HashMap<Account, Element> proxies = new HashMap<Account, Element>();
    for (Pair<Mountpoint, ZFolder> folder : mps) {
        try {
            short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
            Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
            if (owner == null) {
                continue;
            }
            if ((rights & ACL.RIGHT_WRITE) > 0) {
                writeProxies.add(owner);
                proxies.remove(owner);
            }
            if ((rights & ACL.RIGHT_WRITE) == 0 && (rights & ACL.RIGHT_READ) > 0) {
                if (!writeProxies.contains(owner) && !proxies.containsKey(owner)) {
                    Element e = DocumentHelper.createElement(DavElements.E_HREF);
                    e.setText(UrlNamespace.getPrincipalUrl(account, owner));
                    proxies.put(owner, e);
                }
            }
        } catch (ServiceException se) {
            ZimbraLog.dav.warn("can't convert rights", se);
        }
    }
    for (Element e : proxies.values()) {
        proxy.add(e);
    }
    return proxy;
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Element(org.dom4j.Element) ServiceException(com.zimbra.common.service.ServiceException) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Pair(com.zimbra.common.util.Pair) HashSet(java.util.HashSet)

Example 45 with ZFolder

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

the class CalendarProxyWriteFor method toElement.

@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
    Element proxy = super.toElement(ctxt, parent, true);
    if (nameOnly) {
        return proxy;
    }
    ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
    HashSet<Account> proxies = new HashSet<Account>();
    for (Pair<Mountpoint, ZFolder> folder : mps) {
        try {
            short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
            if ((rights & ACL.RIGHT_WRITE) > 0) {
                Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
                if (owner == null) {
                    continue;
                }
                if (!proxies.contains(owner)) {
                    proxy.addElement(DavElements.E_HREF).setText(UrlNamespace.getPrincipalUrl(account, owner));
                    proxies.add(owner);
                }
            }
        } catch (ServiceException se) {
            ZimbraLog.dav.warn("can't convert rights", se);
        }
    }
    return proxy;
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) Element(org.dom4j.Element) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Pair(com.zimbra.common.util.Pair) HashSet(java.util.HashSet)

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