Search in sources :

Example 41 with DavException

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

the class MailItemResource method copy.

/* Copies this resource to another Collection. */
public void copy(DavContext ctxt, Collection dest, String newName) throws DavException {
    try {
        Mailbox mbox = getMailbox(ctxt);
        ArrayList<Integer> ids = new ArrayList<Integer>();
        if (newName == null) {
            ids.add(mId);
            ItemActionHelper.COPY(ctxt.getOperationContext(), mbox, SoapProtocol.Soap12, ids, type, null, dest.getItemId());
        } else {
            // TODO add COPY with RENAME (e.g> cp a.txt b.txt) functionality in ItemActionHelper
            throw MailServiceException.CANNOT_COPY(mId);
        }
    } catch (ServiceException se) {
        int resCode = se instanceof MailServiceException.NoSuchItemException ? HttpServletResponse.SC_NOT_FOUND : HttpServletResponse.SC_FORBIDDEN;
        if (se.getCode().equals(MailServiceException.ALREADY_EXISTS))
            resCode = HttpServletResponse.SC_PRECONDITION_FAILED;
        throw new DavException("cannot copy item", resCode, se);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException) ArrayList(java.util.ArrayList)

Example 42 with DavException

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

the class ScheduleOutbox method getAddressFromPrincipalURL.

/*
     * to workaround the pre release iCal bugs
     */
protected String getAddressFromPrincipalURL(String url) throws ServiceException, DavException {
    url = url.trim();
    if (url.startsWith("http://")) {
        // iCal sets the organizer field to be the URL of
        // CalDAV account.
        //     ORGANIZER:http://jylee-macbook:7070/service/dav/user1
        int pos = url.indexOf("/service/dav/");
        if (pos != -1) {
            int start = pos + 13;
            int end = url.indexOf("/", start);
            String userId = (end == -1) ? url.substring(start) : url.substring(start, end);
            Account organizer = Provisioning.getInstance().get(AccountBy.name, userId);
            if (organizer == null)
                throw new DavException("user not found: " + userId, HttpServletResponse.SC_BAD_REQUEST, null);
            return organizer.getName();
        }
    } else if (url.toLowerCase().startsWith("mailto:")) {
        // iCal sometimes prefixes the email addr with more than one mailto:
        while (url.toLowerCase().startsWith("mailto:")) {
            url = url.substring(7);
        }
    }
    return url;
}
Also used : Account(com.zimbra.cs.account.Account) DavException(com.zimbra.cs.dav.DavException)

Example 43 with DavException

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

the class ScheduleInbox method getAppointmentsByUids.

@Override
public java.util.Collection<DavResource> getAppointmentsByUids(DavContext ctxt, List<String> hrefs) throws ServiceException, DavException {
    List<DavResource> result = new ArrayList<DavResource>();
    if (!DavResource.isSchedulingEnabled()) {
        return result;
    }
    Account target = null;
    Provisioning prov = Provisioning.getInstance();
    if (ctxt.getActingAsDelegateFor() != null) {
        target = prov.getAccountByName(ctxt.getActingAsDelegateFor());
    }
    String query = "is:invite is:unread inid:" + getId() + " after:\"-1month\" ";
    Mailbox mbox = getMailbox(ctxt);
    ZimbraQueryResults zqr = null;
    try {
        zqr = mbox.index.search(ctxt.getOperationContext(), query, SEARCH_TYPES, SortBy.DATE_ASC, 100);
        while (zqr.hasNext()) {
            ZimbraHit hit = zqr.getNext();
            if (hit instanceof MessageHit) {
                Message msg = ((MessageHit) hit).getMessage();
                if (target == null && msg.getCalendarIntendedFor() != null) {
                    continue;
                }
                if (!msg.isInvite() || !msg.hasCalendarItemInfos()) {
                    continue;
                }
                /* Bug 40567.  hide replies to avoid them being deleted by CalDAV clients.
                     * TODO: An alternative approach would be to show them but when they are "deleted", flag them as
                     * absent from the scheduling inbox.
                     */
                if ("REPLY".equals(msg.getCalendarItemInfo(0).getInvite().getMethod())) {
                    continue;
                }
                if (target != null) {
                    if (msg.getCalendarIntendedFor() == null) {
                        continue;
                    }
                    Account apptRcpt = prov.getAccountByName(msg.getCalendarIntendedFor());
                    if (apptRcpt == null || !apptRcpt.getId().equals(target.getId())) {
                        continue;
                    }
                }
                DavResource rs = UrlNamespace.getResourceFromMailItem(ctxt, msg);
                if (rs != null) {
                    String href = UrlNamespace.getRawResourceUrl(rs);
                    if (hrefs == null)
                        result.add(rs);
                    else {
                        boolean found = false;
                        for (String ref : hrefs) {
                            if (HttpUtil.urlUnescape(ref).equals(href)) {
                                result.add(rs);
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                            result.add(new DavResource.InvalidResource(href, getOwner()));
                    }
                }
            }
        }
    } catch (Exception e) {
        ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
    } finally {
        Closeables.closeQuietly(zqr);
    }
    return result;
}
Also used : ZimbraHit(com.zimbra.cs.index.ZimbraHit) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) MessageHit(com.zimbra.cs.index.MessageHit) ArrayList(java.util.ArrayList) Provisioning(com.zimbra.cs.account.Provisioning) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) DavException(com.zimbra.cs.dav.DavException) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraQueryResults(com.zimbra.cs.index.ZimbraQueryResults)

Example 44 with DavException

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

the class MailItemResource method delete.

/* Deletes this resource by moving to Trash folder. Hard deletes if the item is in Trash folder.*/
@Override
public void delete(DavContext ctxt) throws DavException {
    if (mId == 0) {
        throw new DavException("cannot delete resource", HttpServletResponse.SC_FORBIDDEN, null);
    }
    try {
        Mailbox mbox = getMailbox(ctxt);
        if (DebugConfig.enableDAVclientCanChooseResourceBaseName) {
            DavNames.remove(mbox.getId(), mId);
        }
        // hard delete if the item is in Trash.
        if (getMailItem(ctxt).inTrash()) {
            hardDelete(ctxt);
            return;
        }
        mbox.move(ctxt.getOperationContext(), mId, MailItem.Type.UNKNOWN, Mailbox.ID_FOLDER_TRASH);
    } catch (ServiceException se) {
        if (se.getCode().equals(MailServiceException.ALREADY_EXISTS)) {
            hardDelete(ctxt);
            return;
        }
        int resCode = se instanceof MailServiceException.NoSuchItemException ? HttpServletResponse.SC_NOT_FOUND : HttpServletResponse.SC_FORBIDDEN;
        throw new DavException("cannot delete item", resCode, se);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException)

Example 45 with DavException

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

the class MailItemResource method hardDelete.

/* hard delete */
public void hardDelete(DavContext ctxt) throws DavException {
    if (mId == 0)
        throw new DavException("cannot hard delete resource", HttpServletResponse.SC_FORBIDDEN, null);
    try {
        Mailbox mbox = getMailbox(ctxt);
        mbox.delete(ctxt.getOperationContext(), mId, MailItem.Type.UNKNOWN);
    } catch (ServiceException se) {
        int resCode = se instanceof MailServiceException.NoSuchItemException ? HttpServletResponse.SC_NOT_FOUND : HttpServletResponse.SC_FORBIDDEN;
        throw new DavException("cannot delete item", resCode, se);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException)

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