1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-08-13 16:53:51 -04:00

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
This commit is contained in:
mguessan 2010-06-04 12:58:03 +00:00
parent 2fca78c9a0
commit 3e5ee6f24d
2 changed files with 47 additions and 30 deletions

View File

@ -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\"", "<D:collection/>" +
"<CD:addressbook/>");
response.appendProperty("D:resourcetype", "<D:collection/>" +
"<E:addressbook/>");
} else if (folder.isCalendar()) {
response.appendProperty("D:resourcetype", "<D:collection/>" + "<C:calendar/>");
} 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();
}
}
}

View File

@ -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('/');