Caldav: fix floating timezone in iCal: rename TZID for maximum iCal/iPhone compatibility

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1578 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-12-12 21:39:19 +00:00
parent 80712f6063
commit 2f47f173d0
2 changed files with 34 additions and 4 deletions

View File

@ -25,10 +25,7 @@ import org.apache.log4j.Logger;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.*;
/**
* VCalendar object.
@ -146,6 +143,20 @@ public class VCalendar extends VObject {
setPropertyValue("METHOD", "PUBLISH");
}
// rename TZID for maximum iCal/iPhone compatibility
String tzid = null;
if (fromServer) {
// get current tzid
VObject vObject = getVTimezone();
if (vObject != null) {
try {
tzid = ResourceBundle.getBundle("timezones").getString(vObject.getPropertyValue("TZID"));
} catch (MissingResourceException e) {
LOGGER.debug("Timezone rename failed, timezone "+vObject.getPropertyValue("TZID")+" not found in table");
}
}
}
// iterate over vObjects
for (VObject vObject : vObjects) {
if ("VEVENT".equals(vObject.type)) {
@ -187,6 +198,17 @@ public class VCalendar extends VObject {
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);
}
}
} else {
// add organizer line to all events created in Exchange for active sync
String organizer = getEmailValue(vObject.getProperty("ORGANIZER"));

View File

@ -230,6 +230,14 @@ public class VProperty {
addParam(paramName, (String) null);
}
public void setParam(String paramName, String paramValue) {
Param currentParam = getParam(paramName);
if (currentParam != null) {
getParams().remove(currentParam);
}
addParam(paramName, paramValue);
}
public void addParam(String paramName, String paramValue) {
List<String> paramValues = new ArrayList<String>();
paramValues.add(paramValue);