use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ProxyGroupMembership method toElement.
@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
Element group = super.toElement(ctxt, parent, true);
if (nameOnly) {
return group;
}
ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
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) {
group.addElement(DavElements.E_HREF).setText(UrlNamespace.getCalendarProxyWriteUrl(account, owner));
}
} else if ((rights & ACL.RIGHT_READ) > 0) {
Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
if (owner != null) {
group.addElement(DavElements.E_HREF).setText(UrlNamespace.getCalendarProxyReadUrl(account, owner));
}
}
} catch (ServiceException se) {
ZimbraLog.dav.warn("can't convert rights", se);
}
}
return group;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class FilterUtil method addMessage.
/**
* Adds a message to the given folder. Handles both local folders and mountpoints.
* @return the id of the new message, or <tt>null</tt> if it was a duplicate
*/
public static ItemId addMessage(DeliveryContext context, Mailbox mbox, ParsedMessage pm, String recipient, String folderPath, boolean noICal, int flags, String[] tags, int convId, OperationContext octxt) throws ServiceException {
// Do initial lookup.
Pair<Folder, String> folderAndPath = mbox.getFolderByPathLongestMatch(octxt, Mailbox.ID_FOLDER_USER_ROOT, folderPath);
Folder folder = folderAndPath.getFirst();
String remainingPath = folderAndPath.getSecond();
ZimbraLog.filter.debug("Attempting to file to %s, remainingPath=%s.", folder, remainingPath);
if (folder instanceof Mountpoint) {
Mountpoint mountpoint = (Mountpoint) folder;
ZMailbox remoteMbox = getRemoteZMailbox(mbox, mountpoint);
// Look up remote folder.
String remoteAccountId = mountpoint.getOwnerId();
ItemId id = mountpoint.getTarget();
ZFolder remoteFolder = remoteMbox.getFolderById(id.toString());
if (remoteFolder != null) {
if (remainingPath != null) {
remoteFolder = remoteFolder.getSubFolderByPath(remainingPath);
if (remoteFolder == null) {
String msg = String.format("Subfolder %s of mountpoint %s does not exist.", remainingPath, mountpoint.getName());
throw ServiceException.FAILURE(msg, null);
}
}
}
// File to remote folder.
if (remoteFolder != null) {
byte[] content;
try {
content = pm.getRawData();
} catch (Exception e) {
throw ServiceException.FAILURE("Unable to get message content", e);
}
String msgId = remoteMbox.addMessage(remoteFolder.getId(), com.zimbra.cs.mailbox.Flag.toString(flags), null, 0, content, false);
return new ItemId(msgId, remoteAccountId);
} else {
String msg = String.format("Unable to find remote folder %s for mountpoint %s.", remainingPath, mountpoint.getName());
throw ServiceException.FAILURE(msg, null);
}
} else {
if (!StringUtil.isNullOrEmpty(remainingPath)) {
// Only part of the folder path matched. Auto-create the remaining path.
ZimbraLog.filter.info("Could not find folder %s. Automatically creating it.", folderPath);
folder = mbox.createFolder(octxt, folderPath, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
}
try {
DeliveryOptions dopt = new DeliveryOptions().setFolderId(folder).setNoICal(noICal);
dopt.setFlags(flags).setTags(tags).setConversationId(convId).setRecipientEmail(recipient);
Message msg = mbox.addMessage(octxt, pm, dopt, context);
if (msg == null) {
return null;
} else {
return new ItemId(msg);
}
} catch (IOException e) {
throw ServiceException.FAILURE("Unable to add message", e);
}
}
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestJaxb method testGetFolderWithCacheContainingNullParent.
@Test
public void testGetFolderWithCacheContainingNullParent() throws Exception {
TestUtil.createAccount(USER_NAME);
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
ZFolder f1 = TestUtil.createFolder(zmbox, FOLDER_F1);
ZFolder f2 = TestUtil.createFolder(zmbox, SUB_FOLDER_F2);
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
OperationContext octxt = new OperationContext(mbox);
ItemId f1ItemId = new ItemId(mbox, Integer.parseInt(f1.getId()));
ItemId f2ItemId = new ItemId(mbox, Integer.parseInt(f2.getId()));
// ItemId rootItemId = new ItemId(mbox, Mailbox.ID_FOLDER_USER_ROOT);
// mbox.getFolderTree(octxt, rootItemId, false);
Folder f1folder = mbox.getFolderById(octxt, f1ItemId.getId());
Folder f2folder = mbox.getFolderById(octxt, f2ItemId.getId());
// Bug 100588 f1folder/f2folder will have been retrieved from the folder cache. Deliberately poison it
// by setting the parent folder to null, and ensure that can still successfully do a GetFolderRequest
f1folder.setParent(null);
f2folder.setParent(null);
GetFolderResponse gfResp = zmbox.invokeJaxb(new GetFolderRequest());
Assert.assertNotNull("GetFolderResponse null", gfResp);
}
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();
}
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);
}
}
Aggregations