use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class GetFolderTest method mount.
@Test
public void mount() throws Exception {
Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
Folder.FolderOptions fopt = new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT);
int folderId = mbox2.createFolder(null, "foo", fopt).getId();
Folder folder = mbox2.getFolderById(null, folderId);
mbox2.createFolder(null, "bar", folderId, fopt);
mbox2.grantAccess(null, folderId, acct.getId(), ACL.GRANTEE_USER, (short) (ACL.RIGHT_READ | ACL.RIGHT_WRITE), null);
Mountpoint mpt = mbox.createMountpoint(null, Mailbox.ID_FOLDER_USER_ROOT, "remote", acct2.getId(), folderId, folder.getUuid(), MailItem.Type.DOCUMENT, 0, (byte) 2, false);
// fetch the mountpoint directly
Element request = new Element.XMLElement(MailConstants.GET_FOLDER_REQUEST);
request.addElement(MailConstants.E_FOLDER).addAttribute(MailConstants.A_FOLDER, mpt.getId());
Element response = new GetFolder().handle(request, ServiceTestUtil.getRequestContext(acct));
Element root = response.getOptionalElement(MailConstants.E_MOUNT);
Assert.assertNotNull("top-level mountpoint is listed", root);
Assert.assertFalse("top level mountpont is not stubbed", isStubbed(root));
Element leaf = getSubfolder(root, "bar");
Assert.assertNotNull("leaf node present", leaf);
Assert.assertFalse("leaf not stubbed", isStubbed(leaf));
// fetch the entire tree (does not recurse through mountpoint)
request = new Element.XMLElement(MailConstants.GET_FOLDER_REQUEST);
response = new GetFolder().handle(request, ServiceTestUtil.getRequestContext(acct));
root = response.getOptionalElement(MailConstants.E_FOLDER);
Assert.assertNotNull("top-level folder is listed", root);
Element mount = getSubfolder(root, "remote");
Assert.assertNotNull("mountpoint present", mount);
Assert.assertTrue("mountpoint stubbed", isStubbed(mount));
leaf = getSubfolder(mount, "bar");
Assert.assertNull("leaf node not present", leaf);
// fetch the entire tree, traversing mountpoints
request.addAttribute(MailConstants.A_TRAVERSE, true);
response = new GetFolder().handle(request, ServiceTestUtil.getRequestContext(acct));
root = response.getOptionalElement(MailConstants.E_FOLDER);
Assert.assertNotNull("top-level folder is listed", root);
mount = getSubfolder(root, "remote");
Assert.assertNotNull("mountpoint present", mount);
Assert.assertFalse("mountpoint not stubbed", isStubbed(mount));
leaf = getSubfolder(mount, "bar");
Assert.assertNotNull("leaf node present", leaf);
Assert.assertFalse("leaf node not stubbed", isStubbed(leaf));
// fetch the tree to a depth of 1, traversing mountpoints
request.addAttribute(MailConstants.A_TRAVERSE, true).addAttribute(MailConstants.A_FOLDER_DEPTH, 1);
response = new GetFolder().handle(request, ServiceTestUtil.getRequestContext(acct));
root = response.getOptionalElement(MailConstants.E_FOLDER);
Assert.assertNotNull("top-level folder is listed", root);
mount = getSubfolder(root, "remote");
Assert.assertNotNull("mountpoint present", mount);
Assert.assertFalse("mountpoint not stubbed", isStubbed(mount));
leaf = getSubfolder(mount, "bar");
Assert.assertNull("leaf node not present", leaf);
// broken link
mbox2.delete(null, folderId, MailItem.Type.FOLDER);
response = new GetFolder().handle(request, ServiceTestUtil.getRequestContext(acct));
root = response.getOptionalElement(MailConstants.E_FOLDER);
Assert.assertNotNull("top-level folder is listed", root);
mount = getSubfolder(root, "remote");
Assert.assertNotNull("mountpoint present", mount);
Assert.assertTrue("mountpoint is stubbed", isStubbed(mount));
Assert.assertTrue("mountpoint is broken", mount.getAttributeBool(MailConstants.A_BROKEN, false));
leaf = getSubfolder(mount, "bar");
Assert.assertNull("leaf node absent", leaf);
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class ScheduleInbox method getCalendarFolders.
private java.util.Collection<Folder> getCalendarFolders(DavContext ctxt) throws ServiceException, DavException {
ArrayList<Folder> calendars = new ArrayList<Folder>();
Mailbox mbox = getMailbox(ctxt);
for (Folder f : mbox.getFolderList(ctxt.getOperationContext(), SortBy.NONE)) {
if (!(f instanceof Mountpoint) && (f.getDefaultView() == MailItem.Type.APPOINTMENT || f.getDefaultView() == MailItem.Type.TASK)) {
calendars.add(f);
}
}
return calendars;
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class UrlNamespace method getResourceFromMailItem.
/* Returns DavResource for the MailItem. */
public static DavResource getResourceFromMailItem(DavContext ctxt, MailItem item) throws DavException {
DavResource resource = null;
if (item == null) {
return resource;
}
MailItem.Type itemType = item.getType();
try {
MailItem.Type viewType;
switch(itemType) {
case MOUNTPOINT:
Mountpoint mp = (Mountpoint) item;
viewType = mp.getDefaultView();
// don't expose mounted calendars when using iCal style delegation model.
if (!ctxt.useIcalDelegation() && (viewType == MailItem.Type.APPOINTMENT || viewType == MailItem.Type.TASK)) {
resource = new RemoteCalendarCollection(ctxt, mp);
} else if (viewType == MailItem.Type.CONTACT) {
resource = new RemoteAddressbookCollection(ctxt, mp);
} else {
resource = new RemoteCollection(ctxt, mp);
}
break;
case FOLDER:
Folder f = (Folder) item;
viewType = f.getDefaultView();
if (f.getId() == Mailbox.ID_FOLDER_INBOX && DavResource.isSchedulingEnabled()) {
resource = new ScheduleInbox(ctxt, f);
} else if (f.getId() == Mailbox.ID_FOLDER_SENT && DavResource.isSchedulingEnabled()) {
resource = new ScheduleOutbox(ctxt, f);
} else if (viewType == MailItem.Type.APPOINTMENT || viewType == MailItem.Type.TASK) {
resource = getCalendarCollection(ctxt, f);
} else if (viewType == MailItem.Type.CONTACT) {
resource = new AddressbookCollection(ctxt, f);
} else {
resource = new Collection(ctxt, f);
}
break;
case DOCUMENT:
resource = new Notebook(ctxt, (Document) item);
break;
case APPOINTMENT:
case TASK:
resource = new CalendarObject.LocalCalendarObject(ctxt, (CalendarItem) item);
break;
case MESSAGE:
resource = getCalendarItemForMessage(ctxt, (Message) item);
break;
case CONTACT:
resource = new AddressObject(ctxt, (Contact) item);
break;
default:
break;
}
} catch (ServiceException e) {
ZimbraLog.dav.info("cannot create DavResource", e);
}
return resource;
}
use of com.zimbra.cs.mailbox.Mountpoint 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.cs.mailbox.Mountpoint 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);
}
}
}
Aggregations