Search in sources :

Example 36 with DavException

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

the class ScheduleInbox method updateCalendarFreeBusySet.

private void updateCalendarFreeBusySet(DavContext ctxt, ArrayList<String> urls) throws ServiceException, DavException {
    String prefix = DavServlet.DAV_PATH + "/" + getOwner();
    Mailbox mbox = getMailbox(ctxt);
    HashMap<String, Folder> folders = new HashMap<String, Folder>();
    for (Folder f : getCalendarFolders(ctxt)) {
        folders.put(f.getPath(), f);
    }
    for (String origurl : urls) {
        // Clients often encode the "@" we use in our URLs
        String url = HttpUtil.urlUnescape(origurl);
        if (!url.startsWith(prefix)) {
            continue;
        }
        String path = url.substring(prefix.length());
        if (path.endsWith("/"))
            path = path.substring(0, path.length() - 1);
        Folder f = folders.remove(path);
        if (f == null) {
            // check for recently renamed folders
            DavResource rs = UrlNamespace.checkRenamedResource(getOwner(), path);
            if (rs == null || !rs.isCollection())
                throw new DavException("folder not found " + url, DavProtocol.STATUS_FAILED_DEPENDENCY);
            f = mbox.getFolderById(ctxt.getOperationContext(), ((MailItemResource) rs).getId());
        }
        if ((f.getFlagBitmask() & Flag.BITMASK_EXCLUDE_FREEBUSY) == 0)
            continue;
        ZimbraLog.dav.debug("clearing EXCLUDE_FREEBUSY for " + path);
        mbox.alterTag(ctxt.getOperationContext(), f.getId(), MailItem.Type.FOLDER, Flag.FlagInfo.EXCLUDE_FREEBUSY, false, null);
    }
    if (!folders.isEmpty()) {
        for (Folder f : folders.values()) {
            ZimbraLog.dav.debug("setting EXCLUDE_FREEBUSY for " + f.getPath());
            mbox.alterTag(ctxt.getOperationContext(), f.getId(), MailItem.Type.FOLDER, Flag.FlagInfo.EXCLUDE_FREEBUSY, true, null);
        }
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) HashMap(java.util.HashMap) DavException(com.zimbra.cs.dav.DavException) Folder(com.zimbra.cs.mailbox.Folder)

Example 37 with DavException

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

the class ScheduleInbox method patchProperties.

@Override
public void patchProperties(DavContext ctxt, java.util.Collection<Element> set, java.util.Collection<QName> remove) throws DavException, IOException {
    ArrayList<Element> newSet = null;
    for (Element el : set) {
        if (el.getQName().equals(DavElements.E_CALENDAR_FREE_BUSY_SET)) {
            Iterator<?> hrefs = el.elementIterator(DavElements.E_HREF);
            ArrayList<String> urls = new ArrayList<String>();
            while (hrefs.hasNext()) urls.add(((Element) hrefs.next()).getText());
            try {
                updateCalendarFreeBusySet(ctxt, urls);
            } catch (ServiceException e) {
                ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_FREE_BUSY_SET, new DavException("error", DavProtocol.STATUS_FAILED_DEPENDENCY));
            } catch (DavException e) {
                ctxt.getResponseProp().addPropError(DavElements.E_CALENDAR_FREE_BUSY_SET, e);
            }
            if (newSet == null) {
                newSet = new ArrayList<Element>(set);
            }
            newSet.remove(el);
        }
    }
    if (newSet != null)
        set = newSet;
    super.patchProperties(ctxt, set, remove);
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList)

Example 38 with DavException

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

the class ScheduleOutbox method handleEventRequest.

private void handleEventRequest(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo, String rcpt, Element resp) throws ServiceException, DavException {
    if (!DavResource.isSchedulingEnabled()) {
        resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
        resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.3;No scheduling for the user");
        return;
    }
    ArrayList<Address> recipients = new java.util.ArrayList<Address>();
    InternetAddress from, sender, to;
    Account target = null;
    try {
        sender = new JavaMailInternetAddress(delegationInfo.getOriginatorEmail());
        Provisioning prov = Provisioning.getInstance();
        if (ctxt.getActingAsDelegateFor() != null) {
            target = prov.getAccountByName(ctxt.getActingAsDelegateFor());
        }
        if (target != null) {
            from = AccountUtil.getFriendlyEmailAddress(target);
        } else {
            if (delegationInfo.getOwnerEmail() != null) {
                from = new JavaMailInternetAddress(delegationInfo.getOwnerEmail());
            } else {
                target = getMailbox(ctxt).getAccount();
                if (AccountUtil.addressMatchesAccount(target, delegationInfo.getOriginatorEmail())) {
                    // Make sure we don't use two different aliases for From and Sender.
                    // This is a concern with Apple iCal, which picks a random alias as originator.
                    from = sender;
                } else {
                    from = AccountUtil.getFriendlyEmailAddress(target);
                }
            }
        }
        if (sender.getAddress() != null && sender.getAddress().equalsIgnoreCase(from.getAddress())) {
            sender = null;
        }
        to = new JavaMailInternetAddress(CalDavUtils.stripMailto(rcpt));
        recipients.add(to);
    } catch (AddressException e) {
        resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
        resp.addElement(DavElements.E_REQUEST_STATUS).setText("3.7;" + rcpt);
        return;
    }
    String status = req.getPropVal(ICalTok.STATUS, "");
    String method = cal.getPropVal(ICalTok.METHOD, "REQUEST");
    String subject = "";
    if (method.equals("REQUEST")) {
        ZProperty organizerProp = req.getProperty(ICalTok.ORGANIZER);
        if (organizerProp != null) {
            String organizerStr = this.getAddressFromPrincipalURL(new ZOrganizer(organizerProp).getAddress());
            if (!AccountUtil.addressMatchesAccount(getMailbox(ctxt).getAccount(), organizerStr)) {
                ZimbraLog.dav.debug("scheduling appointment on behalf of %s", organizerStr);
            }
        }
    } else if (method.equals("REPLY")) {
        ZProperty attendeeProp = req.getProperty(ICalTok.ATTENDEE);
        if (attendeeProp == null)
            throw new DavException("missing property ATTENDEE", HttpServletResponse.SC_BAD_REQUEST);
        ZAttendee attendee = new ZAttendee(attendeeProp);
        String partStat = attendee.getPartStat();
        if (partStat.equals(IcalXmlStrMap.PARTSTAT_ACCEPTED)) {
            subject = "Accept: ";
        } else if (partStat.equals(IcalXmlStrMap.PARTSTAT_TENTATIVE)) {
            subject = "Tentative: ";
        } else if (partStat.equals(IcalXmlStrMap.PARTSTAT_DECLINED)) {
            subject = "Decline: ";
        }
    }
    if (status.equals("CANCELLED"))
        subject = "Cancelled: ";
    subject += req.getPropVal(ICalTok.SUMMARY, "");
    String uid = req.getPropVal(ICalTok.UID, null);
    if (uid == null) {
        resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
        resp.addElement(DavElements.E_REQUEST_STATUS).setText("3.1;UID");
        return;
    }
    try {
        List<Invite> components = Invite.createFromCalendar(ctxt.getAuthAccount(), null, cal, false);
        FriendlyCalendaringDescription friendlyDesc = new FriendlyCalendaringDescription(components, ctxt.getAuthAccount());
        String desc = friendlyDesc.getAsPlainText();
        String descHtml = req.getDescriptionHtml();
        if ((descHtml == null) || (descHtml.length() == 0))
            descHtml = friendlyDesc.getAsHtml();
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
        MimeMessage mm = CalendarMailSender.createCalendarMessage(target, from, sender, recipients, subject, desc, descHtml, uid, cal);
        mbox.getMailSender().setSendPartial(true).sendMimeMessage(ctxt.getOperationContext(), mbox, true, mm, null, null, null, null, false);
    } catch (ServiceException e) {
        resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
        resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.1");
        return;
    }
    resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
    resp.addElement(DavElements.E_REQUEST_STATUS).setText("2.0;Success");
}
Also used : Account(com.zimbra.cs.account.Account) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) DavException(com.zimbra.cs.dav.DavException) ArrayList(java.util.ArrayList) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) Provisioning(com.zimbra.cs.account.Provisioning) FriendlyCalendaringDescription(com.zimbra.cs.mailbox.calendar.FriendlyCalendaringDescription) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) ZAttendee(com.zimbra.cs.mailbox.calendar.ZAttendee) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 39 with DavException

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

the class UrlNamespace method getPrincipalAtUrl.

public static DavResource getPrincipalAtUrl(DavContext ctxt, String url) throws DavException {
    String name = ctxt.getAuthAccount().getName();
    String proxyPrincipal = "";
    if (url != null) {
        int index = url.indexOf(PRINCIPALS_PATH);
        if (index == -1 || url.endsWith(PRINCIPALS_PATH)) {
            try {
                return new Principal(ctxt.getAuthAccount(), url);
            } catch (ServiceException se) {
                throw new DavException("invalid uri", HttpServletResponse.SC_NOT_FOUND, se);
            }
        }
        index += PRINCIPALS_PATH.length();
        name = url.substring(index);
        if (name.indexOf('/') > 0) {
            proxyPrincipal = name.substring(name.indexOf('/') + 1);
            if (proxyPrincipal.endsWith("/")) {
                proxyPrincipal = proxyPrincipal.substring(0, proxyPrincipal.indexOf('/'));
            }
            name = name.substring(0, name.indexOf('/'));
        }
        name = name.replaceAll("%40", "@");
    } else {
        url = "/";
    }
    ZimbraLog.dav.debug("getPrincipalAtUrl name='%s' url='%s' proxyPrincipal='%s'", name, url, proxyPrincipal);
    try {
        Account acct = Provisioning.getInstance().get(Key.AccountBy.name, name);
        if (acct == null) {
            throw new DavException("user not found", HttpServletResponse.SC_NOT_FOUND, null);
        }
        if (CalendarProxyRead.CALENDAR_PROXY_READ.equals(proxyPrincipal)) {
            if (!ctxt.useIcalDelegation()) {
                throw new DavException("Not available because zimbraPrefAppleIcalDelegationEnabled=FALSE", HttpServletResponse.SC_NOT_FOUND, null);
            }
            return new CalendarProxyRead(acct, url);
        }
        if (CalendarProxyWrite.CALENDAR_PROXY_WRITE.equals(proxyPrincipal)) {
            if (!ctxt.useIcalDelegation()) {
                throw new DavException("Not available because zimbraPrefAppleIcalDelegationEnabled=FALSE", HttpServletResponse.SC_NOT_FOUND, null);
            }
            return new CalendarProxyWrite(acct, url);
        }
        return new User(ctxt, acct, url);
    } catch (ServiceException se) {
        throw new DavException("user not found", HttpServletResponse.SC_NOT_FOUND, null);
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 40 with DavException

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

the class UrlNamespace method getAclUrl.

/* RFC 3744 */
public static String getAclUrl(String principal, String type) throws DavException {
    Account account = null;
    Provisioning prov = Provisioning.getInstance();
    try {
        account = prov.get(AccountBy.id, principal);
        StringBuilder buf = new StringBuilder();
        buf.append(type);
        if (account != null)
            buf.append(account.getName());
        else
            buf.append(principal);
        return getAbsoluteUrl(null, buf.toString());
    } catch (ServiceException e) {
        throw new DavException("cannot create ACL URL for principal " + principal, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DavException(com.zimbra.cs.dav.DavException) Provisioning(com.zimbra.cs.account.Provisioning)

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