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