Exemplo n.º 1
0
 protected void splitExDate(VObject vObject) {
   List<VProperty> exDateProperties = vObject.getProperties("EXDATE");
   if (exDateProperties != null) {
     for (VProperty property : exDateProperties) {
       String value = property.getValue();
       if (value.indexOf(',') >= 0) {
         // split property
         vObject.removeProperty(property);
         for (String singleValue : value.split(",")) {
           VProperty singleProperty = new VProperty("EXDATE", singleValue);
           singleProperty.setParams(property.getParams());
           vObject.addProperty(singleProperty);
         }
       }
     }
   }
 }
Exemplo n.º 2
0
  protected void fixVCalendar(boolean fromServer) {
    // set iCal 4 global X-CALENDARSERVER-ACCESS from CLASS
    if (fromServer) {
      setPropertyValue("X-CALENDARSERVER-ACCESS", getCalendarServerAccess());
    }

    // iCal 4 global X-CALENDARSERVER-ACCESS
    String calendarServerAccess = getPropertyValue("X-CALENDARSERVER-ACCESS");
    String now = ExchangeSession.getZuluDateFormat().format(new Date());

    // fix method from iPhone
    if (!fromServer && getPropertyValue("METHOD") == null) {
      setPropertyValue("METHOD", "PUBLISH");
    }

    // rename TZID for maximum iCal/iPhone compatibility
    String tzid = null;
    if (fromServer) {
      // get current tzid
      VObject vObject = vTimezone;
      if (vObject != null) {
        String currentTzid = vObject.getPropertyValue("TZID");
        // fix TZID with \n (Exchange 2010 bug)
        if (currentTzid != null && currentTzid.endsWith("\n")) {
          currentTzid = currentTzid.substring(0, currentTzid.length() - 1);
          vObject.setPropertyValue("TZID", currentTzid);
        }
        if (currentTzid != null && currentTzid.indexOf(' ') >= 0) {
          try {
            tzid = ResourceBundle.getBundle("timezones").getString(currentTzid);
            vObject.setPropertyValue("TZID", tzid);
          } catch (MissingResourceException e) {
            LOGGER.debug("Timezone " + currentTzid + " not found in rename table");
          }
        }
      }
    }

    if (!fromServer) {
      fixTimezone();
    }

    // iterate over vObjects
    for (VObject vObject : vObjects) {
      if ("VEVENT".equals(vObject.type)) {
        if (calendarServerAccess != null) {
          vObject.setPropertyValue("CLASS", getEventClass(calendarServerAccess));
          // iCal 3, get X-CALENDARSERVER-ACCESS from local VEVENT
        } else if (vObject.getPropertyValue("X-CALENDARSERVER-ACCESS") != null) {
          vObject.setPropertyValue(
              "CLASS", getEventClass(vObject.getPropertyValue("X-CALENDARSERVER-ACCESS")));
        }
        if (fromServer) {
          // remove organizer line for event without attendees for iPhone
          if (vObject.getProperty("ATTENDEE") == null) {
            vObject.setPropertyValue("ORGANIZER", null);
          }
          // detect allday and update date properties
          if (isCdoAllDay(vObject)) {
            setClientAllday(vObject.getProperty("DTSTART"));
            setClientAllday(vObject.getProperty("DTEND"));
            setClientAllday(vObject.getProperty("RECURRENCE-ID"));
          }
          String cdoBusyStatus = vObject.getPropertyValue("X-MICROSOFT-CDO-BUSYSTATUS");
          if (cdoBusyStatus != null) {
            vObject.setPropertyValue(
                "TRANSP", !"FREE".equals(cdoBusyStatus) ? "OPAQUE" : "TRANSPARENT");
          }

          // Apple iCal doesn't understand this key, and it's entourage
          // specific (i.e. not needed by any caldav client): strip it out
          vObject.removeProperty("X-ENTOURAGE_UUID");

          splitExDate(vObject);

          // remove empty properties
          if ("".equals(vObject.getPropertyValue("LOCATION"))) {
            vObject.removeProperty("LOCATION");
          }
          if ("".equals(vObject.getPropertyValue("DESCRIPTION"))) {
            vObject.removeProperty("DESCRIPTION");
          }
          if ("".equals(vObject.getPropertyValue("CLASS"))) {
            vObject.removeProperty("CLASS");
          }
          // rename TZID
          if (tzid != null) {
            VProperty dtStart = vObject.getProperty("DTSTART");
            if (dtStart != null && dtStart.getParam("TZID") != null) {
              dtStart.setParam("TZID", tzid);
            }
            VProperty dtEnd = vObject.getProperty("DTEND");
            if (dtEnd != null && dtStart.getParam("TZID") != null) {
              dtEnd.setParam("TZID", tzid);
            }
            VProperty reccurrenceId = vObject.getProperty("RECURRENCE-ID");
            if (reccurrenceId != null && reccurrenceId.getParam("TZID") != null) {
              reccurrenceId.setParam("TZID", tzid);
            }
          }
          // remove unsupported attachment reference
          if (vObject.getProperty("ATTACH") != null) {
            List<String> toRemoveValues = null;
            List<String> values = vObject.getProperty("ATTACH").getValues();
            for (String value : values) {
              if (value.indexOf("CID:") >= 0) {
                if (toRemoveValues == null) {
                  toRemoveValues = new ArrayList<String>();
                }
                toRemoveValues.add(value);
              }
            }
            if (toRemoveValues != null) {
              values.removeAll(toRemoveValues);
              if (values.size() == 0) {
                vObject.removeProperty("ATTACH");
              }
            }
          }
        } else {
          // add organizer line to all events created in Exchange for active sync
          String organizer = getEmailValue(vObject.getProperty("ORGANIZER"));
          if (organizer == null) {
            vObject.setPropertyValue("ORGANIZER", "MAILTO:" + email);
          } else if (!email.equalsIgnoreCase(organizer)
              && vObject.getProperty("X-MICROSOFT-CDO-REPLYTIME") == null) {
            vObject.setPropertyValue("X-MICROSOFT-CDO-REPLYTIME", now);
          }
          // set OWA allday flag
          vObject.setPropertyValue(
              "X-MICROSOFT-CDO-ALLDAYEVENT", isAllDay(vObject) ? "TRUE" : "FALSE");
          vObject.setPropertyValue(
              "X-MICROSOFT-CDO-BUSYSTATUS",
              !"TRANSPARENT".equals(vObject.getPropertyValue("TRANSP")) ? "BUSY" : "FREE");

          if (isAllDay(vObject)) {
            // convert date values to outlook compatible values
            setServerAllday(vObject.getProperty("DTSTART"));
            setServerAllday(vObject.getProperty("DTEND"));
          } else {
            fixTzid(vObject.getProperty("DTSTART"));
            fixTzid(vObject.getProperty("DTEND"));
          }
        }

        fixAttendees(vObject, fromServer);

        fixAlarm(vObject, fromServer);
      }
    }
  }