Search in sources :

Example 1 with TZRule

use of com.zimbra.cs.util.tnef.mapi.TZRule in project zm-mailbox by Zimbra.

the class SchedulingViewOfTnef method initTZinfo.

/**
     * Initialise timezone related fields.
     * Replies from Outlook 2007 related to a recurrence or an instance
     * of a recurrence had :
     *     PidLidTimeZoneDescription,PidLidTimeZoneStruct,
     *     PidLidAppointmentTimeZoneDefinitionStartDisplay and
     *     PidLidAppointmentTimeZoneDefinitionEndDisplay present but NOT
     *     PidLidAppointmentTimeZoneDefinitionRecur
     * further, the StartDisplay/EndDisplay properties were appropriate to the
     * Outlook client replying and were NOT related to the originally sent ICAL.
     *
     * The Outlook originated TimeZone names associated with
     * StartDisplay/EndDisplay/Recur props seem "nicer" than the names
     * used in PidLidTimeZoneDescription - so, tend to prefer those.
     *
     * @throws IOException
     */
private void initTZinfo() {
    if (tzinfoInitialized) {
        return;
    }
    try {
        RawInputStream tzRis;
        MapiPropertyId mpi;
        mpi = MapiPropertyId.PidLidAppointmentTimeZoneDefinitionStartDisplay;
        tzRis = mpi.getRawInputStreamValue(this);
        if (tzRis != null) {
            startTimeTZinfo = new TimeZoneDefinition(mpi, tzRis);
        }
        mpi = MapiPropertyId.PidLidAppointmentTimeZoneDefinitionEndDisplay;
        tzRis = mpi.getRawInputStreamValue(this);
        if (tzRis != null) {
            endTimeTZinfo = new TimeZoneDefinition(mpi, tzRis);
        }
        mpi = MapiPropertyId.PidLidAppointmentTimeZoneDefinitionRecur;
        tzRis = mpi.getRawInputStreamValue(this);
        if (tzRis != null) {
            recurrenceTZinfo = new TimeZoneDefinition(mpi, tzRis);
        }
        String tzDesc = this.getTimeZoneDescription();
        if (null != tzDesc) {
            TimeZoneDefinition tzStructInfo = this.getTimeZoneStructInfo(tzDesc);
            if (tzStructInfo != null) {
                // We know we have a recurrence related TZ definition.  Make
                // sure we have the most appropriate/nice definition for that.
                TZRule tzsRule = tzStructInfo.getEffectiveRule();
                if (recurrenceTZinfo == null) {
                    if ((startTimeTZinfo != null) && (tzsRule.equivalentRule(startTimeTZinfo.getEffectiveRule()))) {
                        recurrenceTZinfo = startTimeTZinfo;
                        sLog.debug("Using %s for TZ info", "PidLidAppointmentTimeZoneDefinitionStart");
                    } else if ((endTimeTZinfo != null) && (tzsRule.equivalentRule(endTimeTZinfo.getEffectiveRule()))) {
                        recurrenceTZinfo = endTimeTZinfo;
                        sLog.debug("Using %s for TZ info", "PidLidAppointmentTimeZoneDefinitionEnd");
                    } else {
                        recurrenceTZinfo = tzStructInfo;
                        sLog.debug("Using %s for TZ info", "PidLidTimeZoneStruct");
                    }
                } else if (!tzsRule.equivalentRule(recurrenceTZinfo.getEffectiveRule())) {
                    recurrenceTZinfo = tzStructInfo;
                    sLog.debug("Using %s for TZ info", "PidLidAppointmentTimeZoneDefinitionRecur");
                }
            }
        }
    } catch (IOException e) {
        sLog.debug("Problem encountered initialising timezone information", e);
    }
    if (recurrenceTZinfo != null) {
        // For recurrences, we want just one TZ for consistency
        if (endTimeTZinfo == null) {
            endTimeTZinfo = recurrenceTZinfo;
        } else if (recurrenceTZinfo.getEffectiveRule().equivalentRule(endTimeTZinfo.getEffectiveRule())) {
            endTimeTZinfo = recurrenceTZinfo;
        } else if (startTimeTZinfo != null) {
            // for cancel/request, even when related to an exception.
            if (startTimeTZinfo.getEffectiveRule().equivalentRule(endTimeTZinfo.getEffectiveRule())) {
                endTimeTZinfo = recurrenceTZinfo;
            }
        }
        startTimeTZinfo = recurrenceTZinfo;
    }
    if (endTimeTZinfo == null) {
        endTimeTZinfo = startTimeTZinfo;
    } else if (startTimeTZinfo == null) {
        startTimeTZinfo = endTimeTZinfo;
    } else if (startTimeTZinfo.getEffectiveRule().equivalentRule(endTimeTZinfo.getEffectiveRule())) {
        endTimeTZinfo = startTimeTZinfo;
    }
}
Also used : TZRule(com.zimbra.cs.util.tnef.mapi.TZRule) RawInputStream(net.freeutils.tnef.RawInputStream) TimeZoneDefinition(com.zimbra.cs.util.tnef.mapi.TimeZoneDefinition) IOException(java.io.IOException) MapiPropertyId(com.zimbra.cs.util.tnef.mapi.MapiPropertyId)

Aggregations

MapiPropertyId (com.zimbra.cs.util.tnef.mapi.MapiPropertyId)1 TZRule (com.zimbra.cs.util.tnef.mapi.TZRule)1 TimeZoneDefinition (com.zimbra.cs.util.tnef.mapi.TimeZoneDefinition)1 IOException (java.io.IOException)1 RawInputStream (net.freeutils.tnef.RawInputStream)1