Search in sources :

Example 1 with ZParameter

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

the class Attach method parse.

public static Attach parse(ZProperty prop) {
    String value = prop.getValue();
    String ct = null;
    ZParameter fmttype = prop.getParameter(ICalTok.FMTTYPE);
    if (fmttype != null) {
        ct = fmttype.getValue();
    }
    ZParameter valueType = prop.getParameter(ICalTok.VALUE);
    Attach attach = null;
    if ((valueType != null) && (valueType.getValue().equals("BINARY"))) {
        attach = Attach.fromEncodedAndContentType(value, ct);
        ZParameter fn = prop.getParameter(ICalTok.X_FILENAME);
        if (fn == null) {
            fn = prop.getParameter(ICalTok.X_APPLE_FILENAME);
        }
        if (fn != null) {
            attach.setFileName(fn.getValue());
        }
    } else {
        // URI
        attach = Attach.fromUriAndContentType(value, ct);
    }
    return attach;
}
Also used : ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 2 with ZParameter

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

the class Attach method toZProperty.

public ZProperty toZProperty() {
    ZProperty prop;
    if (mUri != null) {
        prop = new ZProperty(ICalTok.ATTACH, mUri);
    } else {
        prop = new ZProperty(ICalTok.ATTACH, mBinaryB64Data);
        prop.addParameter(new ZParameter(ICalTok.VALUE, "BINARY"));
        prop.addParameter(new ZParameter(ICalTok.ENCODING, "BASE64"));
    }
    if (mContentType != null) {
        prop.addParameter(new ZParameter(ICalTok.FMTTYPE, mContentType));
    }
    if (fileName != null) {
        /* We recognise X-FILENAME incoming as well from Microsoft documentation but CalDAV clients are more
             * likely to use X-APPLE-FILENAME
             */
        prop.addParameter(new ZParameter(ICalTok.X_APPLE_FILENAME, fileName));
    }
    return prop;
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 3 with ZParameter

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

the class ParsedDateTime method toProperty.

public ZProperty toProperty(ICalTok tok, boolean useOutlookCompatMode) {
    ZProperty toRet = new ZProperty(tok, getDateTimePartString(useOutlookCompatMode));
    String tzName = getTZName();
    if (!useOutlookCompatMode && !hasTime()) {
        toRet.addParameter(new ZParameter(ICalTok.VALUE, ICalTok.DATE.toString()));
    } else {
        if (tzName != null) {
            toRet.addParameter(new ZParameter(ICalTok.TZID, tzName));
        }
    }
    return toRet;
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 4 with ZParameter

use of com.zimbra.common.calendar.ZCalendar.ZParameter 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 5 with ZParameter

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

the class FreeBusy method parse.

/**
 * Create a FreeBusy object from VFREEBUSY ZComponent.
 * @param comp
 * @return
 * @throws ServiceException
 */
public static FreeBusy parse(ZComponent comp) throws ServiceException {
    String name = null;
    ParsedDateTime dtStart = null;
    ParsedDateTime dtEnd = null;
    List<Interval> intervals = new ArrayList<Interval>();
    TimeZoneMap tzmap = new TimeZoneMap(ICalTimeZone.getUTC());
    Iterator<ZProperty> propIter = comp.getPropertyIterator();
    while (propIter.hasNext()) {
        ZProperty prop = propIter.next();
        ICalTok tok = prop.getToken();
        if (tok == null)
            continue;
        switch(tok) {
            case DTSTART:
                try {
                    dtStart = ParsedDateTime.parse(prop, tzmap);
                } catch (ParseException e) {
                    throw ServiceException.INVALID_REQUEST("bad DTSTART: " + prop.toString(), e);
                }
                break;
            case DTEND:
                try {
                    dtEnd = ParsedDateTime.parse(prop, tzmap);
                } catch (ParseException e) {
                    throw ServiceException.INVALID_REQUEST("bad DTEND: " + prop.toString(), e);
                }
                break;
            case ORGANIZER:
                ZOrganizer att = new ZOrganizer(prop);
                name = att.getAddress();
                break;
            case FREEBUSY:
                String fbStatus = IcalXmlStrMap.FBTYPE_FREE;
                ZParameter fbType = prop.getParameter(ICalTok.FBTYPE);
                if (fbType != null)
                    fbStatus = IcalXmlStrMap.sFreeBusyMap.toXml(fbType.getValue());
                List<String> vals = prop.getValueList();
                for (String fbVal : vals) {
                    Period period;
                    try {
                        period = Period.parse(fbVal, ICalTimeZone.getUTC(), tzmap);
                    } catch (ParseException e) {
                        throw ServiceException.INVALID_REQUEST("bad period value: " + fbVal, e);
                    }
                    intervals.add(new Interval(period.getStart().getUtcTime(), period.getEnd().getUtcTime(), fbStatus));
                }
                break;
        }
    }
    if (name == null)
        throw ServiceException.INVALID_REQUEST("VFREEBUSY missing ORGANIZER", null);
    if (dtStart == null || dtEnd == null)
        throw ServiceException.INVALID_REQUEST("VFREEBUSY missing DTSTART/DTEND", null);
    IntervalList ivalList = new IntervalList(dtStart.getUtcTime(), dtEnd.getUtcTime());
    for (Interval ival : intervals) {
        ivalList.addInterval(ival);
    }
    return new FreeBusy(name, ivalList, dtStart.getUtcTime(), dtEnd.getUtcTime());
}
Also used : ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) Period(com.zimbra.cs.mailbox.calendar.Period) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Aggregations

ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)30 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)22 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)8 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)8 ArrayList (java.util.ArrayList)8 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)7 ParseException (java.text.ParseException)5 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)4 Metadata (com.zimbra.cs.mailbox.Metadata)4 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)3 Element (com.zimbra.common.soap.Element)3 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)3 Attach (com.zimbra.common.calendar.Attach)2 Geo (com.zimbra.common.calendar.Geo)2 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)2 ServiceException (com.zimbra.common.service.ServiceException)2 Account (com.zimbra.cs.account.Account)2 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)2 MailItem (com.zimbra.cs.mailbox.MailItem)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2