mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 03:32: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 {
|
} finally {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
String resultString = result.toString();
|
String resultString = result.toString();
|
||||||
|
|
||||||
|
/* new experimental code
|
||||||
|
VCalendar vCalendar = new VCalendar(icsBody, getEmail());
|
||||||
|
vCalendar.fixVCalendar(fromServer);
|
||||||
|
resultString = vCalendar.toString();
|
||||||
|
*/
|
||||||
dumpICS(resultString, fromServer, true);
|
dumpICS(resultString, fromServer, true);
|
||||||
|
|
||||||
return resultString;
|
return resultString;
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
*/
|
*/
|
||||||
package davmail.exchange;
|
package davmail.exchange;
|
||||||
|
|
||||||
|
import davmail.Settings;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@ -129,18 +131,53 @@ public class VCalendar extends VObject {
|
|||||||
}
|
}
|
||||||
// set OWA allday flag
|
// set OWA allday flag
|
||||||
vObject.setPropertyValue("X-MICROSOFT-CDO-ALLDAYEVENT", isAllDay(vObject) ? "TRUE" : "FALSE");
|
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 {
|
} else {
|
||||||
// remove organizer line for event without attendees for iPhone
|
// remove organizer line for event without attendees for iPhone
|
||||||
if (getProperty("ATTENDEE") == null) {
|
if (getProperty("ATTENDEE") == null) {
|
||||||
vObject.setPropertyValue("ORGANIZER", 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
|
* Replace iCal4 (Snow Leopard) principal paths with mailto expression
|
||||||
*
|
*
|
||||||
@ -155,20 +192,25 @@ public class VCalendar extends VObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixAttendees(VObject vObject) {
|
private void fixAttendees(VObject vObject, boolean fromServer) {
|
||||||
if (properties != null) {
|
if (!fromServer) {
|
||||||
for (VProperty property : properties) {
|
if (vObject.properties != null) {
|
||||||
if ("ATTENDEE".equalsIgnoreCase(property.getKey())) {
|
for (VProperty property : vObject.properties) {
|
||||||
property.setValue(replaceIcal4Principal(property.getValue()));
|
if ("ATTENDEE".equalsIgnoreCase(property.getKey())) {
|
||||||
|
property.setValue(replaceIcal4Principal(property.getValue()));
|
||||||
|
|
||||||
// ignore attendee as organizer
|
// ignore attendee as organizer
|
||||||
if (property.getValue().contains(email)) {
|
if (property.getValue().contains(email)) {
|
||||||
property.setValue(null);
|
property.setValue(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO patch RSVP
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,13 +82,13 @@ public class VProperty {
|
|||||||
} else if (currentChar == ';') {
|
} else if (currentChar == ';') {
|
||||||
// param with no value
|
// param with no value
|
||||||
paramName = line.substring(startIndex, i).toUpperCase();
|
paramName = line.substring(startIndex, i).toUpperCase();
|
||||||
addParam(paramName, null);
|
addParam(paramName);
|
||||||
state = State.PARAM_NAME;
|
state = State.PARAM_NAME;
|
||||||
startIndex = i + 1;
|
startIndex = i + 1;
|
||||||
} else if (currentChar == ':') {
|
} else if (currentChar == ':') {
|
||||||
// param with no value
|
// param with no value
|
||||||
paramName = line.substring(startIndex, i).toUpperCase();
|
paramName = line.substring(startIndex, i).toUpperCase();
|
||||||
addParam(paramName, null);
|
addParam(paramName);
|
||||||
state = State.VALUE;
|
state = State.VALUE;
|
||||||
startIndex = i + 1;
|
startIndex = i + 1;
|
||||||
}
|
}
|
||||||
@ -198,6 +198,16 @@ public class VProperty {
|
|||||||
return false;
|
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) {
|
protected void addParam(String paramName, List<String> paramValues) {
|
||||||
if (params == null) {
|
if (params == null) {
|
||||||
params = new ArrayList<Param>();
|
params = new ArrayList<Param>();
|
||||||
|
@ -476,4 +476,19 @@ public class TestExchangeSessionEvent extends TestCase {
|
|||||||
assertTrue(toServer.contains("ORGANIZER"));
|
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