use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class GetMiniCal method resolveMountpoints.
// Resolve mountpoints for each requested folder. Resolution can result in error per folder. Typical errors
// include PERM_DENIED (if sharer revoked permission), NO_SUCH_FOLDER (if sharer deleted shared folder), and
// NO_SUCH_ACCOUNT (if sharer account has been deleted).
private static Map<ItemId, Resolved> resolveMountpoints(OperationContext octxt, Mailbox mbox, List<ItemId> folderIids) {
Map<ItemId, Resolved> result = new HashMap<ItemId, Resolved>();
for (ItemId iidFolder : folderIids) {
String targetAccountId = iidFolder.getAccountId();
int folderId = iidFolder.getId();
try {
ServiceException error = null;
if (mbox.getAccountId().equals(targetAccountId)) {
boolean isMountpoint = true;
int hopCount = 0;
// resolve local mountpoint to a real folder; deal with possible mountpoint chain
while (isMountpoint && hopCount < ZimbraSoapContext.MAX_HOP_COUNT) {
Folder folder = mbox.getFolderById(octxt, folderId);
isMountpoint = folder instanceof Mountpoint;
if (isMountpoint) {
Mountpoint mp = (Mountpoint) folder;
folderId = mp.getRemoteId();
if (!mp.isLocal()) {
// done resolving if pointing to a different account
targetAccountId = mp.getOwnerId();
Account targetAcct = Provisioning.getInstance().get(Key.AccountBy.id, targetAccountId);
if (targetAcct == null)
error = AccountServiceException.NO_SUCH_ACCOUNT(targetAccountId);
break;
}
hopCount++;
}
}
if (hopCount >= ZimbraSoapContext.MAX_HOP_COUNT)
error = MailServiceException.TOO_MANY_HOPS(iidFolder);
}
result.put(iidFolder, new Resolved(new ItemId(targetAccountId, folderId), error));
} catch (ServiceException e) {
ItemIdFormatter ifmt = new ItemIdFormatter();
ZimbraLog.calendar.warn("Error resolving calendar folder " + ifmt.formatItemId(iidFolder), e);
result.put(iidFolder, new Resolved(new ItemId(targetAccountId, folderId), e));
}
}
return result;
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class ItemAction method forceRemoteSession.
private Account forceRemoteSession(ZimbraSoapContext zsc, Map<String, Object> context, OperationContext octxt, String op, Element action) throws ServiceException {
// only proxying notification from the user's home-server master session
if (!zsc.isNotificationEnabled()) {
return null;
}
Session session = (Session) context.get(SoapEngine.ZIMBRA_SESSION);
if (session instanceof SoapSession.DelegateSession) {
session = ((SoapSession.DelegateSession) session).getParentSession();
}
if (!(session instanceof SoapSession) || session.getMailbox() == null) {
return null;
}
SoapSession ss = (SoapSession) session;
// only have to worry about operations where things can get created in other mailboxes (regular notification works for all other cases)
if (!op.equals(MailConstants.OP_MOVE) && !op.equals(MailConstants.OP_COPY) && !op.equals(MailConstants.OP_SPAM) && !op.equals(MailConstants.OP_RENAME) && !op.equals(MailConstants.OP_UPDATE)) {
return null;
}
String folderStr = action.getAttribute(MailConstants.A_FOLDER, null);
if (folderStr == null) {
return null;
}
// recursively dereference mountpoints to find ultimate target folder
ItemId iidFolder = new ItemId(folderStr, zsc), iidRequested = iidFolder;
Account owner = null;
int hopCount = 0;
ZAuthToken zat = null;
while (hopCount < ZimbraSoapContext.MAX_HOP_COUNT) {
owner = Provisioning.getInstance().getAccountById(iidFolder.getAccountId());
if (Provisioning.onLocalServer(owner)) {
try {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(owner);
Folder folder = mbox.getFolderById(octxt, iidFolder.getId());
if (!(folder instanceof Mountpoint))
break;
iidFolder = ((Mountpoint) folder).getTarget();
} catch (ServiceException e) {
// could be a PERM_DENIED, could be something else -- this is not the right place to fail, however
break;
}
} else {
if (zat == null) {
AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
String pxyAuthToken = at.getProxyAuthToken();
zat = pxyAuthToken == null ? at.toZAuthToken() : new ZAuthToken(pxyAuthToken);
}
ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(owner));
zoptions.setNoSession(true);
zoptions.setTargetAccount(owner.getId());
zoptions.setTargetAccountBy(Key.AccountBy.id);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
zmbx.setName(owner.getName());
/* need this when logging in using another user's auth */
ZFolder zfolder = zmbx.getFolderById(iidFolder.toString(zsc.getAuthtokenAccountId()));
if (!(zfolder instanceof ZMountpoint))
break;
iidFolder = new ItemId(((ZMountpoint) zfolder).getCanonicalRemoteId(), zsc.getAuthtokenAccountId());
}
hopCount++;
}
if (hopCount >= ZimbraSoapContext.MAX_HOP_COUNT) {
throw MailServiceException.TOO_MANY_HOPS(iidRequested);
}
// avoid dereferencing the mountpoint again later on
action.addAttribute(MailConstants.A_FOLDER, iidFolder.toString());
// fault in a session to listen in on the target folder's mailbox
if (iidFolder.belongsTo(session.getAuthenticatedAccountId())) {
return null;
} else if (iidFolder.isLocal()) {
ss.getDelegateSession(iidFolder.getAccountId());
return null;
} else {
try {
proxyRequest(zsc.createElement(MailConstants.NO_OP_REQUEST), context, owner.getId());
return owner;
} catch (ServiceException e) {
return null;
}
}
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class ParseMimeMessage method attachDocument.
private static void attachDocument(MimeMultipart mmp, String path, String contentID, ParseMessageContext ctxt) throws MessagingException, ServiceException {
MailItem item = null;
try {
// first, just blindly try to fetch the item
item = ctxt.mbox.getItemByPath(ctxt.octxt, path);
} catch (NoSuchItemException nsie) {
}
if (item == null) {
// on a miss, check for a mountpoint and, if so, fetch via UserServlet
Pair<Folder, String> match = ctxt.mbox.getFolderByPathLongestMatch(ctxt.octxt, Mailbox.ID_FOLDER_USER_ROOT, path);
if (!(match.getFirst() instanceof Mountpoint)) {
throw MailServiceException.NO_SUCH_DOC(path);
}
Map<String, String> params = new HashMap<String, String>(3);
params.put(UserServlet.QP_NAME, match.getSecond());
attachRemoteItem(mmp, ((Mountpoint) match.getFirst()).getTarget(), contentID, ctxt, params, null);
return;
}
// on a hit, attach it directly
if (!(item instanceof Document))
throw MailServiceException.NO_SUCH_DOC(path);
attachDocument(mmp, (Document) item, contentID, ctxt);
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class ItemActionHelper method schedule.
protected void schedule() throws ServiceException {
boolean targeted = mOperation == Op.MOVE || mOperation == Op.SPAM || mOperation == Op.COPY || mOperation == Op.RENAME || (mOperation == Op.UPDATE && mIidFolder != null);
// deal with local mountpoints pointing at local folders here
if (targeted && mIidFolder.belongsTo(mMailbox) && mIidFolder.getId() > 0 && mIidFolder.getId() != Mailbox.ID_FOLDER_TRASH && mIidFolder.getId() != Mailbox.ID_FOLDER_SPAM) {
try {
Folder folder = mMailbox.getFolderById(mOpCtxt, mIidFolder.getId());
if (folder instanceof Mountpoint && !((Mountpoint) folder).getOwnerId().equals(mIidFolder.getAccountId())) {
mIidFolder = ((Mountpoint) folder).getTarget();
mHopCount++;
}
} catch (ServiceException e) {
// could be a PERM_DENIED, could be something else -- this is not the right place to fail, however
}
}
try {
if (!targeted || mIidFolder.belongsTo(mMailbox))
mResult = executeLocal();
else
mResult = executeRemote();
} catch (IOException | HttpException ioe) {
throw ServiceException.FAILURE("exception reading item blob", ioe);
}
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class DBQueryOperation method expandLocalRemotePart.
@Override
QueryOperation expandLocalRemotePart(Mailbox mbox) throws ServiceException {
if (constraints instanceof DbSearchConstraints.Leaf) {
boolean added = false;
if (includeIsLocalFolders) {
// expanded!
includeIsLocalFolders = false;
DbSearchConstraints.Leaf leaf = (DbSearchConstraints.Leaf) constraints;
for (Folder f : mbox.getFolderById(null, Mailbox.ID_FOLDER_ROOT).getSubfolderHierarchy()) {
if (!(f instanceof Mountpoint) && !(f instanceof SearchFolder)) {
// add local folder ref
leaf.folders.add(f);
added = true;
}
}
if (!added) {
return new NoResultsQueryOperation();
} else {
return this;
}
} else if (includeIsRemoteFolders) {
UnionQueryOperation toRet = new UnionQueryOperation();
// expanded
includeIsRemoteFolders = false;
for (Folder f : mbox.getFolderById(null, Mailbox.ID_FOLDER_ROOT).getSubfolderHierarchy()) {
if (f instanceof Mountpoint) {
Mountpoint mpt = (Mountpoint) f;
if (!mpt.isLocal()) {
// add remote folder ref
DBQueryOperation db = new DBQueryOperation();
db.addInRemoteFolder(mpt.getTarget(), "", true, true);
toRet.add(db);
added = true;
}
}
}
if (!added) {
return new NoResultsQueryOperation();
} else {
return toRet;
}
} else {
return this;
}
} else {
throw new IllegalStateException("expandLocalRemotePart must be called before optimize() is called");
}
}
Aggregations