1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-05 10:47:59 -05:00

Caldav: remove buildCalendarPath method

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1101 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-06-21 13:52:09 +00:00
parent dc6051da1a
commit 88520bb591
4 changed files with 107 additions and 184 deletions

View File

@ -226,7 +226,7 @@ public class CaldavConnection extends AbstractConnection {
// send back principal on search // send back principal on search
} else if (request.isReport() && request.isPathLength(3)) { } else if (request.isReport() && request.isPathLength(3)) {
sendPrincipal(request, "users", session.getEmail()); sendPrincipal(request, "users", session.getEmail());
// iCal current-user-principal request // iCal current-user-principal request
} else if (request.isPropFind() && request.isPathLength(3)) { } else if (request.isPropFind() && request.isPathLength(3)) {
sendPrincipalsFolder(request); sendPrincipalsFolder(request);
} else { } else {
@ -268,50 +268,50 @@ public class CaldavConnection extends AbstractConnection {
} else if (request.isPut()) { } else if (request.isPut()) {
String etag = request.getHeader("if-match"); String etag = request.getHeader("if-match");
String noneMatch = request.getHeader("if-none-match"); String noneMatch = request.getHeader("if-none-match");
ExchangeSession.ItemResult itemResult = session.createOrUpdateItem(request.getExchangeFolderPath(), lastPath, request.getBody(), etag, noneMatch); ExchangeSession.ItemResult itemResult = session.createOrUpdateItem(request.getFolderPath(), lastPath, request.getBody(), etag, noneMatch);
sendHttpResponse(itemResult.status, buildEtagHeader(itemResult.etag), null, "", true); sendHttpResponse(itemResult.status, buildEtagHeader(itemResult.etag), null, "", true);
} else if (request.isDelete()) { } else if (request.isDelete()) {
int status = session.deleteItem(request.getExchangeFolderPath(), lastPath); int status = session.deleteItem(request.getFolderPath(), lastPath);
sendHttpResponse(status); sendHttpResponse(status);
} else if (request.isGet()) { } else if (request.isGet()) {
if (request.path.endsWith("/")) { if (request.path.endsWith("/")) {
// GET request on a folder => build ics content of all folder events // GET request on a folder => build ics content of all folder events
String folderPath = request.getExchangeFolderPath(); String folderPath = request.getFolderPath();
ExchangeSession.Folder folder = session.getFolder(folderPath); ExchangeSession.Folder folder = session.getFolder(folderPath);
if (folder.isContact()) { if (folder.isContact()) {
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(folder.etag), "text/vcard", (byte[])null, true); sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(folder.etag), "text/vcard", (byte[]) null, true);
} else { } else {
List<ExchangeSession.Event> events = session.getAllEvents(folderPath); List<ExchangeSession.Event> events = session.getAllEvents(folderPath);
ChunkedResponse response = new ChunkedResponse(HttpStatus.SC_OK, "text/calendar;charset=UTF-8"); ChunkedResponse response = new ChunkedResponse(HttpStatus.SC_OK, "text/calendar;charset=UTF-8");
response.append("BEGIN:VCALENDAR\r\n"); response.append("BEGIN:VCALENDAR\r\n");
response.append("VERSION:2.0\r\n"); response.append("VERSION:2.0\r\n");
response.append("PRODID:-//davmail.sf.net/NONSGML DavMail Calendar V1.1//EN\r\n"); response.append("PRODID:-//davmail.sf.net/NONSGML DavMail Calendar V1.1//EN\r\n");
response.append("METHOD:PUBLISH\r\n"); response.append("METHOD:PUBLISH\r\n");
for (ExchangeSession.Event event : events) { for (ExchangeSession.Event event : events) {
String icsContent = StringUtil.getToken(event.getBody(), "BEGIN:VTIMEZONE", "END:VCALENDAR"); String icsContent = StringUtil.getToken(event.getBody(), "BEGIN:VTIMEZONE", "END:VCALENDAR");
if (icsContent != null) {
response.append("BEGIN:VTIMEZONE");
response.append(icsContent);
} else {
icsContent = StringUtil.getToken(event.getBody(), "BEGIN:VEVENT", "END:VCALENDAR");
if (icsContent != null) { if (icsContent != null) {
response.append("BEGIN:VEVENT"); response.append("BEGIN:VTIMEZONE");
response.append(icsContent); response.append(icsContent);
} else {
icsContent = StringUtil.getToken(event.getBody(), "BEGIN:VEVENT", "END:VCALENDAR");
if (icsContent != null) {
response.append("BEGIN:VEVENT");
response.append(icsContent);
}
} }
} }
} response.append("END:VCALENDAR");
response.append("END:VCALENDAR"); response.close();
response.close();
} }
} else { } else {
ExchangeSession.Item item = session.getItem(request.getExchangeFolderPath(), lastPath); ExchangeSession.Item item = session.getItem(request.getFolderPath(), lastPath);
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(item.getEtag()), item.getContentType(), item.getBody(), true); sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(item.getEtag()), item.getContentType(), item.getBody(), true);
} }
} else if (request.isHead()) { } else if (request.isHead()) {
// test event // test event
ExchangeSession.Item item = session.getItem(request.getExchangeFolderPath(), lastPath); ExchangeSession.Item item = session.getItem(request.getFolderPath(), lastPath);
sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(item.getEtag()), item.getContentType(), (byte[]) null, true); sendHttpResponse(HttpStatus.SC_OK, buildEtagHeader(item.getEtag()), item.getContentType(), (byte[]) null, true);
} else { } else {
sendUnsupported(request); sendUnsupported(request);
@ -391,11 +391,11 @@ public class CaldavConnection extends AbstractConnection {
* @param response Caldav response * @param response Caldav response
* @param request Caldav request * @param request Caldav request
* @param subFolder calendar folder path relative to request path * @param subFolder calendar folder path relative to request path
* @throws IOException on error
* @return Exchange folder object * @return Exchange folder object
* @throws IOException on error
*/ */
public ExchangeSession.Folder appendFolder(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException { public ExchangeSession.Folder appendFolder(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
ExchangeSession.Folder folder = session.getFolder(request.getExchangeFolderPath(subFolder)); ExchangeSession.Folder folder = session.getFolder(request.getFolderPath(subFolder));
response.startResponse(URIUtil.encodePath(request.getPath(subFolder))); response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
response.startPropstat(); response.startPropstat();
@ -466,16 +466,16 @@ public class CaldavConnection extends AbstractConnection {
public void appendInbox(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException { public void appendInbox(CaldavResponse response, CaldavRequest request, String subFolder) throws IOException {
String ctag = "0"; String ctag = "0";
String etag = "0"; String etag = "0";
String exchangeFolderPath = request.getExchangeFolderPath(subFolder); String folderPath = request.getFolderPath(subFolder);
// do not try to access inbox on shared calendar // do not try to access inbox on shared calendar
if (!session.isSharedFolder(exchangeFolderPath)) { if (!session.isSharedFolder(folderPath)) {
try { try {
ExchangeSession.Folder folder = session.getFolder(exchangeFolderPath); ExchangeSession.Folder folder = session.getFolder(folderPath);
ctag = base64Encode(folder.ctag); ctag = base64Encode(folder.ctag);
etag = base64Encode(folder.etag); etag = base64Encode(folder.etag);
} catch (HttpException e) { } catch (HttpException e) {
// unauthorized access, probably an inbox on shared calendar // unauthorized access, probably an inbox on shared calendar
DavGatewayTray.debug(new BundleMessage("LOG_ACCESS_FORBIDDEN", exchangeFolderPath, e.getMessage())); DavGatewayTray.debug(new BundleMessage("LOG_ACCESS_FORBIDDEN", folderPath, e.getMessage()));
} }
} }
response.startResponse(URIUtil.encodePath(request.getPath(subFolder))); response.startResponse(URIUtil.encodePath(request.getPath(subFolder)));
@ -555,15 +555,15 @@ public class CaldavConnection extends AbstractConnection {
response.startMultistatus(); response.startMultistatus();
appendInbox(response, request, null); appendInbox(response, request, null);
// do not try to access inbox on shared calendar // do not try to access inbox on shared calendar
if (!session.isSharedFolder(request.getExchangeFolderPath(null)) && request.getDepth() == 1 && !Settings.getBooleanProperty("davmail.caldavDisableInbox")) { if (!session.isSharedFolder(request.getFolderPath(null)) && request.getDepth() == 1 && !Settings.getBooleanProperty("davmail.caldavDisableInbox")) {
try { try {
DavGatewayTray.debug(new BundleMessage("LOG_SEARCHING_CALENDAR_MESSAGES")); DavGatewayTray.debug(new BundleMessage("LOG_SEARCHING_CALENDAR_MESSAGES"));
List<ExchangeSession.Event> events = session.getEventMessages(request.getExchangeFolderPath()); List<ExchangeSession.Event> events = session.getEventMessages(request.getFolderPath());
DavGatewayTray.debug(new BundleMessage("LOG_FOUND_CALENDAR_MESSAGES", events.size())); DavGatewayTray.debug(new BundleMessage("LOG_FOUND_CALENDAR_MESSAGES", events.size()));
appendEventsResponses(response, request, events); appendEventsResponses(response, request, events);
} catch (HttpException e) { } catch (HttpException e) {
// unauthorized access, probably an inbox on shared calendar // unauthorized access, probably an inbox on shared calendar
DavGatewayTray.debug(new BundleMessage("LOG_ACCESS_FORBIDDEN", request.getExchangeFolderPath(), e.getMessage())); DavGatewayTray.debug(new BundleMessage("LOG_ACCESS_FORBIDDEN", request.getFolderPath(), e.getMessage()));
} }
} }
response.endMultistatus(); response.endMultistatus();
@ -591,7 +591,7 @@ public class CaldavConnection extends AbstractConnection {
* @throws IOException on error * @throws IOException on error
*/ */
public void sendFolder(CaldavRequest request) throws IOException { public void sendFolder(CaldavRequest request) throws IOException {
String folderPath = request.getExchangeFolderPath(); String folderPath = request.getFolderPath();
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS); CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
response.startMultistatus(); response.startMultistatus();
ExchangeSession.Folder folder = appendFolder(response, request, null); ExchangeSession.Folder folder = appendFolder(response, request, null);
@ -651,7 +651,7 @@ public class CaldavConnection extends AbstractConnection {
* @throws IOException on error * @throws IOException on error
*/ */
public void reportEvents(CaldavRequest request) throws IOException { public void reportEvents(CaldavRequest request) throws IOException {
String folderPath = request.getExchangeFolderPath(); String folderPath = request.getFolderPath();
List<ExchangeSession.Event> events; List<ExchangeSession.Event> events;
List<String> notFound = new ArrayList<String>(); List<String> notFound = new ArrayList<String>();
@ -678,11 +678,11 @@ public class CaldavConnection extends AbstractConnection {
} }
} }
} else if (request.isPath(1, "users") && request.isPath(3, "inbox")) { } else if (request.isPath(1, "users") && request.isPath(3, "inbox")) {
events = session.getEventMessages(request.getExchangeFolderPath()); events = session.getEventMessages(request.getFolderPath());
appendEventsResponses(response, request, events); appendEventsResponses(response, request, events);
} else { } else {
// TODO: handle contacts ? // TODO: handle contacts ?
events = session.getAllEvents(request.getExchangeFolderPath()); events = session.getAllEvents(request.getFolderPath());
appendEventsResponses(response, request, events); appendEventsResponses(response, request, events);
} }
@ -736,7 +736,7 @@ public class CaldavConnection extends AbstractConnection {
response.appendProperty("D:displayname", request.getLastPath()); response.appendProperty("D:displayname", request.getLastPath());
} }
if (request.hasProperty("getctag")) { if (request.hasProperty("getctag")) {
ExchangeSession.Folder rootFolder = session.getFolder(""); ExchangeSession.Folder rootFolder = session.getFolder("");
response.appendProperty("CS:getctag", "CS=\"http://calendarserver.org/ns/\"", response.appendProperty("CS:getctag", "CS=\"http://calendarserver.org/ns/\"",
base64Encode(rootFolder.ctag)); base64Encode(rootFolder.ctag));
} }
@ -1419,56 +1419,40 @@ public class CaldavConnection extends AbstractConnection {
} }
/** /**
* Translate request path to Exchange folder path. * Get request folder path.
* *
* @return exchange folder path * @return exchange folder path
* @throws IOException on error * @throws IOException on error
*/ */
public String getExchangeFolderPath() throws IOException { public String getFolderPath() throws IOException {
return getExchangeFolderPath(null); return getFolderPath(null);
} }
/** /**
* Translate request path with subFolder to Exchange folder path. * Get request folder path with subFolder.
* *
* @param subFolder sub folder name * @param subFolder sub folder path
* @return exchange folder path * @return folder path
* @throws IOException on error * @throws IOException on error
*/ */
public String getExchangeFolderPath(String subFolder) throws IOException { public String getFolderPath(String subFolder) throws IOException {
int endIndex; int endIndex;
if (isFolder()) { if (isFolder()) {
endIndex = getPathLength(); endIndex = getPathLength();
} else { } else {
endIndex = getPathLength() - 1; endIndex = getPathLength() - 1;
} }
if ("users".equals(getPathElement(1))) {
StringBuilder calendarPath = new StringBuilder(); StringBuilder calendarPath = new StringBuilder();
if (getPathLength() > 3) { for (int i = 0; i < endIndex; i++) {
calendarPath.append(getPathElement(3)); if (getPathElement(i).length() > 0) {
}
for (int i = 4; i < endIndex; i++) {
calendarPath.append('/').append(getPathElement(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();
} }
if (subFolder != null && subFolder.length() > 0) {
calendarPath.append('/').append(subFolder);
}
return calendarPath.toString();
} }
} }

View File

@ -2429,28 +2429,13 @@ public abstract class ExchangeSession {
return displayName; return displayName;
} }
/**
* Build Caldav calendar path for principal and folder name.
* - prefix is current user mailbox path if principal is current user,
* else prefix is parent folder of current user mailbox path followed by principal
* - suffix according to well known folder names (internationalized on Exchange)
*
* @param principal calendar principal
* @param folderName requested folder name
* @return Exchange folder path
* @throws IOException on error
*/
public abstract String buildCalendarPath(String principal, String folderName) throws IOException;
/** /**
* Test if folderPath is inside user mailbox. * Test if folderPath is inside user mailbox.
* *
* @param folderPath absolute folder path * @param folderPath absolute folder path
* @return true if folderPath is a public or shared folder * @return true if folderPath is a public or shared folder
*/ */
public boolean isSharedFolder(String folderPath) { public abstract boolean isSharedFolder(String folderPath);
return !folderPath.toLowerCase().startsWith(mailPath.toLowerCase());
}
/** /**
* Build base path for cmd commands (galfind, gallookup). * Build base path for cmd commands (galfind, gallookup).

View File

@ -98,34 +98,34 @@ public class DavExchangeSession extends ExchangeSession {
protected static final String USERS = "/users/"; protected static final String USERS = "/users/";
/** /**
* Convert logical or relative folder path to absolute folder path. * Convert logical or relative folder path to exchange folder path.
* *
* @param folderName folder name * @param folderPath folder name
* @return folder path * @return folder path
*/ */
public String getFolderPath(String folderName) { public String getFolderPath(String folderPath) {
String folderPath; String exchangeFolderPath;
// IMAP path // IMAP path
if (folderName.startsWith(INBOX)) { if (folderPath.startsWith(INBOX)) {
folderPath = mailPath + inboxName + folderName.substring(INBOX.length()); exchangeFolderPath = mailPath + inboxName + folderPath.substring(INBOX.length());
} else if (folderName.startsWith(TRASH)) { } else if (folderPath.startsWith(TRASH)) {
folderPath = mailPath + deleteditemsName + folderName.substring(TRASH.length()); exchangeFolderPath = mailPath + deleteditemsName + folderPath.substring(TRASH.length());
} else if (folderName.startsWith(DRAFTS)) { } else if (folderPath.startsWith(DRAFTS)) {
folderPath = mailPath + draftsName + folderName.substring(DRAFTS.length()); exchangeFolderPath = mailPath + draftsName + folderPath.substring(DRAFTS.length());
} else if (folderName.startsWith(SENT)) { } else if (folderPath.startsWith(SENT)) {
folderPath = mailPath + sentitemsName + folderName.substring(SENT.length()); exchangeFolderPath = mailPath + sentitemsName + folderPath.substring(SENT.length());
} else if (folderName.startsWith("public")) { } else if (folderPath.startsWith("public")) {
folderPath = publicFolderUrl + folderName.substring("public".length()); exchangeFolderPath = publicFolderUrl + folderPath.substring("public".length());
// caldav path // caldav path
} else if (folderName.startsWith(USERS)) { } else if (folderPath.startsWith(USERS)) {
// get requested principal // get requested principal
String principal; String principal;
String localPath; String localPath;
int principalIndex = folderName.indexOf('/', USERS.length()); int principalIndex = folderPath.indexOf('/', USERS.length());
if (principalIndex >= 0) { if (principalIndex >= 0) {
principal = folderName.substring(USERS.length(), principalIndex); principal = folderPath.substring(USERS.length(), principalIndex);
localPath = folderName.substring(USERS.length() + principal.length() + 1); localPath = folderPath.substring(USERS.length() + principal.length() + 1);
if (localPath.startsWith(LOWER_CASE_INBOX)) { if (localPath.startsWith(LOWER_CASE_INBOX)) {
localPath = inboxName + localPath.substring(LOWER_CASE_INBOX.length()); localPath = inboxName + localPath.substring(LOWER_CASE_INBOX.length());
} else if (localPath.startsWith(CALENDAR)) { } else if (localPath.startsWith(CALENDAR)) {
@ -136,82 +136,38 @@ public class DavExchangeSession extends ExchangeSession {
localPath = contactsName + localPath.substring(ADDRESSBOOK.length()); localPath = contactsName + localPath.substring(ADDRESSBOOK.length());
} }
} else { } else {
principal = folderName.substring(USERS.length()); principal = folderPath.substring(USERS.length());
localPath = ""; localPath = "";
} }
if (principal.length() == 0) { if (principal.length() == 0) {
folderPath = rootPath; exchangeFolderPath = rootPath;
} else if (alias.equalsIgnoreCase(principal) || email.equalsIgnoreCase(principal)) { } else if (alias.equalsIgnoreCase(principal) || email.equalsIgnoreCase(principal)) {
folderPath = mailPath + localPath; exchangeFolderPath = mailPath + localPath;
} else { } else {
LOGGER.debug("Detected shared path for principal " + principal + ", user principal is " + email); LOGGER.debug("Detected shared path for principal " + principal + ", user principal is " + email);
folderPath = rootPath + principal + '/' + localPath; exchangeFolderPath = rootPath + principal + '/' + localPath;
} }
// absolute folder path // absolute folder path
} else if (folderName.startsWith("/")) { } else if (folderPath.startsWith("/")) {
folderPath = folderName; exchangeFolderPath = folderPath;
} else { } else {
folderPath = mailPath + folderName; exchangeFolderPath = mailPath + folderPath;
} }
return folderPath; return exchangeFolderPath;
} }
/** /**
* Build Caldav calendar path for principal and folder name. * Test if folderPath is inside user mailbox.
* - prefix is current user mailbox path if principal is current user,
* else prefix is parent folder of current user mailbox path followed by principal
* - suffix according to well known folder names (internationalized on Exchange)
* *
* @param principal calendar principal * @param folderPath absolute folder path
* @param folderName requested folder name * @return true if folderPath is a public or shared folder
* @return Exchange folder path
* @throws IOException on error
* @deprecated user getFolderPath instead
*/ */
@Override @Override
public String buildCalendarPath(String principal, String folderName) throws IOException { public boolean isSharedFolder(String folderPath) {
StringBuilder buffer = new StringBuilder(); return !getFolderPath(folderPath).toLowerCase().startsWith(mailPath.toLowerCase());
// other user calendar => replace principal folder name in mailPath
if (principal != null && !alias.equalsIgnoreCase(principal) && !email.equalsIgnoreCase(principal)) {
LOGGER.debug("Detected shared calendar path for principal " + principal + ", user principal is " + email);
int index = mailPath.lastIndexOf('/', mailPath.length() - 2);
if (index >= 0 && mailPath.endsWith("/")) {
buffer.append(mailPath.substring(0, index + 1)).append(principal).append('/');
} else {
throw new DavMailException("EXCEPTION_INVALID_MAIL_PATH", mailPath);
}
} else if (principal != null) {
buffer.append(mailPath);
}
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('/');
if (index >= 0) {
buffer.append(folderName.substring(index));
}
// replace 'inbox' folder name with i18n name
} else if ("inbox".equals(folderName)) {
buffer.append(inboxUrl.substring(inboxUrl.lastIndexOf('/') + 1));
// append folder name without replace (public folder)
} else if (folderName != null && folderName.length() > 0) {
buffer.append(folderName);
}
return buffer.toString();
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
@ -1037,21 +993,21 @@ public class DavExchangeSession extends ExchangeSession {
* @inheritDoc * @inheritDoc
*/ */
@Override @Override
public List<Folder> getSubFolders(String folderName, Condition condition, boolean recursive) throws IOException { public List<Folder> getSubFolders(String folderPath, Condition condition, boolean recursive) throws IOException {
boolean isPublic = folderName.startsWith("/public"); boolean isPublic = folderPath.startsWith("/public");
String mode = (!isPublic && recursive) ? "DEEP" : "SHALLOW"; String mode = (!isPublic && recursive) ? "DEEP" : "SHALLOW";
List<Folder> folders = new ArrayList<Folder>(); List<Folder> folders = new ArrayList<Folder>();
StringBuilder searchRequest = new StringBuilder(); StringBuilder searchRequest = new StringBuilder();
searchRequest.append("Select \"DAV:nosubs\", \"DAV:hassubs\", \"http://schemas.microsoft.com/exchange/outlookfolderclass\", " + searchRequest.append("Select \"DAV:nosubs\", \"DAV:hassubs\", \"http://schemas.microsoft.com/exchange/outlookfolderclass\", " +
"\"http://schemas.microsoft.com/repl/contenttag\", \"http://schemas.microsoft.com/mapi/proptag/x30080040\", " + "\"http://schemas.microsoft.com/repl/contenttag\", \"http://schemas.microsoft.com/mapi/proptag/x30080040\", " +
"\"urn:schemas:httpmail:unreadcount\" FROM Scope('").append(mode).append(" TRAVERSAL OF \"").append(getFolderPath(folderName)).append("\"')\n" + "\"urn:schemas:httpmail:unreadcount\" FROM Scope('").append(mode).append(" TRAVERSAL OF \"").append(getFolderPath(folderPath)).append("\"')\n" +
" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = True \n"); " WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = True \n");
if (condition != null) { if (condition != null) {
searchRequest.append(" AND "); searchRequest.append(" AND ");
condition.appendTo(searchRequest); condition.appendTo(searchRequest);
} }
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executeSearchMethod( MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executeSearchMethod(
httpClient, URIUtil.encodePath(getFolderPath(folderName)), searchRequest.toString()); httpClient, URIUtil.encodePath(getFolderPath(folderPath)), searchRequest.toString());
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
Folder folder = buildFolder(response); Folder folder = buildFolder(response);
@ -1067,12 +1023,11 @@ public class DavExchangeSession extends ExchangeSession {
* @inheritDoc * @inheritDoc
*/ */
@Override @Override
public void createFolder(String folderName, String folderClass) throws IOException { public void createFolder(String folderPath, String folderClass) throws IOException {
String folderPath = getFolderPath(folderName);
ArrayList<DavConstants> list = new ArrayList<DavConstants>(); ArrayList<DavConstants> list = new ArrayList<DavConstants>();
list.add(Field.createDavProperty("folderclass", folderClass)); list.add(Field.createDavProperty("folderclass", folderClass));
// standard MkColMethod does not take properties, override PropPatchMethod instead // standard MkColMethod does not take properties, override PropPatchMethod instead
PropPatchMethod method = new PropPatchMethod(URIUtil.encodePath(folderPath), list) { PropPatchMethod method = new PropPatchMethod(URIUtil.encodePath(getFolderPath(folderPath)), list) {
@Override @Override
public String getName() { public String getName() {
return "MKCOL"; return "MKCOL";
@ -1089,18 +1044,17 @@ public class DavExchangeSession extends ExchangeSession {
* @inheritDoc * @inheritDoc
*/ */
@Override @Override
public void deleteFolder(String folderName) throws IOException { public void deleteFolder(String folderPath) throws IOException {
DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, URIUtil.encodePath(getFolderPath(folderName))); DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, URIUtil.encodePath(getFolderPath(folderPath)));
} }
/** /**
* @inheritDoc * @inheritDoc
*/ */
@Override @Override
public void moveFolder(String folderName, String targetName) throws IOException { public void moveFolder(String folderPath, String targetPath) throws IOException {
String folderPath = getFolderPath(folderName); MoveMethod method = new MoveMethod(URIUtil.encodePath(getFolderPath(folderPath)),
String targetPath = getFolderPath(targetName); URIUtil.encodePath(getFolderPath(targetPath)), false);
MoveMethod method = new MoveMethod(URIUtil.encodePath(folderPath), URIUtil.encodePath(targetPath), false);
try { try {
int statusCode = httpClient.executeMethod(method); int statusCode = httpClient.executeMethod(method);
if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) { if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
@ -1176,9 +1130,9 @@ public class DavExchangeSession extends ExchangeSession {
} }
@Override @Override
public MessageList searchMessages(String folderName, List<String> attributes, Condition condition) throws IOException { public MessageList searchMessages(String folderPath, List<String> attributes, Condition condition) throws IOException {
MessageList messages = new MessageList(); MessageList messages = new MessageList();
MultiStatusResponse[] responses = searchItems(folderName, attributes, condition); MultiStatusResponse[] responses = searchItems(folderPath, attributes, condition);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
Message message = buildMessage(response); Message message = buildMessage(response);
@ -1193,9 +1147,9 @@ public class DavExchangeSession extends ExchangeSession {
* @inheritDoc * @inheritDoc
*/ */
@Override @Override
protected List<ExchangeSession.Contact> searchContacts(String folderName, List<String> attributes, Condition condition) throws IOException { protected List<ExchangeSession.Contact> searchContacts(String folderPath, List<String> attributes, Condition condition) throws IOException {
List<ExchangeSession.Contact> contacts = new ArrayList<ExchangeSession.Contact>(); List<ExchangeSession.Contact> contacts = new ArrayList<ExchangeSession.Contact>();
MultiStatusResponse[] responses = searchItems(folderName, attributes, condition); MultiStatusResponse[] responses = searchItems(folderPath, attributes, condition);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
contacts.add(new Contact(response)); contacts.add(new Contact(response));
} }
@ -1203,9 +1157,9 @@ public class DavExchangeSession extends ExchangeSession {
} }
@Override @Override
protected List<ExchangeSession.Event> searchEvents(String folderName, List<String> attributes, Condition condition) throws IOException { protected List<ExchangeSession.Event> searchEvents(String folderPath, List<String> attributes, Condition condition) throws IOException {
List<ExchangeSession.Event> events = new ArrayList<ExchangeSession.Event>(); List<ExchangeSession.Event> events = new ArrayList<ExchangeSession.Event>();
MultiStatusResponse[] responses = searchItems(folderName, attributes, condition); MultiStatusResponse[] responses = searchItems(folderPath, attributes, condition);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
String instancetype = getPropertyIfExists(response.getProperties(HttpStatus.SC_OK), "instancetype"); String instancetype = getPropertyIfExists(response.getProperties(HttpStatus.SC_OK), "instancetype");
Event event = new Event(response); Event event = new Event(response);
@ -1227,8 +1181,8 @@ public class DavExchangeSession extends ExchangeSession {
return events; return events;
} }
protected MultiStatusResponse[] searchItems(String folderName, List<String> attributes, Condition condition) throws IOException { protected MultiStatusResponse[] searchItems(String folderPath, List<String> attributes, Condition condition) throws IOException {
String folderUrl = getFolderPath(folderName); String folderUrl = getFolderPath(folderPath);
StringBuilder searchRequest = new StringBuilder(); StringBuilder searchRequest = new StringBuilder();
searchRequest.append("SELECT ") searchRequest.append("SELECT ")
.append(Field.getRequestPropertyString("permanenturl")); .append(Field.getRequestPropertyString("permanenturl"));
@ -1263,7 +1217,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public Item getItem(String folderPath, String itemName) throws IOException { public Item getItem(String folderPath, String itemName) throws IOException {
String itemPath = folderPath + '/' + convertItemNameToEML(itemName); String itemPath = getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName);
Item item; Item item;
try { try {
item = getItem(itemPath); item = getItem(itemPath);

View File

@ -459,8 +459,8 @@ public class EwsExchangeSession extends ExchangeSession {
} }
@Override @Override
public String buildCalendarPath(String principal, String folderName) throws IOException { public boolean isSharedFolder(String folderPath) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override