mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
Caldav: implement VALARM in VCalendar
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1320 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
cae681adc0
commit
5bacc44dea
@ -2189,8 +2189,13 @@ public abstract class ExchangeSession {
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
String resultString = result.toString();
|
||||
|
||||
/* new experimental code
|
||||
VCalendar vCalendar = new VCalendar(icsBody, getEmail());
|
||||
vCalendar.fixVCalendar(fromServer);
|
||||
resultString = vCalendar.toString();
|
||||
*/
|
||||
dumpICS(resultString, fromServer, true);
|
||||
|
||||
return resultString;
|
||||
|
@ -18,6 +18,8 @@
|
||||
*/
|
||||
package davmail.exchange;
|
||||
|
||||
import davmail.Settings;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@ -129,18 +131,53 @@ public class VCalendar extends VObject {
|
||||
}
|
||||
// set OWA allday flag
|
||||
vObject.setPropertyValue("X-MICROSOFT-CDO-ALLDAYEVENT", isAllDay(vObject) ? "TRUE" : "FALSE");
|
||||
fixAttendees(vObject);
|
||||
vObject.setPropertyValue("X-MICROSOFT-CDO-BUSYSTATUS",
|
||||
!"TRANSPARENT".equals(vObject.getPropertyValue("TRANSP")) ? "BUSY" : "FREE");
|
||||
|
||||
} else {
|
||||
// remove organizer line for event without attendees for iPhone
|
||||
if (getProperty("ATTENDEE") == null) {
|
||||
vObject.setPropertyValue("ORGANIZER", null);
|
||||
}
|
||||
// TODO: handle transparent ?
|
||||
}
|
||||
|
||||
fixAttendees(vObject, fromServer);
|
||||
|
||||
// TODO handle BUSYSTATUS
|
||||
|
||||
fixAlarm(vObject, fromServer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fixAlarm(VObject vObject, boolean fromServer) {
|
||||
for (VObject vAlarm : vObject.vObjects) {
|
||||
if ("VALARM".equals(vAlarm.type)) {
|
||||
String action = vAlarm.getPropertyValue("ACTION");
|
||||
if (fromServer && "DISPLAY".equals(action)
|
||||
// convert DISPLAY to AUDIO only if user defined an alarm sound
|
||||
&& Settings.getProperty("davmail.caldavAlarmSound") != null) {
|
||||
// Convert alarm to audio for iCal
|
||||
vAlarm.setPropertyValue("ACTION", "AUDIO");
|
||||
|
||||
if (vAlarm.getPropertyValue("ATTACH") == null) {
|
||||
// Add defined sound into the audio alarm
|
||||
VProperty vProperty = new VProperty("ATTACH", Settings.getProperty("davmail.caldavAlarmSound"));
|
||||
vProperty.addParam("VALUE", "URI");
|
||||
vAlarm.addProperty(vProperty);
|
||||
}
|
||||
|
||||
} else if (!fromServer && "AUDIO".equals(action)) {
|
||||
// Use the alarm action that exchange (and blackberry) understand
|
||||
// (exchange and blackberry don't understand audio actions)
|
||||
vAlarm.setPropertyValue("ACTION", "DISPLAY");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace iCal4 (Snow Leopard) principal paths with mailto expression
|
||||
*
|
||||
@ -155,20 +192,25 @@ public class VCalendar extends VObject {
|
||||
}
|
||||
}
|
||||
|
||||
private void fixAttendees(VObject vObject) {
|
||||
if (properties != null) {
|
||||
for (VProperty property : properties) {
|
||||
if ("ATTENDEE".equalsIgnoreCase(property.getKey())) {
|
||||
property.setValue(replaceIcal4Principal(property.getValue()));
|
||||
private void fixAttendees(VObject vObject, boolean fromServer) {
|
||||
if (!fromServer) {
|
||||
if (vObject.properties != null) {
|
||||
for (VProperty property : vObject.properties) {
|
||||
if ("ATTENDEE".equalsIgnoreCase(property.getKey())) {
|
||||
property.setValue(replaceIcal4Principal(property.getValue()));
|
||||
|
||||
// ignore attendee as organizer
|
||||
if (property.getValue().contains(email)) {
|
||||
property.setValue(null);
|
||||
// ignore attendee as organizer
|
||||
if (property.getValue().contains(email)) {
|
||||
property.setValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
// TODO patch RSVP
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,13 +82,13 @@ public class VProperty {
|
||||
} else if (currentChar == ';') {
|
||||
// param with no value
|
||||
paramName = line.substring(startIndex, i).toUpperCase();
|
||||
addParam(paramName, null);
|
||||
addParam(paramName);
|
||||
state = State.PARAM_NAME;
|
||||
startIndex = i + 1;
|
||||
} else if (currentChar == ':') {
|
||||
// param with no value
|
||||
paramName = line.substring(startIndex, i).toUpperCase();
|
||||
addParam(paramName, null);
|
||||
addParam(paramName);
|
||||
state = State.VALUE;
|
||||
startIndex = i + 1;
|
||||
}
|
||||
@ -198,6 +198,16 @@ public class VProperty {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void addParam(String paramName) {
|
||||
addParam(paramName, (String)null);
|
||||
}
|
||||
|
||||
protected void addParam(String paramName, String paramValue) {
|
||||
List paramValues = new ArrayList();
|
||||
paramValues.add(paramValue);
|
||||
addParam(paramName, paramValues);
|
||||
}
|
||||
|
||||
protected void addParam(String paramName, List<String> paramValues) {
|
||||
if (params == null) {
|
||||
params = new ArrayList<Param>();
|
||||
|
@ -476,4 +476,19 @@ public class TestExchangeSessionEvent extends TestCase {
|
||||
assertTrue(toServer.contains("ORGANIZER"));
|
||||
}
|
||||
|
||||
|
||||
public void testValarm() throws IOException {
|
||||
String itemBody = "BEGIN:VCALENDAR\n" +
|
||||
"BEGIN:VEVENT\n" +
|
||||
"BEGIN:VALARM\n" +
|
||||
"TRIGGER:-PT15M\n" +
|
||||
"ATTACH;VALUE=URI:Basso\n" +
|
||||
"ACTION:AUDIO\n" +
|
||||
"END:VALARM\n" +
|
||||
"END:VEVENT\n" +
|
||||
"END:VCALENDAR";
|
||||
String toServer = fixICS(itemBody, false);
|
||||
System.out.println(toServer);
|
||||
assertTrue(toServer.contains("ACTION:DISPLAY"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user