Search in sources :

Example 21 with ZParameter

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

the class CalendarUser method toString.

public String toString() {
    StringBuilder sb = new StringBuilder();
    addToStringBuilder(sb);
    for (ZParameter xparam : mXParams) {
        sb.append(", ").append(xparam.toString());
    }
    return sb.toString();
}
Also used : ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 22 with ZParameter

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

the class CalendarUser method toProperty.

public ZProperty toProperty() throws ServiceException {
    String addr = getAddress();
    if (addr != null && addr.indexOf(':') < 0)
        addr = "mailto:" + addr;
    ZProperty prop = new ZProperty(getPropertyName(), addr);
    setProperty(prop);
    // x-param
    for (ZParameter xparam : mXParams) {
        prop.addParameter(xparam);
    }
    return prop;
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 23 with ZParameter

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

the class Invite method decodeMetadata.

/**
     * This API is public for RedoLogging to call into it -- you probably don't want to call it from
     * anywhere else!
     *
     * @param mailboxId
     * @param meta
     * @param calItem
     * @param accountTZ
     * @return
     * @throws ServiceException
     */
public static Invite decodeMetadata(int mailboxId, Metadata meta, CalendarItem calItem, ICalTimeZone accountTZ) throws ServiceException {
    byte btype = (byte) meta.getLong(FN_ITEMTYPE, -1);
    MailItem.Type type = btype >= 0 ? MailItem.Type.of(btype) : MailItem.Type.APPOINTMENT;
    String uid = meta.get(FN_UID, null);
    int mailItemId = (int) meta.getLong(FN_INVMSGID);
    int componentNum = (int) meta.getLong(FN_COMPNUM);
    String classProp = meta.get(FN_CLASS, IcalXmlStrMap.CLASS_PUBLIC);
    boolean classPropSetByMe = meta.getBool(FN_CLASS_SETBYME, false);
    String status = meta.get(FN_STATUS, IcalXmlStrMap.STATUS_CONFIRMED);
    String freebusy = meta.get(FN_APPT_FREEBUSY, null);
    String transp = meta.get(FN_TRANSP, IcalXmlStrMap.TRANSP_OPAQUE);
    boolean sentByMe = meta.getBool(FN_SENTBYME);
    String fragment = meta.get(FN_FRAGMENT, "");
    // default to false for backward compat
    boolean descInMeta = meta.getBool(FN_DESC_IN_META, false);
    String desc = descInMeta ? meta.get(FN_DESC, null) : null;
    String descHtml = descInMeta ? meta.get(FN_DESC_HTML, null) : null;
    long completed = meta.getLong(FN_COMPLETED, 0);
    ParsedDateTime dtStart = null;
    ParsedDateTime dtEnd = null;
    ParsedDuration duration = null;
    RecurId recurrenceId = null;
    TimeZoneMap tzMap = Util.decodeFromMetadata(meta.getMap(FN_TZMAP), accountTZ);
    Metadata metaRecur = meta.getMap(FN_RECURRENCE, true);
    Recurrence.IRecurrence recurrence = null;
    if (metaRecur != null) {
        recurrence = Recurrence.decodeMetadata(metaRecur, tzMap);
    }
    String methodStr = meta.get(FN_METHOD, ICalTok.PUBLISH.toString());
    if (ICalTok.CANCEL.toString().equals(methodStr))
        status = IcalXmlStrMap.STATUS_CANCELLED;
    int flags = (int) meta.getLong(FN_APPT_FLAGS, 0);
    try {
        // DtStart
        dtStart = ParsedDateTime.parse(meta.get(FN_START, null), tzMap);
        // DtEnd
        dtEnd = ParsedDateTime.parse(meta.get(FN_END, null), tzMap);
        if ((flags & APPT_FLAG_ALLDAY) != 0) {
            // Fixup historic data with incorrect all-day start/end format.
            if (dtStart != null)
                dtStart.forceDateOnly();
            if (dtEnd != null)
                dtEnd.forceDateOnly();
        }
        // Duration
        duration = ParsedDuration.parse(meta.get(FN_DURATION, null));
        if (meta.containsKey(FN_RECUR_ID)) {
            Metadata rdata = meta.getMap(FN_RECUR_ID);
            recurrenceId = RecurId.decodeMetadata(rdata, tzMap);
        }
    } catch (ParseException e) {
        throw ServiceException.FAILURE(String.format("Error parsing metadata for invite %s-%s in calItem %s", mailItemId, componentNum, (calItem != null) ? Integer.toString(calItem.getId()) : "(null)"), e);
    }
    String name = meta.get(FN_NAME, "");
    String loc = meta.get(FN_LOCATION, null);
    // For existing invites with no partstat, default to ACCEPTED status.
    String partStat = meta.get(FN_PARTSTAT, IcalXmlStrMap.PARTSTAT_ACCEPTED);
    // For existing invites with no RSVP, default to true.
    boolean rsvp = meta.getBool(FN_RSVP, true);
    long dtstamp = meta.getLong(FN_DTSTAMP, 0);
    long lastModified = meta.getLong(FN_LAST_MODIFIED, 0);
    int seqno = (int) meta.getLong(FN_SEQ_NO, 0);
    int lastFullSeqno = (int) meta.getLong(FN_LAST_FULL_SEQ_NO, seqno);
    ZOrganizer org = null;
    try {
        Metadata metaOrg = meta.getMap(FN_ORGANIZER, true);
        org = metaOrg != null ? new ZOrganizer(metaOrg) : null;
    } catch (ServiceException e) {
        sLog.warn("Problem decoding organizer for calItem %s invite %s-%s", (calItem != null) ? Integer.toString(calItem.getId()) : "(null)", mailItemId, componentNum);
    }
    long numAts = meta.getLong(FN_NUM_ATTENDEES, 0);
    ArrayList<ZAttendee> attendees = new ArrayList<ZAttendee>((int) numAts);
    for (int i = 0; i < numAts; i++) {
        try {
            Metadata metaAttendee = meta.getMap(FN_ATTENDEE + i, true);
            if (metaAttendee != null)
                attendees.add(new ZAttendee(metaAttendee));
        } catch (ServiceException e) {
            ZimbraLog.calendar.warn("Problem decoding attendee %s for calendar item %s invite %s-%s", i, (calItem != null) ? Integer.toString(calItem.getId()) : "(null)", mailItemId, componentNum);
        }
    }
    boolean isOrganizer = false;
    if (meta.containsKey(FN_IS_ORGANIZER)) {
        isOrganizer = meta.getBool(FN_IS_ORGANIZER);
    } else {
        // backward compat for invites created before FN_IS_ORGANIZER was introduced
        if (org != null) {
            String orgAddr = org.getAddress();
            Account account = MailboxManager.getInstance().getMailboxById(mailboxId).getAccount();
            AccountAddressMatcher acctMatcher = new AccountAddressMatcher(account);
            isOrganizer = acctMatcher.matches(orgAddr);
        } else {
            // If there are other attendees, it's an Outlook POP/IMAP bug.  If not,
            // it's a properly formatted single-user event.  See isOrganizer()
            // method for more info.
            isOrganizer = numAts < 1;
        }
    }
    String priority = meta.get(FN_PRIORITY, null);
    String pctComplete = meta.get(FN_PCT_COMPLETE, null);
    List<String> comments = null;
    int numComm = (int) meta.getLong(FN_NUM_COMMENTS, 0);
    if (numComm > 0) {
        comments = new ArrayList<String>(numComm);
        for (int i = 0; i < numComm; i++) {
            String comm = meta.get(FN_COMMENT + i, null);
            if (comm != null)
                comments.add(comm);
        }
    }
    List<String> contacts = null;
    int numContacts = (int) meta.getLong(FN_NUM_CONTACTS, 0);
    if (numContacts > 0) {
        contacts = new ArrayList<String>(numContacts);
        for (int i = 0; i < numContacts; i++) {
            String contact = meta.get(FN_CONTACT + i, null);
            if (contact != null)
                contacts.add(contact);
        }
    }
    List<String> categories = null;
    int numCat = (int) meta.getLong(FN_NUM_CATEGORIES, 0);
    if (numCat > 0) {
        categories = new ArrayList<String>(numCat);
        for (int i = 0; i < numCat; i++) {
            String cat = meta.get(FN_CATEGORY + i, null);
            if (cat != null)
                categories.add(cat);
        }
    }
    Geo geo = null;
    Metadata metaGeo = meta.getMap(FN_GEO, true);
    if (metaGeo != null)
        geo = Util.decodeGeoFromMetadata(metaGeo);
    String url = meta.get(FN_URL, null);
    Invite invite = new Invite(type, methodStr, tzMap, calItem, uid, status, priority, pctComplete, completed, freebusy, transp, classProp, dtStart, dtEnd, duration, recurrence, isOrganizer, org, attendees, name, loc, flags, partStat, rsvp, recurrenceId, dtstamp, lastModified, seqno, lastFullSeqno, mailboxId, mailItemId, componentNum, sentByMe, desc, descHtml, fragment, comments, categories, contacts, geo, url);
    // a little hacky, but necessary
    invite.mDescInMeta = descInMeta;
    invite.setClassPropSetByMe(classPropSetByMe);
    long numAlarms = meta.getLong(FN_NUM_ALARMS, 0);
    for (int i = 0; i < numAlarms; i++) {
        try {
            Metadata metaAlarm = meta.getMap(FN_ALARM + i, true);
            if (metaAlarm != null) {
                Alarm alarm = Alarm.decodeMetadata(metaAlarm);
                if (alarm != null)
                    invite.addAlarm(alarm);
            }
        } catch (ServiceException e) {
            ZimbraLog.calendar.warn("Problem decoding alarm %s for calendar item %s invite %s-%s", i, (calItem != null) ? Integer.toString(calItem.getId()) : "(null)", mailItemId, componentNum, e);
        }
    }
    List<ZProperty> xprops = Util.decodeXPropsFromMetadata(meta);
    if (xprops != null) {
        for (ZProperty xprop : xprops) {
            boolean isHtmlDesc = false;
            if (ICalTok.X_ALT_DESC.equals(xprop.getToken())) {
                // Backward compat.  We used to save X-ALT-DESC property as an x-prop.  Now we use it
                // for HTML description, when FMTTYPE=text/html.
                ZParameter fmttype = xprop.getParameter(ICalTok.FMTTYPE);
                if (fmttype != null && MimeConstants.CT_TEXT_HTML.equalsIgnoreCase(fmttype.getValue())) {
                    isHtmlDesc = true;
                    invite.mDescHtml = xprop.getValue();
                }
            }
            if (!isHtmlDesc)
                invite.addXProp(xprop);
        }
    }
    invite.setDontIndexMimeMessage(meta.getBool(FN_DONT_INDEX_MM, false));
    boolean localOnly = meta.getBool(FN_LOCAL_ONLY, false);
    invite.setLocalOnly(localOnly);
    invite.sanitize(false);
    return invite;
}
Also used : IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) Account(com.zimbra.cs.account.Account) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) Metadata(com.zimbra.cs.mailbox.Metadata) ArrayList(java.util.ArrayList) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) Geo(com.zimbra.common.calendar.Geo) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) AccountAddressMatcher(com.zimbra.cs.util.AccountUtil.AccountAddressMatcher) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParseException(java.text.ParseException)

Example 24 with ZParameter

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

the class Invite method toVComponents.

public static ZComponent[] toVComponents(Invite[] invites, boolean includePrivateData, boolean useOutlookCompatAllDayEvents, boolean convertCanceledInstancesToExdates, boolean includeAttaches) throws ServiceException {
    List<ZComponent> comps = new ArrayList<ZComponent>(invites.length);
    if (!convertCanceledInstancesToExdates || invites.length <= 1) {
        for (Invite inv : invites) {
            ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
            comps.add(comp);
        }
    } else {
        // Activate the hack that converts standalone VEVENT/VTODO components with STATUS:CANCELLED
        // into EXDATEs on the series component. (bug 36434)
        Invite seriesInv = null;
        ZComponent seriesComp = null;
        // Find the series invite.
        for (Invite inv : invites) {
            if (inv.isRecurrence()) {
                ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
                seriesComp = comp;
                comps.add(seriesComp);
                seriesInv = inv;
                break;
            }
        }
        for (Invite inv : invites) {
            if (inv != seriesInv) {
                // We already handled the series invite in the previous loop.
                if (inv.hasRecurId() && inv.isCancel()) {
                    // as a standalone component.
                    if (seriesComp != null) {
                        RecurId rid = inv.getRecurId();
                        ZProperty ridProp = rid.toProperty(false);
                        // EXDATE and RECURRENCE-ID have same value types and parameter list.  Just copy over.
                        ZProperty exdateProp = new ZProperty(ICalTok.EXDATE, ridProp.getValue());
                        for (Iterator<ZParameter> paramsIter = ridProp.parameterIterator(); paramsIter.hasNext(); ) {
                            ZParameter param = paramsIter.next();
                            exdateProp.addParameter(param);
                        }
                        seriesComp.addProperty(exdateProp);
                    } else {
                        // But if there is no series component, let the canceled instance be a component.
                        ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
                        if (comp != null)
                            comps.add(comp);
                    }
                } else {
                    // Modified instances are added as standalone components.
                    ZComponent comp = inv.newToVComponent(useOutlookCompatAllDayEvents, includePrivateData, includeAttaches);
                    if (comp != null)
                        comps.add(comp);
                }
            }
        }
    }
    return comps.toArray(new ZComponent[0]);
}
Also used : ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) ArrayList(java.util.ArrayList) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 25 with ZParameter

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

the class Util method encodeXParamsAsMetadata.

public static void encodeXParamsAsMetadata(Metadata meta, Iterator<ZParameter> xparamsIter) {
    int xparamCount = 0;
    for (; xparamsIter.hasNext(); ) {
        ZParameter xparam = xparamsIter.next();
        String paramName = xparam.getName();
        if (paramName == null)
            continue;
        Metadata paramMeta = new Metadata();
        paramMeta.put(FN_NAME, paramName);
        String paramValue = xparam.getValue();
        if (paramValue != null)
            paramMeta.put(FN_VALUE, paramValue);
        meta.put(FN_XPROP_OR_XPARAM + xparamCount, paramMeta);
        xparamCount++;
    }
    if (xparamCount > 0)
        meta.put(FN_NUM_XPROPS_OR_XPARAMS, xparamCount);
}
Also used : Metadata(com.zimbra.cs.mailbox.Metadata) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Aggregations

ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)28 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)20 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)8 ArrayList (java.util.ArrayList)8 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)7 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)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 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 Invite (com.zimbra.cs.mailbox.calendar.Invite)2