Search in sources :

Example 6 with ZProperty

use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.

the class ScheduleOutbox method adjustOrganizer.

/**
     * For Vanilla CalDAV access where Apple style delegation has not been enabled, attempts by the delegate
     * to use a shared calendar acting as themselves are translated to appear as if acting as a delegate,
     * otherwise the experience can be very poor.
     * @throws ServiceException
     */
private void adjustOrganizer(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo) throws ServiceException {
    // BusyCal 2.5.3 seems to post with the wrong organizer even if ical delegation is switched on - even though
    // it uses the right ORGANIZER in the calendar entry.
    // if (ctxt.useIcalDelegation()) { return; }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
    String uid = req.getPropVal(ICalTok.UID, null);
    CalendarItem matchingCalendarEntry = mbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
    if (matchingCalendarEntry == null) {
        List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
        if (sharedCalendars == null) {
            // Can't work out anything useful
            return;
        }
        Set<Account> accts = Sets.newHashSet();
        for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
            accts.add(Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId()));
        }
        for (Account acct : accts) {
            Mailbox sbox = MailboxManager.getInstance().getMailboxByAccount(acct);
            matchingCalendarEntry = sbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
            if (matchingCalendarEntry != null) {
                break;
            }
        }
    }
    if (matchingCalendarEntry == null) {
        return;
    }
    Invite[] invites = matchingCalendarEntry.getInvites();
    if (invites == null) {
        return;
    }
    for (Invite inv : invites) {
        ZOrganizer org = inv.getOrganizer();
        if (org != null) {
            delegationInfo.setOwner(org.getAddress());
            if (Strings.isNullOrEmpty(org.getCn())) {
                Account ownerAcct = Provisioning.getInstance().get(AccountBy.name, org.getAddress());
                if (!Strings.isNullOrEmpty(ownerAcct.getDisplayName())) {
                    delegationInfo.setOwnerCn(ownerAcct.getDisplayName());
                }
            } else {
                delegationInfo.setOwnerCn(org.getCn());
            }
            break;
        }
    }
    if (delegationInfo.getOwner() == null) {
        return;
    }
    AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
    boolean originatorIsCalEntryOrganizer = acctMatcher.matches(delegationInfo.getOwnerEmail());
    if (originatorIsCalEntryOrganizer) {
        return;
    }
    for (ZComponent component : cal.getComponents()) {
        ZProperty organizerProp = component.getProperty(ICalTok.ORGANIZER);
        if (organizerProp != null) {
            organizerProp.setValue(delegationInfo.getOwner());
            ZParameter cn = organizerProp.getParameter(ICalTok.CN);
            if (cn == null) {
                organizerProp.addParameter(new ZParameter(ICalTok.CN, delegationInfo.getOwnerCn()));
            } else {
                cn.setValue(delegationInfo.getOwnerCn());
            }
            ZParameter sentBy = organizerProp.getParameter(ICalTok.SENT_BY);
            if (sentBy == null) {
                organizerProp.addParameter(new ZParameter(ICalTok.SENT_BY, delegationInfo.getOriginator()));
            } else {
                sentBy.setValue(delegationInfo.getOriginator());
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 7 with ZProperty

use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.

the class ScheduleOutbox method handleFreebusyRequest.

private void handleFreebusyRequest(DavContext ctxt, ZComponent vfreebusy, String originator, String rcpt, Element resp) throws DavException, ServiceException {
    ZProperty dtstartProp = vfreebusy.getProperty(ICalTok.DTSTART);
    ZProperty dtendProp = vfreebusy.getProperty(ICalTok.DTEND);
    ZProperty durationProp = vfreebusy.getProperty(ICalTok.DURATION);
    if (dtstartProp == null || dtendProp == null && durationProp == null)
        throw new DavException("missing dtstart or dtend/duration in the schedule request", HttpServletResponse.SC_BAD_REQUEST, null);
    long start, end;
    try {
        ParsedDateTime startTime = ParsedDateTime.parseUtcOnly(dtstartProp.getValue());
        start = startTime.getUtcTime();
        if (dtendProp != null) {
            end = ParsedDateTime.parseUtcOnly(dtendProp.getValue()).getUtcTime();
        } else {
            ParsedDuration dur = ParsedDuration.parse(durationProp.getValue());
            ParsedDateTime endTime = startTime.add(dur);
            end = endTime.getUtcTime();
        }
    } catch (ParseException pe) {
        throw new DavException("can't parse date", HttpServletResponse.SC_BAD_REQUEST, pe);
    }
    ZimbraLog.dav.debug("rcpt: " + rcpt + ", start: " + new Date(start) + ", end: " + new Date(end));
    FreeBusy fb = null;
    if (ctxt.isFreebusyEnabled()) {
        FreeBusyQuery fbQuery = new FreeBusyQuery(ctxt.getRequest(), ctxt.getAuthAccount(), start, end, null);
        fbQuery.addEmailAddress(getAddressFromPrincipalURL(rcpt), FreeBusyQuery.CALENDAR_FOLDER_ALL);
        java.util.Collection<FreeBusy> fbResult = fbQuery.getResults();
        if (fbResult.size() > 0)
            fb = fbResult.iterator().next();
    }
    if (fb != null) {
        String fbMsg = fb.toVCalendar(FreeBusy.Method.REPLY, originator, rcpt, null);
        resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
        resp.addElement(DavElements.E_REQUEST_STATUS).setText("2.0;Success");
        resp.addElement(DavElements.E_CALENDAR_DATA).setText(fbMsg);
    } else {
        resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
        resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.3;No f/b for the user");
    }
}
Also used : FreeBusy(com.zimbra.cs.fb.FreeBusy) DavException(com.zimbra.cs.dav.DavException) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) FreeBusyQuery(com.zimbra.cs.fb.FreeBusyQuery) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException) Date(java.util.Date)

Example 8 with ZProperty

use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.

the class CalendarRequest method notifyCalendarItem.

// Notify attendees following an update to the series of a recurring appointment.  Only the
// added attendees are notified if notifyAllAttendees is false.  If it is true all attendees
// for each invite are notified.  (Some invites may have more attendees than others.)
protected static void notifyCalendarItem(ZimbraSoapContext zsc, OperationContext octxt, Account acct, Mailbox mbox, CalendarItem calItem, boolean notifyAllAttendees, List<ZAttendee> addedAttendees, boolean ignorePastExceptions, MailSendQueue sendQueue) throws ServiceException {
    boolean onBehalfOf = isOnBehalfOfRequest(zsc);
    Account authAcct = getAuthenticatedAccount(zsc);
    boolean hidePrivate = !calItem.isPublic() && !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
    Address from = AccountUtil.getFriendlyEmailAddress(acct);
    Address sender = null;
    if (onBehalfOf)
        sender = AccountUtil.getFriendlyEmailAddress(authAcct);
    List<Address> addedRcpts = CalendarMailSender.toListFromAttendees(addedAttendees);
    long now = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
    mbox.lock.lock();
    try {
        // Refresh the cal item so we see the latest blob, whose path may have been changed
        // earlier in the current request.
        calItem = mbox.getCalendarItemById(octxt, calItem.getId());
        Invite[] invites = calItem.getInvites();
        // Get exception instances.  These will be included in the series update email.
        List<Invite> exceptions = new ArrayList<Invite>();
        for (Invite inv : invites) {
            if (inv.hasRecurId()) {
                exceptions.add(inv);
            }
        }
        // Send the update invites.
        boolean didExceptions = false;
        for (Invite inv : invites) {
            if (ignorePastExceptions && inv.hasRecurId() && !inviteIsAfterTime(inv, now)) {
                continue;
            }
            // Make the new iCalendar part to send.
            ZVCalendar cal = inv.newToICalendar(!hidePrivate);
            // For series invite, append the exception instances.
            if (inv.isRecurrence() && !didExceptions) {
                // Find the VEVENT/VTODO for the series.
                ZComponent seriesComp = null;
                for (Iterator<ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext(); ) {
                    ZComponent comp = compIter.next();
                    ICalTok compName = comp.getTok();
                    if (ICalTok.VEVENT.equals(compName) || ICalTok.VTODO.equals(compName)) {
                        if (comp.getProperty(ICalTok.RRULE) != null) {
                            seriesComp = comp;
                            break;
                        }
                    }
                }
                for (Invite except : exceptions) {
                    if (except.isCancel() && seriesComp != null) {
                        // Cancels are added as EXDATEs in the series VEVENT/VTODO.
                        RecurId rid = except.getRecurId();
                        if (rid != null && rid.getDt() != null) {
                            ZProperty exdate = rid.getDt().toProperty(ICalTok.EXDATE, false);
                            seriesComp.addProperty(exdate);
                        }
                    } else {
                        // Exception instances are added as additional VEVENTs/VTODOs.
                        ZComponent exceptComp = except.newToVComponent(false, !hidePrivate);
                        cal.addComponent(exceptComp);
                    }
                }
                didExceptions = true;
            }
            // Compose email using the existing MimeMessage as template and send it.
            MimeMessage mmInv = calItem.getSubpartMessage(inv.getMailItemId());
            List<Address> rcpts;
            if (notifyAllAttendees) {
                rcpts = CalendarMailSender.toListFromAttendees(inv.getAttendees());
            } else {
                rcpts = addedRcpts;
            }
            if (rcpts != null && !rcpts.isEmpty()) {
                MimeMessage mmModify = CalendarMailSender.createCalendarMessage(authAcct, from, sender, rcpts, mmInv, inv, cal, true);
                CalSendData csd = new CalSendData();
                csd.mMm = mmModify;
                csd.mOrigId = new ItemId(mbox, inv.getMailItemId());
                MailSendQueueEntry entry = new MailSendQueueEntry(octxt, mbox, csd, null);
                sendQueue.add(entry);
            }
        }
    } finally {
        mbox.lock.release();
    }
}
Also used : Account(com.zimbra.cs.account.Account) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) ArrayList(java.util.ArrayList) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) ItemId(com.zimbra.cs.service.util.ItemId) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) MimeMessage(javax.mail.internet.MimeMessage) FixedMimeMessage(com.zimbra.cs.mime.Mime.FixedMimeMessage) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 9 with ZProperty

use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.

the class CalendarUtils method parseXProps.

public static List<ZProperty> parseXProps(Element element) throws ServiceException {
    List<ZProperty> props = new ArrayList<ZProperty>();
    for (Iterator<Element> propIter = element.elementIterator(MailConstants.E_CAL_XPROP); propIter.hasNext(); ) {
        Element propElem = propIter.next();
        String propName = propElem.getAttribute(MailConstants.A_NAME);
        String propValue = propElem.getAttribute(MailConstants.A_VALUE, null);
        ZProperty xprop = new ZProperty(propName);
        xprop.setValue(propValue);
        List<ZParameter> xparams = CalendarUtil.parseXParams(propElem);
        for (ZParameter xparam : xparams) {
            xprop.addParameter(xparam);
        }
        props.add(xprop);
    }
    return props;
}
Also used : Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 10 with ZProperty

use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.

the class CalendarUtils method parseInviteForCreateException.

static ParseMimeMessage.InviteParserResult parseInviteForCreateException(Account account, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap, String uid, Invite defaultInv) throws ServiceException {
    if (tzMap == null) {
        tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
    }
    Invite create = new Invite(ICalTok.PUBLISH.toString(), tzMap, false);
    create.setSentByMe(true);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, create, true, false);
    // DTSTAMP
    if (create.getDTStamp() == 0) {
        //zdsync
        create.setDtStamp(new Date().getTime());
    }
    // UID
    if (uid != null && uid.length() > 0)
        create.setUid(uid);
    // SEQUENCE - Make sure it's greater than the series sequence.  (bugs 19111 and 35036)
    create.setSeqNo(Math.max(create.getSeqNo(), defaultInv.getSeqNo() + 1));
    // Don't allow changing organizer in an exception instance.
    create.setOrganizer(defaultInv.hasOrganizer() ? new ZOrganizer(defaultInv.getOrganizer()) : null);
    create.setIsOrganizer(account);
    // change tracking
    String changes = parseInviteChanges(inviteElem);
    if (changes != null) {
        // Set the changes as x-prop in the serialized iCalendar object, but not to the parsed Invite object.
        create.addXProp(new ZProperty(ICalTok.X_ZIMBRA_CHANGES, changes));
    }
    ZVCalendar iCal = create.newToICalendar(true);
    // Don't set the changes x-prop in the parsed Invite.
    create.removeXProp(ICalTok.X_ZIMBRA_CHANGES.toString());
    String summaryStr = create.getName() != null ? create.getName() : "";
    ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
    toRet.mCal = iCal;
    toRet.mUid = create.getUid();
    toRet.mSummary = summaryStr;
    toRet.mInvite = create;
    return toRet;
}
Also used : ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite) Date(java.util.Date)

Aggregations

ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)49 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)19 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)18 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)13 ArrayList (java.util.ArrayList)12 Account (com.zimbra.cs.account.Account)10 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)9 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)9 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)8 Invite (com.zimbra.cs.mailbox.calendar.Invite)8 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)7 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)6 ServiceException (com.zimbra.common.service.ServiceException)6 ParseException (java.text.ParseException)6 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)5 AccountAddressMatcher (com.zimbra.cs.util.AccountUtil.AccountAddressMatcher)5 Element (com.zimbra.common.soap.Element)4 IOException (java.io.IOException)4 Geo (com.zimbra.common.calendar.Geo)3