From 3e5ee6f24d32f6e42bf7e5760fb84cf80a328fcc Mon Sep 17 00:00:00 2001 From: mguessan Date: Fri, 4 Jun 2010 12:58:03 +0000 Subject: [PATCH] CardDav: improve automatic address book setup for OSX git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1073 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/caldav/CaldavConnection.java | 62 +++++++++++-------- .../davmail/exchange/ExchangeSession.java | 15 ++++- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 0690fe09..d870ce11 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -399,8 +399,8 @@ public class CaldavConnection extends AbstractConnection { if (request.hasProperty("resourcetype")) { if (folder.isContact()) { - response.appendProperty("D:resourcetype", "CD=\"urn:ietf:params:xml:ns:carddav\"", "" + - ""); + response.appendProperty("D:resourcetype", "" + + ""); } else if (folder.isCalendar()) { response.appendProperty("D:resourcetype", "" + ""); } else { @@ -719,6 +719,7 @@ public class CaldavConnection extends AbstractConnection { appendInbox(response, request, "inbox"); appendOutbox(response, request, "outbox"); appendFolder(response, request, "calendar"); + appendFolder(response, request, "contacts"); } response.endResponse(); response.endMultistatus(); @@ -1398,28 +1399,7 @@ public class CaldavConnection extends AbstractConnection { * @throws IOException on error */ public String getExchangeFolderPath() throws IOException { - int endIndex; - if (isFolder()) { - endIndex = getPathLength(); - } else { - endIndex = getPathLength() - 1; - } - if ("users".equals(getPathElement(1))) { - StringBuilder calendarPath = new StringBuilder(); - calendarPath.append(getPathElement(3)); - for (int i = 4; i < endIndex; i++) { - calendarPath.append('/').append(getPathElement(i)); - } - return session.buildCalendarPath(getPathElement(2), calendarPath.toString()); - } else { - StringBuilder calendarPath = new StringBuilder(); - for (int i = 0; i < endIndex; i++) { - if (getPathElement(i).length() > 0) { - calendarPath.append('/').append(getPathElement(i)); - } - } - return calendarPath.toString(); - } + return getExchangeFolderPath(null); } /** @@ -1430,10 +1410,38 @@ public class CaldavConnection extends AbstractConnection { * @throws IOException on error */ public String getExchangeFolderPath(String subFolder) throws IOException { - if (subFolder == null || subFolder.length() == 0) { - return getExchangeFolderPath(); + int endIndex; + if (isFolder()) { + endIndex = getPathLength(); } else { - return getExchangeFolderPath() + '/' + subFolder; + endIndex = getPathLength() - 1; + } + if ("users".equals(getPathElement(1))) { + StringBuilder calendarPath = new StringBuilder(); + if (getPathLength() > 3) { + calendarPath.append(getPathElement(3)); + } + for (int i = 4; i < endIndex; i++) { + calendarPath.append('/').append(getPathElement(i)); + } + if (subFolder != null && subFolder.length() > 0) { + if (calendarPath.length() > 0) { + calendarPath.append('/'); + } + calendarPath.append(subFolder); + } + return session.buildCalendarPath(getPathElement(2), calendarPath.toString()); + } else { + StringBuilder calendarPath = new StringBuilder(); + for (int i = 0; i < endIndex; i++) { + if (getPathElement(i).length() > 0) { + calendarPath.append('/').append(getPathElement(i)); + } + } + if (subFolder != null && subFolder.length() > 0) { + calendarPath.append('/').append(subFolder); + } + return calendarPath.toString(); } } } diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 4bc69a3f..31c5f076 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1040,6 +1040,8 @@ public abstract class ExchangeSession { folderPath = folderName.replaceFirst("Sent", sentitemsUrl); } else if (folderName.startsWith("calendar")) { folderPath = folderName.replaceFirst("calendar", calendarUrl); + } else if (folderName.startsWith("contacts")) { + folderPath = folderName.replaceFirst("contacts", contactsUrl); } else if (folderName.startsWith("public")) { folderPath = publicFolderUrl + folderName.substring("public".length()); // absolute folder path @@ -3260,9 +3262,16 @@ public abstract class ExchangeSession { buffer.append(mailPath); } - if (folderName != null && folderName.startsWith("calendar")) { - // replace 'calendar' folder name with i18n name - buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf('/') + 1)); + if (folderName != null && (folderName.startsWith("calendar") || folderName.startsWith("contacts") + // OSX address book name + || folderName.startsWith("addressbook"))) { + if (folderName.startsWith("calendar")) { + // replace 'calendar' folder name with i18n name + buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf('/') + 1)); + } else { + // replace 'contacts' folder name with i18n name + buffer.append(contactsUrl.substring(contactsUrl.lastIndexOf('/') + 1)); + } // sub calendar folder => append sub folder name int index = folderName.indexOf('/');