diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 35beaf68..6f139cf2 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -2144,6 +2144,10 @@ public abstract class ExchangeSession { super(folderPath, itemName, etag, noneMatch); this.contentClass = contentClass; fixICS(itemBody.getBytes("UTF-8"), false); + // fix task item name + if (vCalendar.isTodo() && this.itemName.endsWith(".ics")) { + this.itemName = itemName.substring(0, itemName.length() - 3)+".EML"; + } } /** diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 96f327e0..682fbe89 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -1303,7 +1303,7 @@ public class DavExchangeSession extends ExchangeSession { @Override public byte[] getEventContent() throws IOException { byte[] result = null; - LOGGER.debug("Get event subject: " + subject + " href: "+getHref()+" permanentUrl: " + permanentUrl); + LOGGER.debug("Get event subject: " + subject + " href: " + getHref() + " permanentUrl: " + permanentUrl); // try to get PR_INTERNET_CONTENT try { result = getICSFromInternetContentProperty(); @@ -1370,6 +1370,9 @@ public class DavExchangeSession extends ExchangeSession { davPropertyNameSet.add(Field.getPropertyName("busystatus")); davPropertyNameSet.add(Field.getPropertyName("reminderset")); davPropertyNameSet.add(Field.getPropertyName("reminderdelta")); + // task + davPropertyNameSet.add(Field.getPropertyName("importance")); + davPropertyNameSet.add(Field.getPropertyName("uid")); PropFindMethod propFindMethod = new PropFindMethod(permanentUrl, davPropertyNameSet, 0); try { @@ -1386,8 +1389,13 @@ public class DavExchangeSession extends ExchangeSession { vEvent.setPropertyValue("CREATED", convertDateFromExchange(getPropertyIfExists(davPropertySet, "created"))); vEvent.setPropertyValue("LAST-MODIFIED", convertDateFromExchange(getPropertyIfExists(davPropertySet, "calendarlastmodified"))); vEvent.setPropertyValue("DTSTAMP", convertDateFromExchange(getPropertyIfExists(davPropertySet, "dtstamp"))); - vEvent.setPropertyValue("UID", getPropertyIfExists(davPropertySet, "calendaruid")); + String uid = getPropertyIfExists(davPropertySet, "calendaruid"); + if (uid == null) { + uid = getPropertyIfExists(davPropertySet, "uid"); + } + vEvent.setPropertyValue("UID", uid); vEvent.setPropertyValue("SUMMARY", getPropertyIfExists(davPropertySet, "subject")); + vEvent.setPropertyValue("PRIORITY", convertPriorityFromExchange(getPropertyIfExists(davPropertySet, "importance"))); if (instancetype == null) { vEvent.type = "VTODO"; } else { @@ -1536,6 +1544,7 @@ public class DavExchangeSession extends ExchangeSession { } propertyValues.add(Field.createPropertyValue("subject", vCalendar.getFirstVeventPropertyValue("SUMMARY"))); propertyValues.add(Field.createPropertyValue("description", vCalendar.getFirstVeventPropertyValue("DESCRIPTION"))); + propertyValues.add(Field.createPropertyValue("importance", convertPriorityToExchange(vCalendar.getFirstVeventPropertyValue("PRIORITY")))); ExchangePropPatchMethod propPatchMethod = new ExchangePropPatchMethod(encodedHref, propertyValues); propPatchMethod.setRequestHeader("Translate", "f"); @@ -2030,6 +2039,9 @@ public class DavExchangeSession extends ExchangeSession { try { responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(itemPath), 0, EVENT_REQUEST_PROPERTIES_NAME_SET); if (responses.length == 0 && isMainCalendar(folderPath)) { + if (itemName.endsWith(".ics")) { + itemName = itemName.substring(0, itemName.length() - 3) + "EML"; + } // look for item in tasks folder responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, URIUtil.encodePath(getFolderPath(TASKS) + '/' + emlItemName), 0, EVENT_REQUEST_PROPERTIES_NAME_SET); } @@ -2150,7 +2162,7 @@ public class DavExchangeSession extends ExchangeSession { status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath); } if (status == HttpStatus.SC_NOT_FOUND) { - LOGGER.debug("Unable to delete "+itemName+": item not found"); + LOGGER.debug("Unable to delete " + itemName + ": item not found"); } } @@ -2771,6 +2783,39 @@ public class DavExchangeSession extends ExchangeSession { return zuluDateValue; } + protected static final Map importanceToPriorityMap = new HashMap(); + + static { + importanceToPriorityMap.put("high", "1"); + importanceToPriorityMap.put("normal", "5"); + importanceToPriorityMap.put("low", "9"); + } + + protected static final Map priorityToImportanceMap = new HashMap(); + + static { + priorityToImportanceMap.put("1", "high"); + priorityToImportanceMap.put("5", "normal"); + priorityToImportanceMap.put("9", "low"); + } + + protected String convertPriorityFromExchange(String exchangeImportanceValue) throws DavMailException { + String value = null; + if (exchangeImportanceValue != null) { + value = importanceToPriorityMap.get(exchangeImportanceValue); + } + return value; + } + + protected String convertPriorityToExchange(String vTodoPriorityValue) throws DavMailException { + String value = null; + if (vTodoPriorityValue != null) { + value = priorityToImportanceMap.get(vTodoPriorityValue); + } + return value; + } + + /** * Format date to exchange search format. * diff --git a/src/java/davmail/exchange/dav/Field.java b/src/java/davmail/exchange/dav/Field.java index 6f38413e..5db7ac33 100644 --- a/src/java/davmail/exchange/dav/Field.java +++ b/src/java/davmail/exchange/dav/Field.java @@ -322,6 +322,9 @@ public class Field { createField("xmozlastack", DistinguishedPropertySetType.PublicStrings); createField("xmozsnoozetime", DistinguishedPropertySetType.PublicStrings); createField("xmozsendinvitations", DistinguishedPropertySetType.PublicStrings); + + // task + createField(URN_SCHEMAS_MAILHEADER, "importance");//PS_INTERNET_HEADERS/importance } protected static String toHexString(int propertyTag) {