Search in sources :

Example 16 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class UrlNamespace method getMailItemById.

private static MailItem getMailItemById(DavContext ctxt, String user, int id) throws DavException, ServiceException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of mail item - no such account '%s' id=%d", user, id);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    return mbox.getItemById(ctxt.getOperationContext(), id, MailItem.Type.UNKNOWN);
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 17 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class UrlNamespace method getFolders.

private static java.util.Collection<DavResource> getFolders(DavContext ctxt, String user) throws ServiceException, DavException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of folders - no such account '%s'", user);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    OperationContext octxt = ctxt.getOperationContext();
    ArrayList<DavResource> rss = new ArrayList<DavResource>();
    for (Folder f : mbox.getVisibleFolders(octxt)) rss.add(getResourceFromMailItem(ctxt, f));
    return rss;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) DavException(com.zimbra.cs.dav.DavException) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) Provisioning(com.zimbra.cs.account.Provisioning)

Example 18 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class UrlNamespace method getMailItemResource.

/**
     *
     * @param ctxt
     * @param user
     * @param path - May contain parameters
     * @return
     */
private static DavResource getMailItemResource(DavContext ctxt, String user, String path) throws ServiceException, DavException {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.name, user);
    if (account == null) {
        // Anti-account name harvesting.
        ZimbraLog.dav.info("Failing GET of mail item resource - no such account '%s' path '%s'", user, path);
        throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
    }
    if (ctxt.getUser().compareTo(user) != 0 || !Provisioning.onLocalServer(account)) {
        try {
            return new RemoteCollection(ctxt, path, account);
        } catch (MailServiceException.NoSuchItemException e) {
            return null;
        }
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    int id = 0;
    int index = path.indexOf('?');
    if (index > 0) {
        Map<String, String> params = HttpUtil.getURIParams(path.substring(index + 1));
        path = path.substring(0, index);
        if (params.containsKey("id")) {
            try {
                id = Integer.parseInt(params.get("id"));
            } catch (NumberFormatException e) {
            }
        }
    }
    // At this point, path will have had any parameters stripped from it
    OperationContext octxt = ctxt.getOperationContext();
    MailItem item = null;
    // simple case.  root folder or if id is specified.
    if (path.equals("/")) {
        item = mbox.getFolderByPath(octxt, "/");
    } else if (id > 0) {
        item = mbox.getItemById(octxt, id, MailItem.Type.UNKNOWN);
    }
    if (item != null) {
        return getResourceFromMailItem(ctxt, item);
    }
    // check for named items (folders, documents)
    try {
        return getResourceFromMailItem(ctxt, mbox.getItemByPath(octxt, path));
    } catch (MailServiceException.NoSuchItemException e) {
    }
    // check if the this is renamed folder.
    DavResource rs = checkRenamedResource(user, path);
    if (rs != null)
        return rs;
    // look up the item from path
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    index = path.lastIndexOf('/');
    String folderPath = path.substring(0, index);
    String baseName = path.substring(index + 1);
    Folder f = null;
    if (index != -1) {
        try {
            f = mbox.getFolderByPath(octxt, folderPath);
        } catch (MailServiceException.NoSuchItemException e) {
        }
    }
    if (f != null) {
        /* First check whether the default name has been over-ridden - perhaps because the name was
             * chosen by a DAV client via PUT to a URL when creating the item. */
        DavNames.DavName davName = null;
        if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
            davName = DavNames.DavName.create(mbox.getId(), f.getId(), baseName);
        }
        if (davName != null) {
            Integer itemId = DavNames.get(davName);
            if (itemId != null) {
                item = mbox.getItemById(octxt, itemId, MailItem.Type.UNKNOWN);
                if ((item != null) && (f.getId() == item.getFolderId())) {
                    return getResourceFromMailItem(ctxt, item);
                }
                item = null;
            }
        }
        if (baseName.toLowerCase().endsWith(CalendarObject.CAL_EXTENSION)) {
            String uid = baseName.substring(0, baseName.length() - CalendarObject.CAL_EXTENSION.length());
            // Unescape the name (It was encoded in DavContext intentionally)
            uid = HttpUtil.urlUnescape(uid);
            index = uid.indexOf(',');
            if (index > 0) {
                try {
                    id = Integer.parseInt(uid.substring(index + 1));
                } catch (NumberFormatException e) {
                }
            }
            if (id > 0) {
                item = mbox.getItemById(octxt, id, MailItem.Type.UNKNOWN);
            } else {
                item = mbox.getCalendarItemByUid(octxt, uid);
            }
            if ((item != null) && (f.getId() != item.getFolderId())) {
                item = null;
            }
        } else if (baseName.toLowerCase().endsWith(AddressObject.VCARD_EXTENSION)) {
            rs = AddressObject.getAddressObjectByUID(ctxt, baseName, account, f);
            if (rs != null) {
                return rs;
            }
        } else if (f.getId() == Mailbox.ID_FOLDER_INBOX || f.getId() == Mailbox.ID_FOLDER_SENT) {
            ctxt.setActingAsDelegateFor(baseName);
            // delegated scheduling and notification handling
            return getResourceFromMailItem(ctxt, f);
        }
    }
    return getResourceFromMailItem(ctxt, item);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) DavException(com.zimbra.cs.dav.DavException) Folder(com.zimbra.cs.mailbox.Folder) Provisioning(com.zimbra.cs.account.Provisioning) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) DavNames(com.zimbra.cs.mailbox.DavNames) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 19 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class Post method handle.

@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    String user = ctxt.getUser();
    String name = ctxt.getItem();
    if (user == null || name == null) {
        throw new DavException("invalid uri", HttpServletResponse.SC_NOT_FOUND);
    }
    DavResource rs = ctxt.getRequestedResource();
    rs.handlePost(ctxt);
    sendResponse(ctxt);
    if (ZimbraLog.dav.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("Response for DAV POST ").append(ctxt.getUri()).append("\n");
        DavServlet.addResponseHeaderLoggingInfo(ctxt.getResponse(), sb);
        ZimbraLog.dav.debug(sb);
    }
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException)

Example 20 with DavException

use of com.zimbra.cs.dav.DavException in project zm-mailbox by Zimbra.

the class PropFind method handle.

@Override
public void handle(DavContext ctxt) throws DavException, IOException, ServiceException {
    if (ctxt.hasRequestMessage()) {
        Document req = ctxt.getRequestMessage();
        Element top = req.getRootElement();
        if (!top.getName().equals(DavElements.P_PROPFIND)) {
            throw new DavException("msg " + top.getName() + " not allowed in PROPFIND", HttpServletResponse.SC_BAD_REQUEST, null);
        }
    }
    RequestProp reqProp = ctxt.getRequestProp();
    DavResponse resp = ctxt.getDavResponse();
    if (ctxt.getDepth() == Depth.one) {
        resp.addResources(ctxt, ctxt.getAllRequestedResources(), reqProp);
    } else {
        DavResource resource = ctxt.getRequestedResource();
        resp.addResource(ctxt, resource, reqProp, false);
    }
    sendResponse(ctxt);
}
Also used : DavResource(com.zimbra.cs.dav.resource.DavResource) DavException(com.zimbra.cs.dav.DavException) DavResponse(com.zimbra.cs.dav.service.DavResponse) RequestProp(com.zimbra.cs.dav.DavContext.RequestProp) Element(org.dom4j.Element) Document(org.dom4j.Document)

Aggregations

DavException (com.zimbra.cs.dav.DavException)67 ServiceException (com.zimbra.common.service.ServiceException)27 Element (org.dom4j.Element)25 Account (com.zimbra.cs.account.Account)18 Mailbox (com.zimbra.cs.mailbox.Mailbox)18 DavResource (com.zimbra.cs.dav.resource.DavResource)15 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)15 ArrayList (java.util.ArrayList)14 Provisioning (com.zimbra.cs.account.Provisioning)11 Document (org.dom4j.Document)9 DavResponse (com.zimbra.cs.dav.service.DavResponse)8 MailItem (com.zimbra.cs.mailbox.MailItem)8 Invite (com.zimbra.cs.mailbox.calendar.Invite)7 ZMailbox (com.zimbra.client.ZMailbox)6 RequestProp (com.zimbra.cs.dav.DavContext.RequestProp)6 IOException (java.io.IOException)6 Collection (com.zimbra.cs.dav.resource.Collection)5 Folder (com.zimbra.cs.mailbox.Folder)5 CalendarCollection (com.zimbra.cs.dav.resource.CalendarCollection)4 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)3